/* Kana Trainer — kikyō bellflower */
:root { --page-color: #5b5bd6; --page-color-soft: rgba(91, 91, 214, 0.10); }

/* Trainer-only semantic colors (correct/incorrect) */
.kt, .kt-toasts {
  --kt-ok: #3fa372;
  --kt-ok-soft: rgba(63, 163, 114, 0.12);
  --kt-no: #d95f4c;
  --kt-no-soft: rgba(217, 95, 76, 0.10);
}

/* --- Title wobble (the motion accent, same as About) ------------------- */
.wobble { display: inline-block; position: relative; }
.wobble::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0.05em;
  height: 0.12em;
  background: var(--page-color);
  opacity: 0.35;
  border-radius: 2px;
  animation: wobble-line 4s ease-in-out infinite;
  transform-origin: center;
}
@keyframes wobble-line {
  0%, 100% { transform: skewX(0deg) scaleX(1); }
  25%      { transform: skewX(-3deg) scaleX(1.02); }
  50%      { transform: skewX(0deg) scaleX(0.99); }
  75%      { transform: skewX(3deg) scaleX(1.02); }
}

.kt-section { margin-top: 72px; }

/* FIX: the hidden attribute must always beat component display values —
   without this the summary overlay renders permanently and blocks the page */
.kt [hidden] { display: none !important; }

/* base.css pill buttons run tight with the trainer's longer labels
   ("Export progress", "End session") — give them room + 44px touch targets */
.kt .btn,
.kt .btn-link {
  height: auto;
  min-height: 44px;
  padding: 10px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  line-height: 1.2;
  box-sizing: border-box;
}

/* .btn-link is used on <button>s here: drop the browser's default grey
   button box so they read as links, and keep the underline under the text */
.kt button.btn-link {
  background: none;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  padding-left: 0;
  padding-right: 0;   /* text-aligned with the content edge; still 44px tall */
}
.kt .btn-link::after { bottom: 10px; }

/* The trainer's views are alternate screens, not stacked sections:
   base.css's section + section spacing pushed the review screen down and
   cut off its bottom */
.container.kt > section + section { margin-top: 0; }

/* ====================== continue card ====================== */
.kt-continue {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 28px 32px;
  margin-top: 32px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.kt-continue:hover { border-color: var(--page-color); }
.kt-continue-line {
  font-family: var(--font-mincho);
  font-size: 1.35rem; font-weight: 500;
  color: var(--ink); margin: 0 0 4px;
}
.kt-continue-sub { color: var(--muted); font-size: 0.95rem; margin: 0; }
.kt-continue-actions { display: flex; align-items: center; gap: 18px; flex-shrink: 0; }

/* ====================== mode chips ====================== */
.kt-modes { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.kt-chip {
  font: 500 13px var(--font-gothic);
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.25s ease,
              border-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
}
.kt-chip:hover { border-color: var(--page-color); }
.kt-chip.is-active {
  color: var(--page-color);
  border-color: var(--page-color);
  background: var(--page-color-soft);
}

/* ====================== progression track ====================== */
.kt-stages {
  list-style: none; padding: 0; margin: 32px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.kt-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 20px;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.kt-stage.open:hover { border-color: var(--page-color); }
.kt-stage.frontier { border-color: var(--page-color); box-shadow: 0 0 0 3px var(--page-color-soft); }
.kt-stage.locked { opacity: .55; }
.kt-stage-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.kt-stage-num {
  font-family: var(--font-mincho);
  font-size: 1.1em;
  color: var(--page-color);
  flex-shrink: 0;
}
.kt-stage-name { font-weight: 500; font-size: 1rem; color: var(--ink); }
.kt-stage-kana { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.kt-bar {
  height: 6px; border-radius: 0;
  background: var(--page-color-soft); overflow: hidden;
}
.kt-bar-fill {
  height: 100%; width: var(--w, 0%);
  background: var(--page-color);
  border-radius: 0;
  transition: width .9s cubic-bezier(.22,1,.36,1);
}
.kt-stage-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; font-size: 0.82rem; color: var(--muted);
}
.kt-stage-go {
  background: none; border: none; cursor: pointer;
  font: 500 0.82rem var(--font-gothic); color: var(--page-color);
  padding: 2px 0;
}
.kt-stage-go:hover { text-decoration: underline; }

/* ====================== mastery grid ====================== */
.kt-grid-hint { color: var(--muted); font-size: 0.88rem; margin: 8px 0 0; }

.kt-grid-legend {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--muted); margin: 20px 0 8px;
}
.kt-cell-demo { width: 14px; height: 14px; border-radius: 2px; display: inline-block; margin-left: 14px; border: 1px solid var(--border); }
.kt-cell-demo:first-child { margin-left: 0; }
.kt-grid-group { margin-top: 24px; }
.kt-grid-label {
  font-size: 0.85rem; font-weight: 500;
  color: var(--muted); margin: 0 0 10px;
}
.kt-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.kt-cell {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-family: 'Noto Sans JP', sans-serif; font-size: 1.05rem;
  border-radius: 2px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: transparent;
  transition: transform 0.25s ease, box-shadow .15s, background .4s;
}
.kt-cell:hover { z-index: 1; }
.kt-cell.m0, .kt-cell-demo.m0 { background: transparent; color: var(--muted); }
.kt-cell.m1, .kt-cell-demo.m1 { background: color-mix(in srgb, var(--page-color) 12%, transparent); color: var(--ink); }
.kt-cell.m2, .kt-cell-demo.m2 { background: color-mix(in srgb, var(--page-color) 30%, transparent); color: var(--ink); }
.kt-cell.m3, .kt-cell-demo.m3 { background: color-mix(in srgb, var(--page-color) 58%, transparent); color: #fff; }
.kt-cell.m4, .kt-cell-demo.m4 { background: var(--page-color); color: #fff; border-color: var(--page-color); }

/* ====================== trouble spots ====================== */
.kt-empty {
  color: var(--muted); font-size: 0.95rem; line-height: 1.65;
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 2px; padding: 24px; margin-top: 24px;
}
.kt-pairs { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.kt-pair {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 2px; padding: 14px 18px;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.kt-pair:hover { border-color: var(--kt-no); }
.kt-pair-kana { font-size: 1.3rem; font-family: 'Noto Sans JP', sans-serif; color: var(--ink); }
.kt-pair-arrow { color: var(--kt-no); font-size: 1rem; margin: 0 4px; }
.kt-pair-meta { font-size: 0.85rem; color: var(--muted); }
.kt-pairs-btn { margin-top: 18px; }

/* ====================== stats ====================== */
.kt-stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px; margin-top: 28px;
}
.kt-stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 2px; padding: 16px; text-align: center;
}
.kt-stat-v {
  display: block;
  font-family: var(--font-mincho); font-size: 1.5rem; font-weight: 500;
  color: var(--ink);
}
.kt-stat-l { font-size: 0.75rem; color: var(--muted); letter-spacing: .04em; }

/* study settings — quiet strip under the mode chips */
.kt-study-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  margin-top: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}
.kt-study-settings .kt-toggle { font-size: 0.88rem; }

.kt-num {
  width: 64px;
  font: 500 0.9rem var(--font-gothic);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 6px 8px;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.kt-num:focus { outline: none; border-color: var(--page-color); box-shadow: 0 0 0 3px var(--page-color-soft); }
.kt-modes-sep {
  font: 500 0.82rem var(--font-gothic); letter-spacing: .02em;
  color: var(--muted); align-self: center; margin: 0 2px 0 8px;
}
@keyframes kt-modes-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30% { box-shadow: 0 0 0 4px var(--page-color-soft); }
}
.kt-modes.kt-pulse { border-radius: 2px; animation: kt-modes-pulse 1.6s ease; }


.kt-settings {
  margin-top: 28px; display: flex; flex-wrap: wrap; gap: 18px;
  justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border); padding-top: 20px;
}
.kt-toggle { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--ink-soft); cursor: pointer; }
.kt-toggle small { color: var(--muted); }
/* Checkboxes only: this used to hit the number input too and shrink it to a 16px circle */
.kt-toggle input[type="checkbox"] { accent-color: var(--page-color); width: 16px; height: 16px; }
.kt-prefs { display: flex; flex-direction: column; gap: 12px; }
.kt-select {
  font: 500 0.9rem var(--font-gothic);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 6px 10px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.kt-select:focus {
  outline: none;
  border-color: var(--page-color);
  box-shadow: 0 0 0 3px var(--page-color-soft);
}
.kt-data-actions { display: flex; gap: 18px; align-items: center; }
.kt-danger { color: var(--kt-no) !important; }

/* ====================== review view ====================== */
/* Focus mode: the BODY becomes the locked, viewport-sized box and the
   review view simply fills it in-flow. No position:fixed on the view —
   a transformed/filtered ancestor (e.g. reveal animations on the page
   shell) silently breaks fixed positioning, which is why the overlay
   approach scrolled with the page. */
body.kt-focus {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body.kt-focus .masthead, body.kt-focus .menu-sheet, body.kt-focus .colophon, body.kt-focus .skip-link, body.kt-focus .navbar,
body.kt-focus .nav-mobile,
body.kt-focus .site-footer { display: none; }
body.kt-focus main,
body.kt-focus .container.kt {
  margin: 0;
  padding: 0;
  max-width: none;
  width: 100%;
  height: 100%;
}

#view-review:not([hidden]) {
  width: 100%;
  height: var(--vvh, 100%);
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 20px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  gap: 4px;
}

.kt-hud {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; gap: 16px; flex-wrap: wrap;
  width: 100%; max-width: 720px; margin: 0 auto;
  flex-shrink: 0;
}
.kt-hud-stats { display: flex; gap: 18px; align-items: center; font-size: 0.88rem; color: var(--muted); }
.kt-hud-mode { color: var(--page-color); font-weight: 500; }
.kt-combo {
  font: 600 0.95rem var(--font-gothic);
  color: var(--muted);
  min-width: 3ch; text-align: right;
  transition: color .3s;
}
.kt-combo.pop { animation: kt-pop .3s ease; }
.kt-combo.hot { color: var(--page-color); }
.kt-combo.blazing {
  color: var(--page-color);
  text-shadow: 0 0 14px color-mix(in srgb, var(--page-color) 60%, transparent);
}
@keyframes kt-pop { 50% { transform: scale(1.35); } }

.kt-session-bar {
  flex-shrink: 0;
  width: 100%; max-width: 720px;
  height: 4px; border-radius: 0;
  background: var(--page-color-soft);
  overflow: hidden;
  margin: 2px auto 10px;   /* centered under the HUD */
}
.kt-session-bar > div {
  height: 100%; width: 0%;
  background: var(--page-color);
  border-radius: 0;
  transition: width .35s cubic-bezier(.22,1,.36,1);
}

.kt-stage-progress {
  flex-shrink: 0;
  text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 6px;
}

.kt-card-zone {
  width: 100%; max-width: 560px; margin: 0 auto;
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  text-align: center;
  /* Sized from the *visible* height (--vvh shrinks when the keyboard opens);
     plain vh stays at full-screen size and overfilled the zone */
  padding: clamp(6px, calc(var(--vvh, 100vh) * 0.03), 32px) 8px;
  gap: clamp(6px, calc(var(--vvh, 100vh) * 0.025), 22px);
  overflow: hidden;
}
/* Flexible spacers center the card when there's room; when there isn't they
   collapse to 0, so content can only run off the bottom — never up over the HUD
   (justify-content: center overflowed in both directions) */
.kt-card-zone::before,
.kt-card-zone::after { content: ''; flex: 1 1 0; min-height: 0; }
.kt-speedbar {
  width: 100%; height: 3px; border-radius: 0;
  background: var(--page-color-soft); overflow: hidden; margin-bottom: 24px;
}
.kt-speedbar > div { height: 100%; width: 100%; background: var(--page-color); transform-origin: left; }
.kt-speedbar > div.run { animation: kt-drain 5s linear forwards; }
@keyframes kt-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.kt-kana {
  font-size: min(clamp(72px, 20vw, 150px), calc(var(--vvh, 100vh) * 0.22));
  line-height: 1.1;
  color: var(--ink);
  font-family: 'Noto Sans JP', sans-serif;
  user-select: none;
  transition: color .25s;
  flex-shrink: 0;
}
.kt-kana.enter { animation: kt-enter .18s ease-out; }
@keyframes kt-enter {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.kt-kana.hit { color: var(--kt-ok); animation: kt-hit .35s ease; }
@keyframes kt-hit { 35% { transform: scale(1.07); } }
.kt-kana.miss { color: var(--kt-no); animation: kt-shake .26s ease; }
@keyframes kt-shake {
  20% { transform: translateX(-5px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}

.kt-feedback {
  min-height: 2.2em; margin: 0;
  font-size: 1rem; color: var(--muted);
  opacity: 0; transform: translateY(-4px);
  transition: opacity .18s, transform .18s;
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; align-items: baseline;
  flex-shrink: 0;
}
.kt-feedback.show { opacity: 1; transform: none; }
.kt-feedback .ok { color: var(--kt-ok); font-weight: 500; }
.kt-feedback .no { color: var(--kt-no); font-weight: 500; }
.kt-feedback .truth strong { color: var(--ink); }
.kt-feedback .confused {
  font-size: 0.85rem;
  background: var(--kt-no-soft); color: var(--kt-no);
  border-radius: 0; padding: 3px 12px;
}

.kt-answer { width: 100%; max-width: 320px; }
#answer-input {
  width: 100%;
  font: 400 1.4rem var(--font-gothic);
  text-align: center;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 14px 18px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#answer-input:focus {
  border-color: var(--page-color);
  box-shadow: 0 0 0 3px var(--page-color-soft);
}
#answer-input::placeholder { color: var(--muted); opacity: .6; }
.kt-hint { margin-top: 4px; font-size: 0.78rem; color: var(--muted); opacity: .7; }

/* Compact review: set by app.js when the visible height is short (phone
   keyboard open, landscape). One-row HUD, smaller kana, no keyboard-shortcut
   hint (phone keyboards have no Esc) */
body.kt-compact .kt-hud { flex-wrap: nowrap; padding: 4px 0; gap: 10px; }
body.kt-compact .kt .kt-hud-back { min-height: 36px; font-size: 13px; }
body.kt-compact .kt-hud-stats { gap: 10px; font-size: 0.8rem; }
body.kt-compact .kt-hud-mode { display: none; }
body.kt-compact .kt-session-bar { margin: 0 auto 4px; }
body.kt-compact .kt-stage-progress { margin-top: 0; font-size: 0.8rem; }
body.kt-compact .kt-kana { font-size: min(clamp(56px, 20vw, 150px), calc(var(--vvh, 100vh) * 0.2)); }
body.kt-compact .kt-feedback { min-height: 1.6em; }
body.kt-compact #answer-input { padding: 10px 16px; font-size: 1.2rem; }   /* stays >16px so iOS doesn't zoom */
body.kt-compact .kt-hint { display: none; }

/* ====================== summary overlay ====================== */
.kt-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 24px;
}
.kt-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
  padding: 36px 40px;
  max-width: 460px; width: 100%;
  max-height: calc(var(--vvh, 100dvh) - 48px);
  overflow-y: auto;
  text-align: center;
  animation: kt-rise .3s cubic-bezier(.22,1,.36,1);
}
@keyframes kt-rise { from { opacity: 0; transform: translateY(16px); } }
.kt-summary-title { font-family: var(--font-mincho); font-size: 2rem; color: var(--ink); margin: 6px 0 20px; }
.kt-summary-stats { display: flex; justify-content: center; gap: 12px; margin-bottom: 18px; }
.kt-summary-stats .kt-stat { min-width: 110px; }
.kt-summary-hook { font-size: 0.95rem; color: var(--muted); margin-bottom: 24px; }
.kt-summary-hook [lang="ja"] { font-size: 1.15rem; color: var(--ink); }
.kt-summary-actions { display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* ====================== placement ====================== */
.kt-placement {
  max-width: 560px; margin: 48px auto 0;
  background: var(--page-color-soft);
  border: 1px solid color-mix(in srgb, var(--page-color) 25%, var(--border));
  border-radius: 2px; padding: clamp(28px, 5vh, 48px);
}
.kt-placement-copy { color: var(--ink-soft); line-height: 1.65; margin: 16px 0; }
.kt-placement-note { font-size: 0.85rem; color: var(--muted); }
.kt-placement-list { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 8px; }
.kt-placement-list li {
  display: flex; justify-content: space-between;
  font-size: 0.92rem; padding: 10px 14px; color: var(--ink-soft);
  border-radius: 2px; border: 1px solid var(--border);
  background: var(--surface);
}
.kt-placement-list li.pass { border-color: color-mix(in srgb, var(--kt-ok) 40%, transparent); }
.kt-placement-list li.pass span:last-child { color: var(--kt-ok); }
.kt-placement-list li.fail { border-color: color-mix(in srgb, var(--kt-no) 35%, transparent); }
.kt-placement-list li.fail span:last-child { color: var(--kt-no); }

/* ====================== toasts ====================== */
.kt-toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 80;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.kt-toast {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-left: 3px solid var(--page-color);
  border-radius: 2px;
  padding: 12px 18px;
  font: 400 0.9rem var(--font-gothic);
  box-shadow: 0 10px 30px rgba(0,0,0,.14);
  opacity: 0; transform: translateY(10px);
  transition: opacity .3s, transform .3s cubic-bezier(.22,1,.36,1);
  max-width: 320px;
}
.kt-toast.in { opacity: 1; transform: none; }
.kt-toast-kana { font-size: 1.2rem; margin-right: 4px; }
.kt-toast-mastered { border-left-color: #c9a227; }
.kt-toast-unlock { border-left-color: var(--kt-ok); }
.kt-toast-error { border-left-color: var(--kt-no); }

/* ====================== motion & responsive ====================== */
@media (prefers-reduced-motion: reduce) {
  .kt *, .kt *::after, .kt-toast, .kt-kana, .kt-summary, .wobble::after {
    animation: none !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 640px) {
  .kt-continue { flex-direction: column; align-items: flex-start; padding: 22px; }
  .kt-continue-actions { flex-wrap: wrap; gap: 8px 18px; }
  .kt-cell { width: 38px; height: 38px; font-size: 0.95rem; }
  .kt-summary { padding: 28px 22px; }
  .kt-settings { flex-direction: column; align-items: flex-start; }
  .kt-study-settings { flex-direction: column; align-items: flex-start; gap: 12px; }
  .kt-data-actions { flex-wrap: wrap; }
  .kt-toasts { left: 16px; right: 16px; align-items: stretch; }
  .kt-toast { max-width: none; }
}
/* Backup status under the Data buttons */
.kt-backup { flex-basis: 100%; margin: 0; font-size: 0.85rem; color: var(--muted); }
.kt-backup.is-nudge { color: var(--ink); }
.kt-backup.is-nudge::before { content: "● "; color: var(--page-color); }
