/* =================================================================
   Wedding Wordle — Sage Garden design system
   Tokens, typography, components ported from the design concept.
   ================================================================= */

:root {
  /* --- Sage Garden palette ----------------------------------------- */
  --paper:        #f5f1e4;   /* warm ivory background */
  --paper-warm:   #ece6d2;   /* sun-warmed cream */
  --ivory:        #fbf8ee;   /* lightest cream */
  --sage-lt:      #cfd7b8;   /* pale eucalyptus */
  --sage:         #9eab85;   /* core sage */
  --sage-dk:      #7d8f63;   /* deep olive */
  --olive:        #6b7d4f;   /* olive branch */
  --forest:       #4d5c39;   /* dark forest text accent */
  --butter:       #ead89c;   /* soft butter sun */
  --honey:        #d9b46b;   /* warm honey accent */
  --blush:        #e8c6b5;   /* dusty summer blush */
  --espresso:     #2b2f1f;   /* ink with green undertone */
  --ink:          #1e2316;   /* deepest ink */
  --rule:         #d2d8bf;   /* sage rule */
  --rule-warm:    #e3d9bf;   /* warm cream rule */
  --mist:         #e6dfc6;   /* pale wash */

  /* --- Tile color tokens ------------------------------------------- */
  --tile-absent:  #c2c3b1;   /* warm light grey */
  --tile-present: #d9b46b;   /* honey instead of harsh yellow */
  --tile-correct: #7d8f63;   /* deep sage */

  --shadow-soft:  0 1px 2px rgba(45, 60, 30, 0.06), 0 8px 24px rgba(45, 60, 30, 0.08);
  --shadow-tile:  0 1px 0 rgba(45, 60, 30, 0.04), 0 2px 4px rgba(45, 60, 30, 0.06);

  /* --- Fonts -------------------------------------------------------- */
  --serif:  'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --serif-sc: 'Cormorant SC', 'Cormorant Garamond', serif;
  --script: 'Pinyon Script', 'Cormorant Garamond', cursive;
  --sans:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;             /* prevent the body itself from scrolling */
}

body {
  font-family: var(--serif);
  color: var(--espresso);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  touch-action: pan-y;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input  { font: inherit; color: inherit; background: none; border: none; outline: none; }
a      { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* =====================================================================
   Top bar (combined logotype: monogram + WEDDING WORDLE wordmark)
   ===================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  background: linear-gradient(180deg, rgba(251,248,238,0.98) 0%, rgba(245,241,228,0.9) 100%);
  border-bottom: 1px solid rgba(77,92,57,0.08);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}
.brand {
  font-family: var(--serif-sc);
  font-weight: 500;
  letter-spacing: 0.18em;
  font-size: 14px;
  color: var(--espresso);
  margin: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.brand .mono {
  font-family: var(--serif-sc);
  letter-spacing: 0.08em;
}
.brand .amp {
  font-family: var(--script);
  letter-spacing: normal;
  color: var(--sage-dk);
  font-size: 22px;
  margin: 0 4px;
  vertical-align: -2px;
  line-height: 1;
}
.brand .wordmark {
  margin-left: 10px;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-soft);
  transition: transform .15s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; stroke: var(--sage-dk); fill: none; stroke-width: 1.6; }

/* =====================================================================
   Stage container — flex column, takes remaining height
   ===================================================================== */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.screen { width: 100%; }

/* =====================================================================
   WELCOME / JOIN SCREEN
   ===================================================================== */
#join-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding-bottom: 18px;
}
#join-screen.hidden { display: none !important; }

.hero {
  position: relative;
  width: 100%;
  height: clamp(220px, 38vh, 340px);
  overflow: hidden;
  background: linear-gradient(135deg, var(--forest) 0%, var(--olive) 50%, var(--sage) 100%);
  flex-shrink: 0;
}
.hero img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  filter: grayscale(8%) contrast(1.02) brightness(1.02);
}
.hero::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(
    180deg,
    rgba(77, 92, 57, 0.15) 0%,
    rgba(77, 92, 57, 0.05) 35%,
    rgba(245, 241, 228, 0.55) 75%,
    var(--paper) 100%
  );
}
.hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 24px 18px;
  z-index: 2;
}
.date-bar {
  font-family: var(--serif-sc);
  font-weight: 400;
  letter-spacing: 0.32em;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  gap: 12px;
}
.date-bar .dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: #fff; opacity: 0.85;
}

.welcome-card {
  margin: -50px 20px 0;
  background: #fff;
  border-radius: 18px;
  padding: 32px 26px 24px;
  box-shadow: var(--shadow-soft);
  position: relative;
  z-index: 3;
  text-align: center;
}
/* leaf-badge ornament on top of the card */
.welcome-card::before {
  content: '';
  position: absolute;
  top: -22px; left: 50%;
  width: 44px; height: 44px;
  transform: translateX(-50%);
  background: var(--ivory);
  border-radius: 50%;
  border: 1px solid var(--sage-lt);
  box-shadow: 0 4px 12px rgba(77,92,57,0.12);
  z-index: 2;
}
.welcome-card::after {
  content: '';
  position: absolute;
  top: -12px; left: 50%;
  width: 22px; height: 22px;
  transform: translateX(-50%);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237d8f63' stroke-width='1.2' stroke-linecap='round'><path d='M12 22V8'/><ellipse cx='9' cy='12' rx='3' ry='1.5' transform='rotate(-30 9 12)' fill='%237d8f63' fill-opacity='0.55'/><ellipse cx='15' cy='12' rx='3' ry='1.5' transform='rotate(30 15 12)' fill='%237d8f63' fill-opacity='0.55'/><ellipse cx='10' cy='17' rx='2.5' ry='1.3' transform='rotate(-30 10 17)' fill='%237d8f63' fill-opacity='0.55'/><ellipse cx='14' cy='17' rx='2.5' ry='1.3' transform='rotate(30 14 17)' fill='%237d8f63' fill-opacity='0.55'/><circle cx='12' cy='6' r='1.3' fill='%23d9b46b'/></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  z-index: 3;
}

.monogram {
  font-family: var(--script);
  font-size: 64px;
  line-height: 0.9;
  color: var(--sage-dk);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.monogram .amp {
  color: var(--honey);
  font-size: 56px;
  margin: 0 6px;
}

.eyebrow {
  font-family: var(--serif-sc);
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--sage-dk);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px 0 22px;
}
.eyebrow::before, .eyebrow::after {
  content: '';
  height: 1px;
  flex: 1;
  max-width: 36px;
  background: linear-gradient(90deg, transparent, var(--sage), transparent);
}

.welcome-card h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 38px;
  letter-spacing: 0.04em;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 12px;
}
.welcome-card .subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.55;
  color: #4f5a3e;
  max-width: 28ch;
  margin: 0 auto 20px;
}
.welcome-card .subtitle strong {
  color: var(--sage-dk);
  font-style: normal;
  font-weight: 600;
}

/* Per-player language toggle on the welcome card. Segmented control with
   a sage outline; the active pill picks up a gold-tinted fill that nods to
   the honey accent without competing with the START PLAYING button. Hidden
   while the player is in a game (their play language is server-locked). */
.lang-toggle {
  display: flex;
  width: 100%;
  margin: 0 0 16px;
  padding: 4px;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: 999px;
  gap: 4px;
}
.lang-toggle.locked { display: none; }
.lang-toggle .lang-opt {
  flex: 1;
  padding: 9px 10px;
  font-family: var(--serif-sc);
  font-weight: 500;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: #6e7a55;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.lang-toggle .lang-opt:hover { color: var(--forest); }
.lang-toggle .lang-opt.active {
  background: linear-gradient(180deg, #f5e2b6 0%, var(--butter) 100%);
  color: var(--forest);
  box-shadow: inset 0 0 0 1px rgba(217,180,107,0.55),
              0 1px 2px rgba(77,92,57,0.12);
}
.lang-toggle .lang-opt:focus-visible {
  outline: 2px solid var(--sage-dk);
  outline-offset: 2px;
}

#join-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#name-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: 10px;
  font-family: var(--serif);
  font-size: 17px;
  font-style: italic;
  color: var(--espresso);
  text-align: center;
  transition: border-color .2s ease, background .2s ease;
}
#name-input::placeholder { color: #a8b08e; font-style: italic; }
#name-input:focus {
  border-color: var(--sage-dk);
  background: #fff;
}

/* Welcome-screen avatar picker. Wedding-themed emoji grid; tap to select. */
.avatar-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}
.avatar-label {
  font-family: var(--serif-sc);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--olive);
  text-align: center;
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}
@media (max-width: 420px) {
  .avatar-grid { grid-template-columns: repeat(6, 1fr); }
}
.avatar-opt {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background: var(--ivory);
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
  padding: 0;
}
.avatar-opt:hover { transform: translateY(-1px); border-color: var(--sage-dk); }
.avatar-opt.selected {
  background: var(--sage-soft, #e8efe0);
  border-color: var(--sage-dk);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px -4px rgba(77, 92, 57, 0.35);
}

.btn-primary {
  width: 100%;
  padding: 16px 20px;
  background: linear-gradient(180deg, var(--sage-dk) 0%, var(--olive) 100%);
  color: #fff;
  border-radius: 12px;
  font-family: var(--serif-sc);
  font-weight: 500;
  letter-spacing: 0.22em;
  font-size: 14px;
  box-shadow: 0 8px 20px -8px rgba(77, 92, 57, 0.55), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: transform .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -10px rgba(77, 92, 57, 0.65), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary:active { transform: translateY(0); }

.welcome-meta {
  margin: 18px 20px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: center;
}
.welcome-meta .cell {
  flex: 1;
  padding: 12px 6px;
  background: rgba(255,255,255,0.6);
  border-radius: 10px;
  border: 1px solid rgba(210,216,191,0.7);
}
.welcome-meta .num {
  display: block;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--sage-dk);
  font-weight: 500;
  line-height: 1;
  margin-bottom: 4px;
}
.welcome-meta .lbl {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.22em;
  color: #6e7a55;
}

.spectate-link {
  margin: 16px auto 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif-sc);
  letter-spacing: 0.22em;
  font-size: 11px;
  color: var(--sage-dk);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: border-color .2s ease;
  align-self: center;
  padding: 6px 8px;
}
.spectate-link:hover { border-color: var(--sage-dk); }
.spectate-link svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.6; }

.footer-credit {
  padding: 14px 0 8px;
  text-align: center;
  font-family: var(--serif-sc);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: #8a9670;
}
.footer-credit .amp {
  font-family: var(--script);
  font-size: 14px;
  color: var(--sage-dk);
  letter-spacing: normal;
  vertical-align: -2px;
}

.error {
  color: #b06a52;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  min-height: 1.2em;
  margin: 4px 0 0;
  text-align: center;
}

/* =====================================================================
   GAME SCREEN
   ===================================================================== */
#game-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0 0 0;
}
#game-screen.hidden { display: none !important; }

.game-header {
  padding: 12px 22px 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-shrink: 0;
}
#word-progress {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  color: var(--espresso);
  letter-spacing: 0.02em;
}
#word-progress em {
  font-style: normal;
  color: var(--sage-dk);
  font-weight: 600;
}
#points-display {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--sage-dk);
  letter-spacing: 0.02em;
}
#points-display .pts-unit {
  font-family: var(--serif-sc);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: #8a9670;
  margin-left: 4px;
  font-weight: 400;
}

.progress-bar {
  margin: 0 22px;
  height: 3px;
  background: var(--mist);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}
.progress-bar .fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--butter) 0%, var(--sage-dk) 100%);
  border-radius: 3px;
  transition: width .4s ease;
}

.progress-meta {
  margin: 8px 22px 0;
  display: flex;
  justify-content: space-between;
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.22em;
  color: #8a9670;
  flex-shrink: 0;
}
.progress-meta .hidden-best { visibility: hidden; }

.decor-rule {
  margin: 10px auto 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--sage-dk);
  opacity: 0.75;
  flex-shrink: 0;
}
.decor-rule::before, .decor-rule::after {
  content: '';
  height: 1px;
  width: 40px;
  background: linear-gradient(90deg, transparent, var(--sage), transparent);
}
.decor-rule svg { width: 22px; height: 14px; }

/* Board wraps with responsive sizing — board fits in available height */
.board-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 0;
  padding: 6px 22px 4px;
  container-type: size;
}
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  /* Pick the smaller of: 100% available width, OR a width that lets
     the 5:6 grid fit in the available height. */
  width: min(100%, 360px, calc((100cqh - 0px) * 5 / 6));
  margin: 0 auto;
  aspect-ratio: 5 / 6;
}
.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.tile {
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid rgba(210, 216, 191, 0.85);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.4rem, 7vw, 1.9rem);
  color: var(--espresso);
  text-transform: uppercase;
  box-shadow: var(--shadow-tile);
  transition: transform .2s ease, background .3s ease, color .3s ease, border-color .3s ease;
  user-select: none;
}
.tile.filled {
  border-color: var(--sage-dk);
  transform: scale(1.02);
}
.tile.absent {
  background: var(--tile-absent);
  border-color: var(--tile-absent);
  color: #fff;
}
.tile.present {
  background: var(--tile-present);
  border-color: var(--tile-present);
  color: #fff;
}
.tile.correct {
  background: var(--tile-correct);
  border-color: var(--tile-correct);
  color: #fff;
}
.tile.pop { animation: pop .14s ease; }
.board-row.shake { animation: shake .42s ease; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.07); } 100% { transform: scale(1); } }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-5px); }
  40%,80% { transform: translateX(5px); }
}

.message {
  text-align: center;
  min-height: 1.4em;
  margin: 4px 22px 2px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--espresso);
  flex-shrink: 0;
}
.message.good { color: var(--sage-dk); font-style: normal; font-weight: 500; }
.message.bad  { color: #b06a52; }

/* Keyboard */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 12px 10px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: linear-gradient(180deg, transparent 0%, rgba(207, 215, 184, 0.4) 100%);
  flex-shrink: 0;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.key {
  flex: 1;
  min-width: 0;
  height: 46px;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  color: var(--espresso);
  letter-spacing: 0.04em;
  box-shadow: 0 1px 0 rgba(45,38,32,0.08), 0 2px 4px rgba(45,38,32,0.06);
  transition: transform .1s ease, background .2s ease;
  user-select: none;
  cursor: pointer;
}
.key:active {
  transform: translateY(1px);
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
.key.wide {
  flex: 1.7;
  font-family: var(--serif-sc);
  letter-spacing: 0.18em;
  font-size: 11px;
}
.key.correct { background: var(--tile-correct); color: #fff; }
.key.present { background: var(--tile-present); color: #fff; }
.key.absent  { background: var(--tile-absent);  color: #fff; }

/* =====================================================================
   FINISH SCREEN
   ===================================================================== */
#finish-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px max(28px, env(safe-area-inset-bottom));
  align-items: center;
  text-align: center;
  justify-content: center;
}
#finish-screen.hidden { display: none !important; }

.finish-card {
  background: #fff;
  border-radius: 18px;
  padding: 36px 28px 30px;
  box-shadow: var(--shadow-soft);
  width: 100%;
  max-width: 360px;
  position: relative;
}
.finish-card .flourish {
  font-family: var(--script);
  font-size: 48px;
  color: var(--sage-dk);
  line-height: 0.9;
  margin-bottom: 6px;
}
.finish-card h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 32px;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin-bottom: 12px;
}
#finish-summary {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  color: #4f5a3e;
  margin-bottom: 8px;
}
.finish-card .subtitle.small {
  font-family: var(--serif-sc);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: #8a9670;
  margin-top: 14px;
}

/* =====================================================================
   LEADERBOARD (full-screen sheet)
   ===================================================================== */
.leaderboard {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(0);
  transition: transform .28s ease;
}
.leaderboard.hidden { display: flex !important; transform: translateY(100%); pointer-events: none; }

.lb-header {
  padding: 22px 22px 28px;
  background:
    radial-gradient(circle at top right, rgba(234, 216, 156, 0.35) 0%, transparent 55%),
    linear-gradient(135deg, var(--sage-dk) 0%, var(--olive) 60%, #5e6f48 100%);
  position: relative;
  overflow: hidden;
  color: #fff;
  flex-shrink: 0;
}
.lb-header .sprig {
  position: absolute;
  left: -10px; bottom: -12px;
  opacity: 0.18;
  pointer-events: none;
  width: 200px;
  height: 120px;
}
.lb-header .row-1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}
.lb-header h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: 0.18em;
  color: #fff;
  margin: 0;
}
.lb-close {
  color: #fff;
  font-size: 22px;
  line-height: 1;
  opacity: 0.85;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
}
.lb-header .sub {
  margin-top: 6px;
  font-family: var(--serif-sc);
  letter-spacing: 0.22em;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.82);
  position: relative;
  z-index: 2;
}

.lb-podium {
  margin: -18px 22px 0;
  padding: 18px 18px 14px;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 8px;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}
.lb-podium .slot {
  flex: 1;
  text-align: center;
  position: relative;
}
.lb-podium .avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sage-lt), var(--sage));
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  position: relative;
}
.lb-podium .slot.first .avatar {
  width: 64px; height: 64px; font-size: 26px;
  background: linear-gradient(135deg, var(--butter), var(--honey));
}
.lb-podium .slot.second .avatar {
  background: linear-gradient(135deg, #d6dac1, #8a9670);
}
.lb-podium .slot.third .avatar {
  background: linear-gradient(135deg, var(--blush), #c89a86);
}
.lb-podium .medal {
  position: absolute;
  bottom: -4px; right: -4px;
  font-size: 18px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}
.lb-podium .name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.lb-podium .pts {
  font-family: var(--serif-sc);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--sage-dk);
  margin-top: 2px;
}

.lb-list {
  list-style: none;
  margin: 18px 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.lb-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid rgba(210,216,191,0.55);
  transition: transform .15s ease, box-shadow .15s ease;
}
.lb-item:hover { transform: translateX(2px); box-shadow: var(--shadow-soft); }
.lb-item.me {
  background: linear-gradient(135deg, #f1f4e0 0%, #e6ecd0 100%);
  border-color: var(--sage);
  border-left: 4px solid var(--sage-dk);
  box-shadow: 0 0 0 1px rgba(158, 171, 133, 0.35), var(--shadow-soft);
}
.lb-rank {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 18px;
  color: var(--sage-dk);
  text-align: center;
}
.lb-rank.medal { font-size: 18px; }
.lb-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
  line-height: 1.15;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-name .you-tag {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--sage-dk);
  margin-left: 6px;
  font-weight: 500;
}
.lb-name .lb-emoji {
  display: inline-block;
  margin-right: 6px;
  font-size: 1.05em;
  vertical-align: -1px;
}
/* Podium tile: when the avatar exists we drop the initial-letter circle in
   favour of a slightly larger emoji glyph. */
.slot .avatar .emoji {
  font-size: 1.3em;
  line-height: 1;
}
.lb-sub {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.22em;
  color: #8a9670;
  margin-top: 3px;
  display: block;
  font-weight: 400;
}
.lb-pts {
  text-align: right;
}
.lb-pts b {
  display: block;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  color: var(--sage-dk);
  line-height: 1;
}
.lb-pts .pts-u {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.22em;
  color: #8a9670;
  margin-top: 2px;
  display: block;
}
.lb-empty {
  text-align: center;
  color: #8a9670;
  font-family: var(--serif);
  font-style: italic;
  padding: 2rem 1rem;
}
.flag { font-size: 0.85rem; margin-left: 4px; }

.lb-foot {
  padding: 14px 22px calc(env(safe-area-inset-bottom, 0px) + 14px);
  border-top: 1px solid rgba(210,216,191,0.6);
  text-align: center;
  font-family: var(--serif-sc);
  letter-spacing: 0.22em;
  font-size: 10px;
  color: #8a9670;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  flex-shrink: 0;
  background: var(--paper);
}
.lb-foot .live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sage-dk);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.lb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 60, 30, 0.35);
  z-index: 35;
}
.lb-backdrop.hidden { display: none; }

/* Topbar icon group keeps the spectate + leaderboard buttons paired. */
.topbar-actions { display: inline-flex; align-items: center; gap: 8px; }
.icon-btn { color: var(--sage-dk); }

/* =====================================================================
   FX overlay (confetti/petals)
   ===================================================================== */
#fx-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
#fx-overlay .petal {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50% 0;
  opacity: 0.9;
  animation: petal-fall var(--dur, 2.4s) ease-in forwards;
}
@keyframes petal-fall {
  0%   { transform: translateY(-10vh) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.9; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* =====================================================================
   SPECTATE PAGE (lives in spectate.html, reuses these styles)
   ===================================================================== */
body.spectate-page {
  background: var(--paper);
}
.spectate-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 18px;
}

.photo-strip {
  position: relative;
  height: clamp(130px, 22vh, 180px);
  overflow: hidden;
  background: linear-gradient(135deg, var(--forest) 0%, var(--sage-dk) 100%);
  flex-shrink: 0;
}
.photo-strip img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: center 40%;
  filter: grayscale(20%) brightness(0.92) sepia(0.05) hue-rotate(-15deg);
  display: block;
}
.photo-strip::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(30,35,22,0.25) 0%, rgba(245,241,228,0.7) 80%, var(--paper) 100%);
}
.ps-title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  padding: 0 24px;
  text-align: center;
}
.ps-title h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
  margin: 0;
}
.ps-title .sub {
  font-family: var(--serif-sc);
  font-size: 10px;
  letter-spacing: 0.32em;
  color: rgba(255,255,255,0.85);
  margin-top: 6px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.4);
}

#spectate-status {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: #8a9670;
  padding: 16px;
}
#spectate-status.hidden { display: none; }

#spectate-grid {
  margin: -10px 16px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  position: relative;
  z-index: 3;
}
@media (max-width: 380px) {
  #spectate-grid { grid-template-columns: 1fr; }
}
@media (min-width: 720px) {
  #spectate-grid { grid-template-columns: repeat(3, 1fr); }
}

.player-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 12px 12px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(210,216,191,0.4);
  display: flex;
  flex-direction: column;
}
.player-card.leader,
.player-card.you {
  background: linear-gradient(135deg, #fff 0%, #f0f4dc 100%);
  border-color: var(--sage);
  box-shadow: 0 0 0 1px rgba(158,171,133,0.4), 0 12px 28px -12px rgba(77,92,57,0.25);
}
.player-card.finished {
  border-color: var(--sage-dk);
}
.player-card.waiting {
  background: linear-gradient(180deg, #fff 0%, var(--ivory) 100%);
}

.player-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2px;
}
.player-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
}
.player-name .you-tag {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--sage-dk);
  margin-left: 6px;
}
.player-name .player-avatar {
  display: inline-block;
  margin-right: 6px;
  font-size: 1.05em;
  vertical-align: -1px;
}
.player-pts {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 14px;
  color: var(--sage-dk);
}

.player-progress {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: #8a9670;
  margin-bottom: 10px;
}
.player-progress .sep { margin: 0 4px; opacity: 0.5; }

.word-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.word-block {
  display: flex;
  flex-direction: column;
}
.word-label {
  font-family: var(--serif-sc);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--sage-dk);
  margin: 6px 0 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.word-label.solved::after { content: '✓'; color: var(--sage-dk); }
.word-label.failed::after { content: '✕'; color: #c89a86; }
.word-label.active::after { content: '…'; }

.mini-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}
.mini-tile {
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid rgba(210, 216, 191, 0.65);
  border-radius: 3px;
}
.mini-tile.absent  { background: var(--tile-absent);  border-color: var(--tile-absent); }
.mini-tile.present { background: var(--tile-present); border-color: var(--tile-present); }
.mini-tile.correct { background: var(--tile-correct); border-color: var(--tile-correct); }

/* Live-typing indicator: tile is "filled" (player has typed this slot)
   but the letter is intentionally hidden. Subtle sage tint + pulse so
   spectators feel the typing in real time. */
.mini-tile.typing {
  background: var(--sage-lt);
  border-color: var(--sage);
  animation: mini-typing-pulse 1.4s ease-in-out infinite;
}
@keyframes mini-typing-pulse {
  0%, 100% { opacity: 0.85; }
  50%      { opacity: 1; }
}

.player-card .waiting-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  color: #8a9670;
  font-size: 14px;
  padding: 28px 0 18px;
}

/* =====================================================================
   Larger viewports: cap the keyboard width
   ===================================================================== */
@media (min-width: 600px) {
  .key { height: 50px; font-size: 15px; }
  .keyboard { max-width: 480px; margin: 0 auto; padding-left: 14px; padding-right: 14px; }
}

/* =====================================================================
   Topbar language pill — spectate page (and any future header toggle).
   Compact, low-contrast at rest; active option lifts with a butter tint
   so the bilingual toggle reads as a status indicator, not a CTA.
   ===================================================================== */
.lang-toggle-topbar {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--rule);
  border-radius: 999px;
  gap: 2px;
}
.lang-toggle-topbar .lang-opt {
  padding: 5px 10px;
  font-family: var(--serif-sc);
  font-weight: 500;
  letter-spacing: 0.16em;
  font-size: 10px;
  color: #6e7a55;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.lang-toggle-topbar .lang-opt.active {
  background: linear-gradient(180deg, #f5e2b6 0%, var(--butter) 100%);
  color: var(--forest);
  box-shadow: inset 0 0 0 1px rgba(217, 180, 107, 0.55);
}

/* =====================================================================
   Safe-area paddings for iOS notch
   ===================================================================== */
@supports (padding: max(0px)) {
  .topbar { padding-top: max(16px, env(safe-area-inset-top, 16px)); }
}
