/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────────────────── */
:root {
  --bg:           #F7F4EF;
  --surface:      #FFFFFF;
  --border:       #E3DDD4;
  --border-focus: #B8AFA2;
  --text:         #1A1814;
  --text-muted:   #9E9489;

  --radius-pill: 100px;
  --radius-card: 20px;
  --radius-btn:  12px;
  --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);
}

html { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ── 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: 60px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-header { margin-bottom: 10px; }
.brand {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.6px;
  color: var(--text);
}
.brand-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* Segmented control (difficulty) */
.seg-control {
  display: flex;
  background: 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 .15s, 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.78rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: .05em;
  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; font-size: 1.1rem; }

/* ═══════════════════════════════════════════════════════════════
   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; }

/* Room 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, box-shadow .15s, background .15s;
  width: 100%;
}
.type-btn:hover {
  border-color: var(--border-focus);
}
.type-btn.active {
  border-color: var(--text);
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}
.type-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}
.type-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.type-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}
.type-desc {
  font-size: 0.78rem;
  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;
}
.room-result-word {
  font-size: 0.87rem;
  color: var(--text-muted);
}
.room-result-word strong {
  color: var(--text);
  font-weight: 700;
  letter-spacing: 1px;
}
.link-block {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  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(--text);
  color: #fff;
  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; }

/* Top bar */
.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;
}
.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 */
.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 area */
.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(--text);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn-send:hover  { opacity: .85; }
.btn-send:active { transform: scale(.94); }

/* Stats row */
.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: 600; }

/* ── Leaderboard panel ──────────────────────────────────────── */
.leaderboard-panel {
  width: 100%;
  max-width: 560px;
  padding: 0 20px;
  margin-bottom: 18px;
}
.lb-header {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: .06em;
  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: #FFFBEB;
}
.lb-row.lb-won .lb-name::after {
  content: ' ✓';
  color: #15803D;
  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: #B45309; }
.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: 0.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;
}

/* Give up */
.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 ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.g-dot {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
}

.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);
}

.g-fill {
  position: absolute;
  inset: 0;
  right: auto;
  width: 0;
  border-radius: inherit;
  opacity: .22;
  transition: width .75s 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 1s ease infinite;
}
@keyframes pulse-dot {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.5); opacity: .7; }
}

/* ═══════════════════════════════════════════════════════════════
   OVERLAYS
═══════════════════════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(247, 244, 239, .88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  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 .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes card-in {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.ov-icon  { font-size: 3rem; line-height: 1; }
.overlay-card h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.4px; }
.ov-sub   { font-size: 0.9rem; color: var(--text-muted); }
.ov-word  {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 28px;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════
   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;
  transition: opacity .15s, transform .1s;
  border: none;
}
.btn-primary:hover,
.btn-outline:hover  { opacity: .82; }
.btn-primary:active,
.btn-outline:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--text); color: #fff; }
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.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 rgba(180,170,160,.18);
}
.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(--text);
  color: #fff;
  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;
}
#toast.show { opacity: 1; top: 24px; }

/* Utility */
.hidden { display: none !important; }

/* ── Telegram Banner ────────────────────────────────────────── */
.tg-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: var(--radius-card);
  text-decoration: none;
  color: var(--text);
  transition: background .15s, transform .1s;
  margin-top: 6px;
}
.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: 40px;
  height: 40px;
  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.9rem;
  font-weight: 700;
  color: var(--text);
}
.tg-banner-sub {
  font-size: 0.77rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tg-banner-btn {
  flex-shrink: 0;
  background: #2563EB;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* ── 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; }
}
