/* The warm paper/ink core is hand-copied from the other apps on this box —
   there is deliberately no shared stylesheet, since each app is its own Docker
   build context. Keep --paper/--paper-2/--card/--ink/--ink-soft/--line in sync
   with apps/main/site/index.html if they ever change. */

:root {
  color-scheme: light;

  --paper: #faf7f2;
  --paper-2: #f2ede4;
  --card: #ffffff;
  --ink: #24211c;
  --ink-soft: #6b6459;
  --line: #e6ddd0;

  /* Indigo is the app accent; it is also the landing-page card's gradient. */
  --indigo: #5b57d9;
  --indigo-dark: #3f3bb3;
  --teal: #12a594;
  --teal-dark: #0b7d70;
  --amber: #e08b2f;
  --amber-dark: #b8651a;

  --ok: #6aaa64;
  --bad: #d64545;

  /* Accents as *text* need more lift on a dark surface than accents as *fill*
     do, so the two are separate. The input borders keep using --ok / --bad. */
  --indigo-text: var(--indigo-dark);
  --ok-text: #4a8a44;
  --bad-text: var(--bad);

  /* Translucent tints take a bare triplet so rgba() can follow the theme —
     hardcoding the RGB inline is what leaves a tint stuck at light values. */
  --indigo-rgb: 91, 87, 217;
  --ok-rgb: 106, 170, 100;
  --bad-rgb: 214, 69, 69;
  --shadow-rgb: 36, 33, 28;

  --card-ring: 0 0 #0000;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --paper: #16130f;
  --paper-2: #262119;
  --card: #1e1a15;
  --ink: #f2ede4;
  --ink-soft: #a79d8e;
  --line: #38312a;

  --indigo-text: #9d9aef;
  --ok-text: #8bc784;
  --bad-text: #e86a6a;

  --ok-rgb: 139, 199, 132;
  --bad-rgb: 232, 106, 106;
  --shadow-rgb: 0, 0, 0;

  /* A hairline keeps every tile readable against the dark page. */
  --card-ring: 0 0 0 1px var(--line);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over the display rules below — screens are
   switched by toggling it, and an author `display` otherwise beats the UA
   default (the same lesson as in the amr and rordle apps). */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Japanese needs its own stack: the Latin system fonts have no kana, and
   letting the browser fall back per-glyph gives wildly inconsistent metrics.
   No web font — nothing here may make an external request. */
.jp, .prompt, [lang="ja"] {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic Medium",
    "Yu Gothic", "Noto Sans JP", Meiryo, "MS PGothic", sans-serif;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 3rem 1.25rem 1.5rem;
}

/* --- header --- */
header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.brand { text-decoration: none; color: inherit; }
.brand h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.9rem, 6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1rem;
}
.brand:hover h1 { color: var(--indigo-text); }

.theme-btn {
  flex: none;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
/* Show the icon for the theme you'd switch *to*. Driven off data-theme rather
   than JS so it's correct on the very first paint. */
.theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] .theme-btn .icon-sun { display: block; }
:root[data-theme="dark"] .theme-btn .icon-moon { display: none; }
.theme-btn:hover {
  color: var(--indigo-text);
  border-color: var(--indigo);
  transform: translateY(-2px);
}

main { flex: 1; }

/* --- home --- */
.tier + .tier { margin-top: 2.5rem; }
.tier h2 {
  margin: 0 0 0.9rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 148px;
  padding: 1.35rem;
  border-radius: 18px;
  text-decoration: none;
  color: white;
  overflow: hidden;
  background: linear-gradient(155deg, var(--indigo), var(--indigo-dark));
  --glow: rgba(91, 87, 217, 0.45);
  box-shadow: var(--card-ring), 0 1px 2px rgba(var(--shadow-rgb), 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tile:hover,
.tile:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--card-ring), 0 16px 32px -12px var(--glow);
}
/* Each tile overrides its gradient and its glow together. */
.tile.kata {
  background: linear-gradient(155deg, var(--teal), var(--teal-dark));
  --glow: rgba(11, 125, 112, 0.45);
}
.tile.sent {
  background: linear-gradient(155deg, var(--amber), var(--amber-dark));
  --glow: rgba(184, 101, 26, 0.45);
}

/* An oversized watermark glyph. It bleeds off the corner, but only just —
   push it further and あ/ア stop being recognisable, which defeats the point. */
.tile .glyph {
  position: absolute;
  top: -0.1em;
  right: 0.05em;
  font-size: 5.6rem;
  line-height: 1;
  opacity: 0.2;
  user-select: none;
  pointer-events: none;
}
.tile .name { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; }
.tile .desc { margin-top: 0.35rem; font-size: 0.9rem; opacity: 0.92; }

/* --- drill --- */
.drill-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 2rem;
  font-size: 0.82rem;
}
.back { color: var(--ink-soft); text-decoration: none; white-space: nowrap; }
.back:hover { color: var(--indigo-text); }

.modes {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--paper-2);
  border: 1px solid var(--line);
}
.mode {
  padding: 0.25rem 0.85rem;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.mode:hover { color: var(--ink); }
.mode.active {
  background: var(--card);
  color: var(--indigo-text);
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), 0.12);
}

.score {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.score .streak { color: var(--ok-text); font-weight: 700; }

.prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 5.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: clamp(3.2rem, 15vw, 5rem);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: 0.02em;
  user-select: none;
}
/* Words and especially sentences need to come down several sizes to fit. */
.prompt.word { font-size: clamp(2.4rem, 11vw, 3.6rem); }
.prompt.sentence {
  font-size: clamp(1.35rem, 5.6vw, 2rem);
  letter-spacing: 0.01em;
  line-height: 1.5;
}

.answer {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.25rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.answer::placeholder { color: var(--ink-soft); opacity: 0.65; font-size: 1rem; }
.answer:focus { border-color: var(--indigo); }
.answer.ok {
  border-color: var(--ok);
  background: rgba(var(--ok-rgb), 0.12);
  color: var(--ok-text);
  font-weight: 600;
}
.answer.bad {
  border-color: var(--bad);
  background: rgba(var(--bad-rgb), 0.1);
  color: var(--bad-text);
  animation: shake 0.4s;
}

.feedback {
  margin-top: 1.1rem;
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--card-ring), 0 1px 2px rgba(var(--shadow-rgb), 0.05);
  animation: rise 0.2s ease;
}
.feedback.correct { border-color: rgba(var(--ok-rgb), 0.5); background: rgba(var(--ok-rgb), 0.07); }
.feedback.shown { border-color: rgba(var(--bad-rgb), 0.4); background: rgba(var(--bad-rgb), 0.06); }

.feedback .romaji {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.feedback.correct .romaji { color: var(--ok-text); }
.feedback.shown .romaji { color: var(--bad-text); }
.feedback .meaning { margin-top: 0.15rem; color: var(--ink); }
.feedback .note {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.feedback .note b { color: var(--ink); font-weight: 600; }
.feedback .group {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

/* The particle nudge, shown instead of a plain wrong answer. */
.particle-hint {
  margin-top: 1.1rem;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  color: var(--bad-text);
  background: rgba(var(--bad-rgb), 0.08);
  border: 1px solid rgba(var(--bad-rgb), 0.3);
}
.particle-hint b { color: var(--ink); }

.drill-actions { margin-top: 1.1rem; display: flex; justify-content: center; }

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 1rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--ink-soft);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { color: var(--indigo-text); border-color: var(--indigo); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn[disabled]:hover { color: var(--ink-soft); border-color: var(--line); }

.tip {
  margin: 2rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* --- footer --- */
footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
footer a { color: var(--ink-soft); text-decoration: none; }
footer a:hover { color: var(--ink); }

/* --- animations --- */
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 480px) {
  .wrap { padding: 2rem 1rem 1.25rem; }
  header { margin-bottom: 2rem; }
  .tiles { grid-template-columns: 1fr; }
  .drill-bar { font-size: 0.76rem; gap: 0.5rem; }
  .mode { padding: 0.25rem 0.6rem; }
}
