:root {
  color-scheme: light;
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #1d2340;
  --muted: #646b85;
  --blue: #3b6cf0;
  --blue-dark: #2b52c4;
  --blue-soft: #e7eeff;
  --green: #168b63;
  --green-soft: #e0f6ec;
  --red: #c43f52;
  --red-soft: #ffe6ea;
  --amber: #e8891c;
  --amber-soft: #fff1dc;
  --card: rgba(255, 255, 255, .94);
  --tile-shadow: 0 6px 16px rgba(35, 60, 130, .18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 0%, #dfe9ff 0, transparent 30rem),
    radial-gradient(circle at 96% 14%, #fff0d8 0, transparent 28rem),
    linear-gradient(150deg, #f6f8ff, #fffaf3);
  overscroll-behavior: none;
}
button { font: inherit; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app-shell { width: min(1100px, calc(100% - 24px)); margin: 0 auto; padding: 16px 0 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 48px; }
.back-link, .done-back { color: var(--blue-dark); font-weight: 850; text-decoration: none; }
.pill-row { display: flex; gap: 8px; }
.score-pill.wallet span { color: #0f6ea3; }
.score-pill { display: flex; gap: 6px; align-items: center; padding: 9px 14px; border-radius: 999px; background: white; box-shadow: 0 8px 24px rgba(40, 60, 120, .12); font-size: 17px; }
.mode-row { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(255,255,255,.7); box-shadow: 0 8px 24px rgba(40, 60, 120, .08); }
.mode-pill { padding: 7px 13px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 800; font-size: 13px; cursor: pointer; }
.mode-pill.active { background: var(--blue); color: white; box-shadow: 0 6px 14px rgba(59, 108, 240, .3); }

.screen { animation: arrive .28s ease both; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.progress-row { display: grid; grid-template-columns: auto minmax(120px, 300px); justify-content: space-between; align-items: center; gap: 18px; margin: 14px 4px 16px; color: #5b6383; font-size: 13px; font-weight: 850; }
.progress-track { height: 8px; border-radius: 999px; background: rgba(59, 108, 240, .16); overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #6f95ff, #3b6cf0); transition: width .3s ease; }

.quiz-panel { position: relative; width: min(860px, 100%); margin: 0 auto; padding: 24px 22px 26px; border: 1px solid rgba(40, 60, 120, .09); border-radius: 28px; background: var(--card); box-shadow: 0 18px 50px rgba(40, 60, 120, .1); text-align: center; transition: box-shadow .2s ease; }
.quiz-panel.answered-correct { box-shadow: 0 18px 50px rgba(22, 139, 99, .24); }
.quiz-panel.answered-wrong { box-shadow: 0 18px 50px rgba(196, 63, 82, .22); }

.instruction { margin: 0 0 14px; font-size: clamp(18px, 3vw, 23px); font-weight: 850; }
.instruction-sub { display: block; margin-top: 4px; color: var(--muted); font-size: .72em; font-weight: 700; }

/* --- the sequence row ------------------------------------------------- */
.sequence { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 4px; margin: 6px 0 18px; }
.cell { position: relative; display: grid; place-items: center; min-width: 118px; height: 64px; padding: 0 10px; border-radius: 16px; font-size: clamp(19px, 3.4vw, 26px); font-weight: 900; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.cell.given { background: var(--blue-soft); color: var(--ink); }
.cell.blank { border: 3px dashed #b9c6ee; background: #f7f9ff; color: #b9c6ee; transition: border-color .15s ease, background .15s ease, transform .15s ease; }
.cell.blank.target { border-color: var(--blue); background: #eaf0ff; transform: scale(1.04); }
.cell.blank.filled { border-style: solid; border-color: transparent; background: transparent; padding: 0; }
.cell.blank.correct { border-color: var(--green); background: var(--green-soft); }
.cell.blank.wrong { border-color: var(--red); background: var(--red-soft); animation: shake .5s ease; }
.comma { font-size: 24px; font-weight: 900; color: #8a93b3; align-self: end; padding-bottom: 8px; }
.step-arrow { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 900; color: var(--amber); white-space: nowrap; opacity: 0; transition: opacity .2s; }
.sequence.show-steps .step-arrow { opacity: 1; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

/* --- tiles -------------------------------------------------------------- */
.tray-wrap { padding: 14px 12px 16px; border-radius: 20px; background: #f2f5ff; }
.tray-label { margin: 0 0 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 64px; }
.tile { display: grid; place-items: center; min-width: 118px; height: 58px; padding: 0 14px; border: 0; border-radius: 16px; background: white; color: var(--ink); box-shadow: var(--tile-shadow); font-size: clamp(19px, 3.4vw, 25px); font-weight: 900; font-variant-numeric: tabular-nums; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; transition: transform .12s ease, box-shadow .12s ease; }
.tile:hover { transform: translateY(-2px); }
.tile.selected { outline: 3px solid var(--blue); outline-offset: 2px; transform: translateY(-3px) scale(1.04); }
.tile.dragging { position: fixed; z-index: 50; pointer-events: none; transform: scale(1.08) rotate(-2deg); box-shadow: 0 18px 40px rgba(35, 60, 130, .3); cursor: grabbing; }
.tile.locked { cursor: default; background: var(--green-soft); color: var(--green); box-shadow: none; }
.tile.locked:hover { transform: none; }
.cell.blank .tile { width: 100%; height: 100%; min-width: 0; }
.cell.blank.wrong .tile { background: var(--red-soft); color: var(--red); }

/* --- feedback ---------------------------------------------------------- */
.feedback { min-height: 26px; margin: 16px auto 0; max-width: 640px; font-size: 16px; line-height: 1.5; font-weight: 750; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }
.feedback .bubble { display: block; margin-top: 8px; padding: 12px 16px; border-radius: 16px; background: var(--amber-soft); color: #6c4404; text-align: left; font-weight: 650; border-left: 5px solid var(--amber); }
.feedback .bubble strong { color: #b35d00; font-variant-numeric: tabular-nums; }

.action-row { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.primary-button { min-width: 170px; padding: 14px 26px; border: 0; border-radius: 16px; color: white; background: linear-gradient(135deg, #6f95ff, #3b6cf0); box-shadow: 0 12px 28px rgba(59, 108, 240, .3); font-weight: 900; cursor: pointer; }
.primary-button:hover:not(:disabled) { transform: translateY(-1px); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.next-button { background: linear-gradient(135deg, #34c48e, #168b63); box-shadow: 0 12px 28px rgba(22, 139, 99, .3); }
.ghost-button { padding: 12px 18px; border: 2px solid var(--amber); border-radius: 14px; background: white; color: #9a5300; font-weight: 850; cursor: pointer; }
.ghost-button.small { padding: 8px 14px; font-size: 13px; }

/* --- counter --------------------------------------------------------------- */
.counter { margin-top: 22px; padding: 16px 14px 16px; border-radius: 22px; background: linear-gradient(180deg, #fff8ec, #fff2dc); border: 1px solid rgba(232, 137, 28, .25); }
.ctr-direction { display: inline-flex; align-items: center; gap: 10px; margin: 0 0 14px; padding: 8px 18px; border-radius: 999px; font-weight: 900; font-size: 17px; letter-spacing: .02em; color: white; }
.ctr-direction.forward { background: linear-gradient(90deg, #168b63, #34c48e); }
.ctr-direction.backward { background: linear-gradient(90deg, #d9457a, #f2708f); }
.ctr-direction .arrow { font-size: 22px; line-height: 1; }
.ctr-direction .arrow.run { animation: nudge .6s ease-in-out infinite alternate; }
@keyframes nudge { from { transform: translateX(-3px); } to { transform: translateX(3px); } }
.ctr-columns { display: flex; justify-content: center; gap: 6px; }
.ctr-col { display: grid; gap: 4px; justify-items: center; }
.ctr-col.gap { margin-right: 10px; }
.ctr-col-label { font-size: 10px; font-weight: 800; color: #a06d1f; letter-spacing: .02em; text-transform: uppercase; }
.ctr-digit { display: grid; place-items: center; width: clamp(40px, 9vw, 56px); height: clamp(52px, 11vw, 70px); border-radius: 12px; background: #2b2b33; color: #fff; font-size: clamp(26px, 6vw, 38px); font-weight: 900; box-shadow: inset 0 -8px 14px rgba(0,0,0,.45), 0 4px 10px rgba(0,0,0,.2); font-variant-numeric: tabular-nums; transition: background .2s; }
.ctr-digit.changed { background: var(--amber); color: #1d1d1d; animation: roll .45s ease; }
.ctr-digit.same { opacity: .8; }
@keyframes roll { 0% { transform: translateY(-40%); opacity: 0; } 100% { transform: none; opacity: 1; } }
.ctr-controls { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.ctr-run { min-width: 190px; padding: 12px 20px; border: 0; border-radius: 14px; background: var(--amber); color: white; font-weight: 900; font-size: 17px; cursor: pointer; box-shadow: 0 10px 22px rgba(232, 137, 28, .35); }
.ctr-run.running { background: #c43f52; box-shadow: 0 10px 22px rgba(196, 63, 82, .35); }
.ctr-note { margin: 12px auto 0; max-width: 560px; min-height: 22px; color: #6c4404; font-weight: 700; font-size: 15px; line-height: 1.45; }
.ctr-note strong { font-variant-numeric: tabular-nums; }

/* --- done screen -------------------------------------------------------- */
.done-screen { width: min(760px, 100%); margin: 30px auto 0; text-align: center; }
.hero-icon { display: grid; place-items: center; width: 82px; height: 82px; margin: 0 auto 15px; border-radius: 28px; background: white; box-shadow: 0 18px 50px rgba(40, 60, 120, .16); font-size: 42px; transform: rotate(-3deg); }
.eyebrow { margin: 0 0 8px; color: var(--blue); text-transform: uppercase; letter-spacing: .13em; font-size: 12px; font-weight: 900; }
h1 { margin: 0; font-size: clamp(38px, 7vw, 64px); line-height: 1; letter-spacing: -.055em; }
.intro { margin: 18px auto 20px; max-width: 610px; color: var(--muted); font-size: 18px; line-height: 1.55; }
.reward-text { margin: -6px 0 18px; font-size: 20px; font-weight: 900; color: #0f6ea3; }
.lesson-list { display: grid; gap: 8px; margin: 0 auto 18px; max-width: 620px; text-align: left; }
.lesson { padding: 12px 16px; border-radius: 14px; background: var(--amber-soft); border-left: 5px solid var(--amber); color: #6c4404; font-weight: 650; font-size: 15px; line-height: 1.45; }
.lesson.clean { background: var(--green-soft); border-color: var(--green); color: #0f5d43; }
.review-list { display: grid; gap: 8px; margin: 0 auto; max-width: 620px; text-align: left; }
.review-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 14px; background: white; box-shadow: 0 6px 18px rgba(40, 60, 120, .08); font-size: 15px; font-variant-numeric: tabular-nums; }
.review-index { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--blue-soft); color: var(--blue-dark); font-weight: 900; font-size: 13px; }
.review-text { font-weight: 800; }
.review-text .ans { color: var(--green); }
.review-stars { font-size: 14px; color: var(--muted); font-weight: 800; }

@media (max-width: 560px) {
  .sequence { gap: 4px 2px; margin-top: 22px; }
  .cell { min-width: 56px; height: 50px; padding: 0 2px; font-size: 13.5px; letter-spacing: 0; border-radius: 11px; }
  .cell.blank { border-width: 2px; }
  .comma { font-size: 12px; padding-bottom: 4px; }
  .cell.blank .tile { font-size: 13.5px; padding: 0; border-radius: 9px; }
  .step-arrow { font-size: 11px; top: -17px; }
  .tile { min-width: 104px; height: 54px; }
  .quiz-panel { padding: 18px 12px 22px; }
  .mode-row { order: 3; width: 100%; justify-content: center; }
}
