:root {
  --bg-main: #f6efe3;
  --bg-accent: radial-gradient(circle at top left, rgba(255, 218, 185, 0.8), transparent 34%), radial-gradient(circle at bottom right, rgba(139, 188, 143, 0.28), transparent 30%), linear-gradient(145deg, #f7f2ea 0%, #f0e7d9 100%);
  --panel-bg: rgba(255, 252, 247, 0.84);
  --panel-border: rgba(110, 88, 53, 0.12);
  --text-main: #2b2218;
  --text-muted: #655646;
  --tile-bg: rgba(255, 255, 255, 0.8);
  --tile-border: #d6c7b1;
  --tile-filled: #8e7352;
  --key-bg: rgba(255, 250, 242, 0.92);
  --key-text: #35281b;
  --key-border: rgba(101, 86, 70, 0.14);
  --shadow-soft: 0 18px 50px rgba(86, 67, 40, 0.12);
  --correct: #4e8b5b;
  --present: #cc9c2f;
  --absent: #8c8275;
  --toast-bg: rgba(37, 31, 24, 0.92);
  --toast-text: #fffdf8;
}

[data-bs-theme="dark"] {
  --bg-main: #171718;
  --bg-accent: radial-gradient(circle at top left, rgba(244, 162, 97, 0.16), transparent 30%), radial-gradient(circle at bottom right, rgba(106, 153, 78, 0.16), transparent 28%), linear-gradient(145deg, #121314 0%, #1b1f20 100%);
  --panel-bg: rgba(28, 31, 33, 0.9);
  --panel-border: rgba(244, 162, 97, 0.12);
  --text-main: #f5efe6;
  --text-muted: #d0c4b4;
  --tile-bg: rgba(34, 38, 39, 0.95);
  --tile-border: #475053;
  --tile-filled: #f2d2a2;
  --key-bg: rgba(38, 44, 46, 0.96);
  --key-text: #f5efe6;
  --key-border: rgba(255, 255, 255, 0.08);
  --shadow-soft: 0 18px 50px rgba(0, 0, 0, 0.32);
  --correct: #5ea86e;
  --present: #d8b04d;
  --absent: #5f6769;
  --toast-bg: rgba(246, 239, 230, 0.94);
  --toast-text: #181615;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  color: var(--text-main);
  background: var(--bg-main);
  background-image: var(--bg-accent);
}

.app-shell {
  padding-inline: 1rem;
}

.game-card {
  max-width: 860px;
  padding: 1.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.display-title {
  font-size: clamp(2.4rem, 5vw, 4rem);
  line-height: 0.95;
  font-weight: 800;
}

.subtitle,
.footer-note {
  color: var(--text-muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--key-bg);
  color: var(--text-main);
}

.stat-pill {
  height: 100%;
  padding: 1rem 1.1rem;
  border-radius: 20px;
  background: var(--tile-bg);
  border: 1px solid var(--panel-border);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.answer-reveal {
  width: min(100%, 380px);
  margin-inline: auto;
  padding: 0.85rem 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--tile-bg);
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  width: min(100%, 380px);
}

.tile {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  border: 2px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--text-main);
  font-weight: 800;
  font-size: clamp(1.35rem, 4vw, 2rem);
  text-transform: uppercase;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.tile.filled {
  border-color: var(--tile-filled);
  transform: scale(1.02);
}

.tile.correct,
.key.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.tile.present,
.key.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.tile.absent,
.key.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.tile.flip {
  animation: flip 0.55s ease forwards;
}

.tile.pop {
  animation: pop 0.13s ease;
}

.board.shake {
  animation: shake 0.38s ease;
}

.board.win {
  animation: winBounce 0.7s ease;
}

.keyboard {
  display: grid;
  gap: 0.5rem;
  width: 100%;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
}

.key {
  flex: 1 1 0;
  min-width: 2.9rem;
  padding: 0.85rem 0.55rem;
  border-radius: 14px;
  border: 1px solid var(--key-border);
  background: var(--key-bg);
  color: var(--key-text);
  font-weight: 700;
  text-transform: uppercase;
  transition: transform 0.12s ease, filter 0.2s ease, background-color 0.2s ease;
}

.key:hover {
  filter: brightness(1.03);
}

.key:active {
  transform: translateY(1px) scale(0.98);
}

.key.action-key {
  flex: 1.5 1 0;
  min-width: 4.9rem;
  font-size: 0.82rem;
}

.key[data-key="backspace"] {
  font-size: 1rem;
}

.game-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(120%);
  padding: 0.9rem 1.2rem;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
  transition: transform 0.25s ease;
  z-index: 10;
}

.game-toast.visible {
  transform: translateX(-50%) translateY(0);
}

@keyframes flip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes pop {
  0% { transform: scale(0.92); }
  100% { transform: scale(1.04); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes winBounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
  55% { transform: translateY(0); }
  75% { transform: translateY(-4px); }
}

@media (max-width: 767px) {
  .app-shell {
    padding-bottom: 14rem;
  }

  .keyboard {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    padding: 0.5rem 0.5rem calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
    background: var(--panel-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--panel-border);
    margin-bottom: 0 !important;
    gap: 0.35rem;
  }

  .key-row {
    gap: 0.28rem;
  }

  .key {
    min-width: 0;
    padding: 0.85rem 0.1rem;
    font-size: 0.82rem;
    border-radius: 10px;
  }

  .key.action-key {
    flex: 1.6 1 0;
    font-size: 0.72rem;
    min-width: 0;
  }
}

@media (max-width: 576px) {
  .game-card {
    padding: 1rem;
    border-radius: 22px;
  }

  .board {
    width: min(100%, 330px);
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 0.5rem;
  }

  .game-card {
    padding: 0.8rem;
  }
}

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-main);
  background-image: var(--bg-accent);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--tile-border);
  border-top-color: var(--correct);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(100%, 420px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  border-radius: 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.modal-card--wide {
  width: min(100%, 600px);
}

/* ── Nickname modal ──────────────────────────────────────────────────────── */
.nickname-input {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1.5px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--text-main);
  font-family: "Outfit", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s;
}

.nickname-input:focus {
  border-color: var(--correct);
}

.nickname-error {
  color: #e05260;
  font-size: 0.88rem;
  font-weight: 600;
}

/* ── Stats tabs ──────────────────────────────────────────────────────────── */
.stats-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--panel-border);
  padding-bottom: 0;
}

.stats-tab {
  padding: 0.6rem 1.2rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: "Outfit", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  margin-bottom: -2px;
  border-radius: 4px 4px 0 0;
  transition: color 0.15s, border-color 0.15s;
}

.stats-tab.active {
  color: var(--text-main);
  border-bottom-color: var(--correct);
}

.tab-content {
  padding-top: 1.5rem;
}

/* ── Personal stat value ─────────────────────────────────────────────────── */
.stat-value {
  display: block;
  font-size: 1.6rem;
  line-height: 1.2;
  margin-top: 0.1rem;
}

/* ── Distribution chart ──────────────────────────────────────────────────── */
.dist-chart { display: flex; flex-direction: column; gap: 0.35rem; }

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.dist-label {
  width: 1rem;
  text-align: right;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.dist-bar-wrap { flex: 1; }

.dist-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: var(--correct);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 28px;
  transition: width 0.4s ease;
}

.dist-bar--zero {
  background: var(--absent);
}

/* ── Leaderboard table ───────────────────────────────────────────────────── */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--panel-border);
  white-space: nowrap;
}

.leaderboard-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.leaderboard-me td {
  background: rgba(78, 139, 91, 0.08);
}

/* ── Calendar grid ───────────────────────────────────────────────────────── */
.cal-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 52px;
  min-height: 52px;
  border-radius: 12px;
  border: 1.5px solid var(--panel-border);
  background: var(--tile-bg);
  padding: 0.3rem 0.2rem;
  position: relative;
}

.cal-day--won     { background: var(--correct); border-color: var(--correct); color: #fff; }
.cal-day--lost    { background: var(--absent);  border-color: var(--absent);  color: #fff; }
.cal-day--skipped { background: var(--present); border-color: var(--present); color: #fff; }
.cal-day--started { border-color: var(--present); border-width: 2px; border-style: dashed; color: var(--present); }
.cal-day--unplayed { opacity: 0.45; }
.cal-day--locked  { cursor: default; }
.cal-day--playable {
  border-color: var(--correct);
  border-width: 2px;
  color: var(--correct);
}
.cal-day--playable:hover {
  background: rgba(78, 139, 91, 0.12);
}
.cal-day[role="button"] { cursor: pointer; }
.cal-day[role="button"]:hover { filter: brightness(0.92); }

.cal-day-date {
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
}

.cal-day-sub {
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.85;
}

.cal-lock {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.55rem;
  opacity: 0.6;
}

/* ── Calendar day detail (modal) ─────────────────────────────────────────── */
.cal-player-entry { }

.cal-guesses {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.cal-guess-row {
  display: flex;
  gap: 3px;
}

.cal-guess-tile {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-weight: 800;
  font-size: 0.78rem;
  color: #fff;
}

.cal-guess-tile.correct { background: var(--correct); }
.cal-guess-tile.present { background: var(--present); }
.cal-guess-tile.absent  { background: var(--absent);  }

.cal-result-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.cal-result--won     { background: rgba(78, 139, 91, 0.15);  color: var(--correct); }
.cal-result--lost    { background: rgba(140, 130, 117, 0.15); color: var(--absent);  }
.cal-result--skipped { background: rgba(204, 156, 47, 0.15); color: var(--present); }

/* ── Day selector (missed days) ──────────────────────────────────────────── */
.day-selector {
  padding: 0.85rem 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--tile-bg);
}

.day-selector-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.delete-zone {
  border-top: 1px solid var(--panel-border);
}
