:root {
  --bg: #102135;
  --card: rgba(255, 255, 255, 0.84);
  --glass: rgba(255, 255, 255, 0.72);
  --ink: #0b1220;
  --muted: #667085;
  --accent: #059669;
  --accent-2: #0284c7;
  --border: rgba(255, 255, 255, 0.35);
  --shadow: 0 16px 50px rgba(15, 23, 42, 0.25);
  --radius: 14px;
  --radius-lg: 20px;
  --font-body: 'M PLUS Rounded 1c', 'Hiragino Sans', 'BIZ UDPGothic', system-ui, sans-serif;
  --font-serif: 'Source Serif 4', 'Yu Mincho', 'Hiragino Mincho ProN', serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  position: relative;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px at 10% 10%, rgba(2, 132, 199, 0.22), transparent),
    radial-gradient(900px at 80% 18%, rgba(5, 150, 105, 0.22), transparent),
    radial-gradient(700px at 50% 90%, rgba(255, 255, 255, 0.08), transparent),
    linear-gradient(180deg, #e7f6f1 0%, #f8fafc 42%, #dbeafe 100%);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 22px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 800;
  display: grid;
  place-items: center;
  letter-spacing: 0.5px;
}

.brand-title {
  font-weight: 700;
  font-size: 18px;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.top-actions .pill {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
}

.view { display: none; }
.view.active { display: block; }

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: center;
}

h1 {
  margin: 4px 0 12px;
  font-size: 34px;
  font-weight: 800;
  color: var(--ink);
}

h2 {
  margin: 8px 0 10px;
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 6px;
  font-weight: 700;
}

.lede {
  color: #334155;
  line-height: 1.6;
  margin: 0 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(8px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-weight: 700;
  color: #111827;
}

.field input,
.field select {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 15px;
  background: white;
}

.field small {
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.stat {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

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

.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
}

.reset-row { margin-top: 4px; }

.btn {
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  background: #e2e8f0;
  color: #0f172a;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #10b981);
  color: white;
  box-shadow: 0 10px 25px rgba(5, 150, 105, 0.35);
}

.btn.secondary {
  background: linear-gradient(135deg, var(--accent-2), #38bdf8);
  color: white;
}

.btn.ghost {
  background: transparent;
  border: 1px solid #cbd5e1;
  box-shadow: none;
}

.note {
  color: #475569;
  font-size: 14px;
  margin-top: 6px;
}

.note.error { color: #b91c1c; }

.panel {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.panel.center { text-align: center; }

.mode-list {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.flow-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 18px;
}

.flow-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #dbe2ec;
  background: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.flow-option input {
  width: 18px;
  height: 18px;
}

.practice-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid #dbe2ec;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.section-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.section-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}

.section-desc {
  color: var(--muted);
  line-height: 1.5;
}

.range-summary {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #dbe2ec;
  background: rgba(255, 255, 255, 0.82);
  line-height: 1.65;
  color: #0f172a;
}

.mode-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
}

.mode-option input {
  width: 18px;
  height: 18px;
}

.mode-title { font-weight: 800; }

.mode-desc {
  color: var(--muted);
  font-size: 14px;
}

.weak-score-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.weak-score-filter-row select {
  flex: 1;
  min-width: 0;
}

.resume {
  border: 1px dashed #94a3b8;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.7);
}

.resume-title { font-weight: 800; }

.resume-state {
  color: #dc2626;
  font-weight: 800;
}

.resume-desc {
  color: var(--muted);
  line-height: 1.5;
}

.study-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.learn-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.learn-image-wrap {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid #dbe2ec;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
}

.learn-image-label {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 10px;
}

.learn-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 250px);
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.learn-image-missing {
  padding: 12px 0 4px;
  color: #b91c1c;
  font-weight: 700;
}

.badge {
  background: rgba(2, 132, 199, 0.16);
  color: #0284c7;
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 700;
}

.progress {
  margin-left: auto;
  font-weight: 800;
  color: #0f172a;
}

.timer {
  margin: 10px 0 14px;
}

.timer-label {
  font-weight: 700;
  color: #0f172a;
}

.timer-bar {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.timer-bar div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.1s linear;
}

.card.focus {
  padding: 20px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title {
  color: var(--muted);
  letter-spacing: 0.08em;
  font-size: 13px;
}

.question {
  font-family: var(--font-serif);
  font-size: 23px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.65;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice-list[hidden] {
  display: none;
}

.choice-option {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.88);
  color: #0f172a;
  font-size: 16px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease, background-color 0.15s ease;
}

.choice-option:hover {
  transform: translateY(-1px);
  border-color: #94a3b8;
}

.choice-option:disabled {
  cursor: default;
  opacity: 1;
}

.choice-option.correct {
  border-color: #16a34a;
  background: rgba(34, 197, 94, 0.12);
}

.choice-option.wrong {
  border-color: #dc2626;
  background: rgba(248, 113, 113, 0.14);
}

.choice-option.reveal {
  border-color: #0284c7;
  background: rgba(2, 132, 199, 0.12);
}

.answer-feedback {
  min-height: 24px;
  font-weight: 800;
  line-height: 1.5;
}

.answer-feedback.correct {
  color: #15803d;
}

.answer-feedback.wrong {
  color: #b91c1c;
}

.answer {
  font-size: 20px;
  color: #1f2937;
  background: rgba(2, 132, 199, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 48px;
  white-space: pre-wrap;
  line-height: 1.6;
}

.answer.hidden {
  color: transparent;
  background: rgba(15, 23, 42, 0.04);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.05);
  text-shadow: none;
}

.study-actions { margin-top: 14px; }

#revealAnswer,
#choiceNext,
#nextCard,
#markWeak {
  min-width: 440px;
  min-height: 112px;
  padding: 32px 36px;
  font-size: 20px;
  font-weight: 800;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 12px 0 18px;
}

.summary-item {
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.summary-label { color: var(--muted); }

.summary-value {
  font-size: 28px;
  font-weight: 800;
}

.review {
  text-align: left;
  margin-top: 18px;
}

.review-title {
  font-weight: 800;
  margin-bottom: 10px;
  color: #0f172a;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 6px;
}

.review-item {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 164px 10px 12px;
  background: rgba(255, 255, 255, 0.7);
  position: relative;
  cursor: pointer;
}

.review-item:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.review-q {
  font-family: var(--font-serif);
  font-weight: 700;
  color: #0f172a;
  line-height: 1.6;
}

.review-a {
  color: #1f2937;
  margin-top: 4px;
  white-space: pre-wrap;
  line-height: 1.6;
}

.review-a.hidden,
.review-q.hidden { display: none; }

.review-tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 6px;
}

.review-tag.ok {
  background: rgba(34, 197, 94, 0.18);
  color: #15803d;
}

.review-tag.ng {
  background: rgba(248, 113, 113, 0.18);
  color: #b91c1c;
}

.review-weak-score {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  margin: -2px 0 6px;
}

.review-actions {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.review-explain {
  min-width: 64px;
  padding: 6px 10px;
  font-size: 13px;
}

.review-explain-plus {
  min-width: 72px;
}

.explain-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1400;
}

.explain-modal.show { display: flex; }

.explain-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
}

.explain-dialog {
  position: relative;
  z-index: 1;
  width: min(99vw, 1500px);
  max-height: 98vh;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #dbe2ec;
  box-shadow: 0 30px 90px rgba(2, 6, 23, 0.34);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.explain-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.explain-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}

.explain-close { flex-shrink: 0; }

.explain-view {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  min-height: 240px;
  max-height: calc(98vh - 72px);
  overflow: auto;
}

.explain-body {
  padding: 12px;
  color: #0f172a;
  white-space: pre-wrap;
  line-height: 1.7;
}

.explain-body.is-gallery {
  white-space: normal;
}

.explain-gallery-note {
  margin-bottom: 14px;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
}

.explain-image-list {
  display: grid;
  gap: 16px;
}

.explain-image-card {
  background: #fff;
  border: 1px solid #dbe2ec;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.explain-image-label {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 10px;
}

.explain-gallery-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(98vh - 170px);
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
}

.explain-image-missing {
  color: #b91c1c;
  font-weight: 700;
}

body.modal-open { overflow: hidden; }

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: rgba(15, 23, 42, 0.92);
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 320px;
  pointer-events: none;
  z-index: 4;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.sp-only { display: none; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .app-shell { padding: 20px 18px 56px; }
  .sp-only { display: inline; }
  h1 { font-size: 28px; }
  .question { font-size: 20px; }
  .study-actions {
    position: fixed;
    bottom: 18px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 3;
  }
  #revealAnswer,
  #choiceNext,
  #nextCard,
  #markWeak {
    min-width: 520px;
    min-height: 144px;
    padding: 40px 42px;
    font-size: 22px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.18);
  }
  #stopSession {
    position: fixed;
    bottom: 18px;
    left: 16px;
    right: auto;
    min-width: 180px;
    min-height: 64px;
    padding: 18px 20px;
    font-size: 17px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
  }
  .app-shell { padding-bottom: 160px; }
}

@media (max-width: 540px) {
  .topbar { flex-direction: column; gap: 10px; align-items: flex-start; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .study-actions { flex-direction: column; align-items: center; }
  .button-row { width: 100%; }
  .button-row .btn { flex: 1; width: 100%; text-align: center; }
  .flow-option { align-items: flex-start; }
  .review-item { padding-right: 12px; padding-bottom: 54px; }
  .review-actions { left: 12px; right: auto; bottom: 10px; }
  .explain-dialog { width: 96vw; padding: 10px; }
  .explain-title { font-size: 16px; }
  .learn-image { max-height: calc(100vh - 220px); }
  .explain-gallery-image { max-height: calc(98vh - 140px); }
}
