:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --ink: #161a2e;
  --ink-soft: #5a607a;
  --line: #e0e3ef;
  --brand: #4338ca;
  --brand-ink: #ffffff;
  --brand-soft: #e0e7ff;
  --accent: #c2410c;        /* orange for text (readable); --accent-fill for shapes */
  --accent-fill: #f59e0b;
  --good: #166534;
  --good-soft: #dcf5e4;
  --bad: #b42318;
  --bad-soft: #fde4df;
  --warn-soft: #fdf0d3;
  --lock: #a0a4b8;
  --topbar-bg: #4338ca;
  --topbar-ink: #ffffff;
  /* one hue per stage (1–7) */
  --s1: #4338ca; --s2: #2563eb; --s3: #a21caf; --s4: #be123c; --s5: #c2410c; --s6: #0e7490; --s7: #a16207;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(22, 26, 46, .05), 0 6px 18px rgba(22, 26, 46, .07);
  --font-bn: 'Noto Sans Bengali', system-ui, sans-serif;
  --font-en: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131a; --surface: #1a1c26; --surface-2: #232634; --ink: #eceef6; --ink-soft: #a5aac0;
    --line: #2f3245; --brand: #818cf8; --brand-ink: #10112a; --brand-soft: #272b5e; --accent: #fbbf24;
    --good: #4ade80; --good-soft: #16321f; --bad: #f87171; --bad-soft: #3b1f1c; --warn-soft: #3a3020;
    --lock: #6b6f82; --topbar-bg: #1e1b4b; --topbar-ink: #eceef6;
    --s1: #818cf8; --s2: #60a5fa; --s3: #e879f9; --s4: #fb7185; --s5: #fb923c; --s6: #22d3ee; --s7: #facc15;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #12131a; --surface: #1a1c26; --surface-2: #232634; --ink: #eceef6; --ink-soft: #a5aac0;
  --line: #2f3245; --brand: #818cf8; --brand-ink: #10112a; --brand-soft: #272b5e; --accent: #fbbf24;
  --good: #4ade80; --good-soft: #16321f; --bad: #f87171; --bad-soft: #3b1f1c; --warn-soft: #3a3020;
  --lock: #6b6f82; --topbar-bg: #1e1b4b; --topbar-ink: #eceef6;
  --s1: #818cf8; --s2: #60a5fa; --s3: #e879f9; --s4: #fb7185; --s5: #fb923c; --s6: #22d3ee; --s7: #facc15;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-bn); font-size: 17px; line-height: 1.6;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }

.topbar {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--topbar-bg); color: var(--topbar-ink);
  position: sticky; top: 0; z-index: 5; box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; min-height: 40px; font-weight: 700; text-decoration: none; color: inherit; font-family: var(--font-en); font-size: 18px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--topbar-ink); color: var(--topbar-bg); font-size: 17px; }
.topbar-sub { min-width: 0; font-size: 14px; text-align: right; opacity: .88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 64px; }

h1, h2, h3 { line-height: 1.3; margin: 0 0 8px; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 18px; }
.en { font-family: var(--font-en); }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

/* buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 11px; cursor: pointer; font-weight: 600; min-height: 44px;
  transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-sm { padding: 6px 12px; min-height: 44px; min-width: 44px; font-size: 15px; }
.btn:focus-visible, .opt:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* home */
.hero { margin-bottom: 18px; }
.hero .kicker { color: var(--accent); font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--stage, var(--brand)); border-radius: 99px; transition: width .3s ease; }
.stages { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.stage {
  --stage: var(--brand);
  display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--stage);
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .15s ease;
}
.stage:hover { border-color: var(--stage); }
.stage:active { transform: scale(.985); }
.stage-num {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-weight: 700; font-size: 19px;
  background: var(--brand-soft); background: color-mix(in srgb, var(--stage) 15%, var(--surface)); color: var(--stage);
}
.stage.is-done { border-left-color: var(--good); }
.stage.is-done .stage-num { background: var(--good); color: #fff; }
/* paragraph list: ring shows how many of the 7 stages are done */
.stage.para { border-left: 1px solid var(--line); }
.ring {
  --pct: 0; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--brand) calc(var(--pct) * 1%), var(--surface-2) 0);
}
.ring > span {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); color: var(--brand); font-weight: 700; font-size: 17px;
}
.stage.is-done .ring { background: var(--good); }
.stage.is-done .ring > span { color: var(--good); }
.stage.is-locked { opacity: .6; pointer-events: none; box-shadow: none; }
.stage.is-locked .stage-num { background: var(--surface-2); color: var(--lock); }
.stage-title { font-weight: 700; }
.stage-desc { color: var(--ink-soft); font-size: 14px; }
.badge { font-size: 14px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-soft); white-space: nowrap; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-now { background: var(--brand-soft); color: var(--brand); }
.badge-seen { background: var(--warn-soft); color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tags-end { justify-content: flex-end; }
.install { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; margin-bottom: 4px; border: 1.5px solid var(--brand); background: var(--brand-soft); }
.install-icon { font-size: 30px; text-align: center; }
/* login */
.login { max-width: 420px; margin: 24px auto 0; }
.login .stack > * + *, .login > * + * { margin-top: 10px; }
.login-mark { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 4px;
  background: var(--brand); color: var(--brand-ink); font-family: var(--font-en); font-weight: 700; font-size: 30px; }
.login h1 { text-align: center; }
.login > p { text-align: center; }
.login-label { display: block; font-weight: 600; font-size: 15px; }
@media (max-width: 520px) { .install { grid-template-columns: 40px 1fr; } .install .btn { grid-column: 1 / -1; } }

/* stage header */
.stage-head { margin-bottom: 16px; }
.back { display: inline-flex; align-items: center; min-height: 44px; padding-right: 12px; margin-bottom: 2px; text-decoration: none; font-size: 15px; font-weight: 600; }
.stage-head > .muted.small:first-of-type { color: var(--stage, var(--accent)); font-weight: 700; }
.meter { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); }
.meter .progress { flex: 1; }

/* learn cards */
.word-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.word-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.word-card .en { font-size: 19px; font-weight: 700; }
.word-card .bn { color: var(--ink-soft); }
.speak { border: none; background: var(--surface-2); border-radius: 10px; min-width: 44px; min-height: 40px; padding: 4px 10px; cursor: pointer; font-size: 16px; align-self: flex-start; vertical-align: middle; }
.speak:active { background: var(--brand-soft); }

/* quiz */
.prompt { font-size: 26px; font-weight: 700; text-align: center; padding: 18px 8px; }
.prompt.en { font-size: 24px; }
.prompt-sentence { font-family: var(--font-en); font-size: 21px; font-weight: 500; text-align: center; padding: 10px 4px 16px; }
.options { display: grid; gap: 10px; counter-reset: opt; }
.opt {
  display: flex; align-items: center; gap: 12px; counter-increment: opt;
  text-align: left; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 18px; min-height: 56px; line-height: 1.4;
  box-shadow: 0 1px 2px rgba(22, 26, 46, .04); touch-action: manipulation;
  transition: border-color .15s ease, background .15s ease, transform .08s ease;
}
/* A B C D marker; turns into ✓ / ✗ after answering */
.opt::before {
  content: counter(opt, upper-alpha); flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-2); color: var(--ink-soft);
  font-family: var(--font-en); font-weight: 700; font-size: 15px;
}
.opt:hover:not(:disabled) { border-color: var(--brand); }
.opt:active:not(:disabled) { transform: scale(.985); background: var(--brand-soft); }
.opt.is-right { border-color: var(--good); background: var(--good-soft); }
.opt.is-right::before { content: '✓'; background: var(--good); color: #fff; }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.is-wrong::before { content: '✗'; background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; color: inherit; opacity: 1; }
.opt:disabled:not(.is-right):not(.is-wrong) { opacity: .55; }
.mcq-next:not(:has(> :not([hidden]))) { display: none; }
.mcq-next > .btn { flex: 1 1 auto; min-height: 50px; font-size: 17px; }

.feedback { border-radius: 12px; padding: 12px 14px; font-weight: 500; }
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback.info { background: var(--warn-soft); }
.feedback ul { margin: 6px 0 0; padding-left: 20px; }

/* structure builder */
.pattern { display: flex; flex-wrap: wrap; gap: 6px; }
.role { font-size: 14px; font-weight: 700; padding: 4px 10px; border-radius: 8px; }
.role-Sub { background: #dbe9fb; color: #1d4f91; }
.role-Verb { background: #fbe0d6; color: #9a3a1c; }
.role-Obj { background: #e3f3dc; color: #2f6b1f; }
.role-Comp { background: #efe2fb; color: #6232a0; }
.role-Adv, .role-Time, .role-Place, .role-Extra { background: #f8edcf; color: #7b5a12; }
.role-Conn { background: #d8f1f0; color: #13615e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .role { filter: brightness(.85) saturate(1.1); }
}
.build-area {
  min-height: 64px; border: 2px dashed var(--line); border-radius: 12px; padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-family: var(--font-en); font-size: 19px;
}
.build-area:empty::before { content: 'নিচের শব্দে ক্লিক করে বাক্য বানান'; color: var(--ink-soft); font-family: var(--font-bn); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-en); font-size: 18px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); min-height: 44px;
}
.chip:hover:not(:disabled) { border-color: var(--brand); }
.chip:disabled { opacity: .3; cursor: default; }
.chip.placed { background: var(--brand-soft); border-color: var(--brand); }
.solved { display: flex; flex-wrap: wrap; gap: 8px; }
.solved .seg { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.solved .seg .en { font-size: 18px; }

/* typing */
.type-input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); font-family: var(--font-en); font-size: 19px;
}
.kbd { display: grid; gap: 6px; user-select: none; -webkit-user-select: none; }
.kbd[hidden] { display: none; }
.kbd-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1 1 0; max-width: 46px; min-width: 0; height: 46px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: inherit;
  font-family: var(--font-en); font-size: 19px; cursor: pointer; touch-action: manipulation;
}
.key:active { background: var(--brand-soft); border-color: var(--brand); }
.key-space { flex: 5 1 0; max-width: 240px; font-size: 15px; }
.key-wide { flex: 1.6 1 0; max-width: 72px; }
.diff { font-family: var(--font-en); }
.diff .w-spelling { color: var(--bad); text-decoration: underline wavy; }

/* rules */
.rule { border-left: 4px solid var(--brand); }
.rule .ex { font-family: var(--font-en); background: var(--surface-2); border-radius: 8px; padding: 2px 8px; display: inline-block; margin: 2px 4px 2px 0; }
.rule-id { font-size: 13px; font-weight: 700; color: var(--brand); }
.rule-meaning { margin: 0; font-weight: 600; font-size: 17px; }
.rule-block { display: grid; gap: 6px; }
.rule-label { font-size: 14px; font-weight: 700; color: var(--accent); }
.ex-line { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 17px; }
.mistake { display: grid; gap: 2px; border-radius: 8px; padding: 6px 10px; background: var(--surface-2); }
.mis-wrong { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.mis-right { color: var(--good); font-weight: 600; }
.rule { scroll-margin-top: 72px; }
.rule-list { margin: 0; padding-left: 22px; }
.rule-list li + li { margin-top: 6px; }
.table-wrap { overflow-x: auto; }
.rule-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.rule-table th, .rule-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rule-table th { background: var(--surface-2); font-weight: 700; }

/* grammar */
.box-words { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border: 1.5px solid var(--ink-soft); border-radius: 10px; font-family: var(--font-en); }
.box-words span { padding: 2px 10px; background: var(--surface-2); border-radius: 6px; }
.passage { font-family: var(--font-en); font-size: 18px; line-height: 2.2; }
.gap { display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.gap .gap-key { font-weight: 700; color: var(--accent); }
.gap input {
  width: 128px; padding: 2px 8px; border: none; border-bottom: 2px solid var(--ink-soft);
  background: var(--surface-2); border-radius: 6px 6px 0 0; font-family: var(--font-en); font-size: 17px;
}
.gap input.is-right { border-bottom-color: var(--good); background: var(--good-soft); }
.gap input.is-wrong { border-bottom-color: var(--bad); background: var(--bad-soft); }
.gap .root { color: var(--ink-soft); font-style: italic; }
.reason-table { width: 100%; border-collapse: collapse; }
.reason-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.reason-table td:first-child { width: 40px; font-weight: 700; color: var(--accent); font-family: var(--font-en); }
.reason-table select { width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); min-height: 44px; }
.reason-table select.is-right { border-color: var(--good); }
.reason-table select.is-wrong { border-color: var(--bad); }
.explain { font-size: 14px; margin-top: 4px; }
.explain.good { color: var(--good); }
.explain.bad { color: var(--bad); }
.ex-list { display: grid; gap: 10px; }
.ex-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: inherit; }
.ex-item:hover { border-color: var(--brand); }

.done-card { text-align: center; padding: 28px 18px; }
.done-card .big { font-size: 48px; animation: pop .5s ease both; }

/* celebration + answer feedback motion */
.celebrate { position: relative; overflow: hidden; }
.confetti { position: absolute; left: 50%; top: 70px; width: 0; height: 0; pointer-events: none; }
.confetti i {
  position: absolute; width: 8px; height: 12px; border-radius: 2px; background: var(--c); opacity: 0;
  animation: burst 1.3s ease-out forwards;
}
@keyframes burst {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  55% { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 1; }
  100% { transform: translate(calc(var(--x) * 1.25), calc(var(--y) + 150px)) rotate(calc(var(--r) * 2)); opacity: 0; }
}
@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.opt.is-right, .feedback.good { animation: pop .3s ease; }
.opt.is-wrong, .feedback.bad { animation: shake .3s ease; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* action buttons: an empty row (only a hidden "next" button) takes no space */
.actions:not(:has(> :not([hidden]))) { display: none; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  h1 { font-size: 22px; }
  .wrap { padding: 14px 14px 32px; }
  .prompt { font-size: 22px; }
  .prompt-sentence { font-size: 19px; }
  .card { padding: 16px; }
  .stage { grid-template-columns: 48px 1fr; gap: 12px; padding: 12px 14px; }
  .stage .badge, .stage .tags { grid-column: 2; justify-self: start; }
  .gap input { width: 104px; }
  /* header on one line: inside a paragraph show only the logo + paragraph name */
  .topbar:has(.topbar-sub:not(:empty)) .brand-text { display: none; }
  .topbar-sub { flex: 1; }
  /* "check" / "next" stay at the bottom of the screen, in thumb reach */
  .actions {
    position: sticky; bottom: 0; z-index: 4; margin-top: 12px !important;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--line);
  }
  /* inside a card (typing, sentence builder, grammar set) buttons stay in place under the content:
     a bar stuck to the screen bottom hid the keyboard's last row and the feedback */
  .card .actions {
    position: static; margin: 12px 0 0 !important; padding: 0;
    background: none; border-top: none;
  }
  .actions > .btn { flex: 1 1 auto; }
  /* while a question is on screen: short header, so question + 4 options + next fit one screen */
  #app:has(.options, .kbd, .chips) .stage-head { margin-bottom: 8px; }
  #app:has(.options, .kbd, .chips) .stage-head > p.muted { display: none; }
  #app:has(.options, .kbd, .chips) .stage-head h1 { font-size: 19px; margin-bottom: 2px; }
  #app:has(.options, .kbd, .chips) .card { padding: 14px; }
  #app:has(.options) .prompt { padding: 6px 4px 8px; }
  #app:has(.options) .prompt-sentence { padding: 4px 2px 10px; }
  .options { gap: 8px; }
  .opt { font-size: 17px; min-height: 54px; padding: 10px 12px; }
}
