:root {
  --bg: #0d0d14;
  --surface: #16161f;
  --card: #1e1e2b;
  --card-hover: #252535;
  --border: #2a2a3a;
  --primary: #e8505b;
  --primary-dim: #e8505b33;
  --secondary: #4ecdc4;
  --secondary-dim: #4ecdc433;
  --gold: #f0b429;
  --gold-dim: #f0b42933;
  --text: #e8e4f0;
  --text-muted: #7b7394;
  --text-dim: #4a4660;
  --success: #4ecdc4;
  --danger: #e8505b;
  --warning: #f0b429;
  --radius: 14px;
  --radius-sm: 8px;
  --nav-height: 72px;
  --header-height: 56px;
  --font-jp: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

html, body {
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== Header ===== */

.app-header {
  height: calc(var(--header-height) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-header h1 span {
  color: var(--primary);
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.header-btn:hover {
  color: var(--text);
  background: var(--card);
}

/* ===== Main Content ===== */

.app-content {
  flex: 1;
  padding: 20px;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px);
  overflow-y: auto;
}

/* ===== Bottom Nav ===== */

.app-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  z-index: 100;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color 0.2s;
  text-transform: uppercase;
  position: relative;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item:hover {
  color: var(--text-muted);
}

.nav-item.active:hover {
  color: var(--primary);
}

.nav-icon {
  width: 24px;
  height: 24px;
}

.nav-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--primary);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===== Dashboard ===== */

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat-value.primary { color: var(--primary); }
.stat-value.secondary { color: var(--secondary); }
.stat-value.gold { color: var(--gold); }

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.action-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  color: var(--text);
  text-align: left;
}

.action-btn:hover {
  background: var(--card-hover);
  border-color: var(--text-dim);
}

.action-btn:active {
  transform: scale(0.98);
}

.action-btn .action-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.action-btn .action-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.action-btn .action-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.action-btn.primary-action {
  border-color: var(--primary-dim);
  background: var(--primary-dim);
}

.action-btn.primary-action:hover {
  background: #e8505b44;
}

/* ===== Section Headers ===== */

.section-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
  margin-top: 8px;
}

/* ===== Progress Bar ===== */

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.progress-fill.primary { background: var(--primary); }
.progress-fill.secondary { background: var(--secondary); }
.progress-fill.gold { background: var(--gold); }

/* ===== Block List ===== */

.block-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.block-item:hover {
  background: var(--card-hover);
}

.block-item.locked {
  opacity: 0.4;
  cursor: default;
}

.block-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-dim);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.block-item.locked .block-num {
  background: var(--border);
  color: var(--text-dim);
}

.block-item.completed .block-num {
  background: var(--secondary-dim);
  color: var(--secondary);
}

.block-info {
  flex: 1;
  min-width: 0;
}

.block-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.block-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Flashcard ===== */

.flashcard-container {
  perspective: 1200px;
  margin: 16px 0;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: 280px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}

.flashcard-back {
  transform: rotateY(180deg);
}

.flashcard-english {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.flashcard-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.flashcard-japanese {
  font-family: var(--font-jp);
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

.flashcard-romaji {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.flashcard-english-back {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 8px;
}

.audio-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin: 12px 0;
}

.audio-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}

.audio-btn:hover {
  background: var(--primary);
  color: white;
}

.audio-btn:active {
  transform: scale(0.92);
}

.audio-btn-slow {
  width: 44px;
  height: 44px;
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-dim);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.audio-btn-slow:hover {
  background: var(--gold);
  color: var(--bg);
}

/* ===== Review Rating Buttons ===== */

.rating-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.rating-btn {
  padding: 14px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-align: center;
}

.rating-btn:active {
  transform: scale(0.95);
}

.rating-btn:nth-child(1) { border-color: #e8505b55; }
.rating-btn:nth-child(1):hover { background: #e8505b33; }
.rating-btn:nth-child(2) { border-color: #f0b42955; }
.rating-btn:nth-child(2):hover { background: #f0b42933; }
.rating-btn:nth-child(3) { border-color: #4ecdc455; }
.rating-btn:nth-child(3):hover { background: #4ecdc433; }
.rating-btn:nth-child(4) { border-color: #a78bfa55; }
.rating-btn:nth-child(4):hover { background: #a78bfa33; }

.rating-label {
  display: block;
  margin-bottom: 2px;
}

.rating-interval {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ===== Review/Quiz Session Bar ===== */

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.session-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.session-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* ===== Quiz Timer ===== */

.quiz-timer {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  margin: 16px auto;
  transition: border-color 0.3s, color 0.3s;
}

.quiz-timer.urgent {
  border-color: var(--danger);
  color: var(--danger);
}

.quiz-result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--card);
}

.quiz-result-row.correct {
  border-left: 3px solid var(--secondary);
}

.quiz-result-row.wrong {
  border-left: 3px solid var(--danger);
}

/* ===== Eval ===== */

.eval-score-display {
  text-align: center;
  padding: 32px 0;
}

.eval-score-number {
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
}

.eval-score-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.eval-delta {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 8px;
}

.eval-delta.up { color: var(--secondary); }
.eval-delta.down { color: var(--danger); }

/* ===== Progress Charts ===== */

.chart-container {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-bottom: 20px;
  position: relative;
}

.bar-chart::after {
  content: '';
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.bar {
  width: 100%;
  max-width: 32px;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
  transition: height 0.5s ease;
  min-height: 2px;
}

.bar-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  position: absolute;
  bottom: -18px;
}

.bar-value {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== Settings ===== */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.setting-label {
  font-size: 0.9rem;
  font-weight: 500;
}

.setting-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-input {
  width: 64px;
  padding: 6px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}

.toggle {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.toggle.on {
  background: var(--primary);
}

.toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.toggle.on::after {
  transform: translateX(20px);
}

/* ===== Buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: #d4444e;
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--card-hover);
}

.btn-ghost {
  background: none;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--card);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1rem;
}

/* ===== Empty States ===== */

.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.empty-state-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* ===== Week Indicator ===== */

.week-banner {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  border-left: 3px solid var(--primary);
}

.week-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.week-value {
  font-size: 1.3rem;
  font-weight: 800;
  margin-top: 2px;
}

.week-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Learn View ===== */

.learn-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.card-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 8px;
}

/* ===== Toast ===== */

.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Phonetic Pronunciation ===== */

.phonetic-text {
  font-size: 1.05rem;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
  font-style: italic;
}

.phonetic-inline {
  color: var(--gold);
  font-size: 0.72rem;
  font-style: italic;
  opacity: 0.85;
}

/* ===== Pill Buttons (inline actions) ===== */

.btn-pill {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-pill:active {
  transform: scale(0.95);
}

.btn-pill-danger {
  color: var(--danger);
  border-color: var(--primary-dim);
}

.btn-pill-danger:hover {
  background: var(--primary-dim);
}

.btn-pill-add {
  color: var(--secondary);
  border-color: var(--secondary-dim);
}

.btn-pill-add:hover {
  background: var(--secondary-dim);
}

/* ===== Animations ===== */

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

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

.fade-in {
  animation: fadeIn 0.25s ease;
}

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

.slide-up {
  animation: slideUp 0.35s ease;
}

/* ===== Responsive ===== */

@media (min-width: 520px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (max-width: 360px) {
  .stat-row {
    grid-template-columns: 1fr 1fr;
  }
  .rating-buttons {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===== Scrollbar ===== */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ===== Utility ===== */

.mt-8  { margin-top:  8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom:  8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-dim    { color: var(--text-dim); }
.text-sm     { font-size: 0.85rem; }
.text-xs     { font-size: 0.75rem; }
.font-bold   { font-weight: 700; }
.gap-8  { gap: 8px; }
.gap-16 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ===== Install (Add to Home Screen) ===== */

.install-card {
  background: var(--primary-dim);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  cursor: pointer;
}

.install-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.install-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.install-sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(5, 5, 10, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.install-sheet[hidden] {
  display: none;
}

.install-sheet-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px 18px;
  animation: slideUp 0.35s ease;
}

.install-sheet-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-jp);
  font-size: 2rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #e8505b, #b82e48);
}

.install-sheet-card h2 {
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.install-sheet-card > p {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.install-steps {
  padding-left: 20px;
  margin-bottom: 20px;
  color: var(--text);
}

.install-steps li {
  margin-bottom: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.ios-share-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: -3px;
  color: var(--secondary);
}

@media (display-mode: standalone) {
  .install-card {
    display: none;
  }
}
