/* =====================================================================
   TABLE OF CONTENTS
   1.  Tokens (colours) + dark theme
   2.  Base
   3.  Layout (app shell, title, splash, banners)
   4.  Controls (mode switch, round buttons)
   5.  Board
   6.  Keyboard
   7.  Toast
   8.  Dialogs (base, win, game info)
   9.  Community (friends, inbox)
   10. Challenge mode
   11. Buttons
   12. User bar, menu, profile
   13. Auth pages
   14. Leaderboard / stats / options
   15. Celebration (confetti)
   16. Player mailbox + admin message form
   17. Admin page
   18. Mobile overrides
   19. Animations (all @keyframes)

   HOW DARK MODE WORKS
   Never write dark-mode selectors per component. Components use the
   variables below; [data-theme="dark"] just swaps the variable values.
   Need a new dark colour? Add/change a variable in section 1.
   ===================================================================== */


/* =====================================================================
   1. TOKENS
   ===================================================================== */
:root {
  --bg: #f4efff;          /* page background */
  --surface: #fff;        /* cards, dialogs, keys, inputs */
  --ink: #392d62;         /* main text */
  --line: #ded5f2;        /* borders + tile shadows */
  --dots: #e3d9fb;        /* dotted background pattern */
  --pill: var(--ink);     /* selected toggle + toast background */

  /* colour + its darker "3D shadow" shade (the *d variables) */
  --hot: #ff6584;  --hotd: #d74767;   /* pink */
  --vio: #765be8;  --viod: #5a40c8;   /* violet (main buttons) */
  --ok:  #47b982;  --okd:  #29865b;   /* green  = correct letter */
  --mid: #f5c84c;  --midd: #d2a52e;   /* yellow = wrong place */
  --no:  #aaa4b7;  --nod:  #81798f;   /* grey   = not in word / muted text */
}

:root[data-theme="dark"] {
  --bg: #17151f;
  --surface: #252230;
  --ink: #eee9fa;
  --line: #454052;
  --dots: #302b3a;
  --nod: #b5adc7;
  --pill: var(--vio);
}

/* the only dark-mode-specific component rules */
:root[data-theme="dark"] #kb button[data-k="Backspace"] {
  background: #c64e69;
  color: #fff;
  box-shadow: 0 3px 0 #8d354b;
}


/* =====================================================================
   2. BASE
   ===================================================================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  margin: 0;
}

/* same dotted background on game, splash and auth pages */
body, #splash-screen, .auth-page {
  background:
    radial-gradient(circle at 1px 1px, var(--dots) 1.5px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}

body {
  display: flex;
  justify-content: center;
  font: 600 16px/1.2 "Baloo 2", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  touch-action: manipulation;
}

/* anything with the hidden attribute is hidden, no exceptions */
[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
}
button:hover:not(:disabled)  { filter: brightness(1.06); }
button:active:not(:disabled) { transform: scale(.97); }

:focus-visible {
  outline: 3px solid var(--vio);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    transition: none !important;
  }
}


/* =====================================================================
   3. LAYOUT
   ===================================================================== */
#app {
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}

main {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 0;
}

/* --- title: six coloured letter tiles --- */
h1 {
  display: flex;
  gap: 5px;
  margin: 4px 0 0;
}
h1 span {
  width: 36px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  font-size: 23px;
  font-weight: 700;
  box-shadow: 0 4px 0 rgba(42, 31, 77, .22);
}
h1 span:nth-child(1) { background: var(--hot); transform: rotate(-5deg); }
h1 span:nth-child(2) { background: var(--vio); transform: rotate(3deg); }
h1 span:nth-child(3) { background: var(--ok);  transform: rotate(-2deg); }
h1 span:nth-child(4) { background: var(--mid); transform: rotate(4deg); color: var(--ink); }
h1 span:nth-child(5) { background: var(--hot); transform: rotate(-3deg); }
h1 span:nth-child(6) { background: var(--vio); transform: rotate(5deg); }

/* --- build number (top-left corner) --- */
#build-info {
  position: fixed;
  top: max(5px, env(safe-area-inset-top));
  left: 8px;
  z-index: 1001;
  color: var(--nod);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .02em;
  opacity: .52;
  pointer-events: none;
  user-select: none;
}

/* --- splash screen --- */
#splash-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  transition: opacity .45s, visibility .45s;
}
#splash-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#splash-screen h1 { display: block; margin: 5px 0 0; font-size: 38px; font-weight: 700; }
#splash-screen p  { margin: 0; color: var(--nod); font-size: 18px; }

.splash-card {
  width: min(100%, 340px);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 36px 24px;
  border-radius: 30px;
  background: var(--surface);
  box-shadow: 0 9px 0 var(--line);
  text-align: center;
  animation: splash-card-in .55s cubic-bezier(.2, 1.4, .4, 1) both;
}
.splash-letter {
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border-radius: 28px;
  background: var(--ok);
  color: #fff;
  font-size: 78px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 7px 0 var(--okd);
  transform: rotate(-5deg);
  animation: splash-letter-bob .8s ease-in-out infinite alternate;
}
.splash-dots { display: flex; gap: 8px; margin-top: 4px; }
.splash-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--hot);
  animation: splash-dot .65s ease-in-out infinite alternate;
}
.splash-dots span:nth-child(2) { background: var(--vio); animation-delay: .16s; }
.splash-dots span:nth-child(3) { background: var(--mid); animation-delay: .32s; }

/* --- maintenance banner --- */
#maint-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  padding: 12px 16px;
  background: #fff0cb;
  color: #634600;
  text-align: center;
  box-shadow: 0 3px 0 #e7c86c;
}

/* --- champion banner (scrolling gold bar, collapsible) --- */
#champion-banner {
  position: relative;
  align-self: flex-end;
  width: 100%;
  max-width: 420px;
  height: 48px;
  overflow: hidden;
  padding: 8px 40px 8px 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #fff4c2, #f4d66f);
  color: #604300;
  box-shadow: 0 3px 0 #d8b64a;
  transition: width .55s cubic-bezier(.2, 1.1, .3, 1), border-radius .4s, padding .4s, box-shadow .4s, background .65s ease;
}
#champion-banner strong { font-weight: 700; }

.champion-marquee {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  clip-path: inset(0);
  transition: opacity .65s ease, clip-path .65s ease;
}
.champion-track {
  display: flex;
  width: max-content;
  will-change: transform;
  animation: champion-marquee-right 38s linear infinite;
}
.champion-group { display: flex; flex: none; align-items: center; }
.champion-item  { display: flex; flex: none; align-items: center; gap: 8px; padding: 0 24px; white-space: nowrap; }

#champion-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f4d66f;
  color: #604300;
  font-size: 27px;
  line-height: 1;
  box-shadow: 0 2px 0 #d8b64a;
  transform: translateY(-50%);
  transition: transform .4s cubic-bezier(.2, 1.1, .3, 1), background .2s;
}

#champion-banner.is-collapsed {
  width: 44px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
}
#champion-banner.is-collapsed .champion-marquee {
  opacity: 0;
  clip-path: inset(0 0 0 100%);
  pointer-events: none;
}
#champion-banner.is-collapsed .champion-track  { animation-play-state: paused; }
#champion-banner.is-collapsed #champion-toggle { transform: translateY(-50%) rotate(180deg); }


/* =====================================================================
   4. CONTROLS
   ===================================================================== */
#ctl {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* segmented switch (word length etc.) */
.seg {
  display: flex;
  background: var(--surface);
  border-radius: 15px;
  padding: 3px;
  box-shadow: inset 0 0 0 2px var(--line);
}
.seg button {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 12px;
  transition: background .15s, color .15s;
}
.seg button[aria-pressed=true] {
  background: var(--pill);
  color: #fff;
}

/* round icon buttons: pink by default, violet for the variants */
.round {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--hot);
  color: #fff;
  font-size: 21px;
  box-shadow: 0 3px 0 var(--hotd);
}
.fullscreen-toggle,
.info-button,
.share-word-button {
  background: var(--vio);
  box-shadow: 0 3px 0 var(--viod);
}
.info-button { font-weight: 800; }
.share-word-button svg {
  width: 21px;
  height: 21px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* "pressed" look for 3D buttons.
   Must stay ABOVE the keyboard rules (section 6) so coloured keys keep their shadow. */
.round:active,
.btn:active,
#kb button:active {
  transform: translateY(3px);
  box-shadow: none;
}

/* debug helpers */
.debug-option {
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--vio);
  font: inherit;
  font-size: 12px;
  box-shadow: 0 2px 0 var(--line);
}
.debug-answer {
  padding: 5px 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--nod);
  font-size: 13px;
}
.debug-answer strong { color: var(--vio); letter-spacing: .08em; }


/* =====================================================================
   5. BOARD
   --t = tile size, shrinks to fit width AND height
   ===================================================================== */
#board {
  --t: min(62px, calc((100vw - 56px) / var(--len, 5)), calc((100dvh - 430px) / 6));
  display: grid;
  gap: 6px;
}
.row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.row i {
  width: var(--t);
  height: var(--t);
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
  font-style: normal;
  font-weight: 700;
  font-size: calc(var(--t) * .55);
}
.row i[role=button] { cursor: pointer; touch-action: manipulation; }

/* tile states (order matters: later rules win) */
.row i.on        { border-color: var(--ink); box-shadow: 0 4px 0 var(--ink); }
.row i.autofilled{ background: var(--ok); border-color: var(--ok); box-shadow: 0 4px 0 var(--okd); color: #fff; }
.row i.selected  { outline: 3px solid var(--vio); outline-offset: 2px; }
.row i[data-s="0"] { background: var(--no);  border-color: var(--no);  box-shadow: 0 4px 0 var(--nod);  color: #fff; }
.row i[data-s="1"] { background: var(--mid); border-color: var(--mid); box-shadow: 0 4px 0 var(--midd); }
.row i[data-s="2"] { background: var(--ok);  border-color: var(--ok);  box-shadow: 0 4px 0 var(--okd);  color: #fff; }

/* animation helpers (added by JS) */
.pop   { animation: pop .14s; }
.flip  { animation: flip .56s both; }
.hop   { animation: hop .5s; }
.shake { animation: shake .4s; }
.row i.tile-refresh {
  animation: tile-refresh .42s cubic-bezier(.2, 1.25, .35, 1) both;
  animation-delay: var(--refresh-delay);
}


/* =====================================================================
   6. KEYBOARD
   ===================================================================== */
#kb {
  width: 100%;
  display: grid;
  gap: 6px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.kr { display: flex; gap: 4px; justify-content: center; }
.kr:nth-child(2) { padding: 0 4%; }

#kb button {
  position: relative;
  flex: 1;
  max-width: 46px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: var(--surface);
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 3px 0 var(--line);
  touch-action: none;
}
#kb button[data-hint]::after {
  content: attr(data-hint);
  position: absolute;
  top: -7px;
  right: -5px;
  z-index: 2;
  min-width: 18px;
  padding: 2px 4px;
  border: 1px solid #fff;
  border-radius: 8px;
  background: var(--vio);
  color: #fff;
  font-size: 10px;
  line-height: 1.2;
  box-shadow: 0 2px 4px #17151f66;
}
#kb button[data-k=Enter],
#kb button[data-k=Backspace] {
  flex: 1.6;
  max-width: 70px;
  font-size: 14px;
}
#kb button[data-k=Enter] { background: var(--hot); color: #fff; box-shadow: 0 3px 0 var(--hotd); }
#kb button[data-s="0"]   { background: var(--no);  color: #fff; box-shadow: 0 3px 0 var(--nod); }
#kb button[data-s="1"]   { background: var(--mid); box-shadow: 0 3px 0 var(--midd); }
#kb button[data-s="2"]   { background: var(--ok);  color: #fff; box-shadow: 0 3px 0 var(--okd); }

/* long-press popup with accented letters */
.key-variants {
  position: fixed;
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 4px 12px #392d6233;
}
.key-variants button {
  width: 42px;
  height: 44px;
  border: 0;
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  touch-action: none;
}
.key-variants button[data-s="2"] { background: var(--ok); color: #fff; box-shadow: 0 3px 0 var(--okd); }
.key-variants button[data-s="1"] { background: var(--mid); color: var(--ink); box-shadow: 0 3px 0 var(--midd); }
.key-variants button.is-hovered:not([data-s]) { background: var(--vio); color: #fff; }
.key-variants button.is-hovered[data-s] { outline: 2px solid var(--vio); outline-offset: 2px; }


/* =====================================================================
   7. TOAST
   ===================================================================== */
#toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--pill);
  color: #fff;
  padding: 9px 18px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 9;
}
#toast.show { opacity: 1; }


/* =====================================================================
   8. DIALOGS
   ===================================================================== */
dialog {
  border: 0;
  border-radius: 26px;
  padding: 24px;
  width: calc(100% - 40px);
  max-width: 340px;
  background: var(--surface);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 8px 0 var(--line);
}
dialog::backdrop { background: rgba(42, 31, 77, .5); }
dialog h2 { margin: 0; font-size: 28px; }
dialog p  { margin: 6px 0 4px; color: var(--nod); }

/* win / result dialogs pop in */
dialog.win[open],
.challenge-result-dialog[open] {
  animation: win-panel-in .5s cubic-bezier(.2, 1.4, .4, 1) both;
}

/* win dialog content */
#dw {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .06em;
  background: var(--ok);
  color: #fff;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 4px 0 var(--okd);
  overflow-wrap: anywhere;
}
#dictionary { display: block; margin: 12px 0; text-decoration: none; }
#ds { display: flex; gap: 8px; margin: 16px 0; }
#ds div { flex: 1; background: var(--bg); border-radius: 14px; padding: 8px 4px; font-size: 13px; }
#ds b { display: block; font-size: 24px; }
.acts { display: flex; gap: 10px; }

/* "how to play" dialog */
.example-title { font-weight: 700; }
.example-guesses { display: grid; gap: 7px; margin: 10px 0; }
.example-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}
.example-tile {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
}
.example-tile.absent    { background: var(--no); }
.example-tile.misplaced { background: var(--mid); color: var(--ink); }
.example-tile.correct   { background: var(--ok); }

.info-legend { display: grid; gap: 10px; margin: 16px 0; text-align: left; }
.info-legend-item { display: flex; align-items: center; gap: 10px; }
.info-chip {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  font-weight: 800;
}
.info-chip.absent    { background: var(--no); }
.info-chip.misplaced { background: var(--mid); color: var(--ink); }
.info-chip.correct   { background: var(--ok); }

.game-info-dialog p { line-height: 1.45; }
.game-info-dialog .btn { width: 100%; margin-top: 10px; }


/* =====================================================================
   9. COMMUNITY (friends, inbox)
   ===================================================================== */
.community-dialog {
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: left;
}
.community-dialog > h2,
.community-dialog > p:first-of-type,
.community-dialog > h3 { text-align: center; }
.community-dialog h3 { margin: 18px 0 8px; }
.community-tabs { margin: 14px 0; }
.community-tab-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 4px; border-radius: 15px; background: var(--bg); }
.community-tab-list button { min-width: 0; min-height: 42px; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 7px 6px; border: 0; border-radius: 11px; background: transparent; color: var(--ink); font: inherit; font-size: 13px; }
.community-tab-list button[aria-selected="true"] { background: var(--vio); color: #fff; box-shadow: 0 2px 0 var(--viod); }
.community-tabs .notification-count { min-width: 18px; height: 18px; font-size: 10px; }
.community-tabs-toggle { display: none; }
.community-panel { min-width: 0; }
#enable-notifications, #close-community { width: 100%; }
#close-community { margin-top: 12px; }

@media (max-width: 800px) {
  .community-tabs { position: relative; }
  .community-tabs-toggle { width: 100%; min-height: 48px; display: flex; align-items: center; gap: 11px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--ink); font: inherit; font-weight: 700; text-align: left; }
  .community-menu-icon { width: 18px; flex: 0 0 18px; display: grid; gap: 4px; }
  .community-menu-icon i { height: 2px; border-radius: 2px; background: var(--vio); transition: transform .2s, opacity .2s; }
  .community-tabs.is-open .community-menu-icon i:first-child { transform: translateY(6px) rotate(45deg); }
  .community-tabs.is-open .community-menu-icon i:nth-child(2) { opacity: 0; }
  .community-tabs.is-open .community-menu-icon i:last-child { transform: translateY(-6px) rotate(-45deg); }
  .community-current-tab { flex: 1; }
  .community-tabs-chevron { color: var(--vio); transition: transform .2s; }
  .community-tabs-toggle[aria-expanded="true"] .community-tabs-chevron { transform: rotate(180deg); }
  .community-tab-list { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; display: none; grid-template-columns: 1fr; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 10px 24px #17151f55; }
  .community-tabs.is-open .community-tab-list { display: grid; }
  .community-tab-list button { min-height: 44px; justify-content: flex-start; padding: 9px 12px; font-size: 14px; }
}

.friend-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  margin-top: 12px;
}
.friend-search-form label { grid-column: 1 / -1; font-size: 14px; }
.friend-search-form input {
  width: 100%;
  min-width: 0;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.friend-search-form .btn { flex: none; padding: 11px 15px; }

.community-list { display: grid; gap: 8px; margin: 12px 0; }
.community-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 13px;
  background: var(--bg);
  text-align: left;
}
.community-entry-name { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.community-entry-actions { display: flex; flex: none; gap: 6px; }
.community-entry .btn { flex: none; padding: 7px 10px; font-size: 13px; }
.community-entry .btn.alt { background: var(--hot); box-shadow: 0 3px 0 var(--hotd); }

.friend-status { flex: none; font-size: 13px; font-weight: 700; }
.friend-status.online  { color: #218a4b; }
.friend-status.offline { color: #d43d4d; }
.friend-score { flex: none; font-size: 13px; font-weight: 800; white-space: nowrap; }

.inbox-button { display: flex; align-items: center; gap: 8px; }
.notification-count {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--hot);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

/* online / offline dot */
.presence-status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13px; }
.presence-dot { display: inline-block; width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; }
.presence-dot.online  { background: #2dbb68; box-shadow: 0 0 0 3px #d8f4e2; }
.presence-dot.offline { background: #e34f5f; box-shadow: 0 0 0 2px #f9dadd; }


/* =====================================================================
   10. CHALLENGE MODE
   ===================================================================== */
.challenge-banner {
  width: min(calc(100% + 16px), 420px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 3px 0 var(--line);
  font-size: 14px;
}
.challenge-topline {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
}
#challenge-heading { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#challenge-score { font-size: 16px; font-weight: 800; }
#challenge-timer {
  align-self: center;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--vio);
  white-space: nowrap;
}
#challenge-timer.is-urgent { color: var(--hot); animation: timer-pulse .8s ease-in-out infinite alternate; }

.challenge-resign {
  min-width: 86px;
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  padding: 7px 10px;
  background: var(--hot);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--hotd);
}

/* taunt emoji buttons */
.challenge-taunts {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  margin: 0;
}
.challenge-taunts button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 27px;
  line-height: 1;
  touch-action: manipulation;
  transition: transform .15s cubic-bezier(.2, 1.5, .4, 1);
}
.challenge-taunts button:active:not(:disabled) { transform: scale(.82) rotate(-8deg); }
.challenge-taunts button:disabled { opacity: .55; cursor: wait; }

.falling-challenge-taunt {
  position: fixed;
  top: -12vh;
  left: var(--taunt-x);
  z-index: 2147483645;
  font-size: var(--taunt-size, 60px);
  line-height: 1;
  pointer-events: none;
  will-change: transform;
  animation: challenge-taunt-fall var(--taunt-duration, 2.4s) cubic-bezier(.2, .7, .3, 1) var(--taunt-delay, 0s) forwards;
}

/* opponent's mini board */
.challenge-opponent-rows { grid-column: 1; grid-row: 2; display: grid; gap: 3px; }
.challenge-feedback-row  { display: flex; gap: 3px; }
.challenge-feedback-tile { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 3px; background: var(--line); }
.challenge-feedback-tile[data-s="0"] { background: var(--no); }
.challenge-feedback-tile[data-s="1"] { background: var(--mid); }
.challenge-feedback-tile[data-s="2"] { background: var(--ok); }

/* challenge setup + result dialogs */
.challenge-lengths { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.challenge-dialog .acts { margin: 12px 0; }
.btn.challenge-accept { background: var(--ok); box-shadow: 0 4px 0 var(--okd); }
.btn.challenge-decline { background: var(--hot); box-shadow: 0 4px 0 var(--hotd); }
.challenge-invite-notice[open] {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  right: auto;
  bottom: auto;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  margin: 0;
  transform: translateX(-50%);
  animation: challenge-invite-drop .42s cubic-bezier(.2, .8, .25, 1) both;
}
.challenge-invite-notice::backdrop { background: #17151f22; }
.challenge-invite-timer { height: 8px; overflow: hidden; border-radius: 99px; background: var(--line); }
.challenge-invite-timer span { width: 100%; height: 100%; display: block; border-radius: inherit; background: var(--ok); transform: scaleX(1); transform-origin: left center; will-change: transform; }
.challenge-invite-countdown { margin: 6px 0; color: var(--nod); text-align: center; font-size: 12px; font-weight: 700; }
@keyframes challenge-invite-drop {
  from { opacity: 0; transform: translate(-50%, -130%); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .challenge-invite-notice[open] { animation: none; }
}
#challenge-timer-choice {
  width: 100%;
  margin: 0 0 10px;
  padding: 11px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.challenge-result-dialog { max-width: 360px; }
#challenge-result-dictionary { display: block; margin: 12px 0; text-decoration: none; }
.challenge-result-actions { display: grid; gap: 8px; margin-top: 12px; }
#challenge-result-action-message:empty { display: none; }
#challenge-result-answer {
  margin: 10px 0;
  padding: 10px;
  border-radius: 14px;
  background: var(--ok);
  color: #fff;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: .08em;
  box-shadow: 0 4px 0 var(--okd);
}
.challenge-result-dialog .btn { width: 100%; }
.challenge-progress-in { animation: challenge-progress-in .35s ease-out both; }
.challenge-start-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #100d1c9c;
  backdrop-filter: blur(7px);
  touch-action: none;
}
.challenge-start-text {
  width: clamp(190px, 58vw, 300px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 4px solid var(--vio);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 10px #7958e833, 0 18px 60px #0006;
  color: var(--vio);
  font-size: clamp(88px, 25vw, 148px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.challenge-start-text.ready {
  width: auto;
  aspect-ratio: auto;
  padding: 20px 28px;
  border-radius: 20px;
  font-size: clamp(24px, 7vw, 38px);
  white-space: nowrap;
}
.challenge-start-text.go {
  border-color: var(--ok);
  color: var(--ok);
  box-shadow: 0 0 0 10px #2dbb6833, 0 18px 60px #0006;
  font-size: clamp(34px, 12vw, 60px);
  letter-spacing: -.04em;
  white-space: nowrap;
}
.challenge-start-text.is-animated { animation: challenge-start-pop .62s cubic-bezier(.18, .85, .28, 1.35) both; }
@keyframes challenge-start-pop {
  0% { opacity: 0; transform: scale(.35) rotate(-10deg); }
  62% { opacity: 1; transform: scale(1.12) rotate(2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  .challenge-start-text.is-animated { animation: none; }
}

/* while a challenge is running, hide everything except board + keyboard */
.challenge-active #app > h1,
.challenge-active #champion-banner,
.challenge-active .user-bar,
.challenge-active #ctl,
.challenge-active #debug-answer-panel { display: none !important; }
.challenge-active #app { gap: 6px; }


/* =====================================================================
   11. BUTTONS
   ===================================================================== */
.btn {
  flex: 1;
  border: 0;
  border-radius: 14px;
  padding: 13px;
  background: var(--vio);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 0 var(--viod);
}
#delete-word { background: var(--hot); box-shadow: 0 4px 0 var(--hotd); }
#again       { background: var(--ok);  box-shadow: 0 4px 0 var(--okd); }

.profile-button {
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  background: var(--vio);
  color: #fff;
  box-shadow: 0 3px 0 var(--viod);
}


/* =====================================================================
   12. USER BAR, MENU, PROFILE
   ===================================================================== */
.user-bar {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--nod);
  font-size: 14px;
}
.user-identity { display: flex; align-items: center; gap: 9px; min-width: 0; }
#welcome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  padding: 0;
  overflow: visible;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 2px 0 var(--line);
  transition: transform .2s, box-shadow .2s;
}
.avatar-button:hover { transform: scale(1.08); box-shadow: 0 0 0 3px var(--line); }
.avatar-button .avatar-frame { width: 100%; height: 100%; }
#profile-avatar { display: block; width: 100%; height: 100%; object-fit: cover; }

/* menu: inline on desktop, hamburger dropdown on mobile (see section 18) */
.main-menu { display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; }
.menu-notification-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 2px solid var(--surface);
  font-size: 10px;
}

/* profile dialog */
#profile-dialog { max-width: 420px; text-align: left; }
.profile-head { display: flex; align-items: center; gap: 18px; text-align: left; }
.profile-view-avatar-frame { width: 80px; height: 80px; flex: 0 0 80px; }
.profile-info { flex: 1 1 auto; min-width: 0; }
.profile-name-row { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.profile-head h2 { min-width: 0; margin: 0; font-size: 25px; line-height: 1.15; overflow-wrap: anywhere; }
.profile-name-row .admin-tag { margin: 0; }
.admin-tag[hidden] { display: none; }
.profile-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }
.profile-actions .upload-label { display: block; width: fit-content; max-width: 100%; }
.profile-actions .remove-avatar-button { margin: 0; }
#avatar { background: var(--bg); }
#profile-message { min-height: 20px; color: var(--nod); }

.avatar-frame { position: relative; display: block; flex: 0 0 auto; border-radius: 50%; }
.avatar-frame img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.remove-avatar-button { display: block; margin-top: 8px; padding: 7px 10px; font-size: 13px; }
#profile-dialog .remove-avatar-button { width: auto; flex: none; }

.streak-badge {
  position: absolute;
  right: -5px;
  bottom: -4px;
  z-index: 1;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: #ffb52e;
  font-size: 12px;
  line-height: 1;
}
.profile-view-avatar-frame .streak-badge { top: auto; right: -2px; bottom: -2px; left: auto; }
#profile-dialog .profile-actions .remove-avatar-button { width: 100%; flex: none; }

.profile-account-form { display: grid; gap: 10px; margin: 12px 0; text-align: left; }
.profile-account-form label { display: grid; gap: 5px; font-size: 14px; }
.profile-account-form input {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}


/* =====================================================================
   13. AUTH PAGES
   ===================================================================== */
.auth-page {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-page code { overflow-wrap: anywhere; }

.auth-card {
  width: min(100%, 390px);
  display: grid;
  gap: 14px;
  padding: 26px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 8px 0 var(--line);
  color: var(--ink);
}
.auth-card h1 { justify-content: center; margin: 0 0 4px; }
.auth-card p  { margin: 0; text-align: center; color: var(--nod); }
.auth-card a  { color: var(--vio); text-align: center; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; }
.auth-card .remember-label { display: flex; align-items: center; gap: 8px; }
.auth-card .remember-label input {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--vio);
}

/* shared text-field look (auth inputs + file-upload label) */
.auth-card input,
.upload-label {
  width: 100%;
  padding: 11px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.upload-label { display: inline-block; width: auto; padding: 7px 10px; cursor: pointer; font-size: 13px; }
.upload-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }


/* =====================================================================
   14. LEADERBOARD / PLAYERS / STATS / OPTIONS
   ===================================================================== */
.stats-wrap { max-width: 100%; overflow: auto; margin: 12px -8px; }

#profile-stats,
#leaderboard-table,
#players-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}
#profile-stats th, #profile-stats td,
#leaderboard-table th, #leaderboard-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}
#players-table th, #players-table td {
  padding: 8px 5px;
  border-bottom: 1px solid var(--line);
}
#profile-stats th, #leaderboard-table th, #players-table th { color: var(--nod); }
#players-table tbody td:first-child { text-align: left; }

#leaderboard-dialog { max-width: 760px; max-height: calc(100dvh - 32px); overflow: hidden; text-align: left; }
#leaderboard-dialog[open] { display: flex; flex-direction: column; }
.leaderboard-heading { flex: 0 0 auto; text-align: center; }
.leaderboard-heading h2 { text-align: center; }
.leaderboard-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  margin: 16px -8px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
#leaderboard-dialog #close-leaderboard { flex: 0 0 auto; margin-top: 8px; }
#leaderboard-table { min-width: 690px; font-size: 13px; }
#leaderboard-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 11px 9px;
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}
#leaderboard-table thead th:nth-child(2) { text-align: left; }
#leaderboard-table tbody tr { background: var(--surface); transition: background .15s ease; }
#leaderboard-table tbody tr:nth-child(even) { background: var(--bg); }
#leaderboard-table tbody tr.leaderboard-row:hover { background: var(--line); }
#leaderboard-table tbody td { padding: 10px 9px; text-align: center; font-variant-numeric: tabular-nums; }
#leaderboard-table .leaderboard-rank { width: 52px; color: var(--nod); font-weight: 800; }
#leaderboard-table .leaderboard-player-cell { min-width: 150px; text-align: left; }
#leaderboard-table .leaderboard-stat { font-weight: 700; }
#leaderboard-table .leaderboard-rank-1 .leaderboard-rank { color: #b8860b; font-size: 16px; }
#leaderboard-table .leaderboard-rank-2 .leaderboard-rank { color: #75819a; font-size: 15px; }
#leaderboard-table .leaderboard-rank-3 .leaderboard-rank { color: #a76536; font-size: 15px; }
#leaderboard-table .leaderboard-empty td { padding: 20px; color: var(--nod); text-align: center; }

.leader-avatar-frame { width: 30px; height: 30px; flex: 0 0 30px; }
.leader-avatar-frame .streak-badge { right: -5px; bottom: -4px; width: 16px; height: 16px; border-width: 1px; font-size: 9px; }
.leader-player { display: flex; align-items: center; gap: 7px; text-align: left; }
.leader-player img { display: block; width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; object-fit: cover; }
.leader-player-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

@media (max-width: 600px) {
  #leaderboard-dialog { max-width: 520px; height: min(88vh, 760px); height: min(88dvh, 760px); max-height: calc(100dvh - 28px); }
  #leaderboard-dialog .leaderboard-table-wrap { margin: 12px 0; overflow-x: hidden; overflow-y: auto; border: 0; background: transparent; }
  #leaderboard-table { display: block; min-width: 0; white-space: normal; }
  #leaderboard-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  #leaderboard-table tbody { display: grid; gap: 10px; }
  #leaderboard-table tbody tr.leaderboard-row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px 6px;
    padding: 9px 9px 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
  }
  #leaderboard-table tbody tr.leaderboard-rank-1 { border-color: #d2a52e; box-shadow: inset 3px 0 #d2a52e; }
  #leaderboard-table tbody tr.leaderboard-rank-2 { box-shadow: inset 3px 0 #9aa4b6; }
  #leaderboard-table tbody tr.leaderboard-rank-3 { box-shadow: inset 3px 0 #b77b50; }
  #leaderboard-table tbody td { min-width: 0; padding: 4px; border: 0; text-align: left; }
  #leaderboard-table .leaderboard-rank { position: absolute; top: 14px; left: 11px; width: 25px; padding: 0 !important; font-size: 12px; }
  #leaderboard-table .leaderboard-player-cell { grid-column: 1 / -1; min-width: 0; padding-left: 36px !important; }
  #leaderboard-table .leader-player-button { max-width: 100%; gap: 8px; font-size: 15px; }
  #leaderboard-table .leader-player-button > span:last-child { overflow: hidden; text-overflow: ellipsis; }
  #leaderboard-table .leaderboard-stat { display: flex; flex-direction: column; gap: 2px; padding: 2px 1px !important; overflow-wrap: anywhere; font-size: 12px; }
  #leaderboard-table .leaderboard-stat::before { content: attr(data-label); color: var(--nod); font-size: 8px; font-weight: 700; line-height: 1.1; }
  #leaderboard-table .leaderboard-empty { display: block; padding: 14px; border: 1px dashed var(--line); border-radius: 14px; color: var(--nod); text-align: center; }
  #leaderboard-table .leaderboard-empty td { display: block; padding: 0; text-align: center; }
}
.leader-player-button:hover span { text-decoration: underline; }

.admin-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 7px;
  background: var(--vio);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  vertical-align: middle;
}

#profile-dialog .btn,
#leaderboard-dialog .btn,
#players-dialog .btn,
#options-dialog .btn { width: 100%; }

/* options dialog */
#options-dialog { max-width: 520px; text-align: left; }
.settings-heading { display: flex; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.settings-heading h2,
.settings-heading p { text-align: center; }
.settings-heading p { margin: 4px 0 0; }
.settings-tabs { margin: 14px 0; }
.settings-tab-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-tab-list button:focus-visible { outline: 3px solid var(--vio); outline-offset: 2px; }
.settings-panel[hidden] { display: none; }
.settings-panel { min-height: 116px; }
#options-dialog .option-toggle { margin: 10px 0; }
#close-options { margin-top: 10px; }
#options-dialog .option-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}
.notification-setting { margin: 16px 0; padding: 12px; border-radius: 14px; background: var(--bg); text-align: left; }
.notification-setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notification-setting-copy { min-width: 0; }
.notification-setting h3 { margin: 0 0 3px; }
.notification-setting-copy p { margin: 0; color: var(--nod); font-size: 13px; line-height: 1.35; }
.notification-setting #notification-message { min-height: 0; margin: 6px 0 0; color: var(--nod); font-size: 11px; line-height: 1.35; }
.notification-icon-toggle {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--nod);
  cursor: pointer;
  transition: color .18s ease, background .18s ease, border-color .18s ease, transform .18s ease;
}
#options-dialog #enable-notifications { width: 42px; }
.notification-icon-toggle:hover { transform: translateY(-1px); }
.notification-icon-toggle:focus-visible { outline: 3px solid var(--vio); outline-offset: 2px; }
.notification-icon-toggle.is-enabled { color: var(--vio); border-color: var(--vio); background: var(--surface); }
.notification-icon-toggle svg { width: 23px; height: 23px; overflow: visible; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.notification-bell-shape { transform-origin: 12px 10px; }
.notification-icon-toggle.is-enabled .notification-bell-shape { animation: notification-bell-ring .55s ease-out; }
.notification-bell-slash { opacity: 1; stroke-dasharray: 23; stroke-dashoffset: 0; transition: opacity .18s ease, stroke-dashoffset .24s ease; }
.notification-icon-toggle.is-enabled .notification-bell-slash { opacity: 0; stroke-dashoffset: 23; }
@keyframes notification-bell-ring {
  0%, 100% { transform: rotate(0); }
  20%, 60% { transform: rotate(-9deg); }
  40%, 80% { transform: rotate(9deg); }
}
@media (prefers-reduced-motion: reduce) {
  .notification-icon-toggle, .notification-bell-slash { transition: none; }
  .notification-icon-toggle.is-enabled .notification-bell-shape { animation: none; }
}
#options-dialog input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: grid;
  place-content: center;
  margin: 0;
  border: 2px solid var(--nod);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
}
#options-dialog input[type="checkbox"]:checked { border-color: var(--vio); background: var(--vio); }
#options-dialog input[type="checkbox"]:checked::before {
  content: "";
  width: 9px;
  height: 5px;
  border: solid #fff;
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg) translate(1px, -1px);
}
.volume-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  margin: 12px 0 18px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
}
#volume-slider { grid-column: 1 / -1; width: 100%; accent-color: var(--vio); }


/* =====================================================================
   15. CELEBRATION
   ===================================================================== */
.celebration {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  pointer-events: none;
  z-index: 2147483647;
}
.celebration[popover] {
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
.confetti-piece {
  position: absolute;
  left: var(--x);
  top: -20px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  background: hsl(calc(var(--i, 0) * 37), 85%, 58%);
  animation: confetti-fall var(--duration) var(--delay) ease-in forwards;
}
.confetti-piece:nth-child(6n)     { background: #ff6584; }
.confetti-piece:nth-child(6n + 1) { background: #765be8; }
.confetti-piece:nth-child(6n + 2) { background: #47b982; }
.confetti-piece:nth-child(6n + 3) { background: #f5c84c; }
.confetti-piece:nth-child(6n + 4) { background: #52bde8; }
.confetti-piece:nth-child(6n + 5) { background: #ff9a55; }
.sad-emoji {
  position: absolute;
  left: var(--x);
  bottom: -50px;
  font-size: clamp(24px, 5vw, 42px);
  animation: emoji-float var(--duration) var(--delay) ease-out forwards;
}


/* =====================================================================
   16. PLAYER MAILBOX + ADMIN MESSAGE FORM (inside game dialogs)
   ===================================================================== */
.admin-message-form {
  display: grid;
  gap: 9px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
}
.admin-message-form h3 { margin: 0 0 2px; text-align: left; }
.admin-message-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 700; }
.admin-message-form input,
.admin-message-form textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
.admin-message-form button { justify-self: start; }
.admin-message-form #admin-message-status { margin: 0; color: var(--nod); font-size: 13px; }
:root[data-theme="dark"] .admin-message-form { background: var(--surface); }
:root[data-theme="dark"] .admin-message-form input,
:root[data-theme="dark"] .admin-message-form textarea { background: #1d1b25; }

.player-mailbox { margin: 14px 0; }
.player-mailbox-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 8px; text-align: left; }
.player-mailbox-heading h3 { flex: 1 1 auto; min-width: 0; margin: 0; }
#mark-all-messages-read { flex: 0 0 auto; width: auto; padding: 8px 10px; border-radius: 10px; font-size: 11px; white-space: nowrap; }
.player-mailbox > h3,
.inbox-requests-heading { margin: 14px 0 8px; text-align: left; }
.player-messages { display: grid; gap: 8px; max-height: 280px; overflow: auto; }
.player-mail-empty {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 13px;
  color: var(--nod);
  text-align: center;
  font-size: 14px;
}
.player-message-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}
.player-message-card.is-unread { border-color: var(--vio); box-shadow: inset 3px 0 var(--vio); }
.player-message-summary {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.player-message-summary strong { overflow-wrap: anywhere; font-size: 15px; }
.player-message-summary > span:nth-child(2) { grid-column: 1; color: var(--nod); font-size: 11px; font-weight: 600; }
.player-message-marker { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--vio); font-size: 11px; font-weight: 800; }
.player-message-content { padding: 0 12px 12px; color: var(--ink); text-align: left; }
.player-message-content p { margin: 0 0 9px; color: var(--ink); font: 14px/1.5 system-ui, sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.player-message-image { display: block; width: auto; max-width: 100%; max-height: 340px; margin: 8px auto 0; border-radius: 10px; object-fit: contain; }


/* =====================================================================
   17. ADMIN PAGE (always dark, ignores the theme switch)
   ===================================================================== */
body.admin-page {
  min-height: 100%;
  height: auto;
  justify-content: flex-start;
  align-items: flex-start;
  padding: clamp(16px, 4vw, 48px);
  background:
    radial-gradient(circle at 1px 1px, var(--dots) 1.5px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  color: var(--ink);
}
.admin-page .admin-shell { width: min(100%, 1080px); margin: 0 auto; display: block; flex: none; }

.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 0 0 24px; }
.admin-header h1 { display: block; margin: 7px 0 3px; color: #f8f5ff; font-size: clamp(30px, 5vw, 42px); letter-spacing: -.03em; }
.admin-header p,
.admin-card-heading p { margin: 0; color: #aaa4bd; font-size: 14px; font-weight: 500; }
.admin-eyebrow { color: #a994ff; font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.admin-back,
.admin-nav button { color: #d6ceee; text-decoration: none; }
.admin-back { padding: 11px 15px; border: 1px solid #3b354b; border-radius: 13px; background: #1c1a25; font-size: 14px; }
.admin-back span { margin-left: 8px; color: #aa96ff; }

.admin-nav { position: sticky; top: max(8px, env(safe-area-inset-top)); z-index: 20; margin-bottom: 18px; padding: 5px; border: 1px solid #302b3b; border-radius: 16px; background: #191720; }
.admin-tabs-list { display: flex; gap: 8px; overflow: auto; }
.admin-tabs-list button { flex: none; min-height: 42px; padding: 10px 14px; border: 0; border-radius: 11px; background: transparent; color: #d6ceee; font: inherit; font-size: 14px; }
.admin-tabs-list button:hover { background: #2b2638; }
.admin-tabs-list button[aria-selected="true"] { background: #332b49; color: #fff; }
.admin-tabs-toggle { display: none; }
.admin-count { display: inline-grid; min-width: 20px; height: 20px; place-items: center; margin-left: 4px; border-radius: 99px; background: #ff6584; color: #fff; font-size: 12px; }

.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.admin-card { min-width: 0; padding: 22px; border: 1px solid #35303f; border-radius: 20px; background: linear-gradient(145deg, #211f2a, #1b1922); box-shadow: 0 14px 36px #0003; }
.admin-maintenance,
.admin-account-card { grid-column: 1 / -1; }
.admin-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.admin-card-heading > div { position: relative; padding-left: 48px; }
.admin-card-heading h2 { margin: 0 0 4px; color: #f4f0ff; font-size: 22px; }
.admin-icon { position: absolute; left: 0; top: 0; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: #332b49; color: #b39cff; font-size: 21px; }
.admin-card form { display: grid; gap: 13px; }

.admin-page label { display: grid; gap: 7px; color: #c9c3d7; font-size: 13px; font-weight: 700; }
.admin-page input,
.admin-page textarea {
  width: 100%;
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid #403a4d;
  border-radius: 12px;
  outline: none;
  background: #15131b;
  color: #f4f0ff;
  font: 500 15px/1.4 system-ui, sans-serif;
}
.admin-page input:focus,
.admin-page textarea:focus { border-color: #967dff; box-shadow: 0 0 0 3px #8063e52e; }
.admin-page input::placeholder,
.admin-page textarea::placeholder { color: #777184; }
.admin-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.admin-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.admin-page .btn { min-height: 42px; padding: 9px 17px; border: 0; border-radius: 12px; background: #795bea; color: #fff; font-weight: 800; box-shadow: 0 3px 0 #5940b8; }
.admin-page .btn.alt { background: #393345; box-shadow: 0 3px 0 #292531; }
.admin-text-button,
.admin-icon-button { border: 0; background: transparent; color: #aaa2bb; font: inherit; }
.admin-text-button { padding: 10px 8px; font-size: 14px; }
.admin-text-button:hover,
.admin-message-actions button:hover { color: #fff; }
.admin-icon-button { width: 38px; height: 38px; border: 1px solid #403a4d; border-radius: 11px; background: #282531; color: #d9d2e9; font-size: 23px; }
.admin-feedback { margin: 0; color: #aaa4bd; font-size: 14px; }
.admin-player-filter { max-width: 360px; margin: 12px 0; }
.admin-player-filter input { padding: 9px 11px; }
.admin-data-wrap { max-width: 100%; overflow: auto; margin: 10px 0 18px; }
.admin-data-table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.admin-data-table th,
.admin-data-table td { padding: 9px 8px; border-bottom: 1px solid #393443; text-align: left; }
.admin-data-table th { color: #aaa4bd; font-weight: 700; }
.admin-data-table td[data-state="online"] { color: #8ee0b2; font-weight: 800; }
.admin-data-table td[data-state="offline"],
.admin-data-table td[data-state="left"] { color: #aaa4bd; }
.admin-data-table td[data-state="timeout"] { color: #f4cd73; }
.admin-data-table td[colspan] { color: #aaa4bd; text-align: center; }

.status-pill { flex: none; padding: 7px 11px; border: 1px solid #454052; border-radius: 99px; background: #302d38; color: #ccc5db; font-size: 12px; font-weight: 800; }
.status-pill[data-state="active"]    { border-color: #713b56; background: #462537; color: #ff9cba; }
.status-pill[data-state="scheduled"] { border-color: #69562d; background: #3a3020; color: #f4cd73; }
.status-pill[data-state="off"]       { border-color: #385c4a; background: #20362b; color: #8ee0b2; }

.admin-inbox-list { display: grid; gap: 10px; max-height: 470px; overflow: auto; }
.admin-empty { margin: 0; padding: 18px; border: 1px dashed #403a4d; border-radius: 13px; color: #aaa4bd; text-align: center; font-size: 14px; }
.admin-message { padding: 14px; border: 1px solid #393443; border-radius: 14px; background: #191720; }
.admin-message.is-unread { border-color: #6550a0; box-shadow: inset 3px 0 #9b80ff; }
.admin-message-header { display: grid; gap: 4px; }
.admin-message-header strong { color: #f4f0ff; overflow-wrap: anywhere; }
.admin-message-header time { color: #9f98ad; font-size: 11px; }
.admin-message > p { margin: 10px 0; color: #d3cedd; font: 14px/1.5 system-ui, sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-message-actions { display: flex; justify-content: flex-end; gap: 14px; }
.admin-message-actions button { padding: 4px 0; border: 0; background: none; color: #aaa2bb; font: 600 12px system-ui, sans-serif; }

/* admin login card */
.admin-page .auth-card { align-self: center; background: #211f2a; color: #f3efff; border: 1px solid #35303f; box-shadow: 0 14px 36px #0005; }
.admin-page .auth-card p,
.admin-page .auth-card a { color: #c5bdd5; }
.admin-page .auth-card input { border: 1px solid #403a4d; background: #15131b; color: #f4f0ff; }

@media (max-width: 700px) {
  body.admin-page { padding: 18px 12px; }
  .admin-header { align-items: flex-start; }
  .admin-header h1 { font-size: 30px; }
  .admin-back { padding: 9px 10px; font-size: 12px; }
  .admin-nav { padding: 0; border: 0; background: transparent; }
  .admin-tabs-toggle { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid #393443; border-radius: 15px; background: #191720; color: #f4f0ff; font: inherit; font-size: 15px; font-weight: 700; text-align: left; box-shadow: 0 4px 12px #0002; }
  .admin-menu-icon { width: 20px; flex: 0 0 20px; display: grid; gap: 4px; }
  .admin-menu-icon i { height: 2px; border-radius: 2px; background: #b39cff; transition: transform .2s, opacity .2s; }
  .admin-nav.is-open .admin-menu-icon i:first-child { transform: translateY(6px) rotate(45deg); }
  .admin-nav.is-open .admin-menu-icon i:nth-child(2) { opacity: 0; }
  .admin-nav.is-open .admin-menu-icon i:last-child { transform: translateY(-6px) rotate(-45deg); }
  .admin-current-tab { flex: 1; }
  .admin-tabs-chevron { margin-left: auto; color: #aa96ff; transition: transform .2s; }
  .admin-tabs-toggle[aria-expanded="true"] .admin-tabs-chevron { transform: rotate(180deg); }
  .admin-tabs-list { position: absolute; top: calc(100% + 7px); left: 0; right: 0; display: none; max-height: calc(100dvh - 130px); overflow: auto; padding: 6px; border: 1px solid #393443; border-radius: 15px; background: #191720; box-shadow: 0 12px 28px #0006; }
  .admin-nav.is-open .admin-tabs-list { display: grid; }
  .admin-tabs-list button { width: 100%; min-height: 46px; padding: 10px 12px; text-align: left; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-maintenance, .admin-account-card { grid-column: auto; }
  .admin-card { padding: 17px; }
  .admin-form-row { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .admin-header { display: block; }
  .admin-back { display: inline-block; margin-top: 14px; }
  .admin-card-heading { display: block; }
  .status-pill { display: inline-block; margin-top: 12px; }
}


/* =====================================================================
   18. MOBILE OVERRIDES (game UI only; admin has its own above)
   ===================================================================== */
@media (max-width: 800px) {
  .user-bar { z-index: 5; }
  .menu-toggle {
    position: relative;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 0;
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 2px 0 var(--line);
  }
  .menu-toggle > span:not(.notification-count) {
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--ink);
    transition: transform .22s, opacity .18s;
  }
  .menu-toggle[aria-expanded="true"] span:first-child  { transform: translateY(7px) rotate(45deg); }
  .menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .main-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 190px;
    display: grid;
    gap: 6px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 10px 28px #392d6226;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-8px) scale(.97);
    transform-origin: top right;
    transition: opacity .2s, transform .2s, visibility .2s;
  }
  .main-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }
  .main-menu .profile-button { width: 100%; padding: 11px 14px; text-align: left; }
}

@media (max-width: 600px) {
  #build-info { top: 4px; left: 4px; z-index: 2001; }

  /* app shell */
  #app { gap: 8px; padding-left: 12px; padding-right: 12px; }
  #ctl { width: 100%; justify-content: center; gap: 6px; flex-wrap: wrap; }
  .seg button { padding: 7px 10px; }
  #ctl .round { width: 38px; height: 38px; flex: 0 0 38px; }

  /* smaller tiles + keys */
  #board { --t: min(56px, calc((100vw - 52px) / var(--len, 5)), calc((100dvh - 440px) / 6)); }
  .challenge-active #board { --t: min(50px, calc((100vw - 52px) / var(--len, 5)), max(22px, calc((100dvh - 400px) / 6))); }
  #kb { gap: 5px; }
  #kb button { height: clamp(42px, 7.3dvh, 50px); }

  /* hamburger menu */
  .user-bar { z-index: 5; }
  .menu-toggle {
    position: relative;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 0;
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 2px 0 var(--line);
  }
  .menu-toggle > span:not(.notification-count) {
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--ink);
    transition: transform .22s, opacity .18s;
  }
  .menu-toggle[aria-expanded="true"] span:first-child     { transform: translateY(7px) rotate(45deg); }
  .menu-toggle[aria-expanded="true"] span:nth-child(2)    { opacity: 0; }
  .menu-toggle[aria-expanded="true"] span:nth-child(3)    { transform: translateY(-7px) rotate(-45deg); }

  .main-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 190px;
    display: grid;
    gap: 6px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 10px 28px #392d6226;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-8px) scale(.97);
    transform-origin: top right;
    transition: opacity .2s, transform .2s, visibility .2s;
  }
  .main-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }
  .main-menu .profile-button { width: 100%; padding: 11px 14px; text-align: left; }

  /* dialogs */
  dialog { max-height: calc(100dvh - 32px); overflow: auto; padding: 18px; width: calc(100% - 28px); }
  .profile-head { align-items: center; gap: 12px; }
  .profile-view-avatar-frame { width: 72px; height: 72px; flex-basis: 72px; }
  #profile-name { font-size: 24px; }
  .stats-wrap { margin: 10px -4px; }

  /* friends / community lists */
  .community-entry { flex-wrap: wrap; }
  .community-entry-name { flex: 1 1 45%; }
  .community-entry-actions { width: 100%; justify-content: flex-end; }
  #friends-list .community-entry { flex-wrap: nowrap; gap: 5px; padding: 8px; }
  #friends-list .community-entry-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  #friends-list .friend-status,
  #friends-list .friend-score { font-size: 11px; }
  #friends-list .community-entry-actions { width: auto; gap: 4px; }
  #friends-list .community-entry-actions .btn { padding: 6px 7px; font-size: 11px; white-space: nowrap; }
}

@media (max-width: 380px) {
  .challenge-taunts { gap: 5px; }
  .challenge-taunts button { width: 44px; height: 44px; font-size: 25px; }
  .challenge-feedback-tile { width: 10px; height: 10px; flex-basis: 10px; }
}
@media (max-width: 320px) {
  .challenge-taunts { gap: 4px; }
  .challenge-taunts button { width: 40px; height: 40px; font-size: 23px; }
  .challenge-feedback-tile { width: 8px; height: 8px; flex-basis: 8px; }
}

@media (max-width: 600px) {
  #options-dialog { max-width: 420px; }
}

@media (max-width: 800px) {
  .settings-tabs .settings-tab-list { grid-template-columns: 1fr; }
}


/* =====================================================================
   19. ANIMATIONS
   ===================================================================== */
@keyframes splash-card-in   { from { opacity: 0; transform: translateY(18px) scale(.92); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes splash-letter-bob{ to { transform: rotate(5deg) translateY(-5px); } }
@keyframes splash-dot       { to { transform: translateY(-7px); opacity: .55; } }
@keyframes champion-marquee-right { from { transform: translateX(-50%); } to { transform: translateX(0); } }

@keyframes pop   { 50% { transform: scale(1.14); } }
@keyframes flip  { 50% { transform: rotateX(90deg); } }
@keyframes hop   { 30% { transform: translateY(-14px); } 60% { transform: translateY(2px); } }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes tile-refresh {
  0%   { opacity: .35; transform: scale(.68) rotateX(-45deg); }
  65%  { opacity: 1;   transform: scale(1.08) rotateX(8deg); }
  100% { opacity: 1;   transform: scale(1) rotateX(0); }
}

@keyframes win-panel-in { from { opacity: 0; transform: translateY(18px) scale(.88); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes timer-pulse  { to { opacity: .55; } }
@keyframes challenge-progress-in { from { opacity: 0; transform: translateY(4px) scale(.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes challenge-taunt-fall {
  0%   { transform: translateY(-8vh) rotate(-15deg) scale(.65); opacity: 0; }
  12%  { opacity: 1; transform: translateY(4vh) rotate(10deg) scale(1.15); }
  100% { transform: translateY(120vh) rotate(420deg) scale(.9); opacity: .9; }
}

@keyframes confetti-fall { to { transform: translate3d(0, 110vh, 0) rotate(var(--rotation)); opacity: 0; } }
@keyframes emoji-float   { to { transform: translate3d(var(--drift), -115vh, 0) rotate(18deg); opacity: 0; } }
