/* ── Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg: #f5f5f2;
  --surface: #eeeeeb;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: rgba(0,0,0,0.2);
  --accent: #c96442;
  --accent-soft: rgba(201,100,66,0.08);
  --accent-hover: #b85535;
  --danger: #b42318;
  --success: #1a7f4b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 3px 10px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
  --transition: 160ms ease;
}

body[data-theme='dark'] {
  --bg: #1a1a1a; --surface: #262626; --panel: #2a2a2a;
  --ink: #e5e5e5; --muted: #999999; --line: rgba(255,255,255,0.25);
  --accent: #d4845a; --accent-soft: rgba(212,132,90,0.12); --accent-hover: #e0956b;
  --danger: #f87171; --success: #4ade80;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.30);
  --shadow-md: 0 3px 10px rgba(0,0,0,0.35);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.40);
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Typography ─────────────────────────────────────────────────── */
h1,h2,h3 { margin-top: 0; line-height: 1.25; }
h2 { font-size: 1.35rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; }
.muted,.meta { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.2rem; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .2rem;
  font-size: .75rem; font-weight: 700; letter-spacing: .01em;
  padding: .15rem .5rem; border-radius: 999px;
  border: 1px solid var(--line);
}
.badge-lang { background: var(--accent-soft); color: var(--accent); border-color: var(--line); }
.badge-level { background: #f0f5ea; color: #3a6b2c; border-color: #c8dfb8; }
body[data-theme='dark'] .badge-level { background: #1e2d18; color: #7fbf60; border-color: #3a5a28; }
.badge-topic { background: #f3eef8; color: #6b4fa0; border-color: #d4c4e8; }
body[data-theme='dark'] .badge-topic { background: #1e1630; color: #b090d0; border-color: #3a2860; }
.badge-time { background: var(--surface); color: var(--muted); }
.badge-pos { background: #fef8ec; color: #8a6200; border-color: #f0d87a; font-size: .7rem; }
body[data-theme='dark'] .badge-pos { background: #2d2010; color: #e0b840; border-color: #5a4010; }
.badge-mastery-new      { background: var(--surface); color: var(--muted); }
.badge-mastery-learning { background: #fef3e2; color: #9a5a00; border-color: #f0c878; }
.badge-mastery-mastered { background: #eaf6ee; color: #1a6b3a; border-color: #a8dfb8; }
body[data-theme='dark'] .badge-mastery-learning { background: #2d1e08; color: #e0a040; border-color: #6a4010; }
body[data-theme='dark'] .badge-mastery-mastered { background: #0d2d1a; color: #50c080; border-color: #1a5830; }
.badge-mastery-tricky { background: #fde8e8; color: #8a1a1a; border-color: #f0a8a8; }
body[data-theme='dark'] .badge-mastery-tricky { background: #2d0d0d; color: #e06060; border-color: #801a1a; }

/* ── Surfaces ───────────────────────────────────────────────────── */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
}
.panel-lite {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-md); padding: .85rem 1rem;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.tab, .primary-btn, .ghost-btn, .settings-link {
  border-radius: var(--radius-sm); padding: .5rem .85rem;
  border: 1px solid transparent; font: inherit; color: var(--ink); cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition),
              opacity var(--transition);
}
.primary-btn {
  background: var(--accent); color: #fff; border-color: transparent;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { opacity: .88; }
.primary-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.ghost-btn, .settings-link {
  background: transparent; color: var(--ink); border: 1.5px solid rgba(0,0,0,0.15);
}
.ghost-btn:hover, .settings-link:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
.ghost-btn:active { opacity: .82; }
.ghost-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.primary-btn:disabled, .ghost-btn:disabled { opacity: .5; cursor: not-allowed; }
.primary-btn.small, .ghost-btn.small { font-size: .82rem; padding: .3rem .65rem; }

/* ── Inputs ─────────────────────────────────────────────────────── */
input, select, textarea {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .5rem .65rem; font: inherit; background: var(--panel); color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
input[type='search'] { appearance: none; }
body[data-theme='dark'] select option { background: var(--panel); color: var(--ink); }

/* ── Layout helpers ─────────────────────────────────────────────── */
.inline-controls {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-bottom: .75rem;
}
.inline-controls label { display: flex; align-items: center; gap: .4rem; font-size: .875rem; }
.actions-row { display: flex; align-items: center; gap: .6rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; }

html { overflow-x: hidden; }

/* ── Shell ───────────────────────────────────────────────────────── */
.shell {
  --sidebar-w: 170px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  overflow: visible;
  transition: grid-template-columns 240ms ease;
}
.shell.sidebar-collapsed { --sidebar-w: 72px; }

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 1rem .8rem; display: flex; flex-direction: column; gap: .85rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 10;
  transition: padding 240ms ease;
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
}
.shell.sidebar-collapsed #sidebarToggleBtn { display: none; }
.brand-btn {
  background: none; border: none; padding: 0; cursor: pointer; display: flex;
  align-items: center; justify-content: center; border-radius: var(--radius-sm);
  transition: opacity var(--transition);
}
.brand-btn:hover { opacity: .8; }
.brand-icon { width: 3rem; height: 3rem; border-radius: 6px; flex-shrink: 0; transition: filter var(--transition); }
body[data-theme='dark'] .brand-icon,
body[data-theme='dark'] .lp-brand-icon { filter: invert(1); }
.icon-btn {
  width: 40px; height: 40px; padding: 0; border-radius: var(--radius-sm); font-size: 1rem;
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon { width: 1rem; height: 1rem; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.side-nav { display: flex; flex-direction: column; gap: .35rem; }
.tab {
  background: transparent; text-align: left;
  display: flex; align-items: center; gap: .55rem;
  width: 100%; min-height: 40px;
  transition: background var(--transition), border-color var(--transition), padding 240ms ease;
}
.tab.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent); font-weight: 700;
}
.tab:hover:not(.active) { background: var(--accent-soft); }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.nav-icon {
  width: 1rem; height: 1rem; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-icon svg {
  width: 1rem; height: 1rem;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-label { transition: opacity 200ms ease, width 200ms ease; white-space: nowrap; overflow: hidden; }

/* ── Sidebar footer ─────────────────────────────────────────────── */
.sidebar-spacer { flex: 1; }
.sidebar-footer {
  display: flex; flex-direction: column; gap: .25rem;
  border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .25rem;
}
.sf-lang-wrap, .sf-account-wrap { position: relative; }
.sf-btn {
  display: flex; align-items: center; gap: .55rem;
  width: 100%; padding: .45rem .5rem; border-radius: var(--radius-sm);
  border: none; background: transparent; font: inherit; cursor: pointer;
  color: var(--ink); text-align: left;
  transition: background var(--transition);
}
.sf-btn:hover { background: var(--accent-soft); }
.sf-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.sidebar-dropdown {
  position: absolute; bottom: calc(100% + .35rem); left: 0;
  min-width: 200px; border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--panel); box-shadow: var(--shadow-lg); overflow: hidden; z-index: 20;
}
/* Collapsed state for sidebar footer */
.shell.sidebar-collapsed .sf-btn { padding: .45rem .5rem; }
.shell.sidebar-collapsed .sidebar-dropdown { left: 100%; bottom: 0; margin-left: .35rem; }

/* Collapsed sidebar */
.shell.sidebar-collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }
.shell.sidebar-collapsed .tab { padding: .5rem .8rem; }

/* ── Main content ───────────────────────────────────────────────── */
.app-main { overflow-y: auto; height: 100vh; }

.circle-btn {
  width: 2.1rem; height: 2.1rem; border-radius: 999px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-color: var(--line);
}
.account-avatar {
  width: 1.55rem; height: 1.55rem; border-radius: 999px;
  background: var(--ink); color: var(--panel); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  text-transform: uppercase; font-size: .75rem;
  background-size: cover; background-position: center;
}

.language-picker {
  display: grid; gap: .2rem; font-size: .84rem; color: var(--muted); padding: .65rem .75rem;
}
.language-picker select { min-width: 160px; }
.menu-item {
  width: 100%; border: 0; background: transparent; text-align: left;
  padding: .55rem .75rem; font: inherit; color: var(--ink); cursor: pointer;
  transition: background var(--transition);
}
.menu-item:hover { background: var(--accent-soft); }

/* ── Tab panels ─────────────────────────────────────────────────── */
.tab-panel { display: none; margin: .8rem; animation: fadeIn 160ms ease; position: relative; }
.tab-panel.active { display: block; }

/* ── Article header actions ─────────────────────────────────────── */
.article-header-actions { display: flex; align-items: center; gap: .35rem; }

.article-translation-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .28rem .65rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition);
}
.article-translation-pill svg { width: .85rem; height: .85rem; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.article-translation-pill:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.article-translation-pill.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Dashboard bar ──────────────────────────────────────────────── */
.dashboard-bar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: .5rem; margin-bottom: 1rem; padding: .65rem .85rem;
  background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius-md);
}
.streak-chip { display: flex; align-items: center; gap: .35rem; font-weight: 700; }
.streak-flame { font-size: 1.15rem; }
#streakCount { font-size: 1.25rem; color: var(--accent); }
.streak-label { color: var(--muted); font-weight: 400; font-size: .875rem; }
.review-nudge { display: flex; align-items: center; gap: .5rem; font-size: .875rem; color: var(--muted); }

/* ── No article state ───────────────────────────────────────────── */
.no-article-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: .75rem; padding: 4rem 1rem; min-height: 50vh;
}
.no-article-state h2 { margin: 0; }
.no-article-state .primary-btn { margin-top: 0.5rem; }
@keyframes pimochi-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.pimochi-float { animation: pimochi-float 3s ease-in-out infinite; }

/* ── Skeleton loader ────────────────────────────────────────────── */
@keyframes shimmer {
  from { background-position: -400px 0; }
  to   { background-position:  400px 0; }
}
.article-skeleton { padding: 2rem 0; }
.loading-mascot {
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  padding: 2rem 0;
}
.loading-mascot-img {
  width: 160px; height: 160px; object-fit: contain;
  animation: mascot-bounce 1.2s ease-in-out infinite;
}
.loading-mascot-text {
  font-size: .95rem; color: var(--muted); font-weight: 500;
}
@keyframes mascot-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ── Article header ─────────────────────────────────────────────── */
.article-header { margin-bottom: .85rem; }
.article-cover-wrap {
  position: relative; border-radius: var(--radius-md); overflow: hidden;
  margin-bottom: .75rem; max-height: 360px;
}
.article-cover { width: 100%; max-height: 360px; object-fit: cover; display: block; }
.article-cover-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(20,30,40,.55) 0%, transparent 60%);
}
.article-meta-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem;
}
.article-badges { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.article-title { font-size: 1.45rem; font-weight: 800; margin: 0; }
.status-text { margin: .3rem 0 .5rem; min-height: 1.2rem; }

/* ── Reading progress ───────────────────────────────────────────── */
.reading-progress {
  height: 3px; background: var(--line); border-radius: 999px;
  margin-bottom: .5rem; overflow: hidden;
}
.reading-progress-fill {
  height: 100%; background: var(--accent); border-radius: 999px;
  width: 0; transition: width .2s ease;
}

/* ── Article audio bar ──────────────────────────────────────────── */
.article-audio-bar {
  display: flex; flex-direction: column; gap: .3rem;
  padding: .5rem 0; margin-bottom: .5rem;
}

/* ── Article text ───────────────────────────────────────────────── */
.article {
  font-family: 'Literata', serif; font-size: 1.06rem; line-height: 1.8;
  padding: .85rem 0; margin-bottom: .25rem;
}
.article p { margin: 0 0 1em; }
.word-chip {
  border: none; background: none; padding: 0 1px; margin: 0;
  font: inherit; font-family: inherit; line-height: inherit; color: inherit;
  cursor: pointer; border-radius: 3px;
  transition: background var(--transition);
}
.word-chip:hover { background: var(--accent-soft); }
.word-chip.long-press-active { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: 1px; }
.word-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.word-chip-known { border-radius: 3px; }
.word-chip-new { background: rgba(232,168,64,0.30); }
.word-chip-learning { background: rgba(232,168,64,0.15); }
.word-chip-tricky { background: rgba(220,80,60,0.28); text-decoration: underline wavy rgba(220,80,60,0.5); }
body[data-theme='dark'] .word-chip-new { background: rgba(232,168,64,0.25); }
body[data-theme='dark'] .word-chip-learning { background: rgba(232,168,64,0.12); }
body[data-theme='dark'] .word-chip-tricky { background: rgba(220,80,60,0.22); text-decoration: underline wavy rgba(220,80,60,0.4); }

/* ── Ruby pronunciation annotations ──────────────────────────── */
.word-chip ruby { ruby-align: center; padding: 0 .1em; }
.word-chip rt { font-size: .55em; color: var(--muted); font-weight: 400; letter-spacing: .01em; user-select: none; white-space: nowrap; }

/* ── Word spacing for CJK languages ──────────────────────────── */
.article.word-spaced .word-chip { margin-right: 0.35em; }
/* When karaoke timestamps exist, space between segments (matches audio) not within */
.article.word-spaced .karaoke-segment .word-chip { margin-right: 0; }
.article.word-spaced .karaoke-segment { margin-right: 0.35em; }

/* ── Per-language settings in preferences ──────────────────────── */
.profile-settings { padding: 0.35rem 0 0; font-size: 0.85rem; }
.profile-settings label { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); }
.profile-settings select { font-size: 0.82rem; padding: 0.2rem 0.35rem; }

/* ── Karaoke highlighting ──────────────────────────────────────── */
.karaoke-segment {
  border-radius: 3px;
  transition: background 0.25s ease, color 0.25s ease;
}
.karaoke-active {
  background: #fde68a;
  color: #1a1a1a;
  box-shadow: 0 2px 0 #f59e0b;
}

/* ── Audio player ───────────────────────────────────────────────── */
.audio-player {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
.audio-play-btn {
  width: 2.1rem; height: 2.1rem; border-radius: 999px; flex-shrink: 0;
  border: 1px solid var(--line); background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  padding: 0;
}
.audio-play-btn:hover:not(:disabled) { background: var(--accent-hover); }
.audio-play-btn:active { transform: scale(.93); }
.audio-play-btn:disabled { background: var(--line); cursor: not-allowed; }
.audio-play-btn svg { width: .75rem; height: .75rem; fill: #fff; stroke: none; }
.audio-skip-btn {
  width: 2.2rem; height: 2.2rem; border-radius: 999px; flex-shrink: 0;
  border: none; background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color var(--transition), transform var(--transition);
  padding: 0;
}
.audio-skip-btn:hover { color: var(--ink); }
.audio-skip-btn:active { transform: scale(.9); }
.audio-track {
  flex: 1; height: 4px; background: var(--line); border-radius: 999px;
  cursor: pointer; position: relative; min-width: 60px;
}
.audio-track-fill {
  height: 100%; background: var(--accent); border-radius: 999px; width: 0%;
  transition: width .1s linear; pointer-events: none;
}
.audio-time-display { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.audio-speed-select { font-size: .82rem; padding: .25rem .4rem; min-width: 58px; }
audio { display: none; }

/* ── Article body wrapper (side-by-side when translation open) ───── */
.article-body-wrap {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  overflow: hidden;
}
.article-body-wrap.translation-open {
  grid-template-columns: 1fr 1px 1fr;
}
.article-body-wrap > .article { padding-right: 1.25rem; }
.translation-divider { background: var(--line); align-self: stretch; }
.article-body-wrap > .translation-full {
  min-width: 0;
  padding-left: 1.25rem;
  transition: transform 300ms ease;
  transform: translateX(0);
}
/* When not open and not animating, translation sits off-screen right */
.article-body-wrap:not(.translation-open) > .translation-full {
  transform: translateX(100%);
}
@media (max-width: 860px) {
  .article-body-wrap, .article-body-wrap.translation-open { grid-template-columns: 1fr; }
  .article-body-wrap > .article { padding-right: 0; }
  .article-body-wrap > .translation-full { padding-left: 0; }
  .translation-divider { display: none; }
  .article-body-wrap:not(.translation-open) > .translation-full {
    transform: none; opacity: 0;
  }
  .article-body-wrap > .translation-full {
    transition: opacity 250ms ease;
  }
}

/* ── Translation section ────────────────────────────────────────── */
.translation-full {
  margin-top: .5rem;
  padding: 0;
  border: none;
  background: transparent;
}
.article-body-wrap.translation-open .translation-full {
  margin-top: 0;
  padding-top: .85rem;
}
.translation-full-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .5rem;
}
.translation-title { font-size: .95rem; font-weight: 700; margin: 0; color: var(--muted); }
.translation-close-btn {
  width: 1.6rem; height: 1.6rem; border-radius: 6px; padding: 0; flex-shrink: 0;
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.translation-close-btn:hover { background: var(--accent-soft); color: var(--accent); }
.translation-close-btn svg { width: .85rem; height: .85rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.translation-text { font-family: 'Literata', serif; font-size: 1.06rem; line-height: 1.8; color: var(--muted); }
.translation-text p { margin: 0 0 1em; }

/* ── Inline translation (below each paragraph) ─────────────────── */
.translation-inline {
  font-family: 'Literata', serif;
  font-size: .92rem;
  line-height: 1.7;
  color: var(--muted);
  margin: -.5em 0 1em;
  padding-left: .75rem;
  border-left: 2px solid var(--line);
}

/* ── Language menu list ─────────────────────────────────────────── */
.lang-menu-list { display: flex; flex-direction: column; min-width: 180px; padding: .3rem 0; }
.lang-menu-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .85rem; border: none; background: transparent;
  font: inherit; cursor: pointer; text-align: left; width: 100%;
  color: var(--ink); font-size: .9rem;
  transition: background var(--transition);
}
.lang-menu-item:hover { background: var(--accent-soft); }
.lang-menu-item.active { color: var(--accent); font-weight: 700; }
.lang-menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }


/* ── Review tab ─────────────────────────────────────────────────── */
.review-start {
  text-align: center; padding: 2.5rem 1rem;
  display: flex; flex-direction: column; align-items: center; gap: .75rem;
}
.review-start-icon { font-size: 2.5rem; }
.review-complete {
  text-align: center; padding: 2.5rem 1rem;
  display: flex; flex-direction: column; align-items: center; gap: .75rem;
  animation: fadeIn 300ms ease;
}

.review-session-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.review-exit-btn { flex-shrink: 0; }
.review-progress-wrap { display: flex; align-items: center; gap: .5rem; flex: 1; max-width: 240px; }
.review-progress-bar { flex: 1; height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.review-progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }

.review-card {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--surface); padding: 1.5rem 1.2rem; text-align: center;
}
.review-term { font-size: 2rem; font-weight: 800; margin: .75rem 0 1rem; letter-spacing: -.01em; }
.review-meaning { font-size: 1.1rem; margin-bottom: .3rem; font-weight: 600; }
.review-example { margin-top: .25rem; }
.review-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.review-action-btn { display: flex; flex-direction: column; align-items: center; gap: .1rem; min-width: 72px; }
.review-action-again { color: var(--danger); border-color: var(--danger); }
.review-action-again:hover { background: rgba(180,35,24,.07); border-color: var(--danger); color: var(--danger); }
body[data-theme='dark'] .review-action-again:hover { background: rgba(248,113,113,.12); }
.rating-hint { font-size: .72rem; }
.review-term-block { display: flex; flex-direction: column; align-items: center; gap: .4rem; margin: .75rem 0 0; }
.review-term-block .review-term { margin: 0; }
.review-pronunciation { margin: 0; font-size: .9rem; color: var(--muted); font-weight: 500; letter-spacing: .02em; }
.review-term-tools { display: flex; gap: .35rem; }
#revealAnswerBtn { margin-top: 1.2rem; }
.review-prompt { margin: .25rem 0 0; font-size: .82rem; }
.review-explore-link { margin-top: .25rem; font-size: .85rem; }
.review-edit-form {
  margin: .75rem 0; padding: .85rem; border: 1px solid var(--line);
  border-radius: var(--radius-md); background: var(--panel);
  display: flex; flex-direction: column; gap: .5rem; text-align: left;
}
.review-edit-label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; }
.review-edit-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }
.review-vocab-section { padding-top: .25rem; }
.word-audio-btn {
  width: 2rem; height: 2rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background var(--transition), color var(--transition);
}
.word-audio-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.word-audio-btn svg {
  width: .9rem; height: .9rem; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.word-audio-btn.playing { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }

/* ── Library tab ────────────────────────────────────────────────── */
.history-filters { margin-bottom: .75rem; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.library-card {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--panel); overflow: hidden; cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  display: flex; flex-direction: column;
}
.library-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.library-card:focus { outline: 3px solid var(--accent); outline-offset: 2px; }
.library-card-thumb {
  width: 100%; height: 120px; object-fit: cover; display: block;
  background: var(--surface);
}
.library-card-body { padding: .65rem .8rem; flex: 1; display: flex; flex-direction: column; gap: .25rem; }
.library-card-title { font-weight: 700; font-size: .88rem; line-height: 1.3; margin: 0; }
.library-card.is-read { border-left: 3px solid var(--success); }
.library-card.is-read .library-card-title::after { content: ' \2713'; color: var(--success); font-weight: 700; }
.library-card-meta { font-size: .78rem; color: var(--muted); }
.library-card-badges { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; }

/* ── Library article detail ─────────────────────────────────────── */
.library-article-detail { position: relative; }
.back-btn {
  display: inline-flex; align-items: center; gap: .35rem;
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: .9rem; font-weight: 500;
  padding: .35rem 0; margin-bottom: .75rem;
}
.back-btn:hover { text-decoration: underline; }
.back-btn svg { flex-shrink: 0; }

/* ── Vocabulary tab ─────────────────────────────────────────────── */
.vocab-filters { margin-bottom: .75rem; }
.vocab-search { flex: 1; min-width: 150px; }
.vocab-all-list { display: flex; flex-direction: column; gap: 0; }
.vocab-all-card {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .75rem; border-bottom: 1px solid var(--line);
  background: var(--panel);
  transition: background var(--transition);
  cursor: pointer; overflow: hidden; min-width: 0;
}
.vocab-all-card:first-child { border-top: 1px solid var(--line); }
.vocab-all-card:hover { background: var(--accent-soft); }
.vocab-all-card.active { background: var(--accent-soft); }
.vocab-all-term { font-weight: 700; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; max-width: 40%; }
.vocab-all-meaning { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 0; min-width: 0; }
.vocab-all-mastery { flex: 0 0 auto; margin-left: auto; }
.vocab-all-meta { display: none; }
.vocab-all-actions { margin-left: auto; display: flex; gap: .35rem; align-items: center; }
.vocab-empty { color: var(--muted); padding: 1.5rem 0; text-align: center; }

/* ── Vocab explorer layout & edit panel ────────────────────────── */
.vocab-explorer-layout { position: relative; display: flex; gap: 0; min-height: 300px; }
.vocab-explorer-list { flex: 1; min-width: 0; transition: flex var(--transition); }
.vocab-edit-panel {
  position: relative; width: 0; overflow: hidden;
  flex-shrink: 0; border-left: 1px solid transparent;
  transition: width 300ms ease, border-color 300ms ease, opacity 300ms ease;
  opacity: 0;
}
.vocab-edit-panel.open {
  width: 50%; border-left-color: var(--line); opacity: 1;
}
.vocab-edit-panel-inner {
  width: 100%; min-width: 280px;
  padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .75rem;
}
.vocab-edit-header {
  display: flex; align-items: center; justify-content: space-between;
}
.vocab-edit-header h3 { margin: 0; font-size: 1.05rem; }
.vocab-edit-close-btn {
  width: 2rem; height: 2rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.vocab-edit-close-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.vocab-edit-close-btn svg { width: .9rem; height: .9rem; }
.vocab-edit-form { display: flex; flex-direction: column; gap: .6rem; }
.vocab-edit-label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; }
.vocab-edit-label textarea { resize: vertical; }
/* ── Vocab tags ────────────────────────────────────────────────── */
.vocab-tag-chip {
  display: inline-flex; align-items: center; gap: .2rem;
  padding: .1rem .45rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .72rem; border: 1px solid var(--line);
}
.vocab-tag-chip.removable { cursor: default; }
.vocab-tag-remove {
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: .85rem; line-height: 1; padding: 0 .1rem; opacity: .6;
}
.vocab-tag-remove:hover { opacity: 1; }
.vocab-tag-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.vocab-tags-row { display: flex; flex-direction: column; gap: .35rem; }
.vocab-tag-input-row { display: flex; gap: .3rem; }
.vocab-tag-input-row input { flex: 1; font-size: .82rem; padding: .3rem .5rem; }

/* ── Vocab images ──────────────────────────────────────────────── */
.vocab-image-preview { margin: .25rem 0; }
.vocab-image-thumb { max-width: 100%; max-height: 150px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.vocab-image-actions { display: flex; gap: .4rem; }
.review-image-wrap { text-align: center; margin-bottom: .4rem; }
.review-image { max-width: 100%; max-height: 120px; border-radius: var(--radius-sm); }

.vocab-edit-history {
  display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
  font-size: .8rem; margin-top: .25rem;
}
.vocab-history-entry {
  display: inline-flex; gap: .25rem; align-items: center;
  padding: .15rem .4rem; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  font-size: .75rem; text-transform: capitalize;
}
.vocab-edit-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .5rem; gap: .5rem;
}
.vocab-edit-actions-right { display: flex; gap: .5rem; }
.vocab-edit-delete-btn { color: var(--danger); border-color: var(--danger); }
.vocab-edit-delete-btn:hover { background: rgba(180,35,24,0.08); }
body[data-theme='dark'] .vocab-edit-delete-btn:hover { background: rgba(248,113,113,0.12); }

/* ── Confirm dialog ────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.confirm-overlay.open { opacity: 1; pointer-events: auto; }
.confirm-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 1.5rem; min-width: 300px; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.confirm-message { margin: 0 0 1.25rem; font-size: .95rem; line-height: 1.45; }
.confirm-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.danger-btn { background: var(--danger); color: #fff; border-color: var(--danger); }
.danger-btn:hover { background: #a52320; border-color: #a52320; }
body[data-theme='dark'] .danger-btn { background: #dc4843; border-color: #dc4843; }
body[data-theme='dark'] .danger-btn:hover { background: #c63b37; border-color: #c63b37; }

/* ── Progress tab ───────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .65rem; margin-bottom: 1rem; }
.forecast-row { text-align: center; margin-bottom: 1rem; }
.stat-card {
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: 1rem .75rem; border: 1px solid var(--line);
  border-radius: var(--radius-md); background: var(--panel); text-align: center;
}
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-trend { font-size: .72rem; font-weight: 600; }
.stat-trend.trend-up { color: var(--success); }
.stat-trend.trend-down { color: var(--danger); }
.stat-trend.trend-flat { color: var(--muted); }

/* ── Weekly goal + Records row ─────────────────────────────────── */
.progress-row { display: grid; grid-template-columns: auto 1fr; gap: 1rem; margin-bottom: 1rem; align-items: start; }
.weekly-goal-card {
  display: flex; flex-direction: column; align-items: center;
  padding: 1rem; min-width: 140px;
}
.goal-ring-wrapper {
  position: relative; width: 140px; height: 140px;
}
.goal-ring { width: 140px; height: 140px; display: block; }
.goal-ring-bg {
  fill: none; stroke: var(--line); stroke-width: 8;
}
.goal-ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 8;
  stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: center;
  transition: stroke-dashoffset .5s ease;
}
.goal-ring-fill.goal-complete { stroke: var(--success); }
.goal-ring-label {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
.goal-ring-count { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.goal-ring-sub { font-size: .65rem; color: var(--muted); max-width: 70px; line-height: 1.2; }

.records-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .65rem; }
.record-card {
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .85rem .5rem; text-align: center;
}
.record-icon { font-size: 1.3rem; }
.record-value { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.record-label { font-size: .72rem; color: var(--muted); }

/* ── Mastery segments (shared between per-lang and funnel) ────── */
.mastery-seg { min-width: 2px; }
.mastery-seg-new { background: #b0b8c0; }
.mastery-seg-learning { background: #e8a840; }
.mastery-seg-mastered { background: #3aaa60; }
.mastery-seg-tricky { background: #dc5040; }
body[data-theme='dark'] .mastery-seg-new { background: #4a5560; }
body[data-theme='dark'] .mastery-seg-learning { background: #c08030; }
body[data-theme='dark'] .mastery-seg-mastered { background: #2a8a48; }
body[data-theme='dark'] .mastery-seg-tricky { background: #b03838; }

/* ── Mastery funnel ────────────────────────────────────────────── */
.mastery-funnel-section { margin-bottom: 1rem; }
.mastery-funnel-section h3 { margin-bottom: .5rem; }
.mastery-bar-wrap {
  background: var(--line); border-radius: 999px; overflow: hidden; height: 18px;
  margin-bottom: .5rem;
}
.mastery-bar { display: flex; height: 100%; }
.mastery-bar .mastery-seg { transition: width .3s ease; }
.mastery-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.mastery-legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.mastery-legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── Heatmap day popover ──────────────────────────────────────── */
.heatmap-day-popover {
  position: fixed; z-index: 50;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  padding: .6rem .85rem; text-align: center; pointer-events: auto;
  animation: heatmapPopIn .15s ease;
}
.heatmap-day-popover.hidden { display: none; }
@keyframes heatmapPopIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.heatmap-popover-date { font-size: .85rem; font-weight: 700; margin-bottom: .15rem; }
.heatmap-popover-count { font-size: .8rem; color: var(--muted); }

/* ── Achievements gallery ──────────────────────────────────────── */
.achievements-section { margin-bottom: 1rem; }
.achievements-header { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .65rem; }
.achievements-header h3 { margin: 0; }
.achievements-count { font-size: .82rem; }
.achievements-grid { display: flex; flex-direction: column; gap: .75rem; }
.achievement-category-header { font-size: .85rem; font-weight: 600; margin-bottom: .25rem; color: var(--ink); }
.achievements-category-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: .5rem;
}
.achievement-cell {
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
  padding: .5rem .25rem; cursor: pointer; border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.achievement-cell:hover { background: var(--accent-soft); }
.achievement-cell img {
  width: 60px; height: 60px; object-fit: contain;
  transition: transform var(--transition);
}
.achievement-cell:hover img { transform: scale(1.08); }
.achievement-cell-name {
  font-size: .68rem; text-align: center; line-height: 1.2;
  max-height: 2.4em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.achievement-cell.locked .achievement-cell-name { color: var(--muted); }

/* Achievement detail sheet */
.achievement-detail-sheet {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.45); align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s ease;
}
.achievement-detail-sheet.open { display: flex; opacity: 1; }
.achievement-detail-card {
  position: relative; padding: 2rem 1.5rem; text-align: center;
  max-width: 340px; width: 90%;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: achievementDetailIn .3s ease;
}
@keyframes achievementDetailIn {
  from { transform: scale(.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.achievement-detail-close {
  position: absolute; top: .5rem; right: .5rem; font-size: 1.3rem;
  width: 32px; height: 32px; padding: 0; line-height: 32px;
}
.achievement-detail-medal { width: 160px; height: 160px; object-fit: contain; margin-bottom: .75rem; }
.achievement-detail-name { font-size: 1.15rem; font-weight: 700; margin-bottom: .25rem; }
.achievement-detail-desc { font-size: .88rem; color: var(--muted); margin-bottom: .65rem; }
.achievement-detail-tier {
  display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; padding: .2rem .6rem; border-radius: 999px;
}
.tier-bronze { background: rgba(204,128,51,.15); color: #cc8033; }
.tier-silver { background: rgba(191,191,199,.2); color: #8a8a92; }
.tier-gold { background: rgba(237,201,41,.15); color: #b89a10; }
.tier-platinum { background: rgba(153,102,230,.15); color: #9966e6; }
body[data-theme='dark'] .tier-bronze { background: rgba(204,128,51,.25); color: #e0a050; }
body[data-theme='dark'] .tier-silver { background: rgba(191,191,199,.2); color: #bbbbc6; }
body[data-theme='dark'] .tier-gold { background: rgba(237,201,41,.2); color: #edc929; }
body[data-theme='dark'] .tier-platinum { background: rgba(153,102,230,.2); color: #b888f0; }
.achievement-detail-progress {
  margin-top: .65rem; font-size: .82rem; color: var(--muted);
}
.achievement-progress-bar {
  height: 6px; border-radius: 3px; background: var(--line); margin-top: .35rem; overflow: hidden;
}
.achievement-progress-fill {
  height: 100%; border-radius: 3px; transition: width .3s ease;
}

/* Achievement celebration overlay */
.achievement-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.55); align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s ease;
}
.achievement-overlay.open { display: flex; opacity: 1; }
.achievement-overlay.closing { opacity: 0; }
.achievement-card {
  display: flex; flex-direction: column; align-items: center;
  padding: 2rem 1.5rem; text-align: center;
  max-width: 360px; width: 90%;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: celebrationIn .45s cubic-bezier(.34,1.56,.64,1);
  position: relative; z-index: 1;
}
@keyframes celebrationIn {
  from { transform: scale(.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.achievement-card-medal { width: 160px; height: 160px; object-fit: contain; margin-bottom: .75rem; }
.achievement-card-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; margin-bottom: .35rem;
}
.achievement-card-name { font-size: 1.25rem; font-weight: 800; margin-bottom: .25rem; }
.achievement-card-desc { font-size: .88rem; color: var(--muted); margin-bottom: 1rem; }
.achievement-card-btn { min-width: 120px; }

/* Confetti */
.achievement-confetti {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.confetti-particle {
  position: absolute; top: -10px;
  animation: confettiFall 2.5s ease-in forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(720deg); }
}

/* ── Heatmap (grid layout) ─────────────────────────────────────── */
.heatmap-section { margin-top: .5rem; }
.heatmap-section h3 { margin-bottom: .65rem; }
.heatmap-grid-wrap { display: flex; gap: .35rem; }
.heatmap-day-labels {
  display: grid; grid-template-rows: repeat(7, 14px); gap: 3px;
  font-size: .65rem; color: var(--muted); padding-top: 18px;
  text-align: right; min-width: 24px;
}
.heatmap-day-label { display: flex; align-items: center; justify-content: flex-end; }
.heatmap-grid-container { display: flex; flex-direction: column; gap: 3px; overflow-x: auto; }
.heatmap-month-labels {
  display: grid; grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px;
  font-size: .65rem; color: var(--muted); height: 15px;
}
.heatmap-month-label { white-space: nowrap; }
.activity-heatmap-grid {
  display: grid; grid-template-rows: repeat(7, 14px);
  grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px;
}
.heatmap-cell {
  width: 14px; height: 14px; border-radius: 3px;
  background: var(--line); cursor: default;
  transition: transform var(--transition);
}
.heatmap-cell:hover { transform: scale(1.3); }
.heatmap-cell[data-count='0'] { background: var(--line); }
.heatmap-cell[data-count='1'] { background: #c8def0; }
.heatmap-cell[data-count='2'] { background: #8ab8dc; }
.heatmap-cell[data-count='3'] { background: var(--accent); }
.heatmap-cell[data-count='future'] { background: transparent; border: 1px dashed var(--line); }
body[data-theme='dark'] .heatmap-cell[data-count='1'] { background: #1e3a52; }
body[data-theme='dark'] .heatmap-cell[data-count='2'] { background: #2e5a7a; }
body[data-theme='dark'] .heatmap-cell[data-count='3'] { background: var(--accent); }

/* ── Settings tab ───────────────────────────────────────────────── */
.settings-shell { display: grid; grid-template-columns: 170px 1fr; gap: .85rem; }
.settings-nav { display: flex; flex-direction: column; gap: .35rem; }
.settings-link { text-align: left; border-radius: var(--radius-sm); background: transparent; border: 1.5px solid rgba(0,0,0,0.15); }
.settings-link:hover { background: var(--accent-soft); }
.settings-link.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 700; }
.pref-panel { display: none; border: 1.5px solid rgba(0,0,0,0.3); border-radius: var(--radius-md); padding: .85rem; background: transparent; gap: .75rem; }
body[data-theme='dark'] .ghost-btn { border-color: rgba(255,255,255,0.18); }
body[data-theme='dark'] .settings-link { border-color: rgba(255,255,255,0.18); }
body[data-theme='dark'] .pref-panel { border-color: rgba(255,255,255,0.35); }
.pref-panel.active { display: grid; }
.grid-form { display: grid; gap: .75rem; }
.grid-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
.lang-profiles { border: 1.5px solid rgba(0,0,0,0.3); border-radius: var(--radius-md); padding: .7rem; background: transparent; }
body[data-theme='dark'] .lang-profiles { border-color: rgba(255,255,255,0.35); }
.lang-profiles legend { background: transparent; padding: 0 .4rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.language-profile { border: 1.5px dashed rgba(0,0,0,0.3); border-radius: var(--radius-sm); padding: .65rem; margin-bottom: .65rem; background: transparent; cursor: pointer; }
body[data-theme='dark'] .language-profile { border-color: rgba(255,255,255,0.35); }
.language-profile.expanded { cursor: default; border: 2px solid var(--accent); background: var(--accent-soft); }
.profile-summary { display: flex; align-items: center; gap: .6rem; }
.profile-summary-lang { font-weight: 600; }
.profile-summary-text { color: var(--muted); font-size: 0.9rem; }
.language-profile .profile-detail { display: none; }
.language-profile.expanded .profile-summary { display: none; }
.language-profile.expanded .profile-detail { display: block; }
.profile-row { display: grid; grid-template-columns: auto auto 1fr 1fr auto; gap: .5rem; align-items: end; }
.profile-lang-name { align-self: center; font-weight: 600; padding: 0 .25rem; }
.profile-lang-select { align-self: center; font-weight: 600; font-size: .95rem; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); }
.profile-lang-icon { align-self: center; display: flex; align-items: center; justify-content: center; }
.profile-lang-icon .pimochi-icon-md { width: 44px; height: 44px; }
#prefTopics { display: flex; flex-wrap: wrap; gap: .45rem; border: 1px solid var(--line); border-radius: var(--radius-md); padding: .75rem; }
.pref-topic-chip {
  padding: .35rem .75rem; border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-family: inherit; font-size: .85rem;
  color: var(--ink); transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.pref-topic-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.pref-topic-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pref-topic-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Theme picker (Claude-style preview cards) */
.theme-picker { display: flex; gap: .75rem; }
.theme-card {
  display: flex; flex-direction: column; align-items: center; gap: .45rem;
  padding: .45rem; border: 2px solid var(--line); border-radius: var(--radius-md);
  background: transparent; cursor: pointer; font: inherit; color: var(--ink);
  transition: border-color var(--transition);
}
.theme-card:hover { border-color: var(--muted); }
.theme-card.active { border-color: var(--accent); }
.theme-preview {
  width: 120px; height: 72px; border-radius: var(--radius-sm);
  padding: .5rem; display: flex; flex-direction: column; gap: .35rem;
  overflow: hidden;
}
.theme-preview-light { background: #faf9f6; border: 1px solid #e5e4df; }
.theme-preview-light .tp-bar { height: 10px; border-radius: 3px; background: #e0dfda; }
.theme-preview-light .tp-lines span { display: block; height: 5px; border-radius: 2px; background: #d5d4cf; margin-bottom: 3px; }
.theme-preview-light .tp-lines span:last-child { width: 60%; }
.theme-preview-dark { background: #1a1a1a; border: 1px solid #333; }
.theme-preview-dark .tp-bar { height: 10px; border-radius: 3px; background: #555; }
.theme-preview-dark .tp-lines span { display: block; height: 5px; border-radius: 2px; background: #444; margin-bottom: 3px; }
.theme-preview-dark .tp-lines span:last-child { width: 60%; }
.theme-label { font-size: .82rem; font-weight: 600; }

.avatar-preview-wrap { display: flex; align-items: center; gap: .75rem; }
.avatar-preview-circle {
  width: 52px; height: 52px; border-radius: 999px;
  background: var(--ink); color: var(--panel);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.25rem; text-transform: uppercase;
  flex-shrink: 0; background-size: cover; background-position: center;
}
.avatar-preview-img { width: 52px; height: 52px; border-radius: 999px; border: 1px solid var(--line); object-fit: cover; }
.avatar-settings-row { display: flex; align-items: center; gap: .75rem; }
.password-criteria {
  list-style: none; margin: .25rem 0 .5rem; padding: 0;
  display: flex; flex-wrap: wrap; gap: .2rem .75rem; font-size: .82rem; color: var(--muted);
}
.password-criteria li { display: flex; align-items: center; gap: .3rem; }
.password-criteria li::before {
  content: ''; display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--line); flex-shrink: 0; transition: all var(--transition);
}
.password-criteria li.met { color: var(--success); }
.password-criteria li.met::before {
  background: var(--success); border-color: var(--success);
  /* CSS checkmark */
  content: '✓'; color: #fff; font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.password-strength-hint { min-height: 1.1rem; }
.password-strength-hint.weak { color: var(--danger); }
.password-strength-hint.strong { color: var(--success); }
.password-mismatch-hint { min-height: 1.1rem; }
.password-mismatch-hint.danger { color: var(--danger); }
.danger-divider { margin: 2rem 0 1rem; border: none; border-top: 1px solid var(--danger); opacity: 0.3; }
.danger-heading { color: var(--danger); font-size: 1rem; margin: 0 0 0.5rem; }
.delete-account-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { flex: 1; padding-right: 2.5rem; }
.pw-toggle {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: .2rem;
  color: var(--muted); line-height: 1; font-size: 0;
}
.pw-toggle::before {
  content: '';
  display: block; width: 20px; height: 20px;
  background: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}
.pw-toggle.visible::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24'/%3E%3Cline x1='1' y1='1' x2='23' y2='23'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24'/%3E%3Cline x1='1' y1='1' x2='23' y2='23'/%3E%3C/svg%3E");
}
.pw-toggle:hover { color: var(--ink); }

/* ── Word popover ───────────────────────────────────────────────── */
.word-popover {
  position: fixed; z-index: 50;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: .85rem 1rem; max-width: 300px; min-width: 220px;
  animation: fadeIn 120ms ease;
}
.popover-loading { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }
.popover-term-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.word-popover-pronunciation { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .35rem; letter-spacing: .02em; }
.word-popover-pronunciation:empty { display: none; }
.popover-def { margin: 0 0 .3rem; font-weight: 600; }
.popover-ex { margin: 0 0 .65rem; font-style: italic; }
.popover-actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* ── Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 1rem; height: 1rem; border-radius: 999px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: .45rem; pointer-events: none; }
.toast {
  pointer-events: auto; min-width: 220px; max-width: 340px;
  padding: .65rem 1rem; border-radius: var(--radius-md);
  background: var(--ink); color: var(--panel);
  font-size: .875rem; font-weight: 600; box-shadow: var(--shadow-lg);
  animation: slideUp 200ms ease;
  display: flex; align-items: center; gap: .5rem;
}
.toast.toast-success { background: var(--success); color: #fff; }
.toast.toast-error { background: var(--danger); color: #fff; }
body[data-theme='dark'] .toast:not(.toast-success):not(.toast-error) {
  background: #e2e8f0; color: #111518;
}
body[data-theme='dark'] .toast.toast-success { background: #166534; color: #fff; }
body[data-theme='dark'] .toast.toast-error { background: #991b1b; color: #fff; }
.toast.toast-fade { animation: fadeOut 300ms ease forwards; }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(8px); } }

/* ── Auth screen ────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.auth-card { width: min(480px, 96vw); }
.auth-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.auth-form { display: none; flex-direction: column; gap: .65rem; }
.auth-form.active { display: flex; }
.auth-form h2, .auth-form-panel h2 { margin-bottom: .25rem; }
.auth-form label, .auth-form-panel label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
.auth-form-panel { display: flex; flex-direction: column; gap: .65rem; }
.auth-back-link { margin-top: .75rem; }
.offline-banner {
  display: flex; align-items: center; justify-content: center;
  padding: .6rem 1rem; background: var(--warning-bg, #fff3cd);
  color: var(--warning-fg, #856404); border-bottom: 1px solid var(--warning-border, #ffc107);
  font-size: .85rem; font-weight: 500; position: sticky; top: 0; z-index: 50;
}
[data-theme="dark"] .offline-banner { background: #332b00; color: #ffd54f; border-color: #665500; }

.verify-banner {
  display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem;
  background: var(--warning-bg, #fff3cd); color: var(--warning-fg, #856404);
  border-bottom: 1px solid var(--warning-border, #ffc107);
  font-size: .85rem; position: relative; z-index: 10;
}
[data-theme="dark"] .verify-banner { background: #332b00; color: #ffd54f; border-color: #665500; }
.verify-banner .ghost-btn { font-size: .8rem; padding: .2rem .6rem; }
.verify-dismiss { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: inherit; margin-left: auto; padding: .2rem .4rem; opacity: .7; }
.verify-dismiss:hover { opacity: 1; }
.forgot-password-link { display: block; text-align: center; margin-top: .5rem; color: var(--muted); text-decoration: none; }
.forgot-password-link:hover { color: var(--ink); text-decoration: underline; }
.success-text { color: var(--success); }

.oauth-buttons { display: flex; flex-direction: column; gap: .5rem; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.oauth-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.oauth-btn svg { flex-shrink: 0; }
.oauth-divider {
  display: flex; align-items: center; gap: .75rem; margin: .25rem 0;
  color: var(--muted); font-size: .82rem;
}
.oauth-divider::before, .oauth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* ── Landing screen ─────────────────────────────────────────────── */
/* ── Landing page (full-page PoC) ─────────────────────────────── */
.landing { display: block; background: #fafafa; color: #1a1a1a; overflow-y: auto; }
/* ── Landing: Layout ────────────────────────────────────────────── */
.lp-container { max-width: 1080px; margin: 0 auto; padding: 0 1.5rem; }
.lp-accent { color: #e85d3a; }
.lp-accent-underline { text-decoration: underline; text-decoration-color: #e85d3a; text-underline-offset: 4px; text-decoration-thickness: 3px; }

/* ── Landing: Nav ──────────────────────────────────────────────── */
.lp-nav { position: sticky; top: 0; z-index: 100; background: rgba(250,250,250,.92); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(0,0,0,.06); padding: .75rem 0; }
.lp-nav .lp-container { display: flex; align-items: center; justify-content: space-between; }
.lp-brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.1rem; }
.lp-brand-icon { width: 2rem; height: 2rem; object-fit: contain; }
.lp-nav-links { display: flex; align-items: center; gap: 1.5rem; }
.lp-nav-link { font-size: .88rem; font-weight: 600; color: #666; cursor: pointer; transition: color 150ms; background: none; border: none; padding: 0; }
.lp-nav-link:hover { color: #1a1a1a; }

/* ── Landing: Buttons ──────────────────────────────────────────── */
.lp-btn-primary { display: inline-flex; align-items: center; gap: .4rem; background: #e85d3a; color: #fff; border: none; border-radius: 999px; padding: .65rem 1.5rem; font: inherit; font-size: .92rem; font-weight: 700; cursor: pointer; transition: background 150ms, transform 150ms, box-shadow 150ms; box-shadow: 0 2px 8px rgba(232,93,58,.25); }
.lp-btn-primary:hover { background: #d14e2e; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(232,93,58,.3); }
.lp-btn-primary:active { transform: scale(.97); }
.lp-btn-primary:focus-visible, .lp-btn-outline:focus-visible, .lp-nav-link:focus-visible { outline: 2px solid #e85d3a; outline-offset: 2px; }
.lp-btn-lg { font-size: 1.05rem; padding: .75rem 2rem; }
.lp-btn-outline { display: inline-flex; align-items: center; gap: .4rem; background: transparent; color: #1a1a1a; border: 2px solid #d0d0d0; border-radius: 999px; padding: .55rem 1.3rem; font: inherit; font-size: .92rem; font-weight: 700; cursor: pointer; transition: background 150ms, color 150ms, border-color 150ms; }
.lp-btn-outline:hover { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.lp-login-link { display: block; margin-top: 1.25rem; border: 0; background: transparent; color: #888; font: inherit; font-size: .88rem; cursor: pointer; padding: 0; text-align: left; }
.lp-login-link:hover { color: #e85d3a; }

/* ── Landing: Hero ─────────────────────────────────────────────── */
.lp-hero { padding: 7rem 0 4rem; background: linear-gradient(170deg, #fdf6f3 0%, #f5f5f2 60%, #fff 100%); position: relative; overflow: hidden; }
.lp-hero .lp-container { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; align-items: center; position: relative; z-index: 2; }
.lp-hero h1 { font-size: 3.2rem; font-weight: 800; margin-bottom: 1.25rem; line-height: 1.12; margin-top: 0; color: #1a1a1a; }
.lp-hero-sub { color: #555; font-size: 1.08rem; line-height: 1.7; max-width: 440px; margin-bottom: 1.75rem; }
.lp-hero-ctas { display: flex; gap: .85rem; flex-wrap: wrap; }

/* Floating background mascots */
.lp-hero-bg { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.lp-hero-float { position: absolute; opacity: .07; object-fit: contain; animation: lp-drift 8s ease-in-out infinite; }
.lp-hf-1 { width: 120px; top: 8%; left: 2%; animation-delay: 0s; }
.lp-hf-2 { width: 90px; top: 60%; left: 8%; animation-delay: 2s; }
.lp-hf-3 { width: 100px; top: 15%; right: 3%; animation-delay: 4s; }
.lp-hf-4 { width: 80px; bottom: 10%; right: 12%; animation-delay: 6s; }
@keyframes lp-drift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-12px) rotate(3deg); }
}

/* Hero visual: central Pimochi with orbiting language icons */
.lp-hero-visual { position: relative; display: flex; align-items: center; justify-content: center; min-height: 360px; }
.lp-hero-pimochi { width: 200px; height: 200px; object-fit: contain; position: relative; z-index: 2; filter: drop-shadow(0 4px 20px rgba(0,0,0,.08)); }
.lp-hero-orbit { position: absolute; inset: 0; }
.lp-orbit-icon { position: absolute; width: 72px; height: 72px; object-fit: contain; background: #fff; border-radius: 50%; padding: 6px; box-shadow: 0 3px 14px rgba(0,0,0,.08); transition: transform 250ms; }
.lp-orbit-icon:hover { transform: scale(1.15) !important; }
.lp-oi-1 { top: 5%; left: 50%; transform: translateX(-50%); }
.lp-oi-2 { top: 30%; right: 5%; }
.lp-oi-3 { bottom: 10%; right: 15%; }
.lp-oi-4 { bottom: 10%; left: 15%; }
.lp-oi-5 { top: 30%; left: 5%; }
@keyframes lp-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.lp-oi-1 { animation: lp-bob 3s ease-in-out infinite; }
.lp-oi-2 { animation: lp-bob 3.5s ease-in-out .5s infinite; }
.lp-oi-3 { animation: lp-bob 2.8s ease-in-out 1s infinite; }
.lp-oi-4 { animation: lp-bob 3.2s ease-in-out 1.5s infinite; }
.lp-oi-5 { animation: lp-bob 3s ease-in-out 2s infinite; }

/* ── Landing: Topic strip ──────────────────────────────────────── */
.lp-topics { padding: 1rem 0; background: #fff; border-top: 1px solid rgba(0,0,0,.04); border-bottom: 1px solid rgba(0,0,0,.04); overflow: hidden; }
.lp-topics-track { display: flex; align-items: center; gap: .4rem; white-space: nowrap; animation: lp-scroll 30s linear infinite; width: max-content; }
.lp-topics-track img { width: 28px; height: 28px; object-fit: contain; margin-left: 1.5rem; }
.lp-topics-track span { font-size: .82rem; font-weight: 600; color: #888; }
@keyframes lp-scroll { 0% { transform: translateX(0); } 100% { transform: translateX(-50%); } }

/* ── Landing: How It Works ─────────────────────────────────────── */
.lp-how { padding: 5rem 0; background: #fff; }
.lp-how .lp-container { text-align: center; }
.lp-how h2 { font-size: 2rem; font-weight: 800; margin-bottom: .5rem; margin-top: 0; }
.lp-section-sub { color: #888; font-size: 1rem; margin-bottom: 3rem; }
.lp-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; }
.lp-step { text-align: center; }
.lp-step-img-wrap { position: relative; width: 160px; height: 160px; margin: 0 auto 1.25rem; background: #fdf6f3; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.lp-step-ill { width: 110px; height: 110px; object-fit: contain; }
.lp-step-badge { position: absolute; top: 0; right: 8px; width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #e85d3a, #f4845f); color: #fff; font-size: .85rem; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(232,93,58,.3); }
.lp-step h3 { font-size: 1.05rem; font-weight: 800; margin-bottom: .4rem; margin-top: 0; }
.lp-step p { color: #666; font-size: .88rem; max-width: 260px; margin: 0 auto; line-height: 1.55; }

/* ── Landing: Features ─────────────────────────────────────────── */
.lp-features { padding: 5rem 0; background: #faf9f7; }
.lp-features .lp-container { text-align: center; }
.lp-features h2 { font-size: 2rem; font-weight: 800; margin-bottom: .5rem; margin-top: 0; }
.lp-feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; text-align: left; }
.lp-feature-card { background: #fff; border: 1px solid rgba(0,0,0,.06); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; transition: transform 200ms, box-shadow 200ms; }
.lp-feature-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.06); }
.lp-fc-wide { grid-column: 1 / -1; flex-direction: row; }
.lp-feature-ill { width: 100%; height: 180px; object-fit: cover; background: #fdf6f3; display: block; }
.lp-feature-ill-sm { object-fit: contain; padding: 1.5rem; }
.lp-fc-wide .lp-feature-ill { width: 45%; height: auto; min-height: 200px; object-fit: contain; padding: 1.5rem; }
.lp-feature-text { padding: 1.25rem 1.5rem; }
.lp-feature-text h3 { font-size: 1.05rem; font-weight: 800; margin-bottom: .35rem; margin-top: 0; }
.lp-feature-text p { color: #666; font-size: .86rem; margin: 0; line-height: 1.55; }

/* ── Landing: Languages ────────────────────────────────────────── */
.lp-languages { padding: 5rem 0; background: #fff; text-align: center; }
.lp-languages h2 { font-size: 2rem; font-weight: 800; margin-bottom: .5rem; margin-top: 0; }
.lp-lang-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; max-width: 780px; margin: 0 auto; }
.lp-lang-card { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .75rem .5rem; border-radius: 14px; transition: transform 200ms, background 200ms; cursor: default; }
.lp-lang-card:hover { transform: translateY(-4px); background: #fdf3ef; }
.lp-lang-card img { width: 72px; height: 72px; object-fit: contain; transition: transform 200ms; }
.lp-lang-card:hover img { transform: scale(1.1) rotate(-3deg); }
.lp-lang-card span { font-size: .8rem; font-weight: 700; color: #555; }

/* ── Landing: Final CTA ───────────────────────────────────────── */
.lp-final-cta { padding: 5rem 0; background: linear-gradient(135deg, #fdf3ef 0%, #f5eeea 50%, #eee8e4 100%); text-align: center; }
.lp-cta-pimochi { width: 120px; height: 120px; object-fit: contain; margin-bottom: 1rem; }
.lp-final-cta h2 { font-size: 2.2rem; font-weight: 800; margin-bottom: .75rem; margin-top: 0; }
.lp-final-cta p { color: #666; font-size: 1.05rem; margin-bottom: 1.75rem; max-width: 460px; margin-left: auto; margin-right: auto; }

/* ── Landing: Footer ───────────────────────────────────────────── */
.lp-footer { padding: 2rem 0; text-align: center; color: #999; font-size: .82rem; border-top: 1px solid rgba(0,0,0,.06); }

/* ── Landing: Dark theme ───────────────────────────────────────── */
body[data-theme='dark'] .landing { background: #1a1a1a; color: #e5e5e5; }
body[data-theme='dark'] .lp-nav { background: rgba(26,26,26,.92); border-bottom-color: rgba(255,255,255,0.08); }
body[data-theme='dark'] .lp-nav-link { color: #999; }
body[data-theme='dark'] .lp-nav-link:hover { color: #e5e5e5; }
body[data-theme='dark'] .lp-hero { background: linear-gradient(170deg, #231a16 0%, #1a1a1a 60%, #1e1e1e 100%); }
body[data-theme='dark'] .lp-hero h1 { color: #e5e5e5; }
body[data-theme='dark'] .lp-hero-sub { color: #999; }
body[data-theme='dark'] .lp-orbit-icon { background: #2a2a2a; box-shadow: 0 3px 14px rgba(0,0,0,.3); }
body[data-theme='dark'] .lp-btn-outline { color: #e5e5e5; border-color: #555; }
body[data-theme='dark'] .lp-btn-outline:hover { background: #e5e5e5; color: #1a1a1a; border-color: #e5e5e5; }
body[data-theme='dark'] .lp-login-link { color: #999; }
body[data-theme='dark'] .lp-login-link:hover { color: #d4845a; }
body[data-theme='dark'] .lp-topics { background: #222; border-color: rgba(255,255,255,0.04); }
body[data-theme='dark'] .lp-topics-track span { color: #666; }
body[data-theme='dark'] .lp-how { background: #1e1e1e; }
body[data-theme='dark'] .lp-section-sub { color: #777; }
body[data-theme='dark'] .lp-step-img-wrap { background: rgba(232,93,58,.08); }
body[data-theme='dark'] .lp-step p { color: #999; }
body[data-theme='dark'] .lp-features { background: #1a1a1a; }
body[data-theme='dark'] .lp-feature-card { background: #262626; border-color: rgba(255,255,255,0.06); }
body[data-theme='dark'] .lp-feature-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.3); }
body[data-theme='dark'] .lp-feature-ill { background: rgba(232,93,58,.06); }
body[data-theme='dark'] .lp-feature-text p { color: #999; }
body[data-theme='dark'] .lp-languages { background: #1e1e1e; }
body[data-theme='dark'] .lp-lang-card:hover { background: rgba(232,93,58,.1); }
body[data-theme='dark'] .lp-lang-card span { color: #ccc; }
body[data-theme='dark'] .lp-final-cta { background: linear-gradient(135deg, #231a16 0%, #1e1e1e 100%); }
body[data-theme='dark'] .lp-final-cta p { color: #999; }
body[data-theme='dark'] .lp-footer { color: #666; border-top-color: rgba(255,255,255,0.06); }

/* ── Landing: Responsive ───────────────────────────────────────── */
@media (max-width: 860px) {
  .lp-hero .lp-container { grid-template-columns: 1fr; text-align: center; }
  .lp-hero h1 { font-size: 2.4rem; }
  .lp-hero-sub { margin-left: auto; margin-right: auto; }
  .lp-hero-ctas { justify-content: center; }
  .lp-login-link { text-align: center; }
  .lp-hero-visual { min-height: 280px; }
  .lp-hero-float { display: none; }
  .lp-steps { grid-template-columns: 1fr; gap: 2.5rem; }
  .lp-feature-grid { grid-template-columns: 1fr; }
  .lp-fc-wide { flex-direction: column; }
  .lp-fc-wide .lp-feature-ill { width: 100%; min-height: 160px; }
  .lp-lang-grid { grid-template-columns: repeat(4, 1fr); }
  .lp-nav-links .lp-nav-link { display: none; }
}
@media (max-width: 480px) {
  .lp-hero h1 { font-size: 1.9rem; }
  .lp-hero { padding: 6rem 0 3rem; }
  .lp-hero-visual { min-height: 240px; }
  .lp-hero-pimochi { width: 140px; height: 140px; }
  .lp-orbit-icon { width: 56px; height: 56px; }
  .lp-lang-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Onboarding ─────────────────────────────────────────────────── */
.onboarding-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(20,28,38,.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  backdrop-filter: blur(4px); animation: fadeIn 180ms ease;
}
body[data-theme='dark'] .onboarding-overlay { background: rgba(0,0,0,.65); }
.onboarding-card { width: min(520px, 96vw); max-height: 92vh; overflow-y: auto; }
.onboarding-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.onboarding-brand { display: flex; align-items: center; gap: .45rem; }
.onboarding-steps { display: flex; gap: .4rem; align-items: center; }
.step-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--line); transition: background var(--transition), width var(--transition); }
.step-dot.active { background: var(--accent); width: 20px; }

.onboarding-step { display: none; flex-direction: column; gap: 1rem; }
.onboarding-step.active { display: flex; }
.onboarding-step h2 { margin: 0; }

.language-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; max-height: 340px; overflow-y: auto; }
.language-tile {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: .6rem .4rem; border: 2px solid var(--line); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600;
  font-family: inherit; transition: border-color var(--transition), background var(--transition);
}
.language-tile .pimochi-icon-md { width: 44px; height: 44px; }
.language-tile span { font-size: .78rem; }
.language-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.language-tile.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.language-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.level-tiles { display: flex; flex-direction: column; gap: .45rem; }
.level-tile {
  display: flex; align-items: center; gap: .85rem; padding: .7rem .9rem;
  border: 2px solid var(--line); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink); cursor: pointer; font-family: inherit; text-align: left;
  transition: border-color var(--transition), background var(--transition);
}
.level-tile strong { font-size: 1rem; min-width: 28px; color: var(--accent); }
.level-tile span { font-size: .87rem; color: var(--muted); }
.level-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.level-tile.selected { border-color: var(--accent); background: var(--accent-soft); }
.level-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topic-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.topic-chip {
  padding: .45rem .9rem; border: 2px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); cursor: pointer; font-family: inherit; font-size: .88rem;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.topic-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.topic-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.topic-chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.ob-form { display: flex; flex-direction: column; gap: .65rem; }
.ob-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
.onboarding-footer { margin-top: 1rem; display: flex; justify-content: flex-start; }

.ob-generate-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .75rem; padding: 2rem 0; }
.ob-generate-state h2 { margin: 0; }

.ob-spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: ob-spin 0.8s linear infinite;
}
@keyframes ob-spin { to { transform: rotate(360deg); } }

.ob-success-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--success); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem; font-weight: 700;
  animation: ob-pop 0.35s ease-out;
}
@keyframes ob-pop { 0% { transform: scale(0); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ── Feature tour ──────────────────────────────────────────────── */
.tour-backdrop {
  position: fixed; inset: 0; z-index: 9998;
  background: transparent;
  transition: opacity 0.2s ease;
}
.tour-spotlight {
  position: fixed; z-index: 9999;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  pointer-events: auto;
  cursor: pointer;
  transition: top 0.3s ease, left 0.3s ease, width 0.3s ease, height 0.3s ease;
}
.tour-tooltip {
  position: fixed; z-index: 10000;
  background: var(--panel); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 1rem 1.25rem;
  animation: tour-fade-in 0.2s ease-out;
}
@keyframes tour-fade-in { from { opacity: 0; } to { opacity: 1; } }
.tour-tooltip-title { font-weight: 700; font-size: 1rem; margin-bottom: .25rem; }
.tour-tooltip-text { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.tour-tooltip-footer { display: flex; justify-content: space-between; align-items: center; margin-top: .75rem; }
.tour-tooltip-actions { display: flex; gap: .5rem; align-items: center; }
.tour-counter { color: var(--muted); font-size: .8rem; }
.tour-next-btn.small { padding: .35rem 1rem; font-size: .85rem; }
.tour-skip-btn.small { padding: .35rem .75rem; font-size: .85rem; }

/* ── Mobile nav ─────────────────────────────────────────────────── */
.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--panel); border-top: 1px solid var(--line);
  padding: .4rem .25rem calc(.4rem + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
body[data-theme='dark'] .mobile-nav { box-shadow: 0 -4px 16px rgba(0,0,0,.30); }
.mobile-nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: .35rem .2rem; border: 0; background: transparent; color: var(--muted);
  font-family: inherit; font-size: .68rem; cursor: pointer;
  transition: color var(--transition);
}
.mobile-nav-btn svg {
  width: 1.2rem; height: 1.2rem; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.mobile-nav-btn.active { color: var(--accent); }
.mobile-nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .shell { height: auto; overflow: visible; }
  .app-main { height: auto; overflow-y: visible; }
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  .tab-panel { margin-bottom: 5rem; }

  .landing-headline { font-size: 1.9rem; }

  .settings-shell { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; }
  .profile-row { grid-template-columns: 1fr; }
  .library-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .progress-row { grid-template-columns: 1fr; }
  .records-grid { grid-template-columns: repeat(3, 1fr); }

  .vocab-explorer-layout { flex-direction: column; }
  .vocab-edit-panel {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    width: 0; z-index: 40; background: var(--panel);
    border-left: none; overflow-y: auto;
  }
  .vocab-edit-panel.open { width: 100%; }
  .vocab-edit-panel-inner { min-width: unset; padding: 1.25rem; }
  .article-meta-row { flex-direction: column; align-items: flex-start; }

  .toast-container { bottom: 5.5rem; right: .75rem; left: .75rem; }
  .toast { max-width: 100%; }
}

@media (min-width: 721px) and (max-width: 980px) {
  .shell { grid-template-columns: 72px 1fr; }
  .shell .nav-label { opacity: 0; width: 0; overflow: hidden; }
  .shell .tab { padding: .5rem .8rem; }
  .shell .sf-btn { padding: .45rem .5rem; }
  .shell .sidebar-dropdown { left: 100%; bottom: 0; margin-left: .35rem; }
  .shell #sidebarToggleBtn { display: none; }
}

/* ── Comprehension Questions ─────────────────────────────────────── */
.comprehension-section {
  margin-top: 1.5rem;
  padding: 0 0.25rem;
}
.comprehension-start-btn {
  width: 100%;
  padding: 0.85rem 1.25rem;
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.comprehension-start-btn:hover {
  background: var(--accent);
  color: #fff;
}
.comprehension-body {
  margin-top: 1rem;
}
.comprehension-question {
  margin-bottom: 1.25rem;
}
.comprehension-question-text {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  line-height: 1.5;
}
.comprehension-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.comprehension-option {
  text-align: start;
  padding: 0.6rem 0.85rem;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.comprehension-option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.comprehension-option:disabled {
  cursor: default;
  opacity: 0.85;
}
.comprehension-option.correct {
  border-color: var(--success);
  background: rgba(26,127,75,0.1);
  color: var(--ink);
  opacity: 1;
}
.comprehension-option.wrong {
  border-color: var(--danger);
  background: rgba(180,35,24,0.08);
  color: var(--ink);
  opacity: 1;
}
body[data-theme='dark'] .comprehension-option.correct {
  background: rgba(74,222,128,0.12);
}
body[data-theme='dark'] .comprehension-option.wrong {
  background: rgba(248,113,113,0.12);
}
.comprehension-explanation {
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.75rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}
.comprehension-result {
  text-align: center;
  margin-top: 1rem;
  padding: 1rem;
}
.comprehension-result h3 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}
.comprehension-result .muted {
  margin: 0;
}
.comprehension-retake-btn {
  margin-top: 0.75rem;
  padding: 0.5rem 1.5rem;
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.comprehension-retake-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Feedback emoji row (used in settings panel) ─────────────── */
.feedback-emoji-row {
  display: flex; justify-content: center; gap: .5rem; margin-bottom: .5rem;
}
.feedback-emoji-btn {
  width: 48px; height: 48px; font-size: 1.6rem;
  background: var(--surface); border: 2px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.feedback-emoji-btn:hover { transform: scale(1.12); }
.feedback-emoji-btn.selected { border-color: var(--accent); background: var(--accent-soft); }

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

/* Pimochi mascot images */
.pimochi-icon-sm { width: 28px; height: 28px; object-fit: contain; vertical-align: middle; }
.pimochi-icon-md { width: 80px; height: 80px; object-fit: contain; }
.pimochi-icon-lg { width: 200px; height: 200px; object-fit: contain; margin: 0 auto 1rem; display: block; }

/* Pack card row — horizontal scrollable article cards */
.pack-card-row {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  padding: .5rem 0 .75rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.pack-card {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  cursor: pointer;
  font-size: .82rem;
  max-width: 200px;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pack-card:hover { border-color: var(--accent); }
.pack-card.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pack-card .pack-card-title { overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.pack-card .pack-card-status { font-size: .7rem; color: var(--muted); }
.pack-card .pack-card-check { color: var(--success, #3a8a4a); font-size: .85rem; flex-shrink: 0; }
.pack-card-gen {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .75rem;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  cursor: pointer;
  font-size: .82rem;
  color: var(--accent);
  font-weight: 600;
  transition: background .15s, opacity .15s;
}
.pack-card-gen:hover { background: var(--accent); color: #fff; }
.pack-card-gen:disabled { opacity: .4; cursor: not-allowed; }
.pack-card-gen .gen-remaining { font-size: .7rem; color: var(--muted); font-weight: 400; }
.pack-card-generating {
  border-style: dashed;
  border-color: var(--accent);
  animation: card-pulse 1.5s ease-in-out infinite;
}
.pack-card-generating .pack-card-title { color: var(--muted); font-style: italic; }
@keyframes card-pulse { 0%, 100% { opacity: .5; } 50% { opacity: .9; } }

/* Mark as Read button */
.mark-read-section { text-align: center; padding: 2rem 0; }
.mark-read-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 2rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.mark-read-btn:hover { opacity: .85; }
.mark-read-btn:disabled { opacity: .5; cursor: default; }
.mark-read-btn.is-read {
  background: var(--success, #3a8a4a);
  cursor: default;
  opacity: .8;
}
