:root {
  --bg: #0f172a;
  --card: rgba(255, 255, 255, 0.84);
  --glass: rgba(255, 255, 255, 0.72);
  --ink: #0b1220;
  --muted: #667085;
  --accent: #f97316;
  --accent-2: #0ea5e9;
  --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(14, 165, 233, 0.25), transparent),
              radial-gradient(900px at 80% 20%, rgba(249, 115, 22, 0.28), transparent),
              radial-gradient(700px at 50% 90%, rgba(255, 255, 255, 0.08), transparent),
              linear-gradient(180deg, #e2ecff 0%, #f8fafc 40%, #e5e7eb 100%);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  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 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), #fb923c); color: white; box-shadow: 0 10px 25px rgba(249, 115, 22, 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; }

.sync-block { margin: 12px 0; padding: 10px; border: 1px dashed #cbd5e1; border-radius: 12px; background: rgba(255,255,255,0.6); }
.sync-title { font-weight: 800; margin-bottom: 6px; color: #0f172a; }
.sync-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.sync-status { font-size: 13px; color: #0f172a; margin-bottom: 4px; }

.mode-list { display: grid; gap: 10px; margin: 14px 0; }
.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; }

.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-desc { color: var(--muted); }

.study-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.badge { background: rgba(14, 165, 233, 0.16); color: #0ea5e9; 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: 26px; font-weight: 700; color: var(--ink); }
.answer { font-size: 20px; color: #1f2937; background: rgba(14, 165, 233, 0.08); border-radius: 10px; padding: 10px 12px; min-height: 48px; }
.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; }
#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 12px; background: rgba(255,255,255,0.7); }
.review-q { font-family: var(--font-serif); font-weight: 700; color: #0f172a; }
.review-a { color: #1f2937; margin-top: 4px; }
.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; }

.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; }
  .study-actions {
    position: fixed;
    bottom: 18px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 3;
  }
  #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; }
}
