:root {
  --paper: #F4F6F8;
  --ink: #18202E;
  --muted: #5B6578;
  --line: #D5DAE2;
  --ai: #2A4A80;        /* indigo: actions */
  --on-ai: #FFFFFF;
  --shu: #D2553F;       /* vermilion: practice-square guides, highlighted word */
  --guide: rgba(210, 85, 63, 0.45);
  --mark: rgba(210, 85, 63, 0.13);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121620;
    --ink: #E7EAF0;
    --muted: #9AA3B5;
    --line: #2C3446;
    --ai: #8DA8E6;
    --on-ai: #0F1524;
    --shu: #F0806B;
    --guide: rgba(240, 128, 107, 0.5);
    --mark: rgba(240, 128, 107, 0.18);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible { outline: 3px solid var(--ai); outline-offset: 3px; }

[hidden] { display: none !important; }

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.25rem, env(safe-area-inset-bottom));
}

/* ---------- buttons ---------- */

.big {
  width: 100%;
  min-height: 4.25rem;
  border-radius: 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  border: 2px solid var(--line);
}

.big.primary {
  background: var(--ai);
  border-color: var(--ai);
  color: var(--on-ai);
}

.big:active { transform: scale(0.98); }

/* ---------- home ---------- */

#home h1 {
  margin: 0.5rem 0 0;
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: 0.12em;
}

.learned { margin-top: 2.5rem; }

.track {
  height: 0.6rem;
  border-radius: 1rem;
  background: var(--line);
  overflow: hidden;
}

#learned-bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ai);
  border-radius: inherit;
}

#learned-text {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: 1.2rem;
  text-align: center;
}

footer { margin-top: 1rem; text-align: center; }

.links { display: flex; justify-content: center; gap: 0.5rem; }

.links button {
  min-height: 2.75rem;
  padding: 0 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.note { color: var(--muted); font-size: 0.95rem; line-height: 1.5; }

/* ---------- study ---------- */

#study header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon {
  width: 3rem;
  height: 3rem;
  margin-left: -0.75rem;
  display: grid;
  place-items: center;
}

.icon svg {
  width: 1.5rem;
  height: 1.5rem;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

#counter { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Front stays put when the answer appears below it. */
#card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: clamp(1rem, 9vh, 5rem) 0 1.5rem;
  text-align: center;
}

/* Practice-paper square: the kana sits on a dashed centre cross. */
.square {
  width: min(64vw, 15rem);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: min(46vw, 10.75rem);
  line-height: 1;
  font-weight: 400;
  border: 1.5px solid var(--shu);
  background-image:
    repeating-linear-gradient(90deg, var(--guide) 0 6px, transparent 6px 12px),
    repeating-linear-gradient(180deg, var(--guide) 0 6px, transparent 6px 12px);
  background-size: 100% 1px, 1px 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.square.pair { font-size: min(27vw, 6.4rem); } /* きゃ etc.: two characters */

.sentence {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.8;
  word-spacing: 0.3em;
  word-break: keep-all;   /* wrap only at the spaces between words */
  line-break: strict;
}

mark {
  color: inherit;
  background: var(--mark);
  border-bottom: 2px solid var(--shu);
  padding: 0 0.1em;
}

.rule-front { margin: 0; font-size: 2.25rem; line-height: 1.5; word-break: keep-all; }
.prompt { margin: 0; color: var(--muted); }

.listen {
  width: 7rem;
  height: 7rem;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
}

.listen svg { width: 3rem; height: 3rem; }

/* ---------- back of the card ---------- */

#back {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  animation: reveal 160ms ease-out;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(6px); }
}

@media (prefers-reduced-motion: reduce) {
  #back { animation: none; }
  .big:active { transform: none; }
}

#back p { margin: 0; }

.romaji { font-size: 2.5rem; font-weight: 600; }

.word { font-size: 1.6rem; font-weight: 600; }
.word .r { font-weight: 400; color: var(--muted); font-size: 1.1rem; margin-left: 0.4rem; }
.meaning { font-size: 1.25rem; }
.en { color: var(--muted); font-style: italic; }
.later, .hook { color: var(--muted); font-size: 0.95rem; }
.later span { font-size: 1.1rem; color: var(--ink); }

#back .note {
  max-width: 22rem;
  margin: 0.25rem auto 0;
  text-align: left;
}

#back .rule-back { white-space: pre-line; font-size: 1.05rem; color: var(--ink); }

.replay {
  align-self: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-top: 0.25rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
}

.replay svg, .listen svg {
  stroke: var(--ink);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.replay svg { width: 1.5rem; height: 1.5rem; }

.no-audio .replay, .no-audio .listen { display: none; }

.actions { min-height: 4.25rem; }

#grades { display: flex; gap: 0.75rem; }
