/* ==========================================================================
   Spelling Game — smohith.com theme
   Tokens copied from the live Writing Desk page (smohith.com/tools/writing-desk).
   Theme is driven by <html data-theme="light|dark">, same as the rest of the site.
   The site's /css/site.css defines the shared tokens; the ones here repeat them
   as a fallback and add a few game-only ones (--del, --hilite, --inset…).
   ========================================================================== */

:root {
  --bg: #F2F5FB;
  --line: #E1E7F4;
  --ink: #161C40;
  --muted: #4B5578;
  --accent: #3B60B5;
  --hand: #3B60B5;
  --teal-ink: #1E766D;
  --card: #FFFFFF;
  --rule: #B9C4E0;
  --btn-bg: #161C40;
  --btn-fg: #F2F5FB;
  --yellow: #FFC75A;
  --blue: #6E93E0;
  --blue-soft: #8FB0F0;
  --teal: #5FB8AE;
  --teal-soft: #7FD3C8;
  --sky: #8FC9F7;
  --mint: #A8DCC6;
  --night: #0B0F24;
  --night-muted: #A9B2D0;
  --margin-rule: #5FB8AE;
  --del: #B8392C;
  --hilite: rgba(255, 199, 90, .55);
  --inset: #F7F9FD;
  --inset-line: #E1E7F4;
  --shadow-photo: 0 2px 0 rgba(22, 28, 64, .08), 0 24px 50px -18px rgba(22, 28, 64, .45);

  --f-display: "Bricolage Grotesque", system-ui, sans-serif;
  --f-body: "Bricolage Grotesque", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, monospace;
  --f-hand: "Caveat", cursive;

  --gutter: clamp(24px, 5vw, 64px);
  --max: 1320px;
  --read: 890px;
  --tilt: rotate(-2deg);
}

:root[data-theme="dark"] {
  --bg: #0F1328;
  --line: #1A2144;
  --ink: #EEF1FA;
  --muted: #A9B2D0;
  --accent: #8FB0F0;
  --hand: #FFC75A;
  --teal-ink: #7FD3C8;
  --card: #171D3A;
  --rule: #3A4470;
  --btn-bg: #FFC75A;
  --btn-fg: #161C40;
  --del: #F2958A;
  --hilite: rgba(255, 199, 90, .32);
  --inset: #0F1328;
  --inset-line: #232B55;
}

/* Accessibility toggles (set on <html>) */
:root[data-easyread="on"] {
  --f-body: Verdana, Tahoma, "Trebuchet MS", system-ui, sans-serif;
  --f-display: Verdana, Tahoma, "Trebuchet MS", system-ui, sans-serif;
}
:root[data-easyread="on"] body { letter-spacing: .04em; word-spacing: .12em; }
:root[data-largetext="on"] { font-size: 118%; }
:root[data-contrast="on"] { --muted: var(--ink); --rule: var(--ink); --line: var(--rule); }

/* ---------- base ----------
   The page uses the site's own /css/site.css for the body, notebook paper,
   margin rules, header and footer. Everything below is scoped to .sg (the game
   area) so it never changes the site chrome. */
.sg { font-family: var(--f-body); font-size: 17px; line-height: 1.6; color: var(--ink); }
.sg *, .sg *::before, .sg *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main:focus { outline: none; }

/* ---------- page heading ---------- */
.sg .crumb-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 36px 0 8px; }
.sg .crumb-row .crumb { margin: 0; }
.sg .gear-link { display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink); text-decoration: none; border: 1px solid var(--rule); border-radius: 999px; padding: 8px 14px; }
.sg .gear-link:hover { border-color: var(--ink); }
.sg .crumb { display: flex; align-items: center; gap: 10px; margin: 36px 0 8px; font-family: var(--f-mono); font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.sg .crumb .g-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 5px rgba(255, 199, 90, .22); flex: none; }
.sg .crumb a { color: var(--ink); }
.sg h1, .sg .h1 {
  font-family: var(--f-display); font-weight: 800; letter-spacing: -.05em; line-height: .95;
  font-size: clamp(48px, 7.2vw, 86px); margin: 6px 0 22px;
}
.sg .dot-y { color: var(--yellow); }
.sg h2, .sg .h2 { font-family: var(--f-display); font-weight: 800; letter-spacing: -.03em; line-height: 1.1; font-size: clamp(24px, 3vw, 30px); margin: 0 0 12px; }
.sg h3 { font-family: var(--f-display); font-weight: 800; letter-spacing: -.02em; font-size: 21px; line-height: 1.2; margin: 0 0 6px; }
.sg .lead { font-size: 18px; color: var(--muted); max-width: 620px; margin: 0 0 36px; }
.sg .g-hand { font-family: var(--f-hand); color: var(--hand); font-size: 26px; line-height: 1.1; display: inline-block; transform: var(--tilt); }

/* ---------- cards with tabs ---------- */
.sg .card {
  position: relative; background: var(--card); border: 1px solid var(--rule); border-radius: 4px;
  padding: 34px clamp(18px, 2.6vw, 26px) 26px; margin: 22px 0 36px;
}
.sg .g-tab {
  position: absolute; top: -13px; left: 18px;
  font-family: var(--f-mono); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase;
  padding: 4px 10px; color: #161C40; background: var(--yellow); line-height: 1.5;
}
.sg .tab-b { background: var(--blue-soft); }
.sg .tab-t { background: var(--teal-soft); }
.sg .micro { display: block; font-family: var(--f-mono); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.sg .sep { border: 0; border-top: 1px dashed var(--rule); margin: 22px 0; }
.sg .inset { background: var(--inset); border: 1px solid var(--inset-line); border-radius: 4px; padding: 18px 16px; }

/* mode cards on home */
.sg .g-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 26px; margin-bottom: 18px; }
.sg .mode { display: flex; flex-direction: column; margin: 14px 0 0; text-decoration: none; color: var(--ink); transition: transform .15s, box-shadow .15s; }
.sg .mode:hover { transform: translateY(-3px); box-shadow: var(--shadow-photo); }
.sg .mode .icon { width: 54px; height: 54px; margin-bottom: 14px; color: var(--ink); }
.sg .mode p { color: var(--muted); margin: 0 0 18px; flex: 1; }
.sg .mode .go { font-family: var(--f-mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }

/* ---------- chips & buttons ---------- */
.sg .field { margin: 0 0 20px; }
.sg .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sg .chip {
  font-family: var(--f-mono); font-size: 13px; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--rule); border-radius: 999px; background: transparent; color: var(--ink);
  padding: 9px 14px; cursor: pointer; line-height: 1.1;
}
.sg .chip.lang { text-transform: none; letter-spacing: .02em; }
.sg .chip:hover { border-color: var(--ink); }
.sg .chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.sg .g-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--f-mono); font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  border-radius: 999px; padding: 14px 24px; border: 1.6px solid var(--btn-bg);
  background: var(--btn-bg); color: var(--btn-fg); cursor: pointer; text-decoration: none; line-height: 1;
  transform: var(--tilt); transition: transform .12s;
}
.sg .g-btn:hover { transform: rotate(-2deg) translateY(-1px); }
.sg .g-btn:disabled { opacity: .45; cursor: not-allowed; }
.sg .btn-out {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--f-mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--rule); border-radius: 999px; padding: 9px 14px; background: transparent; color: var(--ink); cursor: pointer; line-height: 1.1; text-decoration: none;
}
.sg .btn-out:hover { border-color: var(--ink); }
.sg .btn-out:disabled { opacity: .45; cursor: not-allowed; }
.sg .btn-out[aria-pressed="true"] { background: var(--yellow); color: #161C40; border-color: #161C40; }
.sg .linkish { background: none; border: 0; padding: 0; font-family: var(--f-mono); font-size: 13px; color: var(--accent); text-decoration: underline; cursor: pointer; }
.sg .g-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.sg .g-row.spread { justify-content: space-between; }
.sg .g-note { font-size: 15px; color: var(--muted); margin: 14px 0 0; }
.sg .mt { margin-top: 22px; }

/* badges */
.sg .g-badge { display: inline-block; font-family: var(--f-mono); font-size: 12px; padding: 3px 10px; border-radius: 999px; color: #161C40; background: var(--yellow); line-height: 1.5; }
.sg .badge-b { background: var(--blue-soft); }
.sg .badge-t { background: var(--teal-soft); }

/* form controls */
.sg .input {
  width: 100%; font: inherit; color: var(--ink); background: var(--inset);
  border: 1px solid var(--rule); border-radius: 4px; padding: 11px 14px;
}
textarea.input {
  min-height: 180px; resize: vertical; line-height: 32px; padding-top: 4px;
  background-image: repeating-linear-gradient(transparent 0, transparent 31px, var(--line) 31px, var(--line) 32px);
}
.sg .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sg .input-code { font-family: var(--f-display); font-weight: 800; font-size: 40px; text-transform: uppercase; letter-spacing: .3em; text-align: center; max-width: 340px; }
.sg .switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; }
.sg .switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- play ---------- */
.sg .progress { display: flex; align-items: center; gap: 12px; font-family: var(--f-mono); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.sg .g-bar { flex: 1; height: 6px; border-radius: 6px; background: var(--inset-line); overflow: hidden; }
.sg .g-bar i { display: block; height: 100%; background: var(--yellow); border-radius: 6px; transition: width .3s; }

.sg .speaker {
  display: grid; place-items: center; width: 132px; height: 132px; margin: 14px auto 6px;
  border-radius: 50%; border: 1.6px solid #161C40; background: var(--yellow); color: #161C40; cursor: pointer;
  transform: var(--tilt); transition: transform .15s;
}
.sg .speaker:hover { transform: rotate(-2deg) scale(1.03); }
.sg .speaker svg { width: 56px; height: 56px; }
.sg .speaker.playing { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 199, 90, .55); } 50% { box-shadow: 0 0 0 18px rgba(255, 199, 90, 0); } }
.sg .center { text-align: center; }
.sg .center .g-row { justify-content: center; }
.sg .slots { font-family: var(--f-mono); font-size: 22px; letter-spacing: .4em; color: var(--muted); margin: 10px 0 16px; }
.sg .answer {
  display: block; width: 100%; max-width: 520px; margin: 0 auto; text-align: center;
  font-family: var(--f-display); font-weight: 800; font-size: clamp(28px, 5vw, 44px); letter-spacing: -.01em;
  color: var(--ink); background: transparent; border: 0; border-bottom: 2px solid var(--rule); padding: 8px 4px; border-radius: 0;
}
.sg .answer:focus { outline: none; border-bottom-color: var(--yellow); }
:root[data-largetext="on"] .sg .answer { font-size: clamp(36px, 7vw, 56px); }

/* reveal */
.sg .reveal-word { font-family: var(--f-display); font-weight: 800; font-size: clamp(40px, 7vw, 72px); letter-spacing: -.03em; line-height: 1.05; margin: 6px 0 10px; word-break: break-word; }
.sg .reveal-word .miss { background: var(--hilite); box-shadow: inset 0 -4px 0 var(--yellow); }
.sg .attempt { font-family: var(--f-display); font-size: 22px; }
.sg .attempt s { color: var(--del); }
.sg .attempt .ok { color: var(--teal-ink); }
.sg .feedback { font-family: var(--f-hand); color: var(--hand); font-size: 34px; transform: var(--tilt); display: inline-block; margin-bottom: 4px; line-height: 1.1; }
.sg .meaning .m-main { font-size: 22px; font-weight: 700; }
.sg .meaning .m-en { color: var(--muted); }
.sg .phon { font-family: var(--f-mono); font-size: 14px; color: var(--muted); }

/* list rows */
.sg .list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.sg .item { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; background: var(--inset); border: 1px solid var(--inset-line); border-radius: 4px; padding: 14px 16px; }
.sg .item .w { font-family: var(--f-display); font-weight: 800; font-size: 21px; letter-spacing: -.01em; }
.sg .item .m { color: var(--muted); flex: 1; min-width: 160px; }
.sg .item .acts { display: flex; gap: 6px; margin-left: auto; }
.sg .g-empty { color: var(--muted); font-style: italic; }
.sg .rules { margin: 0; padding-left: 20px; }
.sg .rules li { margin: 4px 0; }

/* host / room */
.sg .g-code { font-family: var(--f-display); font-weight: 800; font-size: clamp(64px, 12vw, 140px); letter-spacing: .06em; line-height: 1; }
.sg .stat { font-family: var(--f-display); font-weight: 800; font-size: 44px; line-height: 1; }
.sg .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 26px; }
.sg .heat { display: grid; gap: 8px; }
.sg .heat-row { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; font-size: 15px; }
.sg .heat-row .hw { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg .heat-row .hb { height: 14px; border-radius: 7px; background: var(--inset-line); overflow: hidden; }
.sg .heat-row .hb i { display: block; height: 100%; border-radius: 7px; }
.sg .heat-row .hp { font-family: var(--f-mono); font-size: 13px; text-align: right; }
.sg .players { display: flex; flex-wrap: wrap; gap: 8px; }
.sg .player { font-family: var(--f-mono); font-size: 13px; border: 1px solid var(--rule); border-radius: 999px; padding: 6px 12px; }
.sg .player.done { background: var(--teal-soft); color: #161C40; border-color: var(--teal-soft); }
.sg .avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.sg .avatar { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; font-size: 24px; cursor: pointer; }
.sg .avatar[aria-pressed="true"] { background: var(--yellow); border-color: #161C40; }

/* spelling bee */
.sg .bee-word { font-family: var(--f-display); font-weight: 800; font-size: clamp(56px, 11vw, 150px); letter-spacing: -.04em; line-height: 1; margin: 10px 0; word-break: break-word; }
.sg .tiles { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: .18em; vertical-align: bottom; }
.sg .tiles i { display: inline-block; width: .5em; height: .72em; border-bottom: .07em solid var(--rule); }
.sg .tiles b { font-weight: 800; color: var(--muted); }
.sg .center .tiles { justify-content: center; }
.sg .timer { font-family: var(--f-mono); font-size: clamp(36px, 6vw, 64px); letter-spacing: .05em; line-height: 1; }
.sg .timer.low { color: var(--del); }
.sg .grade { width: 100%; border-collapse: collapse; font-size: 15px; }
.sg .grade th, .sg .grade td { border-bottom: 1px solid var(--inset-line); padding: 8px 6px; text-align: center; white-space: nowrap; }
.sg .grade th:first-child, .sg .grade td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
.sg .grade th { font-family: var(--f-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 400; }
.sg .tick { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; cursor: pointer; font-size: 15px; color: var(--ink); }
.sg .tick[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal-soft); color: #161C40; }
.sg .scroll-x { overflow-x: auto; }

/* modal + toast */
.sg .modal-back { position: fixed; inset: 0; background: rgba(11, 15, 36, .55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.sg .modal-back .card { max-width: 480px; width: 100%; margin: 0; }
.sg .toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); font-family: var(--f-mono); font-size: 13px; padding: 12px 18px; border-radius: 999px; max-width: calc(100% - 32px); text-align: center;
}
.sg .spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* confetti */
.sg .confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.sg .confetti i { position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .sg .confetti { display: none; } .sg .speaker.playing { animation: none; } }

@media (max-width: 640px) {
  .sg { font-size: 16px; }
  .sg .heat-row { grid-template-columns: 96px 1fr 40px; }
  .sg .g-btn { padding: 13px 20px; }
}

@media print {
  .site-header, .sf, .margin-rule, .sg .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ---------- loading animation ---------- */
.sg .loader-back { animation: fadeIn .2s ease-out; }
.sg .loader-back.out { opacity: 0; transition: opacity .25s; }
.sg .loader { max-width: 520px; text-align: center; padding-top: 40px; }
.sg .loader-tiles { display: flex; justify-content: center; gap: 6px; perspective: 400px; flex-wrap: wrap; }
.sg .loader-tiles i {
  font-style: normal; display: inline-grid; place-items: center; width: 44px; height: 52px; border-radius: 6px;
  font-family: var(--f-display); font-weight: 800; font-size: 26px; color: #161C40; background: var(--yellow);
  border: 1.6px solid #161C40; box-shadow: 0 3px 0 #161C40; animation: tileFlip 2.4s ease-in-out infinite;
}
.sg .loader-tiles i:nth-child(3n+2) { background: var(--blue-soft); }
.sg .loader-tiles i:nth-child(3n) { background: var(--teal-soft); }
@keyframes tileFlip {
  0%, 55%, 100% { transform: rotateX(0) translateY(0); }
  20% { transform: rotateX(180deg) translateY(-6px); }
  35% { transform: rotateX(360deg) translateY(0); }
}
.sg .loader-line { display: block; margin: 0 auto 18px; min-height: 1.3em; }
.sg .loader-line.in { animation: lineIn .4s ease-out; }
@keyframes lineIn { from { opacity: 0; transform: rotate(-2deg) translateY(6px); } to { opacity: 1; transform: rotate(-2deg) translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sg .loader-bar { height: 6px; border-radius: 6px; background: var(--inset-line); overflow: hidden; }
.sg .loader-bar i { display: block; height: 100%; width: 35%; border-radius: 6px; background: var(--yellow); animation: barSlide 1.4s ease-in-out infinite; }
@keyframes barSlide { 0% { transform: translateX(-110%); } 100% { transform: translateX(320%); } }
@media (max-width: 520px) { .sg .loader-tiles i { width: 32px; height: 40px; font-size: 20px; } }
@media (prefers-reduced-motion: reduce) { .sg .loader-tiles i, .sg .loader-bar i, .sg .loader-line.in { animation: none; } }

/* ---------- student / teacher split ---------- */
.sg .teacher-link { margin-top: 8px; font-size: 15px; }
