:root {
  --bg: #0b0d11;
  --bg-card: #14171d;
  --bg-elev: #1c212a;
  --line: #262c38;
  --text: #eef1f6;
  --muted: #858d9c;
  --accent: #f0a23a;        /* warm amber — ties to the hot/cold theme */
  --accent-hover: #ffb24f;
  --accent-ink: #1c1304;    /* text on amber */
  --error: #ff7a7a;
  --radius: 14px;
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 480px at 50% -15%, #161a22 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Calm, slow ambient motion behind everything */
body::before, body::after {
  content: ""; position: fixed; z-index: -1; border-radius: 50%;
  filter: blur(90px); pointer-events: none; opacity: 0.13;
}
body::before {
  width: 55vw; height: 55vw; left: -12vw; top: -18vh;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  animation: drift-a 28s ease-in-out infinite alternate;
}
body::after {
  width: 48vw; height: 48vw; right: -14vw; bottom: -20vh;
  background: radial-gradient(circle, #3a78ff, transparent 70%);
  animation: drift-b 34s ease-in-out infinite alternate;
}
@keyframes drift-a {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(9vw, 11vh) scale(1.18); }
}
@keyframes drift-b {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-11vw, -9vh) scale(1.12); }
}
@media (prefers-reduced-motion: reduce) {
  body::before, body::after { animation: none; }
}

#app { max-width: 1000px; margin: 0 auto; padding: 24px 16px 64px; }

.screen { animation: fade 0.3s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Join screen */
.logo {
  font-size: 56px; font-weight: 700; text-align: center; margin: 40px 0 0;
  color: var(--text); letter-spacing: -2px;
}
.logo .o-dot { color: var(--accent); }
.logo.small { font-size: 22px; margin: 0; letter-spacing: -1px; }
.tagline { text-align: center; color: var(--muted); margin: 10px 0 30px; font-size: 15px; }

.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; max-width: 380px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}
.mode-tabs { display: flex; gap: 6px; background: var(--bg-elev); padding: 4px; border-radius: 10px; }
.mode-tab {
  flex: 1; background: transparent; color: var(--muted); padding: 9px 8px; font-size: 14px;
  border-radius: 7px;
}
.mode-tab.active { background: var(--accent); color: var(--accent-ink); }
.mode-tab:not(.active):hover { color: var(--text); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

/* Language picker — an explicit, required choice (no default) */
.lang-field { display: flex; flex-direction: column; gap: 8px; }
.lang-label { font-size: 14px; color: var(--muted); }
.lang-options { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-btn {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.lang-btn .flag { font-size: 18px; }
.lang-btn:hover { border-color: var(--accent); }
.lang-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:active { transform: none; }
.hint { font-weight: 400; opacity: 0.7; }
input, select {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  font-family: inherit;
  border-radius: 10px; padding: 12px 14px; font-size: 16px; outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240, 162, 58, 0.15); }
.row { display: flex; gap: 10px; }
button {
  cursor: pointer; border: none; border-radius: 10px; padding: 12px 18px; font-size: 15px;
  font-weight: 600; font-family: inherit; transition: background 0.15s, transform 0.05s, border 0.15s;
}
button:active { transform: translateY(1px); }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { background: var(--accent-hover); }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.ghost:hover { color: var(--text); border-color: var(--accent); }
.full { width: 100%; margin-top: 12px; }
.error { color: var(--error); font-size: 14px; min-height: 18px; margin: 0; text-align: center; }

/* Game header */
.game-header { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.room-badge, .round-badge, .count-badge { color: var(--muted); font-size: 14px; }
.room-badge strong, .round-badge strong, .count-badge strong { color: var(--text); letter-spacing: 1px; }
.game-header .ghost { padding: 7px 14px; }
.game-header #sound-btn { margin-left: auto; }
.icon-btn { padding: 7px 11px !important; font-size: 15px; }

.conn-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600;
  background: rgba(255, 122, 122, 0.12); border: 1px solid rgba(255, 122, 122, 0.4); color: var(--error);
}
.conn-bar button { padding: 7px 14px; }

.banner { padding: 16px; border-radius: var(--radius); text-align: center; font-weight: 700; margin-bottom: 18px; }
.banner:not(.hidden) { animation: bannerPop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.25); }
.banner.win { background: linear-gradient(120deg, #1c7d4a, #34b56f); color: white; box-shadow: 0 8px 30px -10px rgba(52, 181, 111, 0.5); }
.banner.lose { background: var(--bg-elev); color: var(--text); }

@keyframes bannerPop {
  0% { opacity: 0; transform: translateY(-12px) scale(0.96); }
  100% { opacity: 1; transform: none; }
}

/* Transient "you guessed X" popup near the top — instant feedback without scrolling */
.toast {
  position: fixed; top: 80px; left: 50%; z-index: 50; pointer-events: none;
  display: flex; align-items: center; gap: 12px; white-space: nowrap;
  padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: 17px;
  background: var(--bg-elev); border: 1px solid var(--line);
  box-shadow: 0 12px 34px -10px rgba(0, 0, 0, 0.7);
}
.toast .t-rank { font-variant-numeric: tabular-nums; }
.toast.show { animation: toastPop 1.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }

@keyframes toastPop {
  0%   { opacity: 0; transform: translate(-50%, -14px) scale(0.9); }
  12%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  72%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.98); }
}

.game-grid {
  display: grid; gap: 24px;
  grid-template-columns: 190px 1fr 230px;
  grid-template-areas: "history main stats";
}
main { grid-area: main; }
#stats { grid-area: stats; align-self: start; position: sticky; top: 16px; }
@media (max-width: 900px) {
  .game-grid { grid-template-columns: 190px 1fr; grid-template-areas: "history main" "stats stats"; }
  #stats { position: static; }
}
@media (max-width: 760px) {
  .game-grid { grid-template-columns: 1fr; grid-template-areas: "main" "stats" "history"; }
  #history { position: static; max-height: none; }
}

/* Session stats */
.stats-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.stat { background: var(--bg-card); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.stat-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.stat-lbl { font-size: 12px; color: var(--muted); }
.stats-empty { color: var(--muted); font-size: 13px; }
.stats-chart-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stats-chart { display: flex; align-items: flex-end; gap: 5px; height: 120px; }
.chart-col { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart-bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); }
.chart-bar.good { background: hsl(140, 60%, 48%); }
.chart-bar.ok { background: var(--accent); }
.chart-bar.far { background: hsl(215, 55%, 55%); }
.chart-bar.gaveup { background: var(--error); opacity: 0.7; }
.chart-num { text-align: center; font-size: 11px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }

/* Difficulty buttons */
.diff-btn {
  flex: 1; background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  padding: 9px 12px; border-radius: 10px; font-size: 14px;
}
.diff-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.diff-btn:not(.active):hover { border-color: var(--accent); }

/* Rank card (#7) */
.rank-card { background: var(--bg-card); border-radius: 10px; padding: 14px; }
.rank-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.rank-name { font-weight: 700; font-size: 18px; }
.rank-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.rank-bar { height: 8px; background: var(--bg-elev); border-radius: 999px; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 999px; transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.rank-sub { color: var(--muted); font-size: 12px; margin: 8px 0 12px; }

/* Achievements modal — grouped into rows */
.modal.ach-modal-box { max-width: 760px; width: calc(100% - 32px); max-height: 86vh; overflow-y: auto; }
.ach-modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.ach-modal-head h3 { margin: 0; font-size: 19px; }
.ach-grid { display: flex; flex-direction: column; gap: 18px; }
.ach-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.ach-group-title span { color: var(--text); font-weight: 600; }
.ach-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ach { flex: 1 1 130px; min-width: 120px; display: flex; flex-direction: column; gap: 3px; background: var(--bg-elev); border: 1px solid transparent; border-radius: 10px; padding: 11px 12px; opacity: 0.5; }
.ach.earned { opacity: 1; border-color: var(--line); }
.ach-icon { font-size: 22px; line-height: 1.1; filter: grayscale(1); }
.ach.earned .ach-icon { filter: none; }
.ach-name { font-weight: 700; font-size: 13px; }
.ach-desc { font-size: 11px; color: var(--muted); line-height: 1.25; }

/* Mobile polish (#6) */
@media (max-width: 600px) {
  #app { padding: 16px 12px 48px; }
  .logo { font-size: 44px; }
  .game-header { gap: 8px 10px; }
  .logo.small { font-size: 19px; }
  .round-badge, .count-badge { font-size: 13px; }
  .game-header .ghost { padding: 6px 10px; font-size: 13px; }
  .game-header #sound-btn { margin-left: auto; }
  .guess-row { padding: 10px 12px; }
  .card { padding: 20px; }
}

/* Solo mode: drop the multiplayer scoreboard/feed (keep the history column) */
#game.solo .game-grid { grid-template-columns: 200px 1fr; grid-template-areas: "history main"; max-width: 880px; }
#game.solo #sidebar { display: none; }
#game.solo .room-badge { display: none; }
#game.daily .room-badge,
#game.daily .round-badge { display: none; }

/* Chronological guess history (left column) */
#history { grid-area: history; align-self: start; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.history-list li {
  display: flex; align-items: center; gap: 8px; padding: 7px 11px; border-radius: 8px;
  background: var(--bg-card); font-size: 14px;
}
.history-list .hword { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.history-list .hrank { font-variant-numeric: tabular-nums; font-weight: 700; }
.history-list li.is-new { outline: 1px solid var(--accent); }
.history-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.daily-badge { color: var(--accent); font-size: 14px; font-weight: 600; }

/* Daily mode */
.mode-note { color: var(--muted); font-size: 13px; margin: -4px 0 0; }
.daily-result {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; text-align: center;
}
.daily-streak { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.daily-come-back { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

/* Daily leaderboard panel */
.leaderboard {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.lb-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 700; font-size: 16px; margin-bottom: 4px;
}
.lb-head span { color: var(--muted); font-weight: 500; font-size: 13px; }
.lb-streak {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px;
  background: rgba(240, 162, 58, 0.14); color: var(--accent);
  padding: 4px 12px; border-radius: 999px; font-weight: 600; font-size: 14px;
}
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lb-list li {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px;
  background: var(--bg-elev); font-size: 15px;
}
.lb-list li.you { border: 1px solid var(--accent); }
.lb-rank { width: 28px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }
.lb-list li:nth-child(1) .lb-rank { color: #f0c34a; }
.lb-name { flex: 1; font-weight: 600; }
.lb-guesses { font-variant-numeric: tabular-nums; color: var(--muted); }
.lb-guesses b { color: var(--text); }
.lb-you-rank { margin-top: 10px; color: var(--muted); font-size: 14px; }
.lb-share { width: 100%; margin-top: 14px; }
.action-row { display: flex; gap: 10px; margin-bottom: 14px; }
.hint-btn { flex: 1; color: var(--accent); border-color: rgba(240, 162, 58, 0.4); }
.hint-btn:disabled { color: var(--muted); border-color: var(--line); }
.giveup-btn { color: var(--muted); }
.giveup-btn:hover { color: var(--error); border-color: var(--error); }

#guess-form { display: flex; gap: 10px; }
#guess-form input { flex: 1; }
.guess-msg { color: var(--muted); min-height: 18px; font-size: 14px; margin: 8px 2px; }
.guess-msg.bad { color: var(--error); }

/* Guess rows */
.guesses { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.guess-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 15px; border-radius: 10px;
  background: var(--bg-card); position: relative; overflow: hidden;
  border: 1px solid transparent;
  transition: opacity 0.35s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* entrance state for a freshly played guess (removed on next frame) */
.guess-row.enter { opacity: 0; transform: translateY(-10px) scale(0.98); }
.guess-row .bar {
  position: absolute; inset: 0; opacity: 0.16; z-index: 0; border-radius: 10px;
  transition: width 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.guess-row .word { font-weight: 600; z-index: 1; flex: 1; letter-spacing: -0.2px; }
.guess-row .rank { z-index: 1; font-variant-numeric: tabular-nums; font-weight: 700; }
.guess-row.is-new { border-color: var(--accent); animation: glow 1.1s ease-out; }
.guess-row.solved { animation: solvedPop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3); }

@keyframes glow {
  0% { box-shadow: 0 0 0 0 rgba(240, 162, 58, 0.45); }
  100% { box-shadow: 0 0 0 10px rgba(240, 162, 58, 0); }
}
@keyframes solvedPop {
  0% { transform: scale(0.96); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Sidebar */
aside h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 18px 0 8px; }
.scoreboard, .feed { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.scoreboard li {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-card);
  border-radius: 8px; font-size: 14px;
}
.scoreboard .pname { flex: 1; font-weight: 600; }
.scoreboard .pstat { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.scoreboard li.me { border: 1px solid var(--accent); }
.scoreboard li.solved { background: #16331f; }
.feed li { color: var(--muted); font-size: 13px; padding: 3px 2px; }
.feed li b { color: var(--text); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 12, 0.6); backdrop-filter: blur(3px); animation: fade 0.18s ease;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; width: calc(100% - 32px); max-width: 380px;
  box-shadow: 0 24px 70px -18px rgba(0, 0, 0, 0.75);
  animation: bannerPop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}
.modal p { margin: 0 0 22px; font-size: 16px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.primary.danger { background: var(--error); color: #2a0d0d; }
.primary.danger:hover { background: #ff9090; }
