:root {
  --saffron: #e2731c;
  --saffron-soft: #fde9d6;
  --indigo: #2b3467;
  --indigo-soft: #e6e8f5;
  --cream: #fbf7f0;
  --ink: #1f2430;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e7e0d4;
  --green: #2f9e6e;
  --green-soft: #e3f5ec;
  --red: #d64545;
  --red-soft: #fbe4e4;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(43, 52, 103, 0.08);
  --font: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-hi: "Noto Sans Devanagari", "Kohinoor Devanagari", "Devanagari Sangam MN", "Nirmala UI", "Mangal", sans-serif;
  --pad-h: 46vh;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
.hi, .lc-hi, .fc-hi, .q-hi, .line-hi, .q-opt-hi, .resume-hi, .glyph {
  font-family: var(--font-hi);
}
a { color: var(--indigo); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.4em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); color: var(--indigo); }
.lede { color: var(--muted); max-width: 60ch; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; color: var(--saffron); font-weight: 700; margin: 0 0 0.25rem; }

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(251, 247, 240, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--indigo);
  font-weight: 700;
  font-size: 1.1rem;
}
.brand .glyph {
  background: var(--saffron);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
}
.site-nav { display: flex; gap: 0.25rem; margin-left: auto; flex-wrap: wrap; }
.site-nav a {
  text-decoration: none;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--indigo);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.site-nav a:hover { background: var(--indigo-soft); }
.site-nav a.active { background: var(--indigo); color: #fff; }

/* ---------- layout ---------- */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
}
.content { min-width: 0; padding-bottom: 72px; }
body.pad-open .content { padding-bottom: calc(var(--pad-h) + 110px); }

@media (min-width: 1000px) {
  /* Pad column grows with the screen: ~44% on an iPad in landscape, capped on big monitors. */
  .layout { grid-template-columns: minmax(0, 1fr) clamp(420px, 44vw, 560px); align-items: start; }
  /* A long word or sentence is being traced: give the pad most of the row. */
  body.pad-wide .layout { grid-template-columns: minmax(0, 1fr) clamp(420px, 58vw, 760px); }
  .content { padding-bottom: 2rem; }
  body.pad-open .content { padding-bottom: 2rem; }
}
/* Drawer mode: a taller pad when the guide wraps onto several lines. */
body.pad-tall { --pad-h: 64vh; }
@media (max-height: 640px) and (max-width: 999px) {
  body.pad-tall { --pad-h: 52vh; }
}

/* ---------- hero / level ---------- */
.level-hero, .home-hero {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.home-hero { display: grid; gap: 0.5rem; }
.home-hero .big-hi {
  font-family: var(--font-hi);
  font-size: clamp(3rem, 10vw, 5rem);
  color: var(--saffron);
  line-height: 1.1;
}
.progress { display: grid; gap: 0.35rem; margin: 0.75rem 0; }
.bar { height: 10px; background: var(--indigo-soft); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--saffron), #f0a35b); border-radius: 999px; transition: width 0.3s ease; }
.bar-text { font-size: 0.85rem; color: var(--muted); }
.tips summary { cursor: pointer; font-weight: 600; color: var(--indigo); padding: 0.4rem 0; }
.tips ul { margin: 0.25rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.tips li { margin: 0.25rem 0; }

.toc { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.25rem; }
.toc a {
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--indigo);
}
.toc a:hover { border-color: var(--indigo); }

/* ---------- sections ---------- */
.card-section { margin-bottom: 2rem; scroll-margin-top: 80px; }
.section-head { margin-bottom: 0.75rem; }
.section-head .lede { margin-bottom: 0.5rem; }

.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.letter-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.letter-card:hover { transform: translateY(-2px); border-color: var(--saffron); }
.letter-card.learned { border-color: var(--green); background: linear-gradient(180deg, #fff, var(--green-soft)); }
.letter-card.is-current, .line.is-current { border-color: var(--saffron); box-shadow: 0 0 0 3px var(--saffron-soft); }
.lc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.lc-hi {
  font-size: 2.6rem;
  line-height: 1.15;
  color: var(--indigo);
  background: none;
  border: 0;
  padding: 0.1rem 0.3rem 0 0;
  cursor: pointer;
  text-align: left;
  font-weight: 600;
}
.lc-hi:hover { color: var(--saffron); }
.lc-learned {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  color: transparent;
  cursor: pointer;
  font-weight: 700;
  flex-shrink: 0;
}
.lc-learned[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.lc-roman { font-weight: 700; font-size: 1.05rem; }
.lc-sound { font-size: 0.82rem; color: var(--muted); }
.lc-word { font-size: 0.85rem; margin-top: 0.15rem; }
.lc-word .hi { font-size: 1.15rem; font-weight: 600; }
.lc-wr { color: var(--indigo); }
.lc-mean { color: var(--muted); }
.lc-practice { margin-top: auto; align-self: flex-start; }

.line-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.line {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.4rem;
}
.line-hi { font-size: 1.7rem; font-weight: 600; color: var(--indigo); line-height: 1.5; }
.line-roman { font-weight: 600; }
.line-easy { color: var(--indigo); font-size: 0.95rem; }
.line-mean { color: var(--muted); }
.line-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.next-level { text-align: center; padding: 1.5rem 0 2rem; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--indigo);
  padding: 0.5rem 0.9rem;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  text-decoration: none;
  touch-action: manipulation;
}
.btn[hidden] { display: none; }

/* Speaker buttons (text-to-speech) */
.btn-say {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--indigo);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  padding: 0;
  touch-action: manipulation;
}
.btn-say:hover { border-color: var(--indigo); background: var(--indigo-soft); }
.btn-say.saying { background: var(--saffron-soft); border-color: var(--saffron); }
.btn-say-sm { width: 28px; height: 28px; font-size: 0.9rem; }
.btn-say[hidden] { display: none; }
html.no-speech .btn-say, html.no-speech [data-say] { display: none !important; }
.lc-icons { display: flex; gap: 0.35rem; align-items: center; }
.pad-say { flex: 0 0 auto; }
.pad-voice { font-size: 0.85rem; color: var(--muted); }
.pad-voice[hidden] { display: none; }
.pad-voice select {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  min-height: 40px;
}
.q-prompt .btn-say { margin-left: 0.4rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 520px);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.btn:hover { border-color: var(--indigo); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-primary:hover { background: #222a55; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-lg { min-height: 52px; padding: 0.7rem 1.4rem; font-size: 1.05rem; }
.btn-reset { background: var(--saffron-soft); border-color: var(--saffron); color: #8a3f00; }
.btn-good { background: var(--green-soft); border-color: var(--green); color: #14613f; }
.btn-bad { background: var(--red-soft); border-color: var(--red); color: #8a1f1f; }
.btn:focus-visible, .lc-hi:focus-visible, .tab:focus-visible, .q-opt:focus-visible, .flashcard:focus-visible, .pad-color:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

/* ---------- practice pad ---------- */
.pad-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -6px 24px rgba(43, 52, 103, 0.15);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}
.pad-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.pad-toggle {
  font: inherit;
  font-weight: 700;
  color: var(--indigo);
  background: var(--indigo-soft);
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  min-height: 44px;
  cursor: pointer;
}
.pad-toggle-icon { color: var(--saffron); }
.pad-current {
  font-family: var(--font-hi), var(--font);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.pad-next { flex: 0 0 auto; min-height: 40px; white-space: nowrap; }
.pad-body { display: grid; gap: 0.5rem; padding: 0.5rem 0.75rem 0.75rem; }
.pad-panel.collapsed .pad-body { display: none; }
.pad-canvas-wrap {
  position: relative;
  height: var(--pad-h);
  min-height: 220px;
  background: #fff;
  border: 2px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.pad-canvas-wrap canvas { position: absolute; inset: 0; display: block; }
.pad-ink { touch-action: none; cursor: crosshair; }
/* Faint dashed centre lines, drawn in CSS so they are always exactly centred. */
.pad-canvas-wrap {
  background-image:
    repeating-linear-gradient(to bottom, rgba(43, 52, 103, 0.14) 0 4px, transparent 4px 10px),
    repeating-linear-gradient(to right, rgba(43, 52, 103, 0.14) 0 4px, transparent 4px 10px);
  background-size: 1px 100%, 100% 1px;
  background-position: center top, left center;
  background-repeat: no-repeat;
}
/* The tracing guide: a real text element under the ink canvas. */
.pad-guide {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-hi);
  font-weight: 600;
  line-height: 1.3;
  color: rgba(43, 52, 103, 0.18);
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad-guide-probe {
  visibility: hidden;
  left: 0;
  top: 0;
  transform: none;
  display: inline-block;
}
.pad-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.4rem;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  pointer-events: none;
  padding: 0 0.5rem;
}
.pad-tools { display: grid; gap: 0.4rem; }
.pad-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.pad-row .btn { flex: 1 1 auto; }
.pad-size { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); flex: 1; }
.pad-size input { flex: 1; min-width: 80px; accent-color: var(--indigo); }
.pad-colors { display: flex; gap: 0.35rem; }
.pad-color {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
  cursor: pointer;
  padding: 0;
}
.pad-color.active { border-color: var(--saffron-soft); box-shadow: 0 0 0 2px var(--saffron); }

@media (min-width: 1000px) {
  .pad-panel {
    position: sticky;
    top: 76px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding-bottom: 0;
  }
  .pad-panel.collapsed .pad-body { display: grid; }
  .pad-toggle { pointer-events: none; }
  /* Fill the column height: viewport minus header, pad head and tool rows. */
  .pad-canvas-wrap { height: clamp(320px, calc(100vh - 330px), 560px); }
}
@media (max-height: 640px) and (max-width: 999px) {
  :root { --pad-h: 38vh; }
  .pad-canvas-wrap { min-height: 170px; }
}

/* ---------- flashcards & quiz ---------- */
.fc-controls { display: grid; gap: 0.6rem; margin-bottom: 0.75rem; }
.fc-deck { font-size: 0.9rem; color: var(--muted); display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.fc-deck select {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  min-height: 44px;
  max-width: 100%;
}
.tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tab {
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--indigo);
  padding: 0.45rem 0.9rem;
  min-height: 44px;
  cursor: pointer;
}
.tab.active { background: var(--saffron); border-color: var(--saffron); color: #fff; }
.fc-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.flashcard-wrap { display: grid; gap: 0.75rem; justify-items: center; }
.flashcard {
  width: min(100%, 420px);
  height: 230px;
  position: relative;
  perspective: 1000px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.fc-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  border: 1px solid var(--border);
  display: grid;
  place-content: center;
  gap: 0.3rem;
  text-align: center;
  padding: 1rem;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.45s ease;
  box-shadow: var(--shadow);
}
.fc-front { background: linear-gradient(160deg, #fff, var(--indigo-soft)); }
.fc-back { background: linear-gradient(160deg, #fff, var(--saffron-soft)); transform: rotateY(180deg); }
.flashcard.flipped .fc-front { transform: rotateY(180deg); }
.flashcard.flipped .fc-back { transform: rotateY(0); }
.fc-hi { font-size: clamp(3rem, 12vw, 5.5rem); color: var(--indigo); font-weight: 600; line-height: 1.2; }
.fc-roman { font-size: 2rem; font-weight: 700; color: var(--indigo); line-height: 1.2; }
.fc-sound { color: var(--muted); }
.fc-word { font-size: 0.95rem; }
.fc-word .hi { font-size: 1.3rem; font-weight: 600; }
.fc-meta { font-size: 0.85rem; color: var(--muted); }
.fc-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }

.quiz { display: grid; gap: 0.75rem; }
.quiz-bar { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); }
.q-prompt { text-align: center; color: var(--indigo); font-weight: 600; }
.q-hi { font-size: clamp(3rem, 12vw, 5rem); line-height: 1.2; text-align: center; color: var(--indigo); font-weight: 600; }
.q-roman { font-size: clamp(1.8rem, 6vw, 2.6rem); }
.q-ask { text-align: center; margin: 0; color: var(--muted); }
.q-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.5rem; }
.q-opt {
  font: inherit;
  font-weight: 600;
  font-size: 1.1rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--ink);
  padding: 0.75rem;
  min-height: 60px;
  cursor: pointer;
}
.q-opt-hi { font-size: 2rem; }
.q-opt:hover:not(:disabled) { border-color: var(--indigo); }
.q-opt.correct { border-color: var(--green); background: var(--green-soft); }
.q-opt.wrong { border-color: var(--red); background: var(--red-soft); }
.q-feedback { margin: 0; text-align: center; font-weight: 600; min-height: 1.5em; }
.q-feedback.ok { color: #14613f; }
.q-feedback.bad { color: #8a1f1f; }
.q-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.q-answer { display: grid; gap: 0.5rem; text-align: center; }
.results h3 { color: var(--indigo); }
.review-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.review-list li { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.review-list .hi { font-size: 1.6rem; color: var(--indigo); font-weight: 600; }

/* ---------- home ---------- */
.level-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.9rem; margin: 1rem 0 1.5rem; }
.level-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.level-card:hover { transform: translateY(-2px); border-color: var(--saffron); }
.level-card .glyph { font-size: 2.4rem; color: var(--saffron); font-weight: 600; }
.level-card h3 { margin: 0; color: var(--indigo); }
.level-card p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0.5rem 0 0; display: grid; gap: 0.6rem; }
.steps li { position: relative; padding-left: 2.4rem; color: var(--muted); }
.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
}
.steps strong { color: var(--ink); }
.tips-list { color: var(--muted); padding-left: 1.2rem; margin: 0 0 1rem; }
.tips-list li { margin: 0.4rem 0; }
.tips-list strong { color: var(--ink); }
.try-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.try-row .btn { font-family: var(--font-hi); font-size: 1.4rem; min-width: 56px; }
.resume { background: var(--saffron-soft); border: 1px solid var(--saffron); border-radius: var(--radius); padding: 0.8rem 1rem; display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.resume-hi { font-size: 2rem; font-weight: 600; color: var(--indigo); }

.site-footer { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 1rem; }

/* iPad landscape and small laptops: three letters per row so cards stay readable next to the wide pad. */
@media (min-width: 1000px) and (max-width: 1399px) {
  .letter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* iPad portrait: three per row instead of four. */
@media (min-width: 700px) and (max-width: 999px) {
  .letter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .letter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lc-hi { font-size: 2.3rem; }
  .site-nav a { padding: 0.45rem 0.65rem; font-size: 0.92rem; }
}
