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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2e3a;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --vocab: #3b82f6;
  --grammar: #a855f7;
  --kanji: #f97316;
  --grade-0: #ef4444;
  --grade-1: #f97316;
  --grade-2: #eab308;
  --grade-3: #84cc16;
  --grade-4: #22c55e;
  --grade-5: #06b6d4;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: "Inter", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Dashboard */
.app-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-top: 20px;
}

.app-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

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

.stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stats-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.stats-detail h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.detail-row:last-child {
  border-bottom: none;
}

.stages {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.stages h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stage-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.btn-start {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-start:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-start:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Flashcard View */
.flashcard-header {
  margin-bottom: 16px;
  position: relative;
}

.progress-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.btn-back-arrow {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  position: absolute;
  left: 16px;
}

.btn-back-arrow:hover {
  color: var(--text);
  border-color: var(--primary);
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

.card-badges {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-vocabulary {
  background: rgba(59, 130, 246, 0.15);
  color: var(--vocab);
}

.badge-grammar {
  background: rgba(168, 85, 247, 0.15);
  color: var(--grammar);
}

.badge-kanji {
  background: rgba(249, 115, 22, 0.15);
  color: var(--kanji);
}

.badge-card-type {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.flashcard {
  perspective: 1000px;
  min-height: 240px;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 240px;
  transition: transform 0.5s ease, height 0.4s ease;
  transform-style: preserve-3d;
}

.flashcard:hover .flashcard-inner {
  box-shadow: 0 0 0 1px var(--primary);
  border-radius: var(--radius);
}

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

.flashcard-front,
.flashcard-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
}

.flashcard-front {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
  word-break: keep-all;
}

.flashcard-back {
  transform: rotateY(180deg);
  font-size: 15px;
  line-height: 1.7;
}

.back-field {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.back-field:last-child {
  border-bottom: none;
}

.back-field-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.back-field-value {
  font-size: 15px;
}

.back-field-value.jp {
  font-family: "Noto Sans JP", sans-serif;
  font-size: 20px;
  font-weight: 500;
}

.flip-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
  transition: opacity 0.15s;
}

.flip-hint.hidden {
  opacity: 0;
}

.grade-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.grade-buttons.visible {
  opacity: 1;
  pointer-events: auto;
}

.grade-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.grade-btn:hover {
  transform: translateY(-1px);
}

.grade-btn:active {
  transform: translateY(0);
}

.grade-key {
  font-size: 18px;
  font-weight: 700;
}

.grade-label {
  font-size: 11px;
  color: var(--text-muted);
}

.grade-0 { border-color: var(--grade-0); }
.grade-0:hover { background: rgba(239, 68, 68, 0.15); }
.grade-0 .grade-key { color: var(--grade-0); }

.grade-1 { border-color: var(--grade-1); }
.grade-1:hover { background: rgba(249, 115, 22, 0.15); }
.grade-1 .grade-key { color: var(--grade-1); }

.grade-2 { border-color: var(--grade-2); }
.grade-2:hover { background: rgba(234, 179, 8, 0.15); }
.grade-2 .grade-key { color: var(--grade-2); }

.grade-3 { border-color: var(--grade-3); }
.grade-3:hover { background: rgba(132, 204, 22, 0.15); }
.grade-3 .grade-key { color: var(--grade-3); }

.grade-4 { border-color: var(--grade-4); }
.grade-4:hover { background: rgba(34, 197, 94, 0.15); }
.grade-4 .grade-key { color: var(--grade-4); }

.grade-5 { border-color: var(--grade-5); }
.grade-5:hover { background: rgba(6, 182, 212, 0.15); }
.grade-5 .grade-key { color: var(--grade-5); }

/* Complete View */
.complete-icon {
  font-size: 64px;
  text-align: center;
  color: var(--grade-4);
  margin-top: 60px;
  margin-bottom: 16px;
}

#view-complete h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 32px;
}

.complete-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.complete-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
}

.complete-value {
  font-size: 28px;
  font-weight: 700;
  display: block;
}

.complete-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

/* Loading state */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.loading::after {
  content: "";
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Grade button disabled during API call */
.grade-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Responsive */
@media (min-width: 640px) {
  .container {
    padding: 32px 20px;
  }

  .flashcard-inner {
    min-height: 300px;
  }

  .flashcard-front {
    font-size: 44px;
  }

  .grade-buttons {
    grid-template-columns: repeat(6, 1fr);
  }
}
