:root {
  --bg: #ffffff;
  --surface: #f3f4f6;
  --surface-2: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --tile-bg: #ffffff;
  --tile-empty: #ffffff;
  --tile-filled-border: #9ca3af;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --key-bg: #d3d6da;
  --key-text: #111827;
  --key-pressed: #b9bcc1;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
  --radius: 20px;
  --board-gap: 0.34rem;
  --key-gap: 0.35rem;
  --tile-size: 3.4rem;
  --header-height: 4.2rem;
  --keyboard-height: 15rem;
}

:root[data-theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"] {
  --bg: #121213;
  --surface: #1a1a1b;
  --surface-2: #2a2a2c;
  --text: #f5f5f5;
  --muted: #a1a1aa;
  --border: #3a3a3c;
  --tile-bg: #121213;
  --tile-empty: #121213;
  --tile-filled-border: #565758;
  --key-bg: #818384;
  --key-text: #f5f5f5;
  --key-pressed: #9a9b9d;
  --absent: #3a3a3c; 
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
}

:root[data-theme="passaflora"],
html[data-theme="passaflora"],
body[data-theme="passaflora"] {
  --bg: #eaf9ef;
  --surface: #f8fffb;
  --surface-2: #dff5e7;
  --text: #154a2e;
  --muted: #3e7a5c;
  --border: #b9e1c8;
  --tile-bg: #ffffff;
  --tile-empty: #ffffff;
  --tile-filled-border: #7db391;
  --key-bg: #d7f0e1;
  --key-text: #154a2e;
  --key-pressed: #c3e6d1;
  --absent: #6f8a78;
  --shadow: 0 12px 30px rgba(21, 74, 46, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% -20% auto;
  height: 52vh;
  background: radial-gradient(45% 45% at 30% 35%, color-mix(in srgb, var(--correct) 16%, transparent), transparent 70%);
  pointer-events: none;
  z-index: -1;
  animation: ambientFloat 8s ease-in-out infinite;
}

body[data-theme="passaflora"]::before {
  inset: -10% -12% auto;
  height: 68vh;
  background:
    radial-gradient(circle at 15% 35%, rgba(106, 170, 100, 0.26) 0 20px, transparent 22px),
    radial-gradient(circle at 19% 39%, rgba(255, 255, 255, 0.92) 0 8px, transparent 9px),
    radial-gradient(circle at 78% 26%, rgba(106, 170, 100, 0.24) 0 18px, transparent 20px),
    radial-gradient(circle at 82% 30%, rgba(255, 255, 255, 0.92) 0 7px, transparent 8px),
    radial-gradient(circle at 55% 18%, rgba(106, 170, 100, 0.2) 0 16px, transparent 18px),
    radial-gradient(circle at 58% 22%, rgba(255, 255, 255, 0.9) 0 6px, transparent 7px),
    radial-gradient(45% 45% at 30% 35%, color-mix(in srgb, var(--correct) 22%, transparent), transparent 70%);
}

body[data-theme="passaflora"]::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(circle at 9% 80%, rgba(255, 255, 255, 0.62) 0 9px, transparent 10px),
    radial-gradient(circle at 86% 76%, rgba(255, 255, 255, 0.62) 0 8px, transparent 9px),
    radial-gradient(circle at 68% 90%, rgba(106, 170, 100, 0.2) 0 11px, transparent 12px),
    radial-gradient(circle at 34% 86%, rgba(106, 170, 100, 0.16) 0 10px, transparent 11px);
}

body .app-shell {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 240ms ease, transform 240ms ease, filter 240ms ease;
}

body.page-transition-out .app-shell {
  opacity: 0;
  transform: translateY(8px) scale(0.992);
  filter: blur(2px);
}

.hidden { display: none !important; }

.app-loader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 50% -20%, rgba(106, 170, 100, 0.22), transparent 65%),
    linear-gradient(160deg, var(--bg), var(--surface));
  opacity: 1;
  visibility: visible;
  transition: opacity 420ms ease, visibility 420ms ease;
}

.app-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}

.loader-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(2.2rem, 2.9rem));
  gap: 0.42rem;
}

.loader-tile {
  aspect-ratio: 1/1;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--tile-bg);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
  animation: loaderPulse 1.45s ease-in-out infinite;
}

.loader-tile:nth-child(1) { animation-delay: 0ms; }
.loader-tile:nth-child(2) { animation-delay: 90ms; }
.loader-tile:nth-child(3) { animation-delay: 180ms; }
.loader-tile:nth-child(4) { animation-delay: 270ms; }
.loader-tile:nth-child(5) { animation-delay: 360ms; }
.loader-tile:nth-child(6) { animation-delay: 450ms; }

.loader-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@keyframes loaderPulse {
  0%, 100% {
    transform: translateY(0) scale(1);
    background: var(--tile-bg);
    border-color: var(--border);
  }
  45% {
    transform: translateY(-5px) scale(1.02);
    background: color-mix(in srgb, var(--correct) 88%, white 12%);
    border-color: var(--correct);
    color: #fff;
  }
}

button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(0.85rem, env(safe-area-inset-top)) max(0.85rem, env(safe-area-inset-right)) max(0.85rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left));
}

.topbar {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0.2rem 0.75rem;
}

.topbar__left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar__right {
  display: flex;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.title-icon {
  width: 1.4rem;
  height: 1.4rem;
  color: var(--correct);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  letter-spacing: 0.08em;
  line-height: 1;
}

.author-credit {
  margin: 0.15rem 0 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.05em;
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

a.icon-button {
  text-decoration: none;
}

.icon-button svg {
  width: 1.25rem;
  height: 1.25rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.14);
}

.icon-button:active {
  transform: translateY(0);
}

.account-menu-wrap {
  position: relative;
}

.account-menu-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 10.8rem;
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.18);
  z-index: 60;
}

.account-menu-item {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 0.58rem 0.68rem;
  text-align: left;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.account-menu-item:hover {
  background: color-mix(in srgb, var(--surface-2) 74%, transparent);
}

.hint-button { position: relative; }
.hint-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--correct);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg);
  transition: background-color 0.2s ease;
}
.hint-badge.empty {
  background: var(--muted);
}

.game {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: stretch;
}

.meta-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0.2rem 0;
  flex: 1;
}

.board {
  display: grid;
  gap: var(--board-gap);
  justify-content: center;
  align-content: center;
  width: fit-content;
  max-width: 100%;
}

.row {
  display: grid;
  gap: var(--board-gap);
  grid-template-columns: repeat(var(--word-length, 5), var(--tile-size));
}

.tile {
  width: var(--tile-size);
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border);
  background: var(--tile-empty);
  display: grid;
  place-items: center;
  border-radius: 0.35rem;
  font-size: clamp(1.2rem, 4vw, 1.9rem);
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.06);
  transition: transform 0.1s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.tile.filled { border-color: var(--tile-filled-border); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12); }
.tile.pop { animation: pop 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

.tile.correct, .key.correct { background: var(--correct); border-color: var(--correct); color: #fff !important; }
.tile.present, .key.present { background: var(--present); border-color: var(--present); color: #fff !important; }
.tile.absent, .key.absent { background: var(--absent); border-color: var(--absent); color: #fff !important; }

.message {
  margin: 0;
  min-height: 1.4rem;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  opacity: 0;
  transform: translateY(0.2rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.message.show {
  opacity: 1;
  transform: translateY(0);
}

.keyboard-wrap {
  padding-bottom: 0.15rem;
}

.keyboard {
  display: grid;
  gap: var(--key-gap);
  user-select: none;
}

.keyboard-row {
  display: flex;
  gap: var(--key-gap);
  justify-content: center;
}

.key {
  height: clamp(3rem, 7.5vw, 3.4rem);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 0.65rem;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: clamp(0.78rem, 2.9vw, 0.98rem);
  font-weight: 700;
  padding: 0 0.35rem;
  flex: 1 1 0;
  min-width: 0;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease, box-shadow 0.18s ease;
}

.key.wide { flex: 1.55 1 0; }
.key.wide {
  font-size: clamp(0.66rem, 2.55vw, 0.92rem);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.key:active { transform: translateY(2px); background: var(--key-pressed); }
.key:disabled { opacity: 0.5; cursor: not-allowed; }
.key:hover:not(:disabled) { transform: translateY(-1px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08), 0 7px 16px rgba(0, 0, 0, 0.12); }

/* Modal and Base Inputs */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.64);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 20;
}

.modal__card {
  width: min(92vw, 28rem);
  background: var(--bg);
  color: var(--text);
  border-radius: 24px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  text-align: center;
  position: relative;
  transform-origin: center;
}

.modal:not(.hidden) .modal__card {
  animation: modalIn 220ms ease;
}

.modal__kicker { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.modal__title { margin: 0; font-size: clamp(1.35rem, 4.8vw, 1.8rem); }
.modal__countdown { min-height: 1.2rem; margin: 0.55rem 0 1rem; color: var(--muted); font-size: 0.96rem; }

.modal-word-highlight {
  color: var(--correct);
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.primary-button { width: 100%; border: none; border-radius: 14px; background: var(--text); color: var(--bg); padding: 0.9rem 1rem; font-weight: 800; cursor: pointer; }

.close-top-right { position: absolute; top: 12px; right: 16px; background: none; border: none; font-size: 24px; color: var(--muted); cursor: pointer; }

.text-input { width: 100%; padding: 0.8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 1rem; margin-top: 1rem; font-family: inherit; }

.walkthrough-card {
  width: min(94vw, 33rem);
  text-align: left;
  background: var(--surface);
  background:
    radial-gradient(120% 95% at 0% 0%, color-mix(in srgb, var(--correct) 12%, transparent), transparent 60%),
    linear-gradient(165deg, color-mix(in srgb, var(--bg) 90%, var(--surface) 10%), var(--surface));
}

.walkthrough-demo {
  margin: 0.65rem 0 0.85rem;
  border: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
  border-radius: 14px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  padding: 0.7rem;
}

.walkthrough-row {
  display: flex;
  gap: 0.34rem;
  justify-content: center;
}

.walkthrough-tile {
  width: 2.1rem;
  height: 2.1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  background: var(--tile-empty);
  color: var(--text);
}

.walkthrough-demo.length-transition .walkthrough-row-length {
  animation: walkthroughLengthSwap 380ms ease;
}

.walkthrough-row-length .walkthrough-tile {
  transform-origin: center;
}

.walkthrough-demo.show-colors .walkthrough-tile:nth-child(1),
.walkthrough-demo.show-colors .walkthrough-tile:nth-child(4) {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.walkthrough-demo.show-colors .walkthrough-tile:nth-child(2) {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.walkthrough-demo.show-colors .walkthrough-tile {
  animation: walkthroughFlip 520ms ease;
}

.walkthrough-legend {
  display: grid;
  gap: 0.36rem;
  margin-top: 0.68rem;
}

.walkthrough-badge {
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.77rem;
  font-weight: 760;
  padding: 0.22rem 0.52rem;
  display: inline-flex;
  width: fit-content;
}

.walkthrough-badge.neutral {
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  border-color: color-mix(in srgb, var(--border) 75%, transparent);
}

.walkthrough-badge.correct {
  background: color-mix(in srgb, var(--correct) 18%, transparent);
  border-color: color-mix(in srgb, var(--correct) 46%, var(--border));
}

.walkthrough-badge.present {
  background: color-mix(in srgb, var(--present) 18%, transparent);
  border-color: color-mix(in srgb, var(--present) 44%, var(--border));
}

.walkthrough-progress {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 0.62rem;
}

.walkthrough-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: center;
}

.walkthrough-actions.skip-collapsed {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 22rem);
  margin-inline: auto;
}

.walkthrough-actions.skip-collapsed.final-step-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 34rem);
}

.walkthrough-skip,
.walkthrough-prev,
.walkthrough-account {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
}

.walkthrough-account {
  white-space: normal;
  line-height: 1.15;
}

.walkthrough-next-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
}

.walkthrough-account.account-cta-primary {
  background: #ffffff;
  color: #111827;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: 0 10px 22px rgba(255, 255, 255, 0.26), 0 8px 20px rgba(0, 0, 0, 0.16);
}

:root:not([data-theme="dark"]) .walkthrough-account.account-cta-primary {
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.15);
}

.walkthrough-hint-showcase {
  display: grid;
  place-items: center;
}

.walkthrough-hint-showcase .hint-button {
  pointer-events: none;
}

.walkthrough-notify-showcase {
  display: grid;
  place-items: center;
}

.walkthrough-notify-btn {
  width: auto;
  min-width: min(88vw, 14rem);
  padding-inline: 1rem;
  background: linear-gradient(140deg, color-mix(in srgb, var(--correct) 74%, #fff 26%), var(--correct));
  color: #fff;
}

.walkthrough-notify-btn:disabled {
  opacity: 0.78;
  cursor: default;
}

.hint-button.walkthrough-hint-focus {
  border-color: var(--correct);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--correct) 26%, transparent), var(--shadow);
  animation: walkthroughHintPulse 880ms ease-in-out infinite;
}

.walkthrough-card.pulse-account {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--correct) 20%, transparent), var(--shadow);
}

@keyframes walkthroughFlip {
  0% { transform: rotateX(0); }
  45% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes walkthroughLengthSwap {
  0% { opacity: 0.72; transform: translateY(4px) scale(0.985); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes walkthroughHintPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-1px) scale(1.04); }
}

@supports not ((backdrop-filter: blur(3px)) or (-webkit-backdrop-filter: blur(3px))) {
  .modal {
    background: rgba(0, 0, 0, 0.72);
  }
}

@supports not (color: color-mix(in srgb, white 50%, black)) {
  body::before {
    background: radial-gradient(45% 45% at 30% 35%, rgba(106, 170, 100, 0.2), transparent 70%);
  }

  .account-menu-panel,
  .modal__card,
  .walkthrough-card,
  .walkthrough-demo,
  .leaderboard-card {
    background: var(--surface);
    background: var(--surface);
    border-color: var(--border);
  }

  .modal {
    background: rgba(0, 0, 0, 0.7);
  }

  .walkthrough-badge.correct,
  .walkthrough-badge.present,
  .walkthrough-badge.neutral {
    background: var(--surface-2);
    border-color: var(--border);
  }

  .hint-button.walkthrough-hint-focus {
    box-shadow: 0 0 0 3px rgba(106, 170, 100, 0.28), var(--shadow);
  }
}

@media (max-width: 420px) {
  .walkthrough-actions .primary-button {
    font-size: 0.82rem;
    padding: 0.72rem 0.5rem;
  }

  .key.wide {
    font-size: clamp(0.6rem, 2.7vw, 0.8rem);
  }
}

select.text-input {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1em;
  padding-right: 2.5rem;
}

/* Leaderboard Specific Styling (full redesign) */
.leaderboard-card {
  width: min(96vw, 44rem);
  min-height: min(82vh, 44rem);
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 1.5rem 1.5rem 1.25rem;
  border-radius: 28px;
  background: var(--surface);
  background:
    radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--correct) 14%, transparent), transparent 58%),
    linear-gradient(165deg, color-mix(in srgb, var(--bg) 88%, var(--surface) 12%), var(--surface));
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  box-shadow: 0 24px 44px rgba(0, 0, 0, 0.24), 0 10px 24px rgba(0, 0, 0, 0.16);
}

#close-leaderboard {
  top: 14px;
  right: 14px;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-2) 75%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  padding: 0;
  transition: transform 0.16s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

#close-leaderboard svg {
  width: 1.03rem;
  height: 1.03rem;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#close-leaderboard:hover {
  transform: translateY(-1px) rotate(90deg);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

#username-view,
#stats-view {
  display: flex;
  flex-direction: column;
  flex: 1;
}

#username-view .modal__title,
#stats-view .modal__title {
  font-size: clamp(1.5rem, 3.4vw, 2rem);
  letter-spacing: 0.02em;
}

#username-view .modal__countdown {
  margin: 0.45rem 0 0.8rem;
  line-height: 1.45;
  max-width: 44ch;
}

.text-input {
  border-radius: 12px;
  padding: 0.9rem 0.95rem;
  font-size: 0.98rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.text-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--correct) 58%, var(--border));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--correct) 18%, transparent);
}

.lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  padding-right: 2.8rem;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-top: 0.7rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
  padding: 0.35rem;
  border-radius: 14px;
}

.tab-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
  padding: 0.62rem;
  border-radius: 10px;
  transition: transform 0.16s ease, color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

.tab-btn.active {
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.16);
}

.tab-content {
  flex: 1;
  margin-top: 0.95rem;
  overflow-y: auto;
  max-height: min(54vh, 31rem);
  text-align: left;
  padding-right: 0.3rem;
}

.tab-content::-webkit-scrollbar { width: 8px; }
.tab-content::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 55%, transparent);
  border-radius: 999px;
}

.lb-loading {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 2.1rem;
  animation: pulseText 1.35s ease-in-out infinite;
}

.lb-empty {
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.lb-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.68rem;
}

.lb-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 88%, white 12%), var(--surface));
  padding: 0.86rem 1rem;
  border-radius: 14px;
  font-size: 0.96rem;
  font-weight: 620;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  animation: leaderboardRise 260ms ease both;
}

.lb-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.14);
  border-color: color-mix(in srgb, var(--correct) 42%, var(--border));
}

.lb-item.rank-1 {
  background:
    radial-gradient(110% 120% at 0% 0%, rgba(255, 247, 185, 0.78), transparent 58%),
    linear-gradient(140deg, #ffe37a 0%, #ffc635 46%, #f4b400 100%);
  color: #1e1e1e;
  border: 1px solid #f0be2d;
  box-shadow: 0 12px 26px rgba(255, 190, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.62);
  transform: scale(1.02);
}

.lb-item.rank-2 {
  background:
    radial-gradient(110% 120% at 0% 0%, rgba(255, 255, 255, 0.55), transparent 58%),
    linear-gradient(140deg, #f4f4f5 0%, #d8d8dc 52%, #b9b9bf 100%);
  color: #1e1e1e;
  border: 1px solid #b0b0b7;
  box-shadow: 0 10px 22px rgba(166, 166, 172, 0.32);
}

.lb-item.rank-3 {
  background:
    radial-gradient(110% 120% at 0% 0%, rgba(255, 241, 226, 0.58), transparent 58%),
    linear-gradient(140deg, #e9b27f 0%, #c78243 52%, #a55e26 100%);
  color: #1e1e1e;
  border: 1px solid #9d5720;
  box-shadow: 0 10px 22px rgba(165, 93, 36, 0.34);
}

.lb-left {
  display: inline-flex;
  align-items: center;
  gap: 0.44rem;
  min-width: 0;
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 16rem;
}

.lb-self {
  opacity: 0.62;
  font-size: 0.82em;
  font-weight: 500;
}

.lb-medal { width: 1.1rem; height: 1.1rem; margin-right: 0.3rem; vertical-align: text-bottom; }

.lb-item .rank {
  color: var(--muted);
  margin-right: 0.38rem;
  font-size: 0.83rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.lb-item.rank-1 .rank { color: rgba(30, 30, 30, 0.62); }

.lb-item.rank-1 .rank,
.lb-item.rank-2 .rank,
.lb-item.rank-3 .rank {
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.lb-score {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1rem;
  margin-left: 0.8rem;
}

.lb-item.rank-1 .lb-score,
.lb-item.rank-2 .lb-score,
.lb-item.rank-3 .lb-score { color: #1e1e1e; }

/* Hint tooltip wrapper — use inline-flex and center alignment */
.has-tooltip { position: relative; display: inline-flex; align-items: center; gap: 0.28rem; cursor: help; }

/* Tooltip placement: keep it from being clipped but center on the icon */
.has-tooltip:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 140%;
  right: -8px;
  background: var(--text);
  color: var(--bg);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: none;
  transform-origin: right center;
}

.leaderboard-logout {
  display: inline-grid;
  place-items: center;
  gap: 0;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
  touch-action: manipulation;
  transition: transform 0.14s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.leaderboard-logout svg { width: 1.05rem; height: 1.05rem; stroke: currentColor; fill: none; }

.leaderboard-logout:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
}

.leaderboard-logout:active {
  transform: translateY(1px);
}

/* Ensure the in-list hint pseudo tooltip is disabled — we'll use a portal tooltip so it can escape overflow/clipping */
.has-tooltip::after { display: none !important; }

/* Global tooltip (appended to body) — overrides everything so it won't be clipped */
.global-tooltip {
  position: fixed;
  background: var(--text);
  color: var(--bg);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 9999;
  box-shadow: 0 6px 24px rgba(0,0,0,0.28);
  pointer-events: none;
  transform-origin: center;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

/* Visible state */
.global-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

/* Hint icon vertical centering tweaks */
.lb-hint-icon {
  width: 1rem;
  height: 1rem;
  margin-left: 0.35rem;
  vertical-align: middle;
  stroke: var(--text);
  opacity: 0.9;
}

/* Keyboard Animations for Hints */
@keyframes hintHighlight {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(201, 180, 88, 0.7); }
  50% { transform: scale(1.15); box-shadow: 0 0 15px 5px rgba(201, 180, 88, 0); background-color: var(--present); color: white; border-color: var(--present); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(201, 180, 88, 0); }
}
.hint-highlight-anim { animation: hintHighlight 0.9s ease-out forwards; z-index: 10; position: relative; }

@keyframes hintEliminate {
  0% { transform: scale(1); background-color: var(--key-bg); }
  50% { transform: scale(0.85); background-color: var(--absent); color: white; opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}
.hint-eliminate-anim { animation: hintEliminate 0.9s ease-out forwards; }

@keyframes pop { 
  0% { transform: scale(0.85); opacity: 0.7; } 
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); } 
}

@keyframes ambientFloat {
  0%, 100% { transform: translate3d(0, 0, 0); opacity: 0.95; }
  50% { transform: translate3d(0, 10px, 0); opacity: 1; }
}

@keyframes modalIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes leaderboardRise {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes pulseText {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake { animation: shake 0.35s ease; }
.flip { animation: flip 0.52s ease-in-out; }

@keyframes flip {
  0% { transform: rotateX(0); }
  45% { transform: rotateX(90deg); }
  55% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@media (max-width: 420px) {
  :root { --board-gap: 0.28rem; --key-gap: 0.28rem; }
  .topbar { padding-bottom: 0.55rem; }
  .message { font-size: 0.9rem; }
  .key { height: clamp(2.7rem, 8vw, 3.2rem); border-radius: 0.55rem; }
  .icon-button { width: 2.4rem; height: 2.4rem; }
  .loader-grid { grid-template-columns: repeat(6, minmax(2rem, 2.4rem)); gap: 0.34rem; }
  .loader-tile { font-size: 1rem; }
}

@media (min-width: 700px) {
  .app-shell { max-width: 560px; margin: 0 auto; width: 100%; }
  .board-wrap { padding-top: 0.35rem; }
}