/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ══════════════════════════════════════════════════════════════
   DARK THEME — default
══════════════════════════════════════════════════════════════ */
:root {
  --bg:           #0D0C0A;
  --surface:      #171512;
  --surface-2:    #1E1B17;
  --border:       #2A2620;
  --border-focus: #4A4138;
  --text:         #EDE8E0;
  --text-muted:   #6B6560;
  --accent:       #C8A87C;
  --accent-dim:   rgba(200,168,124,.13);
  --primary-bg:   #EDE8E0;
  --primary-fg:   #0D0C0A;
  --overlay-bg:   rgba(10,9,7,.85);

  --radius-pill: 100px;
  --radius-card: 20px;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.2);
  --shadow-card: 0 12px 48px rgba(0,0,0,.6), 0 2px 12px rgba(0,0,0,.4);
}

/* ══════════════════════════════════════════════════════════════
   LIGHT THEME
══════════════════════════════════════════════════════════════ */
[data-theme="light"] {
  --bg:           #F7F4EF;
  --surface:      #FFFFFF;
  --surface-2:    #F0EDE7;
  --border:       #E3DDD4;
  --border-focus: #B8AFA2;
  --text:         #1A1814;
  --text-muted:   #9E9489;
  --accent:       #8B6D3C;
  --accent-dim:   rgba(139,109,60,.10);
  --primary-bg:   #1A1814;
  --primary-fg:   #FFFFFF;
  --overlay-bg:   rgba(247,244,239,.88);

  --shadow-sm:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-card: 0 8px 32px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.06);
}

/* ── Global ─────────────────────────────────────────────────── */
html { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .2s;
}

/* ── Theme toggle ───────────────────────────────────────────── */
.btn-theme {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 400;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}
.btn-theme:hover { color: var(--text); border-color: var(--border-focus); transform: rotate(18deg); }

/* Dark mode → show moon, hide sun */
.theme-icon--moon { display: block; }
.theme-icon--sun  { display: none; }
[data-theme="light"] .theme-icon--moon { display: none; }
[data-theme="light"] .theme-icon--sun  { display: block; }

/* ── Views ──────────────────────────────────────────────────── */
.view {
  display: none;
  min-height: 100svh;
  flex-direction: column;
  align-items: center;
}
.view.active { display: flex; }

/* ══════════════════════════════════════════════════════════════
   HOME
══════════════════════════════════════════════════════════════ */
.home-wrap {
  width: 100%;
  max-width: 400px;
  padding: 56px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-header { margin-bottom: 4px; }

.brand-row {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-bottom: 8px;
}
.brand-emoji {
  font-size: 2.1rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
  filter: drop-shadow(0 2px 10px rgba(255,190,80,.25));
}
.brand {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.6px;
  color: var(--text);
  line-height: 1.1;
}
.brand-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* ── Nick bar ───────────────────────────────────────────────── */
.home-nick-bar { margin-top: 6px; }

.home-nick-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  width: fit-content;
  max-width: 100%;
  transition: background .2s;
}
.home-nick-wave { font-size: 0.95rem; }
.home-nick-name {
  font-size: 0.87rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.btn-nick-edit {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 2px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color .15s;
}
.btn-nick-edit:hover { color: var(--accent); }

.btn-nick-prompt {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  width: fit-content;
  transition: border-color .15s, color .15s;
}
.btn-nick-prompt:hover { border-color: var(--border-focus); color: var(--text); }

/* ── Segmented control ──────────────────────────────────────── */
.seg-control {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px;
}
.seg {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .18s, color .15s, box-shadow .15s;
}
.seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ── Separator ──────────────────────────────────────────────── */
.sep {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.sep::before, .sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row { display: flex; gap: 8px; }
.join-row .input { flex: 1; text-transform: uppercase; letter-spacing: 2px; }
.btn-outline.sq { flex-shrink: 0; width: 50px; padding: 0; }

/* ══════════════════════════════════════════════════════════════
   CREATE ROOM
══════════════════════════════════════════════════════════════ */
.create-wrap {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.create-wrap h2 { font-size: 1.4rem; font-weight: 800; letter-spacing: -.4px; }
.hint { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }

/* Type selector */
.type-control { display: flex; flex-direction: column; gap: 8px; }
.type-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s, box-shadow .15s;
  width: 100%;
}
.type-btn:hover { border-color: var(--border-focus); }
.type-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: var(--shadow-sm);
}
.type-icon { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.type-text { display: flex; flex-direction: column; gap: 2px; }
.type-name { font-size: 0.92rem; font-weight: 700; color: var(--text); }
.type-desc { font-size: 0.77rem; color: var(--text-muted); line-height: 1.4; }

/* Room result */
.room-result {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: pop-in .22s ease;
}
.room-result-word { font-size: 0.87rem; color: var(--text-muted); }
.room-result-word strong { color: var(--accent); font-weight: 700; letter-spacing: 1px; }
.link-block {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 8px 8px 16px;
}
.link-url { flex: 1; font-size: 0.77rem; color: var(--text); word-break: break-all; line-height: 1.4; }
.btn-copy {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--primary-bg);
  color: var(--primary-fg);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn-copy:hover { opacity: .8; }

/* ══════════════════════════════════════════════════════════════
   GAME VIEW
══════════════════════════════════════════════════════════════ */
#view-game { padding-bottom: 80px; }

.game-topbar {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  padding: 18px 20px 14px;
  gap: 12px;
}
.game-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.2px;
  color: var(--text-muted);
}
.attempt-counter {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 5px 13px;
  white-space: nowrap;
}

.room-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  margin-bottom: 6px;
}
.room-badge strong { color: var(--text); }

.input-row {
  width: 100%;
  max-width: 560px;
  padding: 0 20px;
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.btn-send {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--primary-bg);
  color: var(--primary-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: opacity .15s, transform .1s;
}
.btn-send:hover  { opacity: .85; }
.btn-send:active { transform: scale(.92); }
.btn-send:disabled { opacity: .3; cursor: not-allowed; }

.stats-row {
  width: 100%;
  max-width: 560px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.stat-best { font-weight: 700; color: var(--accent); }

/* ── Leaderboard ────────────────────────────────────────────── */
.leaderboard-panel {
  width: 100%;
  max-width: 560px;
  padding: 0 20px;
  margin-bottom: 18px;
}
.lb-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.lb-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.lb-first  { background: var(--accent-dim); }
.lb-row.lb-won .lb-name::after { content: ' ✓'; color: #22C55E; font-weight: 700; }
.lb-rank { width: 20px; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-align: center; flex-shrink: 0; }
.lb-row.lb-first .lb-rank { color: var(--accent); }
.lb-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-variant-numeric: tabular-nums; font-weight: 700; font-size: .88rem; color: var(--text); flex-shrink: 0; }
.lb-att   { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }
.lb-word  { font-size: 0.78rem; font-weight: 500; color: var(--text-muted); margin-left: 6px; }
.lb-empty { padding: 16px; font-size: 0.83rem; color: var(--text-muted); text-align: center; }

.giveup-row {
  width: 100%;
  max-width: 560px;
  padding: 18px 20px 0;
  text-align: center;
}

/* ══════════════════════════════════════════════════════════════
   GUESS LIST
══════════════════════════════════════════════════════════════ */
.guesses-list {
  width: 100%;
  max-width: 560px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.g-item {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: pop-in .22s cubic-bezier(.34,1.4,.64,1);
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.g-dot {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px currentColor);
}

.g-pill {
  flex: 1;
  position: relative;
  height: 52px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: border-color .2s;
  cursor: default;
}
.g-pill:hover { border-color: var(--border-focus); }

.g-fill {
  position: absolute;
  inset: 0;
  right: auto;
  width: 0;
  border-radius: inherit;
  opacity: .18;
  transition: width .8s cubic-bezier(.4,0,.2,1);
}

.g-word {
  position: relative;
  z-index: 1;
  font-size: 0.95rem;
  font-weight: 600;
  padding-left: 18px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-score {
  position: relative;
  z-index: 1;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  padding-right: 18px;
  letter-spacing: -.3px;
  flex-shrink: 0;
}

.g-item.is-win .g-dot { animation: pulse-dot 1.1s ease infinite; }
.g-item.is-win .g-pill { border-color: rgba(255,215,0,.4); box-shadow: 0 0 14px rgba(255,215,0,.12); }
@keyframes pulse-dot {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.6); opacity: .7; }
}

/* ══════════════════════════════════════════════════════════════
   OVERLAYS
══════════════════════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fade-in .2s ease;
}
.overlay.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 40px 32px 36px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-card);
  animation: card-in .28s cubic-bezier(.34,1.46,.64,1);
  position: relative;
  overflow: hidden;
}
@keyframes card-in {
  from { transform: scale(.88); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Win card golden glow */
.overlay-card--win::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(ellipse at top, rgba(255,215,0,.1), transparent 60%);
  pointer-events: none;
}

.ov-icon {
  font-size: 3rem;
  line-height: 1;
}
.ov-icon--bounce {
  animation: icon-bounce .55s cubic-bezier(.34,1.56,.64,1) .1s both;
}
@keyframes icon-bounce {
  from { transform: scale(0) rotate(-15deg); }
  to   { transform: scale(1) rotate(0); }
}

.overlay-card h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.4px; }
.ov-sub { font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; }
.ov-word {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 28px;
  width: 100%;
  color: var(--accent);
}

/* ══════════════════════════════════════════════════════════════
   SHARED COMPONENTS
══════════════════════════════════════════════════════════════ */
.btn-primary,
.btn-outline {
  width: 100%;
  padding: 13px 20px;
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity .15s, transform .1s;
}
.btn-primary:hover,
.btn-outline:hover  { opacity: .82; }
.btn-primary:active,
.btn-outline:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { background: var(--primary-bg); color: var(--primary-fg); }
.btn-outline  { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--border-focus); }

.back-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 2px;
  transition: color .15s;
}
.back-btn:hover { color: var(--text); }

.btn-ghost-sm {
  background: none;
  border: none;
  font-size: 0.83rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  transition: color .15s;
  font-weight: 500;
}
.btn-ghost-sm:hover { color: var(--text); }

/* ── Input ──────────────────────────────────────────────────── */
.input {
  width: 100%;
  height: 48px;
  padding: 0 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input.center { text-align: center; font-size: 1.05rem; font-weight: 600; letter-spacing: 1px; }
.input::placeholder { color: var(--text-muted); }

/* ── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-bg);
  color: var(--primary-fg);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: var(--radius-pill);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, top .2s;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-card);
}
#toast.show { opacity: 1; top: 24px; }

/* Utility */
.hidden { display: none !important; }

/* ── TG Banner ──────────────────────────────────────────────── */
.tg-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #18243F;
  border: 1px solid #253150;
  border-radius: var(--radius-card);
  text-decoration: none;
  color: var(--text);
  transition: background .15s, transform .1s;
  margin-top: 6px;
}
[data-theme="light"] .tg-banner { background: #EFF6FF; border-color: #BFDBFE; }
.tg-banner:hover  { background: #1E2E4D; }
[data-theme="light"] .tg-banner:hover { background: #DBEAFE; }
.tg-banner:active { transform: scale(.99); }

.tg-banner--game {
  width: 100%;
  max-width: 560px;
  margin: 18px 20px 0;
  align-self: center;
}
.tg-banner-icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2563EB;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tg-banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.tg-banner-title { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.tg-banner-sub   { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.tg-banner-arr   { flex-shrink: 0; color: var(--text-muted); font-size: 1rem; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 420px) {
  .home-wrap    { padding: 40px 18px 60px; }
  .create-wrap  { padding: 24px 18px 60px; }
  .g-pill       { height: 46px; }
  .overlay-card { padding: 32px 22px 28px; }
  .btn-theme    { top: 12px; right: 12px; width: 36px; height: 36px; }
}
