/* ==========================================================================
   فهيم — Spelling practice (spelling.html). Builds on reading.css (mode cards,
   chips) and lesson.css (hub layout); same tokens, nothing new to theme.
   ========================================================================== */
.spell-page .main > section { min-width: 0; }
.spell-page .card { min-width: 0; }

/* ---------- hub ---------- */
.sp-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-16); margin-bottom: var(--s-24); }
.sp-stat { display: grid; gap: 2px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-card); }
.sp-stat span { font-size: 13px; color: var(--muted); }
.sp-stat b { font-size: 28px; font-weight: var(--w-display); line-height: 1.3; }
.sp-stat small { font-size: 12px; color: var(--muted); }
.sp-stat:first-child { background: var(--highlight-soft); border-color: var(--border-strong); }
.sp-stat:first-child span, .sp-stat:first-child small { color: var(--ink-2); }

.sp-setup { padding: var(--s-24); }
.spell-page .modes { margin-top: var(--s-16); }
.spell-page .mode.is-off { opacity: .5; cursor: not-allowed; }
.sp-levels { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: var(--s-16); font-size: 13px; color: var(--muted); }
.sp-levels .filters { margin: 0; }
.sp-levels .chip small { font-size: 11px; opacity: .8; }
.sp-go { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.sp-go__note { font-size: 13px; color: var(--muted); }

/* ---------- session ---------- */
.sp-session { max-width: 640px; margin-inline: auto; }
.sp-top { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.sp-count { font-weight: var(--w-semibold); color: var(--ink); }
.sp-modename { margin-inline-start: auto; }
.sp-progress { height: 6px; border-radius: var(--r-pill); background: var(--lilac); overflow: hidden; margin-bottom: var(--s-24); }
.sp-progress span { display: block; height: 100%; width: 0; background: var(--ink); border-radius: inherit; transition: width .4s var(--ease-out, ease-out); }

.sp-card {
  position: relative; display: grid; gap: 14px; justify-items: center; text-align: center;
  padding: 32px 24px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel);
}
.sp-again { position: absolute; top: -11px; inset-inline-start: 18px; font-size: 11px; font-weight: var(--w-semibold); background: var(--tint-peach); border: 1px solid var(--ink); border-radius: var(--r-pill); padding: 0 10px; }
.sp-eyebrow { font-size: 13px; color: var(--muted); }
.sp-word { font-size: 40px; font-weight: var(--w-display); letter-spacing: .02em; line-height: 1.2; }
.sp-meaning { font-size: 22px; font-weight: var(--w-display); line-height: 1.5; }
.sp-meaning small { font-size: 12px; font-weight: var(--w-medium); color: var(--muted); border: 1px solid var(--border-strong); border-radius: var(--r-pill); padding: 1px 8px; vertical-align: middle; }
.sp-example { max-width: 46ch; font-size: 15px; line-height: 1.8; color: var(--ink-2); }
.sp-blank { display: inline-block; min-width: 4.5em; border-bottom: 2px solid var(--ink); color: transparent; }

.sp-timer { width: min(260px, 100%); height: 4px; border-radius: var(--r-pill); background: var(--lilac); overflow: hidden; }
.sp-timer span { display: block; height: 100%; background: var(--ink); transform-origin: left center; animation: sp-shrink linear forwards; }
@keyframes sp-shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.sp-listen { width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; background: var(--highlight); border: 1px solid var(--border-strong); box-shadow: none; cursor: pointer; transition: transform var(--dur-fast); }
.sp-listen .icon { width: 36px; height: 36px; }
.sp-listen:hover:not(:disabled) { transform: scale(1.04); }
.sp-listen:disabled { background: var(--lilac); box-shadow: none; cursor: default; }
.sp-plays { font-size: 13px; color: var(--muted); min-height: 1.6em; }

.sp-form { display: flex; gap: 8px; width: min(420px, 100%); }
.sp-input {
  flex: 1; min-width: 0; height: 52px; padding: 0 16px; font-size: 22px; font-weight: var(--w-semibold); text-align: center; letter-spacing: .03em;
  font-family: var(--font); color: var(--ink); background: var(--canvas); border: 1.5px solid var(--border-strong); border-radius: var(--r-input);
}
.sp-input:focus { outline: none; border-color: var(--ink); background: var(--surface); }
.sp-input::placeholder { font-size: 15px; font-weight: var(--w-regular); letter-spacing: 0; color: var(--faint); }
.sp-input:disabled { color: var(--ink-2); }
.sp-input.is-shake { animation: sp-shake .35s; border-color: var(--terracotta); }
@keyframes sp-shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.sp-form .btn { min-height: 52px; }

.sp-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px 14px; }
.sp-actions .btn .icon { width: 16px; height: 16px; }
.sp-hintnote { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.sp-first { font-size: 14px; }
.sp-first b { font-size: 18px; }

/* feedback */
.sp-feedback { width: 100%; display: grid; gap: 12px; justify-items: center; }
.sp-feedback:empty { display: none; }
.sp-ok { display: flex; gap: 10px; align-items: flex-start; text-align: start; width: min(420px, 100%); padding: 12px 14px; background: var(--tint-violet); border: 1px solid var(--border-strong); border-radius: var(--r-card); }
.sp-ok > .icon { width: 22px; height: 22px; flex: none; margin-top: 2px; }
.sp-ok p { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.sp-bad { width: min(460px, 100%); display: grid; gap: 10px; padding: 14px; text-align: start; background: #fdf1ea; border: 1px solid var(--terracotta); border-radius: var(--r-card); }
.sp-diff { display: grid; gap: 6px; }
.sp-diff > div { display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: baseline; gap: 10px; }
.sp-diff span { font-size: 12px; color: var(--muted); }
.sp-diff b { font-size: 22px; font-weight: var(--w-semibold); letter-spacing: .06em; text-align: left; word-break: break-all; }
.sp-diff mark { background: var(--highlight); color: var(--ink); border-radius: 3px; padding: 0 1px; }
.sp-diff del { color: var(--terracotta); text-decoration: line-through 2px; }
.sp-gap { display: inline-block; width: .55em; height: .9em; margin: 0 1px; vertical-align: -0.1em; border-bottom: 3px solid var(--terracotta); }
.sp-none { font-size: 14px; font-weight: var(--w-regular); color: var(--muted); letter-spacing: 0; }
.sp-tips { display: grid; gap: 4px; padding-top: 8px; border-top: 1px dashed rgba(203, 85, 33, .4); }
.sp-tips li { font-size: 13.5px; line-height: 1.7; color: var(--ink); }
.sp-copylabel { font-size: 13px; color: var(--ink-2); }

/* ---------- summary ---------- */
.sp-summary { max-width: 720px; margin-inline: auto; display: grid; gap: var(--s-16); }
.sp-result { display: grid; gap: 8px; justify-items: start; padding: var(--s-24); }
.sp-score { font-size: 18px; }
.sp-score b { font-size: 44px; font-weight: var(--w-display); line-height: 1.1; }
.sp-score small { font-size: 13px; color: var(--muted); }
.sp-sub { font-size: 13px; color: var(--muted); margin-top: -6px; }
.sp-line { font-size: 15px; color: var(--ink-2); }
.sp-warn { font-size: 13px; color: var(--terracotta); }
.sp-result .sp-actions { justify-content: flex-start; margin-top: 8px; }
.sp-rows { display: grid; gap: 8px; }
.sp-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-card); }
.sp-row--bad { border-color: var(--terracotta); }
.sp-row__word b { font-size: 17px; font-weight: var(--w-display); margin-inline-end: 8px; }
.sp-row__word span { font-size: 13px; color: var(--muted); }
.sp-row .sp-diff { grid-column: 1 / -1; }
.sp-row .sp-diff b { font-size: 17px; }
.sp-tag { font-size: 12px; font-weight: var(--w-semibold); border-radius: var(--r-pill); padding: 2px 10px; border: 1px solid var(--border-strong); white-space: nowrap; }
.sp-tag--ok { background: var(--tint-violet); }
.sp-tag--help { background: var(--highlight); }
.sp-tag--bad { background: #fbe1d3; border-color: var(--terracotta); color: var(--terracotta); }

/* ---------- writing hub card (writing.html) ---------- */
.w-spell { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px 28px; align-items: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel); padding: 22px; }
.w-spell h3 { font-size: 20px; font-weight: var(--w-display); line-height: 1.45; }
.w-spell p { font-size: 14.5px; line-height: 1.85; color: var(--muted); }
.w-spell__claim { display: inline-block; font-size: 13px; font-weight: var(--w-semibold); color: var(--ink); background: var(--highlight); border-radius: var(--r-pill); padding: 2px 10px; margin-bottom: 6px; }
.w-spell__modes { display: grid; gap: 8px; }
.w-spell__modes li { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--ink-2); }
.w-spell__modes .icon { width: 18px; height: 18px; flex: none; }
.w-spell__modes b { color: var(--ink); }
.w-spell__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.w-spell__stat { font-size: 13px; color: var(--muted); }

@media (max-width: 760px) {
  .sp-stats { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .sp-stat { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .sp-stat b { grid-row: 1 / span 2; grid-column: 2; font-size: 24px; }
  .w-spell { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .sp-card { padding: 26px 16px; }
  .sp-word { font-size: 32px; }
  .sp-meaning { font-size: 19px; }
  .sp-form { flex-direction: column; }
  .sp-diff b { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  .sp-input.is-shake { animation: none; }
  .sp-timer span { animation-duration: 0s !important; }
}

/* ---------- «لمحة», the game: the door on the hub ---------- */
.sg-door {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 14px 18px;
  padding: 18px 22px; margin-bottom: var(--s-24); background: var(--t-writing); border: 1px solid var(--l-writing); border-radius: var(--r-panel);
}
.sg-door__icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--l-writing); color: var(--c-writing); }
.sg-door__icon .icon { width: 28px; height: 28px; fill: currentColor; stroke-width: 1.4; }
.sg-door__text h2 { font-size: 22px; font-weight: var(--w-display); line-height: 1.3; }
.sg-door__text p { font-size: 13px; color: var(--ink-2); }
.sg-door__best { display: grid; justify-items: center; line-height: 1.2; }
.sg-door__best span { font-size: 12px; color: var(--ink-2); }
.sg-door__best b { font-size: 24px; font-weight: var(--w-display); }

/* ---------- the game screen ---------- */
.sg { max-width: 560px; margin-inline: auto; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sg-top { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 12px; margin-bottom: 12px; }
.sg-iconbtn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--surface); border: 1px solid var(--border-strong); color: var(--ink); cursor: pointer; }
.sg-iconbtn:hover { background: var(--lilac); }
.sg-iconbtn .icon { width: 18px; height: 18px; }
.sg-iconbtn.is-off { color: var(--faint); position: relative; }
.sg-iconbtn.is-off::after { content: ""; position: absolute; width: 22px; height: 2px; background: currentColor; transform: rotate(-45deg); border-radius: 2px; }

.sg-hearts { display: flex; gap: 4px; }
.sg-hearts.is-hurt { animation: sg-hurt .4s; }
@keyframes sg-hurt { 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }
.sg-heart { position: relative; width: 26px; height: 26px; }
.sg-heart svg { position: absolute; inset: 0; width: 100%; height: 100%; fill: var(--lilac); stroke: var(--border-strong); stroke-width: 1.4; }
.sg-heart .sg-heart__fill { fill: var(--terracotta); stroke: var(--terracotta); }
.sg-heart--half .sg-heart__fill { clip-path: inset(0 50% 0 0); }
.sg-heart--empty .sg-heart__fill { display: none; }

.sg-score { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.sg-score b { font-size: 28px; font-weight: var(--w-display); line-height: 1; font-variant-numeric: tabular-nums; }
.sg-combo { font-size: 14px; font-weight: var(--w-bold); background: var(--highlight); border: 1px solid var(--highlight-edge); border-radius: var(--r-pill); padding: 1px 10px; }
.sg-combo.is-pop { animation: sg-pop .35s var(--ease-spring); }
@keyframes sg-pop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }

.sg-stage {
  position: relative; display: grid; justify-items: center; align-content: center; gap: 10px; min-height: 230px; padding: 34px 20px 20px; text-align: center;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel); overflow: hidden;
  transition: background var(--dur), border-color var(--dur);
}
.sg-stage.is-hot { background: var(--highlight-soft); border-color: var(--highlight-line); }
.sg-stage.is-fire { background: var(--highlight-soft); border-color: var(--highlight-edge); box-shadow: inset 0 0 0 2px var(--highlight); }
.sg-level { position: absolute; top: 12px; inset-inline-start: 16px; font-size: 12px; color: var(--muted); }
.sg-level b { color: var(--c-writing); }
.sg-show { min-height: 96px; display: grid; place-items: center; width: 100%; }
.sg-word { font-size: 44px; font-weight: var(--w-display); line-height: 1.2; letter-spacing: .02em; word-break: break-word; }
.sg-word--phrase { font-size: 34px; }
.sg-word--ok { color: var(--c-speaking); animation: sg-pop .3s var(--ease-spring); }
.sg-word--fix { font-size: 36px; }
.sg-word--fix mark { background: transparent; color: var(--terracotta); text-decoration: underline 3px; text-underline-offset: 6px; }
.sg-gone { width: 64px; height: 4px; border-radius: 2px; background: var(--border-strong); }
.sg-count { font-size: 64px; font-weight: var(--w-display); line-height: 1; animation: sg-pop .3s var(--ease-spring); }

.sg-listen { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; background: var(--highlight); border: 1px solid var(--highlight-edge); color: var(--ink); cursor: pointer; animation: sg-pulse 1.4s ease-in-out infinite; }
.sg-listen .icon { width: 36px; height: 36px; }
.sg-listen:disabled { background: var(--lilac); border-color: var(--border-strong); animation: none; cursor: default; }
@keyframes sg-pulse { 50% { transform: scale(1.06); } }

.sg-fb { min-height: 28px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 12px; }
.sg-verdict { font-size: 14px; font-weight: var(--w-bold); color: var(--terracotta); background: #fde5e5; border-radius: var(--r-pill); padding: 2px 12px; }
.sg-verdict--near { color: var(--c-plan); background: var(--highlight-soft); }
.sg-typed { font-size: 16px; color: var(--muted); text-decoration: line-through 2px var(--terracotta); }
.sg-nudge { position: absolute; bottom: 12px; font-size: 12px; color: var(--ink-2); background: var(--lilac); border-radius: var(--r-pill); padding: 2px 12px; }

.sg-float { position: absolute; top: 38%; inset-inline: 0; margin-inline: auto; width: max-content; font-size: 26px; font-weight: var(--w-display); color: var(--c-speaking); pointer-events: none; animation: sg-up .9s var(--ease-out) forwards; }
@keyframes sg-up { 0% { opacity: 0; transform: translateY(10px) scale(.8); } 20% { opacity: 1; transform: translateY(0) scale(1.1); } 100% { opacity: 0; transform: translateY(-60px) scale(1); } }

.sg-banner { display: grid; justify-items: center; line-height: 1.2; animation: sg-pop .35s var(--ease-spring); }
.sg-banner span { font-size: 14px; color: var(--muted); }
.sg-banner b { font-size: 60px; font-weight: var(--w-display); }
.sg-banner small { font-size: 14px; font-weight: var(--w-semibold); }
.sg-banner--revenge b { color: var(--c-writing); }

.sg-form { margin-top: 14px; }
.sg-input {
  width: 100%; height: 60px; padding: 0 18px; font-size: 26px; font-weight: var(--w-semibold); text-align: center; letter-spacing: .04em;
  font-family: var(--font); color: var(--ink); background: var(--surface); border: 2px solid var(--border-strong); border-radius: var(--r-card);
  user-select: text; -webkit-user-select: text;
}
.sg-input:focus { outline: none; border-color: var(--ink); }
.sg-input::placeholder { font-size: 15px; font-weight: var(--w-regular); letter-spacing: 0; color: var(--faint); }
.sg-input.is-ok { border-color: var(--c-speaking); background: var(--t-speaking); }
.sg-input.is-bad { border-color: var(--terracotta); }
.sg-input.is-shake { animation: sp-shake .35s; }
.sg-time { height: 6px; margin-top: 10px; border-radius: var(--r-pill); background: var(--lilac); overflow: hidden; }
.sg-time span { display: block; height: 100%; background: var(--ink); border-radius: inherit; transform-origin: right center; transform: scaleX(0); }

/* the result */
.sg-result { display: grid; justify-items: center; gap: 8px; padding: 34px 22px 26px; text-align: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel); }
.sg-result.is-record { background: var(--highlight-soft); border-color: var(--highlight-line); }
.sg-result__score b { font-size: 72px; font-weight: var(--w-display); line-height: 1.1; font-variant-numeric: tabular-nums; }
.sg-rec { font-size: 18px; font-weight: var(--w-bold); background: var(--highlight); border-radius: var(--r-pill); padding: 2px 16px; animation: sg-pop .4s var(--ease-spring); }
.sg-close { font-size: 16px; font-weight: var(--w-semibold); color: var(--c-writing); }
.sg-best { font-size: 14px; color: var(--muted); }
.sg-result__facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.sg-result__go { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 10px; }
.sg-missed { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--border); width: 100%; }
.sg-missed li { font-size: 15px; font-weight: var(--w-semibold); background: var(--lilac); border-radius: var(--r-pill); padding: 2px 12px; }

@media (max-width: 560px) {
  .sg-door { grid-template-columns: auto minmax(0, 1fr) auto; padding: 16px; }
  .sg-door .btn { grid-column: 1 / -1; justify-self: stretch; justify-content: center; }
  .sg-stage { min-height: 180px; padding: 30px 14px 16px; }
  .sg-word { font-size: 36px; }
  .sg-word--phrase, .sg-word--fix { font-size: 28px; }
  .sg-input { height: 54px; font-size: 22px; }
  .sg-heart { width: 22px; height: 22px; }
  .sg-result__score b { font-size: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  .sg-listen, .sg-float, .sg-hearts.is-hurt, .sg-combo.is-pop, .sg-input.is-shake { animation: none; }
}
