/* IELTS Coach — design system. Calm SaaS: white surfaces, slate text, one indigo accent, light borders. */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;
  --brand-border: #c7d2fe;
  --text: #111827;
  --muted: #6b7280;
  --soft: #94a3b8;
  --border: #e8eef5;
  --border-strong: #cbd5e1;
  --good: #15803d;
  --good-soft: #ecfdf3;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --warn: #92400e;
  --warn-soft: #fff7ed;
  --shadow-card: 0 1px 4px rgba(15, 23, 42, 0.035);
  --shadow-hover: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-pop: 0 12px 40px rgba(15, 23, 42, 0.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --topbar: 64px;
  --tabbar: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-x: none; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
h4 { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem; }
p { margin: 0 0 0.75rem; }
p:last-child { margin-bottom: 0; }
small, .muted { color: var(--muted); }
.soft { color: var(--soft); }
.tiny { font-size: 0.8rem; }
code, pre { font-family: var(--mono); font-size: 0.9em; }
pre { white-space: pre-wrap; background: var(--surface-soft); padding: 0.75rem 0.9rem; border-radius: var(--radius-md); border: 1px solid var(--border); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
ul, ol { padding-left: 1.2rem; margin: 0 0 0.75rem; }
li { margin-bottom: 0.3rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--brand-soft); }

/* ---------- App shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#topbar { position: sticky; top: 0; z-index: 40; height: var(--topbar); background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 1px 8px rgba(15, 23, 42, 0.04); }
.topbar-inner { max-width: 1120px; margin: 0 auto; height: 100%; padding: 0 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 0.95rem; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 0.72rem; margin-top: -2px; }
#nav { display: flex; align-items: center; gap: 2px; margin-left: 8px; }
#nav a { padding: 8px 12px; border-radius: var(--radius-md); color: var(--muted); font-weight: 500; font-size: 0.92rem; display: inline-flex; align-items: center; gap: 7px; }
#nav a:hover { background: var(--surface-soft); color: var(--text); }
#nav a.active { color: var(--brand); background: var(--brand-soft); }
#nav a .ico { width: 17px; height: 17px; display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#streak-badge { font-size: 0.85rem; color: var(--muted); padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); white-space: nowrap; }
#streak-badge:empty { display: none; }
.icon-btn { width: 38px; height: 38px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); color: var(--muted); display: inline-grid; place-items: center; padding: 0; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn .ico { width: 18px; height: 18px; }
#view { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 28px 24px 56px; }
#tabbar { display: none; }
.ico { display: inline-block; width: 18px; height: 18px; flex: none; vertical-align: middle; line-height: 0; }
.ico svg { width: 100%; height: 100%; display: block; }

@media (max-width: 860px) {
  :root { --topbar: 54px; }
  .topbar-inner { padding: 0 16px; }
  #nav, .topbar-right #streak-badge { display: none; }
  #view { padding: 16px 16px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }
  #tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); }
  #tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 0.66rem; font-weight: 500; color: var(--soft); }
  #tabbar a .ico { width: 22px; height: 22px; }
  #tabbar a.active { color: var(--brand); }
  h1 { font-size: 1.3rem; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom on focus */
}

/* ---------- Layout helpers ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: 4px 0 0; max-width: 60ch; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .cols-3, .cols-4 { grid-template-columns: 1fr 1fr; } .cols-2 { grid-template-columns: 1fr; } .cols-2.keep { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .cols-3, .cols-4 { grid-template-columns: 1fr; } .cols-4.keep, .cols-3.keep, .cols-2.keep { grid-template-columns: 1fr 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 16px; } .mb-s { margin-bottom: 8px; }
.center { text-align: center; } .right { text-align: right; }
.hide { display: none !important; }
.grow { flex: 1; min-width: 0; }
.wrap { overflow-wrap: anywhere; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 18px 20px; }
.card.soft { background: var(--surface-soft); box-shadow: none; }
.card.good { background: var(--good-soft); border-color: #bbf7d0; box-shadow: none; }
.card.bad { background: var(--bad-soft); border-color: #fecaca; box-shadow: none; }
.card.warn { background: var(--warn-soft); border-color: #fed7aa; box-shadow: none; }
.card.tight { padding: 14px 16px; }
.card > h3 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.section-title { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }
@media (max-width: 860px) { .card { padding: 16px; border-radius: 14px; } }

/* ---------- Buttons ---------- */
.btn, button.btn, button:not(.plain) { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 14px; border-radius: var(--radius-md); border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.92rem; line-height: 1.2; transition: background .15s, border-color .15s, color .15s; white-space: nowrap; }
button:not(.plain):hover, .btn:hover { border-color: var(--soft); background: #fafbfd; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary, button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.primary:hover, button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.ghost, button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.ghost:hover, button.ghost:hover { background: var(--surface-soft); color: var(--text); border-color: transparent; }
.danger, button.danger { color: var(--bad); }
.big, button.big { min-height: 48px; padding: 10px 20px; font-size: 1rem; }
.small, button.small { min-height: 32px; padding: 4px 10px; font-size: 0.82rem; border-width: 1px; }
.block { width: 100%; }
.btn .ico, button .ico { width: 17px; height: 17px; }
button.plain { border: 0; background: none; padding: 0; }
button.rec { width: 88px; height: 88px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); color: var(--text); font-weight: 600; font-size: 0.85rem; display: inline-grid; place-items: center; gap: 2px; transition: transform .1s; }
button.rec .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--bad); display: block; }
button.rec.on { border-color: var(--bad); box-shadow: 0 0 0 6px var(--bad-soft); animation: pulse 1.4s infinite; }
button.rec.on .dot { border-radius: 5px; }
button.rec:active { transform: scale(0.97); }
@keyframes pulse { 0% { box-shadow: 0 0 0 4px var(--bad-soft); } 50% { box-shadow: 0 0 0 12px rgba(185, 28, 28, 0.08); } 100% { box-shadow: 0 0 0 4px var(--bad-soft); } }

/* ---------- Forms ---------- */
input, select, textarea { width: 100%; background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius-md); padding: 9px 12px; color: var(--text); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=checkbox] { width: 20px; height: 20px; padding: 0; accent-color: var(--brand); }
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
textarea.essay { min-height: 420px; font-size: 1rem; line-height: 1.7; }
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; }
.field { margin-bottom: 14px; }
.field small { display: block; margin-top: 4px; }
.seg { display: inline-flex; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 3px; gap: 2px; flex-wrap: wrap; max-width: 100%; }
.seg button { border: 0; background: transparent; color: var(--muted); min-height: 34px; padding: 6px 12px; font-weight: 500; border-radius: 8px; }
.seg button:hover { background: transparent; color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs button { border: 0; background: none; border-radius: 0; color: var(--muted); font-weight: 500; padding: 10px 14px; min-height: 42px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { background: none; color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.choice { display: grid; gap: 10px; }
.choice .opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-md); cursor: pointer; background: var(--surface); }
.choice .opt.active { border-color: var(--brand); background: var(--brand-soft); }
.choice .opt b { display: block; font-size: 0.95rem; }
.choice .opt span { color: var(--muted); font-size: 0.85rem; }
.choice .opt .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; margin-top: 2px; }
.choice .opt.active .radio { border-color: var(--brand); background: radial-gradient(var(--brand) 45%, transparent 50%); }

/* ---------- Tags / status ---------- */
.tag { display: inline-block; font-size: 0.74rem; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-sm); background: var(--surface-soft); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }
.pill { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--soft); }
.quote { background: var(--bad-soft); color: #7f1d1d; padding: 1px 5px; border-radius: 4px; }
.fix { background: var(--good-soft); color: #14532d; padding: 1px 5px; border-radius: 4px; }

/* ---------- Stats / bands ---------- */
.band { font-size: 2.4rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.band.small { font-size: 1.5rem; }
.band.brand { color: var(--brand); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 0.82rem; }
.stat .s { color: var(--soft); font-size: 0.78rem; }
.crit { border-left: 3px solid var(--border-strong); }
.crit.b8 { border-left-color: var(--good); } .crit.b7 { border-left-color: var(--soft); } .crit.b6 { border-left-color: #fca5a5; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.35rem; letter-spacing: -0.01em; }
.timer.low { color: var(--bad); }
.progress { height: 6px; background: var(--surface-soft); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); transition: width .3s; border-radius: 999px; }
.meter { display: flex; align-items: center; gap: 10px; }
.meter .progress { flex: 1; }
.ring { position: relative; width: 84px; height: 84px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .v { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; letter-spacing: -0.02em; }

/* ---------- Lists & tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
.list > * + * { border-top: 1px solid var(--border); }
.item { padding: 12px 0; display: flex; gap: 12px; align-items: center; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.item.link { cursor: pointer; }
.item.link:hover .title { color: var(--brand); }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; }
.check input[type=checkbox] { flex: none; margin-top: 3px; }
.check.done .t { text-decoration: line-through; color: var(--soft); }
details > summary { cursor: pointer; font-weight: 600; padding: 6px 0; color: var(--muted); font-size: 0.9rem; list-style: none; }
details > summary::before { content: '▸ '; color: var(--soft); }
details[open] > summary::before { content: '▾ '; }
.chev { color: var(--soft); flex: none; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ico { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--soft); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, var(--surface-soft) 25%, #e9eef4 37%, var(--surface-soft) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-md); height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- Content blocks ---------- */
.prompt-box { white-space: pre-wrap; background: var(--surface-soft); border: 1px solid var(--border); padding: 14px 16px; border-radius: var(--radius-md); font-size: 0.98rem; line-height: 1.6; }
.svgwrap { background: #fff; border-radius: var(--radius-md); padding: 8px; overflow: auto; border: 1px solid var(--border); }
.svgwrap svg { display: block; margin: 0 auto; }
.cue { border: 1.5px solid var(--brand-border); background: var(--brand-soft); border-radius: var(--radius-lg); padding: 16px 18px; text-align: left; }
.cue .bigq { font-size: 1.15rem; font-weight: 600; }
.examiner-line { font-size: 1.12rem; line-height: 1.5; padding: 16px 18px; background: var(--surface-soft); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.bigq { font-size: 1.2rem; font-weight: 600; line-height: 1.4; }
.essay-text { white-space: pre-wrap; line-height: 1.75; }
.diffcols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .diffcols { grid-template-columns: 1fr; } }
.sticky-top { position: sticky; top: var(--topbar); z-index: 20; background: var(--bg); padding: 6px 0 10px; margin-top: -6px; }
.flash { min-height: 240px; display: flex; flex-direction: column; justify-content: center; text-align: center; cursor: pointer; font-size: 1.1rem; user-select: none; }
.flash .front { font-size: 1.3rem; font-weight: 600; }
.flash .back { text-align: left; font-size: 0.98rem; }
.speech { display: grid; gap: 8px; }
.speech .turn { padding: 10px 14px; border-radius: var(--radius-md); background: var(--surface-soft); border: 1px solid var(--border); }
.speech .turn b { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.level { display: flex; align-items: flex-end; gap: 3px; height: 40px; }
.level i { width: 5px; background: var(--brand); border-radius: 2px; opacity: 0.85; }
.resource { display: flex; gap: 12px; padding: 12px 0; align-items: flex-start; }
.chartline { width: 100%; height: 170px; }
.tile { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card); }
.tile .ico { width: 22px; height: 22px; color: var(--brand); flex: none; }
.tile b { display: block; font-size: 0.92rem; }
.tile span { color: var(--muted); font-size: 0.8rem; }
.kbd { font-size: 0.78rem; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: grid; place-items: center; z-index: 100; padding: 16px; backdrop-filter: blur(2px); }
.overlay .card { max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-pop); }
@media (max-width: 640px) {
  .overlay { place-items: end center; padding: 0; }
  .overlay .card { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .overlay .card::before { content: ''; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: -6px auto 14px; }
}
.overlay.full { background: var(--bg); backdrop-filter: none; place-items: center; padding: 16px; }
.overlay.full .card { border-radius: var(--radius-lg); max-width: 400px; }
.overlay.full .card::before { display: none; }
#toasts { position: fixed; top: calc(var(--topbar) + 10px); right: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; align-items: center; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: var(--radius-md); box-shadow: var(--shadow-pop); max-width: 520px; font-size: 0.92rem; }
.toast.err { background: var(--bad); }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.sheet-list a { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-radius: var(--radius-md); font-weight: 500; }
.sheet-list a .ico { width: 20px; height: 20px; color: var(--muted); }
.sheet-list a:hover { background: var(--surface-soft); }
.sheet-list a.active { color: var(--brand); }

/* ---------- Focus mode (speaking test) ---------- */
.focus { max-width: 640px; margin: 0 auto; }
.focus .status-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.focus .rec-area { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px 0 8px; }

/* Two-column setup layout: main form + side notes; stacks on phones. */
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
button.drill-btn { justify-content: flex-start; text-align: left; white-space: normal; font-weight: 500; }
button, .btn { max-width: 100%; }
