/* Japanese Vocab — stylesheet
 * Performance notes:
 *  - backdrop-filter is intentionally limited to 2 surfaces (toolbar, progress card)
 *    because Firefox creates a new compositor layer per blurred surface.
 *  - The body has a static gradient, no animated drift, no dot-grid pseudo
 *    (those caused continuous repaints in Firefox).
 *  - The progress bar uses a static gradient, not an infinite shimmer.
 *  - Cards use `contain: layout paint` so flipping one does not invalidate
 *    layout/paint of siblings.
 */

/* Brand palette pulled directly from the imo logo:
 *   coral  #d77771  →  primary accent
 *   orange #ff7100  →  secondary / hot accent
 *   cream  #fff7ee  →  background
 * Supporting neutrals are warm-tinted (toasted browns, not purple/grey)
 * so they sit naturally against the brand colors. */
@font-face {
  font-family: "LINESeedJP";
  src: url("fonts/LINESeedJP_OTF_Rg.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "LINESeedJP";
  src: url("fonts/LINESeedJP_OTF_Bd.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #fff7ee;
  --bg-grad-1: #ffd6c2;
  --bg-grad-2: #ffe5cf;
  --bg-grad-3: #fde2cf;
  --surface: #ffffff;
  --surface-glass: rgba(255, 247, 238, 0.82);
  --surface-muted: #fbeede;
  --text: #2a1a0e;
  --text-soft: #5a3f30;
  --muted: #a08770;
  --accent: #d77771;
  --accent-2: #f0a097;
  --accent-3: #ff7100;
  --success: #2f9e44;
  --danger: #e03131;
  --border: rgba(42, 26, 14, 0.08);
  --border-strong: rgba(42, 26, 14, 0.16);
  --shadow-sm: 0 1px 2px rgba(42, 26, 14, 0.06), 0 2px 6px rgba(42, 26, 14, 0.04);
  --shadow-md: 0 6px 18px rgba(42, 26, 14, 0.08), 0 1px 3px rgba(42, 26, 14, 0.06);
  --shadow-lg: 0 16px 40px rgba(42, 26, 14, 0.14), 0 2px 6px rgba(42, 26, 14, 0.06);
  --shadow-glow: 0 10px 30px rgba(255, 113, 0, 0.28);
  --focus: #ff7100;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  /* Vertical rhythm between blocks on a page. */
  --stack-gap: 1.2rem;
}

[data-theme="dark"] {
  --bg: #161616;
  --bg-grad-1: #212121;
  --bg-grad-2: #252525;
  --bg-grad-3: #111111;
  --surface: #323232;
  --surface-glass: rgba(32, 32, 32, 0.78);
  --surface-muted: #333333;
  --text: #fff7ee;
  --text-soft: #e0cab5;
  --muted: #b09080;
  --accent: #e88a82;
  --accent-2: #f5a59c;
  --accent-3: #ff8838;
  --success: #5ad17a;
  --danger: #ff7373;
  --border: rgba(255, 247, 238, 0.08);
  --border-strong: rgba(255, 247, 238, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 10px 30px rgba(255, 113, 0, 0.32);
  --focus: #ff8838;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
*::selection { background: var(--accent); color: #fff; }
html { scroll-behavior: smooth; }

body {
  font-family: "LINESeedJP", system-ui, sans-serif;
  color: var(--text);
  min-height: 100vh;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  overflow-x: hidden;
  /* Static gradient — no animation, no dot grid. Much cheaper for Firefox. */
  background:
    radial-gradient(60% 50% at 12% 8%, var(--bg-grad-1) 0%, transparent 80%),
    radial-gradient(55% 45% at 90% 14%, var(--bg-grad-2) 0%, transparent 80%),
    radial-gradient(70% 60% at 50% 110%, var(--bg-grad-3) 0%, transparent 80%),
    var(--bg);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input { font: inherit; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; }

/* Inline Lucide icons. Width/height are baked into the SVG markup; this
 * rule just keeps them from being squished by flex containers and ensures
 * stroke colors follow the parent's currentColor. */
.lucide { flex-shrink: 0; display: inline-block; vertical-align: middle; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard shortcuts popover (nav) */
.shortcut-wrap {
  position: relative;
}
.shortcut-toggle[aria-expanded="true"] {
  box-shadow: var(--shadow-md), 0 0 0 3px rgba(215, 119, 113, 0.35);
  color: var(--accent);
}
.shortcut-panel {
  position: absolute;
  z-index: 120;
  top: calc(100% + 12px);
  right: 0;
  width: min(19.5rem, calc(100vw - 2rem));
  max-height: min(72vh, 560px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow:
    var(--shadow-lg),
    0 0 0 1px var(--border-strong);
  transform-origin: top right;
}
/* Author `display:flex` above beats the default [hidden] rule; tie hidden explicitly. */
.shortcut-panel[hidden] {
  display: none !important;
}
.shortcut-panel:not([hidden]) {
  animation: shortcutPanelIn 0.38s cubic-bezier(0.34, 1.35, 0.5, 1) both;
}
@keyframes shortcutPanelIn {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .shortcut-panel:not([hidden]) { animation: none; }
}
.shortcut-panel-tail {
  position: absolute;
  top: -7px;
  right: 14px;
  width: 14px;
  height: 14px;
  background: var(--surface);
  border-radius: 3px;
  transform: rotate(45deg);
  border-right: 1px solid var(--border-strong);
  border-top: 1px solid var(--border-strong);
  z-index: 1;
}
.shortcut-panel-inner {
  position: relative;
  z-index: 2;
  overflow-y: auto;
  padding-bottom: 0.35rem;
}
.shortcut-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 1rem 1rem 0.85rem;
  background: linear-gradient(135deg, rgba(215, 119, 113, 0.18), rgba(255, 113, 0, 0.12));
  border-bottom: 1px solid var(--border);
}
.shortcut-banner-icon {
  flex-shrink: 0;
  display: inline-flex;
  line-height: 0;
  filter: drop-shadow(0 2px 4px rgba(42, 26, 14, 0.12));
  color: var(--accent);
}
.shortcut-banner-icon .lucide {
  width: 1.75rem;
  height: 1.75rem;
}
.shortcut-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.shortcut-banner-title {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.15;
  background: linear-gradient(120deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.shortcut-banner-sub {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.35;
}
.shortcut-section {
  padding: 0.75rem 1rem 0.5rem;
}
.shortcut-section + .shortcut-section {
  border-top: 1px solid var(--border);
}
.shortcut-section-accent {
  background: linear-gradient(180deg, rgba(255, 113, 0, 0.06), transparent 72%);
}
.shortcut-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.shortcut-pill {
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 113, 0, 0.25);
}
.shortcut-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.shortcut-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.45rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-soft);
  line-height: 1.35;
}
.shortcut-desc { flex: 1; min-width: 8rem; font-weight: 700; color: var(--text); }
.shortcut-note {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}
.shortcut-dot {
  font-weight: 800;
  color: var(--muted);
  font-size: 0.72rem;
}
.shortcut-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  padding: 0.2rem 0.42rem;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface-muted);
  border-radius: 8px;
  border: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 2px 0 var(--border-strong);
}
[data-theme="dark"] .shortcut-kbd {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 0 rgba(0, 0, 0, 0.35);
}
.shortcut-kbd.wide {
  min-width: auto;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.shortcut-panel:focus {
  outline: none;
}
.shortcut-panel:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-lg);
}

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: var(--surface);
  border: none;
  box-shadow: var(--shadow-sm);
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.icon-btn:active { transform: translateY(0) scale(0.97); }

/* Liquid mouse-reactive theme toggle. Uses the same --mx/--my pattern
 * the category bubbles do, set by attachLiquidHover() in app.js. */
.theme-toggle {
  --mx: 0;
  --my: 0;
  --mxp: 50%;
  --myp: 50%;
  --pull: 2px;
  --tilt: 2deg;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 0.34s cubic-bezier(0.34, 1.3, 0.64, 1),
    box-shadow 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
  transform-origin: center;
  will-change: transform;
}
.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    80px circle at var(--mxp) var(--myp),
    rgba(255, 255, 255, 0.45),
    rgba(255, 255, 255, 0) 60%
  );
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
  transition: opacity 0.25s ease;
  z-index: 0;
}
.theme-toggle:hover {
  transform: translateY(-1px) scale(1.06);
  box-shadow: var(--shadow-md);
}
.theme-toggle.is-tracking {
  transform:
    translate(calc(var(--mx) * var(--pull)), calc(var(--my) * var(--pull) - 1px))
    rotate(calc(var(--mx) * var(--tilt)))
    scale(1.05);
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.theme-toggle.is-tracking::before { opacity: 1; }
.theme-toggle:active {
  transform:
    translate(calc(var(--mx) * 1px), calc(var(--my) * 1px))
    scale(0.92);
  transition-duration: 0.08s;
  transition-timing-function: ease-out;
}

/* Sun/moon swap: both icons live stacked at center; the leaving icon
 * spins out and shrinks while the arriving one spins in from the
 * opposite side and pops to size — much more fun than a fade. */
.theme-toggle .lucide {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  transition:
    opacity 0.32s ease,
    transform 0.55s cubic-bezier(0.34, 1.45, 0.64, 1);
}
[data-theme="light"] .theme-toggle .moon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}
[data-theme="light"] .theme-toggle .sun {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(120deg) scale(0.2);
  pointer-events: none;
}
[data-theme="dark"] .theme-toggle .sun {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}
[data-theme="dark"] .theme-toggle .moon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-120deg) scale(0.2);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle.is-tracking { transform: none; transition: none; }
  .theme-toggle::before { display: none; }
  .theme-toggle .lucide { transition: opacity 0.15s ease; }
  [data-theme="light"] .theme-toggle .sun,
  [data-theme="dark"] .theme-toggle .moon {
    transform: translate(-50%, -50%);
  }
  [data-theme="light"] .theme-toggle .moon,
  [data-theme="dark"] .theme-toggle .sun {
    transform: translate(-50%, -50%);
  }
}

.eyebrow {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 0.72rem; font-weight: 700;
  color: var(--text-soft);
  background: var(--surface-glass);
  border: none;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  letter-spacing: 0.18em;
}
.eyebrow::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(215, 119, 113, 0.22);
}
/* ---------- Stats row ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin: 0 auto var(--stack-gap);
  max-width: 600px;
}
.stat {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.7rem 0.8rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 0.66rem; font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}
.stat-value { font-size: 1.25rem; font-weight: 900; letter-spacing: -0.02em; }
.stat-value.accent { color: var(--accent); }

html.chrome-boot .theme-toggle,
html.chrome-boot .theme-toggle::before,
html.chrome-boot .theme-toggle .lucide {
  transition: none !important;
}

.search-wrap { position: relative; width: 100%; }
.search-ico {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  display: inline-flex;
}
.search-input {
  width: 100%;
  background: var(--surface);
  border: none;
  border-radius: 14px;
  padding: 0.78rem 2.2rem 0.78rem 2.4rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  transition: background-color 0.15s ease;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; background: var(--surface); }
.search-clear {
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: none;
  place-items: center;
  background: var(--border-strong);
  color: var(--text);
  transition: background-color 0.15s ease;
}
.search-clear:hover { background: var(--accent); color: #fff; }
.search-clear.visible { display: grid; }
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
}
.chip {
  /* Same cursor-driven liquid hover as .cat-btn (see app.js attachLiquidHoverDelegated). */
  --mx: 0;
  --my: 0;
  --mxp: 50%;
  --myp: 50%;
  --pull: 3px;
  --tilt: 1.5deg;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: none;
  color: var(--text-soft);
  transition:
    transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1),
    background-color 0.2s ease,
    color 0.2s ease;
  transform-origin: center;
  will-change: transform;
}
.chip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    140px circle at var(--mxp) var(--myp),
    rgba(255, 255, 255, 0.45),
    rgba(255, 255, 255, 0) 60%
  );
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
  transition: opacity 0.25s ease;
  z-index: 0;
}
.chip > * { position: relative; z-index: 1; }
.chip:hover {
  transform: translateY(-1px) scale(1.04);
}
.chip.is-tracking {
  transform:
    translate(calc(var(--mx) * var(--pull)), calc(var(--my) * var(--pull) - 1px))
    rotate(calc(var(--mx) * var(--tilt)))
    scale(1.04);
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.chip.is-tracking::before { opacity: 1; }
.chip:active {
  transform:
    translate(calc(var(--mx) * 1px), calc(var(--my) * 1px))
    scale(0.9);
  transition-duration: 0.08s;
  transition-timing-function: ease-out;
}
.chip.on {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
  transform: translateY(-1px) scale(1.05);
}
.chip.on.is-tracking {
  transform:
    translate(calc(var(--mx) * var(--pull)), calc(var(--my) * var(--pull) - 1px))
    rotate(calc(var(--mx) * var(--tilt)))
    scale(1.05);
}
.chip.on:active {
  transform: translateY(0) scale(0.95);
}
.chip.danger:hover {
  background: rgba(224, 49, 49, 0.12);
  color: var(--danger);
}
.chip .label-on, .chip .label-off { display: none; }
.chip[data-state="on"] .label-on { display: inline; }
.chip[data-state="off"] .label-off { display: inline; }
.chip[data-state="static"] .label-on { display: inline; }

/* ---------- Categories ---------- */
.cats-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.15rem 0 0;
  margin-bottom: var(--stack-gap);
  justify-content: center;
}
.cat-btn {
  /* Cursor-driven custom properties (set via JS pointermove).
   *  --mx / --my : -1..1 horizontal/vertical offset from button center.
   *  --mxp/ --myp: 0%..100% cursor position (used by gloss gradient).
   *  --pull / --tilt: how strongly the bubble follows the cursor. */
  --mx: 0;
  --my: 0;
  --mxp: 50%;
  --myp: 50%;
  --pull: 3px;
  --tilt: 1.5deg;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--surface);
  border: none;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--text-soft);
  /* Spring-style easing makes the bubble overshoot on release for a
     gummy/blobby feel. Box-shadow + color stay on a calmer curve. */
  transition:
    transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
  transform-origin: center;
  will-change: transform;
}
/* Cursor-following gloss highlight. Lives behind the text/icon. */
.cat-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    140px circle at var(--mxp) var(--myp),
    rgba(255, 255, 255, 0.45),
    rgba(255, 255, 255, 0) 60%
  );
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
  transition: opacity 0.25s ease;
  z-index: 0;
}
.cat-btn > * { position: relative; z-index: 1; }
.cat-btn:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: var(--shadow-sm);
}
/* Liquid magnet: while the cursor is over the bubble, follow it with a
   short ease so it glides instead of springing. The spring takes back
   over on pointerleave (when the class is removed). */
.cat-btn.is-tracking {
  transform:
    translate(calc(var(--mx) * var(--pull)), calc(var(--my) * var(--pull) - 1px))
    rotate(calc(var(--mx) * var(--tilt)))
    scale(1.04);
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.cat-btn.is-tracking::before { opacity: 1; }
.cat-btn.is-tracking .dot {
  /* Subtle parallax: dot drifts slightly opposite the cursor. */
  transform: translate(calc(var(--mx) * -1px), calc(var(--my) * -1px)) scale(1.03);
}
.cat-btn:active {
  /* Snappy squish on press — bite first, then the spring on release. */
  transform:
    translate(calc(var(--mx) * 1px), calc(var(--my) * 1px))
    scale(0.9);
  transition-duration: 0.08s;
  transition-timing-function: ease-out;
}
.cat-btn .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  transition: transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, opacity 0.2s ease;
}
.cat-btn:active .dot { transform: scale(0.7); }
.cat-btn .ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.cat-btn.active {
  color: #fff;
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px) scale(1.05);
  animation: catBloop 0.38s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.cat-btn.active.is-tracking {
  /* Selected bubble still follows the cursor, just a touch stronger. */
  transform:
    translate(calc(var(--mx) * var(--pull)), calc(var(--my) * var(--pull) - 1px))
    rotate(calc(var(--mx) * var(--tilt)))
    scale(1.05);
}
.cat-btn.active:active {
  transform: translateY(0) scale(0.95);
}
.cat-btn.active .dot {
  background: rgba(255, 255, 255, 0.85);
  opacity: 1;
  animation: dotBloop 0.38s cubic-bezier(0.34, 1.3, 0.64, 1);
}

/* "Bloop" — squash → overshoot → settle. Triggered when a category becomes
   selected (the cats list re-renders, so the new .active node re-animates). */
@keyframes catBloop {
  0%   { transform: translateY(0) scale(0.94); }
  45%  { transform: translateY(-1px) scale(1.06); }
  100% { transform: translateY(-1px) scale(1.05); }
}
@keyframes dotBloop {
  0%   { transform: scale(0.7); }
  55%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .cat-btn,
  .cat-btn .dot { transition: none; animation: none; }
  .cat-btn.active,
  .cat-btn.active .dot { animation: none; }
  .cat-btn.is-tracking,
  .cat-btn.active.is-tracking { transform: none; }
  .cat-btn.is-tracking .dot { transform: none; }
  .cat-btn::before { display: none; }
  .chip { transition: none; }
  .chip.is-tracking { transform: none; }
  .chip::before { display: none; }
}

/* ---------- Card grid ---------- *
 * Predictable column counts at each breakpoint avoids the auto-fill
 * "5 vs 6 columns" jitter at common desktop widths. */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}
@media (min-width: 560px) { .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 760px) { .card-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; } }
@media (min-width: 1000px) { .card-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.card {
  position: relative;
  background: transparent;
  border-radius: var(--radius-lg);
  min-height: 180px;
  cursor: pointer;
  animation: cardIn 0.4s cubic-bezier(0.3, 1.4, 0.4, 1) both;
  transition: transform 0.2s ease;
  outline: none;
  /* Per-card perspective so each flip pivots around its own center.
   * Putting it on the grid would warp side cards. */
  perspective: 1200px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.card:hover { transform: translateY(-3px); }

.card-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 180px;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.5, 1.4, 0.4, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-front, .card-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.85rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: none;
  box-shadow: var(--shadow-md);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  text-align: center;
}
.card.is-learned .card-front {
  background: linear-gradient(160deg, var(--surface), var(--surface-muted));
}
.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-muted) 100%);
}
.c-jp {
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.c-front-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.3rem;
}
.speak-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-size: 0.85rem;
  border: none;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.speak-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}
.hint {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  position: absolute;
  bottom: 0.7rem;
  left: 0;
  right: 0;
  text-align: center;
  opacity: 0.7;
}
.c-en { font-size: 1.05rem; font-weight: 900; letter-spacing: -0.01em; }
.c-emoji {
  font-size: clamp(2rem, 8vw, 2.75rem);
  line-height: 1;
  margin-bottom: 0.25rem;
  user-select: none;
}
.c-romaji {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
  font-style: italic;
  margin-top: 0.15rem;
  letter-spacing: 0.04em;
}
.learned-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: none;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.card.is-learned .learned-badge { display: grid; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- Answer buttons (quiz rounds) ---------- */
.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 0.5rem 0 1.1rem;
}
.answer-btn {
  background: var(--surface-muted);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  font-weight: 800;
  font-size: 0.95rem;
  text-align: left;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: background-color 0.15s ease, transform 0.15s ease;
  position: relative;
}
[data-theme="dark"] .answer-btn {
  background: #3c3c3c;
}
.answer-btn::before {
  content: attr(data-letter);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  border: none;
  flex-shrink: 0;
}
.answer-btn:hover { transform: translateY(-1px); }
.answer-btn.selected { background: rgba(255, 113, 0, 0.08); }
.answer-btn.selected::before { background: var(--accent-3); color: #fff; }
.answer-btn.correct {
  background: linear-gradient(135deg, rgba(47, 158, 68, 0.12), rgba(47, 158, 68, 0.04));
  color: var(--success);
}
.answer-btn.correct::before { background: var(--success); color: #fff; content: "+"; font-size: 1rem; line-height: 1; }
.answer-btn.wrong {
  background: linear-gradient(135deg, rgba(224, 49, 49, 0.12), rgba(224, 49, 49, 0.04));
  color: var(--danger);
  animation: shake 0.35s ease;
}
.answer-btn.wrong::before { background: var(--danger); color: #fff; content: "-"; font-size: 1rem; line-height: 1; font-weight: 900; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.quiz-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}
.btn {
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: box-shadow 0.15s ease;
  border: none;
  background: var(--surface-muted);
  color: var(--text);
}
.btn:hover:not(:disabled) { box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 14px 32px rgba(215, 119, 113, 0.35); }

/* ---------- Empty state ---------- */
.empty-state {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-lg);
  padding: 2.4rem 1.4rem;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}
.empty-state .ico { font-size: 2.4rem; display: block; margin-bottom: 0.5rem; }

/* ---------- Dictionary mode ---------- */
.dict-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: min(600px, 100%);
  margin-inline: auto;
  width: 100%;
  box-sizing: border-box;
}
.dict-group {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.dict-group-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 1rem;
  color: #fff;
  font-weight: 800;
  position: relative;
  overflow: hidden;
}
.dict-group-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.3), transparent 60%);
  pointer-events: none;
}
.dict-group-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}
.dict-group-label {
  flex: 1;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  min-width: 0;
}
.dict-group-count {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.22);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.dict-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}
.dict-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.65rem 1rem;
  transition: background-color 0.12s ease;
}
.dict-row:nth-child(even) { background: var(--surface-muted); }
.dict-row:hover { background: rgba(215, 119, 113, 0.08); }
.dict-jp-block {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}
.dict-jp {
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
  line-height: 1.2;
}
.dict-romaji {
  font-size: 0.74rem;
  color: var(--muted);
  font-style: italic;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.dict-en {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  max-width: 14em;
  line-height: 1.25;
}
.dict-meaning {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
}
.dict-emoji {
  font-size: 1.35rem;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}
.dict-row .speak-btn {
  width: 30px;
  height: 30px;
}
.dict-row.is-learned .dict-jp { color: var(--accent); }
.dict-row.is-learned .dict-jp::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 0.45rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  vertical-align: middle;
}
@media (max-width: 480px) {
  .dict-row { grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; }
  .dict-meaning {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }
  .dict-en {
    text-align: left;
    font-size: 0.86rem;
    color: var(--text-soft);
    max-width: none;
  }
  .dict-row .speak-btn { grid-column: 2; grid-row: 1; }
}

/* ---------- Kana mode (gojuon charts) ---------- */
.kana-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.kana-chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.kana-chart-block {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1rem 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.kana-chart-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.kana-chart-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}
.kana-chart {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
.kana-chart thead th {
  padding: 0.35rem 0.2rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: none;
}
.kana-corner {
  width: 1.75rem;
}
.kana-chart tbody th.kana-row-label {
  padding: 0.35rem 0.35rem 0.35rem 0;
  font-weight: 800;
  color: var(--muted);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}
.kana-chart td {
  padding: 0.2rem 0.15rem;
  vertical-align: middle;
}
.kana-cell {
  text-align: center;
}
.kana-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.2rem 0.15rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  border-radius: 8px;
  transition: transform 0.02s ease, color 0.12s ease;
}
.kana-char:hover {
  transform: scale(1.05);
}
.kana-empty {
  min-width: 1.5rem;
}
.kana-roma {
  display: block;
  margin-top: 0.08rem;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.03em;
  color: var(--muted);
  line-height: 1.2;
}
.kana-n-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--surface-muted);
}
.kana-n-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.04em;
  min-width: 1rem;
  text-align: right;
}
.kana-n-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.25rem 0.45rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  border-radius: 8px;
  transition: transform 0.12s ease;
}
button.kana-n-char:hover {
  transform: scale(1.05);
}
span.kana-n-char {
  cursor: default;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}
.kana-n-row .kana-roma {
  margin-top: 0;
}

.kana-learn-section .kana-learn-drill-inner {
  max-width: 22rem;
  margin: 0 auto;
  padding: 0 0 0.75rem;
}
.kana-learn-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  margin-bottom: 0.75rem;
}

.kana-learn-progress-num {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.kana-learn-score-mini {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
.kana-learn-exit-chip {
  margin-left: auto;
}
.kana-learn-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}
.kana-learn-form--frozen {
  pointer-events: none;
}
.kana-learn-form--frozen .kana-learn-input {
  opacity: 0.88;
  cursor: not-allowed;
}
.kana-learn-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-soft);
  text-align: center;
}
.kana-learn-ring {
  align-self: center;
  width: 100%;
  max-width: 18rem;
  padding: 0.55rem 0.75rem 0.75rem;
  border-radius: 18px;
  border: none;
  background: transparent;
  box-shadow: none;
  transition: box-shadow 0.2s ease;
}
.kana-learn-status-slot {
  min-height: 2.1rem;
}
.kana-learn-status {
  min-height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  font-size: 0.86rem;
  font-weight: 800;
  margin: 0 0 0.25rem;
  text-align: center;
  line-height: 1.25;
}
.kana-learn-status--ok {
  color: #2b8a3e;
}
.kana-learn-status--bad {
  color: var(--danger, #c92a2a);
}
.kana-learn-status--bad strong {
  font-weight: 900;
  color: var(--accent);
}
.kana-learn-glyph {
  font-weight: 900;
}
.kana-learn-n-hint {
  font-weight: 600;
  font-size: 0.78em;
  color: var(--muted);
}
.kana-learn-ring--ok {
  animation: kanaLearnRingPulseOk 0.42s ease;
}
.kana-learn-ring--bad {
  animation: kanaLearnRingShake 0.45s ease;
}
@keyframes kanaLearnRingPulseOk {
  from {
    transform: scale(0.97);
    filter: brightness(0.98);
  }
  to {
    transform: scale(1);
    filter: none;
  }
}
@keyframes kanaLearnRingShake {
  0%,
  100% {
    transform: translateX(0);
  }
  18% {
    transform: translateX(-5px);
  }
  36% {
    transform: translateX(5px);
  }
  54% {
    transform: translateX(-3px);
  }
  72% {
    transform: translateX(3px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .kana-learn-ring--ok,
  .kana-learn-ring--bad {
    animation: none;
  }
}
[data-theme="dark"] .kana-learn-status--ok {
  color: #69db7c;
}
.kana-learn-section .kana-learn-ring .kana-learn-char {
  margin: 0 auto;
  padding: 0.35rem 0.5rem 0.55rem;
  font-family: "LINESeedJP", system-ui, sans-serif;
  font-size: clamp(3rem, 18vw, 5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  color: var(--text);
  text-shadow: 0 2px 18px rgba(215, 119, 113, 0.15);
  text-align: center;
}
.kana-learn-input {
  width: 100%;
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  font-family: inherit;
  font-weight: 600;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.kana-learn-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(215, 119, 113, 0.25);
}
.kana-learn-input:disabled {
  opacity: 0.92;
}
.kana-learn-footer {
  margin-top: 0.35rem;
  display: flex;
  justify-content: center;
}
.inline-kbd {
  display: inline-block;
  padding: 0.08rem 0.35rem;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  font-size: 0.76em;
  font-weight: 800;
  font-family: inherit;
}
.kana-learn-complete {
  text-align: center;
  padding: 1.75rem 1rem 1rem;
  max-width: 22rem;
  margin: 0 auto;
}
.kana-learn-complete-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.kana-learn-stats {
  margin: 0 0 0.45rem;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-soft);
}
.kana-learn-hint-sub {
  margin: 0 0 1.35rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
}
.kana-learn-complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
}

/* ---------- Focus / a11y ---------- */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
.card:focus-visible { outline-offset: 5px; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: 0.6rem; }
}
@media (max-width: 420px) {
  .card-grid { gap: 0.65rem; }
  .card, .card-inner { min-height: 160px; }
  .c-jp { font-size: 1.5rem; }
}

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