:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #1d2a3a;
  --muted: #64748b;
  --line: #dbe3ee;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --orange: #ea8a0c;
  --orange-soft: #fff1d6;
  --purple: #7c3aed;
  --purple-soft: #f1e9ff;
  --radius: 1.1rem;
  --head: 'Baloo 2', 'Noto Sans Devanagari', system-ui, sans-serif;
  --read: 'Noto Sans', 'Noto Sans Devanagari', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: clamp(14px, 1.05vw + 6px, 22px); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--head); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* top bar */
.top { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 1.2rem; background: linear-gradient(90deg, #1e40af, #2563eb 60%, #3b82f6); color: #fff; position: sticky; top: 0; z-index: 5; }
.top .logo { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.02em; }
.top .logo small { display: block; font-size: 0.8rem; font-weight: 600; opacity: 0.85; margin-top: -0.3rem; }
.top .sp { flex: 1; }
.top .who { font-size: 0.95rem; opacity: 0.95; text-align: right; }
.top button { background: rgba(255,255,255,0.16); border: 0.12rem solid rgba(255,255,255,0.45); color: #fff; border-radius: 0.8rem; padding: 0.3rem 0.9rem; font-weight: 700; }
.top button:hover { background: rgba(255,255,255,0.28); }

main { max-width: 78rem; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
h1, h2, h3 { margin: 0.2rem 0 0.6rem; line-height: 1.2; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.25rem; }
p { margin: 0.3rem 0 0.8rem; }
.muted { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); border: 0.1rem solid var(--line); box-shadow: 0 0.3rem 1rem rgba(30,64,175,0.06); padding: 1.2rem 1.4rem; margin-bottom: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; }

/* buttons */
.btn { border: 0; border-radius: 0.9rem; padding: 0.6rem 1.3rem; font-weight: 800; font-size: 1.05rem; background: var(--blue); color: #fff; box-shadow: 0 0.2rem 0 rgba(0,0,0,0.15); transition: transform 0.08s; }
.btn:active { transform: translateY(0.12rem); box-shadow: none; }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.orange { background: var(--orange); }
.btn.purple { background: var(--purple); }
.btn.ghost { background: #fff; color: var(--blue); border: 0.13rem solid var(--blue); box-shadow: none; }
.btn.big { font-size: 1.4rem; padding: 0.8rem 1.8rem; border-radius: 1.1rem; }
.btn.small { font-size: 0.9rem; padding: 0.3rem 0.8rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* home */
.hero { text-align: center; padding: 1.4rem 0 0.6rem; }
.hero h1 { font-size: 2.4rem; color: #1e3a8a; }
.hero p { font-size: 1.15rem; color: var(--muted); max-width: 46rem; margin: 0 auto 1rem; }
.choose { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1.4rem; max-width: 60rem; margin: 1rem auto; }
.choose button { background: #fff; border: 0.18rem solid var(--line); border-radius: 1.5rem; padding: 1.8rem 1.2rem; text-align: center; transition: transform 0.12s, border-color 0.12s; }
.choose button:hover { transform: translateY(-0.2rem); border-color: var(--blue); }
.choose .ic { font-size: 4rem; display: block; }
.choose b { font-size: 1.7rem; display: block; margin: 0.3rem 0; }
.choose span { color: var(--muted); font-size: 1rem; }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.8rem; max-width: 60rem; margin: 1.6rem auto 0; }
.how div { background: #fff; border-radius: 1rem; padding: 0.8rem 1rem; border: 0.1rem dashed var(--line); font-size: 0.98rem; }
.how b { display: block; font-size: 1.1rem; }

/* forms */
label.f { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 700; font-size: 0.95rem; }
input.in, select.in, textarea.in { border: 0.13rem solid var(--line); border-radius: 0.7rem; padding: 0.5rem 0.7rem; background: #fff; font-family: var(--read); font-size: 1.05rem; min-width: 0; }
input.in:focus, select.in:focus, textarea.in:focus { outline: none; border-color: var(--blue); }
.err-msg { color: var(--red); font-weight: 700; min-height: 1.3rem; }

/* pills */
.pills { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.pill { border: 0.15rem solid var(--line); background: #fff; border-radius: 999px; padding: 0.5rem 1.2rem; font-weight: 800; font-size: 1.15rem; }
.pill.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.pill.lv-easy.on { background: var(--green); border-color: var(--green); }
.pill.lv-medium.on { background: var(--orange); border-color: var(--orange); }
.pill.lv-hard.on { background: var(--red); border-color: var(--red); }
.step { margin-bottom: 1rem; }
.step > b { display: block; margin-bottom: 0.4rem; font-size: 1.1rem; }

/* tabs */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs button { border: 0; background: #e2e8f0; border-radius: 0.8rem; padding: 0.5rem 1.1rem; font-weight: 800; font-size: 1.05rem; }
.tabs button.on { background: var(--blue); color: #fff; }

/* tables */
.tbl-wrap { overflow-x: auto; border-radius: 0.8rem; border: 0.1rem solid var(--line); }
table.t { border-collapse: collapse; width: 100%; font-family: var(--read); font-size: 0.95rem; background: #fff; }
table.t th, table.t td { border-bottom: 0.08rem solid var(--line); padding: 0.45rem 0.6rem; text-align: center; white-space: nowrap; }
table.t th { background: #eef3fb; font-family: var(--head); font-size: 0.95rem; position: sticky; top: 0; }
table.t td.l, table.t th.l { text-align: left; }
table.t tr:hover td { background: #f8fafc; }
table.t .sub th { background: #f6f8fc; font-size: 0.82rem; color: var(--muted); }
.del { border: 0; background: none; color: var(--red); font-size: 1.1rem; }
.stu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.6rem; }
.stu-grid button { border: 0.15rem solid var(--line); background: #fff; border-radius: 0.9rem; padding: 0.6rem; text-align: left; font-weight: 700; }
.stu-grid button.on { border-color: var(--blue); background: var(--blue-soft); }
.stu-grid button .r { display: inline-block; min-width: 2rem; background: var(--purple-soft); color: var(--purple); border-radius: 0.5rem; padding: 0 0.3rem; margin-right: 0.3rem; text-align: center; }
.stu-grid button .done { float: right; color: var(--green); }

/* reader */
.rd-head { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.rd-info { font-size: 1rem; }
.rd-info b { font-size: 1.25rem; }
.tag { display: inline-block; border-radius: 0.5rem; padding: 0.05rem 0.55rem; font-weight: 800; font-size: 0.9rem; margin-right: 0.3rem; }
.tag.easy { background: var(--green-soft); color: var(--green); }
.tag.medium { background: var(--orange-soft); color: #b45309; }
.tag.hard { background: var(--red-soft); color: var(--red); }
.tag.lang { background: var(--blue-soft); color: var(--blue); }
.timer { position: relative; width: 6.2rem; height: 6.2rem; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer .n { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.9rem; font-weight: 800; }
.passage { font-family: var(--read); font-size: clamp(1.35rem, 1.2vw + 1rem, 2.3rem); line-height: 1.9; background: #fffdf6; border: 0.15rem solid #f0e6c8; border-radius: var(--radius); padding: 1.1rem 1.5rem; user-select: none; }
.passage[lang="hi"] { line-height: 2.05; }
.passage .w { border-radius: 0.35rem; padding: 0 0.12rem; transition: background 0.15s; cursor: pointer; }
.passage .w.ok { background: var(--green-soft); color: #14532d; }
.passage .w.miss { background: var(--orange-soft); color: #9a3412; text-decoration: underline wavy #f59e0b; }
.passage .w.err { background: var(--red-soft); color: #991b1b; text-decoration: line-through; text-decoration-thickness: 0.08em; }
.passage .w.cur { outline: 0.15rem solid var(--blue); }
.passage .w.after { color: #a8b3c2; }
.passage .w.end { box-shadow: inset -0.25rem 0 0 var(--purple); }
.passage.blur .w { filter: blur(0.35rem); }
.heard { font-family: var(--read); color: var(--muted); font-size: 1rem; min-height: 1.6rem; margin: 0.5rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
.heard span { direction: ltr; unicode-bidi: plaintext; }
.ctrl { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; margin-top: 0.8rem; }
.mic-on { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 0.6rem rgba(220,38,38,0.18); } }
.legend { display: flex; flex-wrap: wrap; gap: 0.8rem; font-size: 0.9rem; color: var(--muted); }
.legend i { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 0.25rem; vertical-align: -0.1rem; margin-right: 0.25rem; }
.mode-sw { display: inline-flex; border: 0.13rem solid var(--line); border-radius: 0.8rem; overflow: hidden; }
.mode-sw button { border: 0; background: #fff; padding: 0.4rem 0.9rem; font-weight: 800; }
.mode-sw button.on { background: var(--purple); color: #fff; }
.note { background: var(--blue-soft); border-radius: 0.8rem; padding: 0.6rem 0.9rem; font-size: 0.95rem; }
.note.warn { background: var(--orange-soft); }

/* result */
.res-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; margin: 0.8rem 0; }
.stat { border-radius: 1.1rem; padding: 1rem; text-align: center; background: var(--blue-soft); }
.stat .v { font-size: 3rem; font-weight: 800; line-height: 1; }
.stat .k { font-weight: 800; margin-top: 0.3rem; }
.stat .s { font-size: 0.9rem; color: var(--muted); }
.stat.sp { background: var(--blue-soft); color: #1e3a8a; }
.stat.ac { background: var(--green-soft); color: #14532d; }
.stat.pu { background: var(--purple-soft); color: #4c1d95; }
.stars { font-size: 2.4rem; text-align: center; letter-spacing: 0.3rem; }
.badge { text-align: center; font-size: 1.4rem; font-weight: 800; }
.practice { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.practice button { border: 0.13rem solid var(--red-soft); background: #fff; border-radius: 0.8rem; padding: 0.35rem 0.8rem; font-family: var(--read); font-size: 1.15rem; }
.punct-pick { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.punct-pick button { border: 0.15rem solid var(--line); background: #fff; border-radius: 0.8rem; padding: 0.4rem 0.9rem; font-weight: 800; }
.punct-pick button.on { border-color: var(--purple); background: var(--purple-soft); color: var(--purple); }

/* chart */
.chart { width: 100%; height: auto; background: #fff; border-radius: 0.8rem; border: 0.1rem solid var(--line); }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: #1e293b; color: #fff; padding: 0.7rem 1.3rem; border-radius: 0.9rem; font-weight: 700; z-index: 50; box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.25); }
footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 1rem; }

@media (max-width: 640px) {
  .top { padding: 0.5rem 0.8rem; }
  .top .logo { font-size: 1.25rem; }
  .top .who { display: none; }
  main { padding: 0.8rem 0.6rem 2rem; }
  .card { padding: 0.9rem 0.9rem; }
  .hero h1 { font-size: 1.8rem; }
  .passage { padding: 0.8rem 0.9rem; }
  .timer { width: 4.8rem; height: 4.8rem; }
  .timer .n { font-size: 1.5rem; }
}
@media print {
  .top, .tabs, .btn, footer { display: none !important; }
}

/* voice recording */
.rec-sw { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; padding: 0.4rem 0.8rem; border-radius: 0.8rem; background: #fff; border: 0.1rem solid #e2e8f0; cursor: pointer; }
.rec-sw input { width: 1.2rem; height: 1.2rem; }
#voice { margin: 0.5rem 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
#voice:empty { display: none; }
.rec-dot { color: var(--red); font-weight: 800; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
audio.voice { height: 2.4rem; max-width: 100%; }
.voice-box { margin: 0.8rem 0; padding: 0.8rem; border-radius: 0.9rem; background: var(--green-soft); display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.voice-box audio.voice { flex: 1 1 16rem; }
.play { border: 0; background: var(--blue); color: #fff; border-radius: 50%; width: 2rem; height: 2rem; font-size: 0.9rem; cursor: pointer; }
td audio.voice { width: 16rem; min-width: 16rem; height: 2rem; }
.rec-sw.off { opacity: 0.5; cursor: not-allowed; }
