:root {
  color-scheme: light;
  --navy: #102a43;
  --ink: #243b53;
  --muted: #627d98;
  --paper: #f7f9fb;
  --white: #ffffff;
  --line: #d9e2ec;
  --teal: #2a9d8f;
  --orange: #e76f51;
  --gold: #e9c46a;
  --blue: #486581;
  --shadow: 0 12px 32px rgba(16, 42, 67, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.shell { min-height: 100vh; padding-bottom: 82px; }

.topbar {
  align-items: center;
  background: var(--navy);
  color: var(--white);
  display: flex;
  justify-content: space-between;
  padding: 18px 20px 20px;
}

.topbar h1 { font-size: 20px; letter-spacing: 0.02em; margin: 2px 0 0; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; margin: 0; text-transform: uppercase; }
.topbar .eyebrow { color: #9fb3c8; }
.muted { color: var(--muted); }

.sync-pill, .tag {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  font-size: 12px;
  padding: 6px 9px;
}

.sync-pill[data-state="online"] { background: rgba(42, 157, 143, 0.2); border-color: rgba(42, 157, 143, 0.6); }
.sync-pill[data-state="error"] { background: rgba(231, 111, 81, 0.2); border-color: rgba(231, 111, 81, 0.6); }

.app { margin: 0 auto; max-width: 1120px; padding: 24px 18px; }
.view { animation: rise 180ms ease-out; }
.hidden { display: none !important; }

.welcome {
  background: #e9f5f3;
  border-left: 4px solid var(--teal);
  border-radius: 6px;
  padding: 22px;
}

h2, h3 { color: var(--navy); margin: 5px 0 0; }
h2 { font-size: clamp(26px, 5vw, 38px); letter-spacing: -0.02em; }
h3 { font-size: 18px; }
.welcome p { line-height: 1.65; max-width: 560px; }

.primary-button, .secondary-button, .reveal-button {
  border: 0;
  border-radius: 5px;
  font-weight: 800;
  padding: 12px 16px;
}

.primary-button { background: var(--navy); color: var(--white); margin-top: 8px; }
.secondary-button { background: #e8eef4; color: var(--navy); }
.reveal-button { background: #e8eef4; color: var(--navy); width: 100%; }
.primary-button:hover, .secondary-button:hover, .reveal-button:hover { filter: brightness(0.97); }

.stat-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); margin: 16px 0 30px; }
.stat-card { background: var(--white); border-top: 3px solid var(--blue); box-shadow: var(--shadow); padding: 14px; }
.stat-card span, .stat-card small { color: var(--muted); display: block; font-size: 12px; }
.stat-card strong { color: var(--navy); display: block; font-size: 29px; line-height: 1.1; margin: 8px 0 4px; }
.accent-teal { border-color: var(--teal); }
.accent-orange { border-color: var(--orange); }
.accent-gold { border-color: var(--gold); }

.section-heading, .view-header { align-items: end; display: flex; justify-content: space-between; margin: 24px 0 12px; }
.text-button { background: transparent; border: 0; color: var(--teal); font-weight: 800; padding: 8px 0; }
.unit-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
.unit-card { background: var(--white); border: 1px solid var(--line); padding: 14px; text-align: left; }
.unit-card strong { color: var(--navy); display: block; font-size: 16px; }
.unit-card span { color: var(--muted); display: block; font-size: 12px; margin-top: 7px; }

.progress-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.review-card { background: var(--white); box-shadow: var(--shadow); margin: 20px auto 0; max-width: 680px; padding: 20px; }
.card-meta { align-items: center; display: flex; gap: 7px; }
.card-meta .icon-button { margin-left: auto; }
.tag { background: #f0f4f8; border: 0; color: var(--navy); display: inline-block; font-weight: 800; }
.tag-quiet { background: #f0f4f8; color: var(--muted); }
.icon-button, .small-icon-button { background: #edf7f5; border: 0; border-radius: 50%; color: var(--teal); height: 34px; width: 34px; }
.small-icon-button { height: 28px; width: 28px; }
.review-term { padding: 34px 0 26px; text-align: center; }
.review-term h3 { font-size: clamp(42px, 12vw, 72px); letter-spacing: 0.04em; margin: 0; }
.review-term p { color: var(--orange); font-size: 20px; margin: 8px 0 0; }
.review-details { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.meaning-row { align-items: center; display: flex; gap: 9px; padding: 8px 0; }
.meaning-row strong { color: var(--navy); flex: 1; font-size: 18px; }
.language-label { color: var(--muted); font-size: 12px; width: 54px; }
.example-block { background: #f7f9fb; margin-top: 12px; padding: 13px; }
.example-line { align-items: start; display: flex; gap: 8px; }
.example-line p { color: var(--navy); flex: 1; font-size: 17px; line-height: 1.55; margin: 0; }
.example-block .muted { font-size: 14px; margin: 7px 0 0; }
.review-actions { display: grid; gap: 8px; grid-template-columns: repeat(2, 1fr); margin-top: 18px; }
.review-button { background: var(--white); border: 1px solid var(--line); border-radius: 5px; color: var(--ink); font-weight: 800; padding: 12px 8px; }
.review-button:hover { border-color: var(--teal); color: var(--teal); }
.review-button.again { border-bottom: 3px solid var(--orange); }
.review-button.hard { border-bottom: 3px solid var(--gold); }
.review-button.good { border-bottom: 3px solid var(--teal); }
.review-button.easy { border-bottom: 3px solid var(--blue); }

.stack-list, .library-list { display: grid; gap: 10px; }
.grammar-card, .library-item { background: var(--white); border: 1px solid var(--line); padding: 15px; }
.grammar-card header, .library-item header { align-items: start; display: flex; gap: 10px; justify-content: space-between; }
.grammar-card h3, .library-item h3 { margin: 0; }
.grammar-card .meaning, .library-item .meaning { color: var(--orange); font-weight: 800; margin: 7px 0; }
.grammar-card p, .library-item p { line-height: 1.55; margin: 5px 0 0; }
.library-item .kana { color: var(--orange); font-size: 13px; }
.item-actions { display: flex; gap: 6px; }

.filter-bar { display: grid; gap: 8px; grid-template-columns: 1fr auto auto; margin-bottom: 14px; }
.search-field input, .filter-bar select { background: var(--white); border: 1px solid var(--line); border-radius: 4px; color: var(--ink); min-height: 42px; padding: 9px 11px; width: 100%; }
.filter-button { background: var(--white); border: 1px solid var(--line); border-radius: 4px; color: var(--muted); padding: 0 12px; }
.filter-button[data-active="true"] { background: #e9f5f3; border-color: var(--teal); color: var(--teal); }
.empty-state { background: var(--white); border: 1px dashed var(--line); padding: 28px; text-align: center; }
.empty-state strong { color: var(--navy); display: block; font-size: 18px; }
.empty-state p { color: var(--muted); margin: 8px 0 18px; }

.bottom-nav { background: rgba(255, 255, 255, 0.97); border-top: 1px solid var(--line); bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); left: 0; position: fixed; right: 0; z-index: 5; }
.nav-button { background: transparent; border: 0; color: var(--muted); display: grid; gap: 3px; justify-items: center; padding: 10px 5px 9px; }
.nav-button span { font-size: 19px; line-height: 1; }
.nav-button small { font-size: 11px; }
.nav-button.active { color: var(--teal); }
.toast { background: var(--navy); border-radius: 4px; bottom: 88px; color: var(--white); left: 50%; opacity: 0; padding: 10px 13px; pointer-events: none; position: fixed; transform: translate(-50%, 10px); transition: 160ms ease; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sr-only { clip: rect(0, 0, 0, 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }

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

@media (min-width: 760px) {
  .shell { padding-bottom: 0; }
  .topbar { padding-left: max(28px, calc((100vw - 1084px) / 2)); padding-right: max(28px, calc((100vw - 1084px) / 2)); }
  .app { padding: 42px 28px 56px; }
  .bottom-nav { border: 1px solid var(--line); border-radius: 6px; bottom: 20px; left: auto; margin-right: 20px; right: 20px; width: 360px; }
  .unit-grid { grid-template-columns: repeat(4, 1fr); }
  .review-actions { grid-template-columns: repeat(4, 1fr); }
}
