/* ============================
   DESIGN SYSTEM
   ============================ */
:root {
  /* Colors */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-glass: rgba(22, 33, 62, 0.7);
  --text-primary: #e8e8f0;
  --text-secondary: #9a9ab0;
  --accent: #00d4ff;
  --accent-glow: rgba(0, 212, 255, 0.25);
  --green: #00e676;
  --green-deep: #1b5e20;
  --green-light: #66bb6a;
  --yellow: #ffc107;
  --red: #ff5252;
  --red-deep: #b71c1c;
  --correct-bg: rgba(0, 230, 118, 0.12);
  --incorrect-bg: rgba(255, 82, 82, 0.12);

  /* Typography */
  --font: 'Noto Sans JP', sans-serif;

  /* Spacing */
  --gap: 16px;
  --radius: 16px;
  --radius-sm: 10px;

  /* Transition */
  --speed: 0.3s;
}

/* ============================
   RESET & BASE
   ============================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--gap);
  position: relative;
}

/* ============================
   PAGE TRANSITIONS
   ============================ */
.page {
  display: none;
  animation: fadeSlideIn 0.35s ease forwards;
  padding-bottom: 40px;
}

.page.active {
  display: block;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================
   HOME
   ============================ */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}

.hero-title {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.hero-title .accent {
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* Topic Grid */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  margin-bottom: 24px;
}

.topic-grid .topic-card:last-child {
  grid-column: 1 / -1;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 22px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform var(--speed), box-shadow var(--speed), border-color var(--speed);
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--font);
  color: var(--text-primary);
  font-size: 1rem;
}

.topic-card:hover, .topic-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 28px var(--accent-glow);
  border-color: var(--accent);
  outline: none;
}

.topic-card:active {
  transform: scale(0.97);
}

.topic-icon {
  font-size: 2rem;
  line-height: 1;
}

.topic-label {
  font-weight: 700;
  font-size: 1.05rem;
}

.topic-acc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.05);
  padding: 2px 10px;
  border-radius: 20px;
}

/* Stats Button */
.btn-stats {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--speed), border-color var(--speed);
}

.btn-stats:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

/* ============================
   QUIZ
   ============================ */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 12px;
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
}

.btn-back:hover { text-decoration: underline; }

.quiz-topic-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.06);
  padding: 4px 14px;
  border-radius: 20px;
}

.quiz-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Question Card */
.question-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 28px 22px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-text {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.85;
  text-align: center;
}

/* Answer Buttons */
.answer-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.btn-answer {
  padding: 20px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: 2rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  font-family: var(--font);
}

.btn-answer:active { transform: scale(0.93); }

.btn-maru {
  background: rgba(0, 230, 118, 0.1);
  color: var(--green);
  border-color: rgba(0, 230, 118, 0.25);
}

.btn-maru:hover {
  box-shadow: 0 0 20px rgba(0, 230, 118, 0.25);
  border-color: var(--green);
}

.btn-batsu {
  background: rgba(255, 82, 82, 0.1);
  color: var(--red);
  border-color: rgba(255, 82, 82, 0.25);
}

.btn-batsu:hover {
  box-shadow: 0 0 20px rgba(255, 82, 82, 0.25);
  border-color: var(--red);
}

.btn-answer:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Result Area */
.result-area {
  animation: fadeSlideIn 0.3s ease;
}

.result-area.hidden { display: none; }

.result-badge {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.result-badge.correct {
  background: var(--correct-bg);
  color: var(--green);
}

.result-badge.incorrect {
  background: var(--incorrect-bg);
  color: var(--red);
}

.explanation-box {
  background: var(--bg-secondary);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 16px 18px;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.btn-next {
  display: block;
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 1.05rem;
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
  transition: opacity var(--speed), transform 0.15s;
}

.btn-next:hover { opacity: 0.9; }
.btn-next:active { transform: scale(0.97); }

/* ============================
   STATS
   ============================ */
.stats-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 16px;
}

.stats-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.stats-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Heatmap */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 700;
  font-size: 0.8rem;
  transition: transform var(--speed);
}

.heatmap-cell:hover { transform: scale(1.06); }

.heatmap-cell .hm-icon { font-size: 1.3rem; }
.heatmap-cell .hm-pct  { font-size: 1rem; font-weight: 900; }
.heatmap-cell .hm-lbl  { font-size: 0.65rem; opacity: 0.8; }

.heatmap-cell.level-red    { background: rgba(255, 82, 82, 0.3); color: var(--red); }
.heatmap-cell.level-yellow { background: rgba(255, 193, 7, 0.25); color: var(--yellow); }
.heatmap-cell.level-lgreen { background: rgba(102, 187, 106, 0.25); color: var(--green-light); }
.heatmap-cell.level-dgreen { background: rgba(0, 230, 118, 0.3); color: var(--green); }
.heatmap-cell.level-none   { background: rgba(255,255,255,0.05); color: var(--text-secondary); }

/* Stats Detail */
.stats-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-row {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-row .stat-icon { font-size: 1.5rem; }

.stat-row .stat-info {
  flex: 1;
}

.stat-row .stat-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.stat-row .stat-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-row .stat-pct {
  font-size: 1.3rem;
  font-weight: 900;
}

/* Progress bar */
.stat-bar-wrapper {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.stat-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* Loading */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.loading-spinner::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Utility */
.hidden { display: none !important; }
