/* ============================================
   ИГРА В СЛОВА — Design Tokens & Base Styles
   ============================================ */

:root {
  /* Palette — playful game with TV-show DNA */
  --bg-deep:        #0a0824;
  --bg-mid:         #1a1147;
  --bg-glow:        #2d1b69;
  --surface:        #ffffff;
  --surface-soft:   #f7f4ff;
  --surface-dark:   #1d1547;

  --ink-1:          #0e0b2e;
  --ink-2:          #2a2454;
  --ink-3:          #6b6493;
  --ink-on-dark:    #ffffff;
  --ink-on-dark-2:  rgba(255,255,255,0.72);
  --ink-on-dark-3:  rgba(255,255,255,0.48);

  --gold:           #FFD93D;
  --gold-deep:      #F5B400;
  --magenta:        #FF3D8C;
  --magenta-deep:   #D91A6A;
  --cyan:           #4ECDC4;
  --violet:         #8B5CF6;
  --coral:          #FF6B6B;
  --green:          #5EEAA0;

  --tile-default:   #ffffff;
  --tile-used:      #ffd93d;
  --tile-star-bg:   linear-gradient(135deg, #FFE066, #F5B400);

  --shadow-card:    0 8px 32px rgba(8,4,40,0.18), 0 2px 6px rgba(8,4,40,0.10);
  --shadow-pop:     0 14px 40px rgba(141,82,255,0.35), 0 4px 12px rgba(255,61,140,0.18);
  --shadow-tile:    0 6px 0 #d4ad00, 0 10px 20px rgba(0,0,0,0.3);
  --shadow-tile-press: 0 2px 0 #d4ad00, 0 4px 8px rgba(0,0,0,0.3);

  --radius-sm:      10px;
  --radius-md:      18px;
  --radius-lg:      28px;
  --radius-pill:    999px;

  /* Type */
  --font-display:   "Unbounded", "Manrope", system-ui, -apple-system, sans-serif;
  --font-body:      "Manrope", system-ui, -apple-system, sans-serif;
  --font-mono:      "JetBrains Mono", ui-monospace, monospace;

  /* Spacing */
  --pad-x:          24px;
  --gap-sm:         8px;
  --gap-md:         16px;
  --gap-lg:         24px;
  --gap-xl:         40px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink-on-dark);
  background: var(--bg-deep);
  min-height: 100vh;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(139, 92, 246, 0.35), transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(255, 61, 140, 0.25), transparent 60%),
    linear-gradient(180deg, #14093d 0%, #0a0824 100%);
  background-attachment: fixed;
}

/* Star field background */
.starfield {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.starfield::before, .starfield::after {
  content: "";
  position: absolute;
  inset: -50%;
  background-image:
    radial-gradient(1px 1px at 20% 30%, white, transparent 50%),
    radial-gradient(1px 1px at 70% 80%, white, transparent 50%),
    radial-gradient(2px 2px at 40% 60%, rgba(255,217,61,0.8), transparent 50%),
    radial-gradient(1px 1px at 90% 20%, white, transparent 50%),
    radial-gradient(1px 1px at 10% 80%, white, transparent 50%),
    radial-gradient(2px 2px at 55% 15%, rgba(255,217,61,0.6), transparent 50%),
    radial-gradient(1px 1px at 30% 85%, white, transparent 50%),
    radial-gradient(1px 1px at 85% 55%, white, transparent 50%);
  background-size: 600px 600px;
  opacity: 0.5;
  animation: twinkle 8s linear infinite;
}
.starfield::after {
  background-size: 400px 400px;
  background-position: 100px 50px;
  opacity: 0.3;
  animation-duration: 12s;
  animation-direction: reverse;
}
@keyframes twinkle {
  0% { transform: translate(0, 0); }
  100% { transform: translate(-60px, -60px); }
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Type ===== */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
  letter-spacing: 0;
  line-height: 1.05;
}
.display-1 { font-size: 78px; font-weight: 800; letter-spacing: 0; }
.display-2 { font-size: 42px; font-weight: 700; letter-spacing: 0; }
.h-section { font-size: 24px; font-weight: 600; letter-spacing: 0; }
.label-up  { font-family: var(--font-body); font-size: 12px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-on-dark-2); }
.mono { font-family: var(--font-mono); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  padding: 16px 28px;
  border-radius: var(--radius-pill);
  transition: transform 80ms ease, box-shadow 80ms ease, background 120ms ease;
  user-select: none;
  letter-spacing: 0.01em;
}
.btn:active { transform: translateY(2px) scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: var(--ink-1);
  box-shadow: 0 6px 0 var(--gold-deep), 0 10px 24px rgba(255,217,61,0.35);
}
.btn-primary:hover { box-shadow: 0 8px 0 var(--gold-deep), 0 14px 30px rgba(255,217,61,0.45); transform: translateY(-1px); }
.btn-primary:active { box-shadow: 0 2px 0 var(--gold-deep); }

.btn-secondary {
  background: linear-gradient(135deg, var(--magenta) 0%, var(--magenta-deep) 100%);
  color: white;
  box-shadow: 0 6px 0 var(--magenta-deep), 0 10px 24px rgba(255,61,140,0.35);
}
.btn-secondary:hover { transform: translateY(-1px); }
.btn-secondary:active { box-shadow: 0 2px 0 var(--magenta-deep); }

.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: var(--ink-on-dark);
  border: 1.5px solid rgba(255,255,255,0.16);
}
.btn-ghost:hover { background: rgba(255,255,255,0.14); }

.btn-sm { padding: 10px 18px; font-size: 14px; }
.btn-lg { padding: 22px 40px; font-size: 20px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

/* ===== Inputs ===== */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-on-dark-2);
  margin-bottom: 8px;
}
.field {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.14);
  color: white;
  font-family: var(--font-body);
  font-size: 18px;
  padding: 18px 20px;
  border-radius: var(--radius-md);
  transition: border-color 120ms, background 120ms;
}
.field:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(255,255,255,0.1);
}
.field::placeholder { color: var(--ink-on-dark-3); }

/* ===== Card ===== */
.card {
  background: var(--surface);
  color: var(--ink-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px;
}
.card-dark {
  background: rgba(255,255,255,0.04);
  border: 1.5px solid rgba(255,255,255,0.10);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(8px);
}

/* ===== Avatar ===== */
.avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  flex-shrink: 0;
  position: relative;
  border: 3px solid white;
}
.avatar-sm { width: 40px; height: 40px; font-size: 18px; border-width: 2px; }
.avatar-lg { width: 88px; height: 88px; font-size: 36px; border-width: 4px; }

/* ===== Star icon (inline SVG via mask) ===== */
.star {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 2l2.92 6.91L22 10l-5.5 4.77L18.18 22 12 18.27 5.82 22l1.68-7.23L2 10l7.08-1.09z'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 2l2.92 6.91L22 10l-5.5 4.77L18.18 22 12 18.27 5.82 22l1.68-7.23L2 10l7.08-1.09z'/></svg>") center/contain no-repeat;
}

/* ===== Letter tile ===== */
.tile {
  --tile-size: 84px;
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 16px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(var(--tile-size) * 0.5);
  background: white;
  color: var(--ink-1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  border: none;
  user-select: none;
  transition: transform 100ms cubic-bezier(.2,.8,.2,1.4), box-shadow 100ms, opacity 200ms;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 10px 22px rgba(0,0,0,0.28);
  letter-spacing: 0;
}
.tile:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 9px 0 rgba(0,0,0,0.18), 0 14px 28px rgba(0,0,0,0.32); }
.tile:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 10px rgba(0,0,0,0.28); }
.tile--used {
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0.92);
}
.tile--star {
  background: var(--tile-star-bg);
  color: var(--ink-1);
}
.tile--in-word {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-deep) 100%);
}

/* ===== Player chip ===== */
.player-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 10px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-pill);
  transition: all 200ms;
  white-space: nowrap;
}
.player-chip--ready {
  border-color: var(--green);
  background: rgba(94,234,160,0.12);
  box-shadow: 0 0 0 0 rgba(94,234,160,0.4);
  animation: ready-pulse 1.6s infinite;
}
@keyframes ready-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(94,234,160,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(94,234,160,0); }
}
.player-chip--me { border-color: var(--gold); }

/* ===== Layout ===== */
.shell {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px var(--pad-x);
  flex: 1;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.mobile-bottom-nav {
  display: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.01em;
  color: white;
  text-decoration: none;
}
.brand .star {
  font-size: 28px;
  color: var(--gold);
  filter: drop-shadow(0 0 12px rgba(255,217,61,0.6));
  animation: star-spin 8s linear infinite;
}
@keyframes star-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== Toast ===== */
.toast-stack {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink-1);
  color: white;
  padding: 14px 22px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  box-shadow: var(--shadow-card);
  animation: toast-in 200ms ease-out;
  pointer-events: all;
}
@keyframes toast-in {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== Animations ===== */
@keyframes drop-in {
  0% { transform: translateY(-200px) rotate(-30deg); opacity: 0; }
  60% { transform: translateY(20px) rotate(8deg); opacity: 1; }
  100% { transform: translateY(0) rotate(0); opacity: 1; }
}
.drop-in {
  animation: drop-in 600ms cubic-bezier(.2,.8,.2,1.2) backwards;
}

@keyframes pop-in {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: pop-in 280ms cubic-bezier(.2,.8,.2,1.4) backwards; }

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

@keyframes confetti-fall {
  0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== Timer ring ===== */
.timer-ring {
  position: relative;
  width: 100px;
  height: 100px;
}
.timer-ring svg { transform: rotate(-90deg); }
.timer-ring__track { stroke: rgba(255,255,255,0.1); fill: none; }
.timer-ring__bar { fill: none; stroke-linecap: round; transition: stroke 500ms; }
.timer-ring__label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
}

/* ===== Chat panel emoji float ===== */
@keyframes float-up {
  0%   { transform: translateY(0) scale(0.6); opacity: 0; }
  15%  { transform: translateY(-12px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-200px) scale(1); opacity: 0; }
}
.float-emoji {
  position: absolute;
  font-size: 44px;
  pointer-events: none;
  animation: float-up 2.4s cubic-bezier(.2,.6,.2,1) forwards;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
  z-index: 60;
}

/* ===== Utility ===== */
.row { display: flex; align-items: center; gap: var(--gap-md); }
.col { display: flex; flex-direction: column; gap: var(--gap-md); }
.center { display: flex; align-items: center; justify-content: center; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-md); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.text-muted { color: var(--ink-on-dark-3); }
.text-gold { color: var(--gold); }
.text-green { color: var(--green); }
.text-magenta { color: var(--magenta); }
.text-center { text-align: center; }
.mono-num { font-variant-numeric: tabular-nums; }

@media (max-width: 960px) {
  .display-1 { font-size: 58px; }
  .display-2 { font-size: 34px; }
}

/* ===== Mobile adjustments ===== */
@media (max-width: 720px) {
  :root { --pad-x: 14px; }
  html, body { overflow-x: hidden; }
  body { background-attachment: scroll; }
  #app { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .shell {
    max-width: 100%;
    min-height: 100svh;
    padding: 12px var(--pad-x) calc(92px + env(safe-area-inset-bottom));
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-wrap: nowrap;
    gap: 8px;
    margin: -12px calc(var(--pad-x) * -1) 16px;
    padding: max(10px, env(safe-area-inset-top)) var(--pad-x) 10px;
    background: rgba(10, 8, 36, 0.78);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(14px);
  }
  .topbar-nav { display: none; }
  .topbar-actions {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }
  .topbar-actions > .row { display: none; }
  .topbar-actions > .btn,
  .topbar-actions > button {
    min-height: 40px;
    padding: 8px 11px;
    font-size: 12px;
  }
  .topbar-actions a[href="#profile"] {
    max-width: none !important;
    padding: 6px 8px !important;
    gap: 4px !important;
  }
  .topbar-actions a[href="#profile"] > span:nth-child(2) { display: none; }
  .brand {
    min-width: 0;
    gap: 9px;
    font-size: 16px;
    letter-spacing: 0;
  }
  .brand > span:first-child {
    width: 34px !important;
    height: 34px !important;
    border-radius: 10px !important;
    flex: 0 0 auto;
  }
  .brand > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .brand .star { font-size: 22px; }
  .display-1 { font-size: 40px; line-height: 1.06; }
  .display-2 { font-size: 28px; line-height: 1.12; overflow-wrap: anywhere; }
  .h-section { font-size: 20px; line-height: 1.15; }
  .label-up { font-size: 11px; letter-spacing: 0.12em; }
  .card,
  .card-dark {
    padding: 16px;
    border-radius: 16px;
  }
  .btn {
    min-height: 44px;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }
  .btn-sm { min-height: 40px; padding: 9px 12px; font-size: 12px; }
  .btn-lg { min-height: 48px; padding: 14px 16px; font-size: 16px; }
  .field {
    min-height: 48px;
    padding: 14px 15px;
    border-radius: 14px;
    font-size: 16px;
  }
  .between { flex-wrap: wrap; align-items: flex-start; }
  .row { min-width: 0; }
  .avatar { width: 48px; height: 48px; font-size: 20px; }
  .avatar-sm { width: 34px; height: 34px; font-size: 15px; }
  .player-chip {
    width: 100%;
    min-width: 0;
    border-radius: 16px;
    padding: 10px;
    white-space: normal;
  }
  .player-chip strong {
    display: inline-block;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
    white-space: nowrap;
  }
  .toast-stack {
    top: max(12px, env(safe-area-inset-top));
    width: calc(100% - 24px);
  }
  .toast {
    width: 100%;
    border-radius: 16px;
    text-align: center;
  }
  .timer-ring { width: 74px; height: 74px; }
  .timer-ring svg { width: 74px; height: 74px; }
  .timer-ring__label { font-size: 24px; }
  .tile {
    --tile-size: min(62px, calc((100vw - 76px) / 5));
    border-radius: 12px;
  }
  .letter-pool { gap: 8px !important; }
  .game-shell { padding-bottom: calc(92px + env(safe-area-inset-bottom)) !important; }
  .game-topbar {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .game-topbar .brand { display: none; }
  .game-status-row {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px !important;
  }
  .game-status-row a[href="#profile"] {
    max-width: none !important;
    padding: 6px 8px !important;
    gap: 4px !important;
  }
  .game-status-row a[href="#profile"] > span:nth-child(2) { display: none; }
  .game-mini-card {
    padding: 7px 10px !important;
    border-radius: 14px !important;
    white-space: nowrap;
  }
  .game-controls {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  .game-controls .btn-primary { grid-column: 1 / -1; }
  .join-code-row {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 10px !important;
  }
  .option-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
  }
  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(13, 10, 40, 0.92);
    border-top: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 -12px 28px rgba(0,0,0,0.34);
    backdrop-filter: blur(18px);
  }
  .mobile-bottom-nav__item {
    min-width: 0;
    min-height: 54px;
    border-radius: 14px;
    color: var(--ink-on-dark-2);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 800;
  }
  .mobile-bottom-nav__item.is-active {
    color: var(--ink-1);
    background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  }
  .mobile-bottom-nav__icon {
    font-family: var(--font-display);
    font-size: 20px;
    line-height: 1;
  }
  .mobile-bottom-nav__label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    line-height: 1;
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  :root { --pad-x: 12px; }
  .display-1 { font-size: 34px; }
  .display-2 { font-size: 25px; }
  .h-section { font-size: 19px; }
  .tile { --tile-size: min(56px, calc((100vw - 64px) / 5)); }
  .mobile-bottom-nav { padding-left: 6px; padding-right: 6px; }
  .mobile-bottom-nav__label { font-size: 9px; }
  .topbar-actions > .btn:not([href="#profile"]),
  .topbar-actions > button {
    padding-left: 9px;
    padding-right: 9px;
  }
}

/* Hide scrollbar but allow scroll on horizontal containers */
.scroll-x {
  overflow-x: auto;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }
