:root {
  --bg: #07111f;
  --card: rgba(11, 22, 40, 0.72);
  --card-border: rgba(255, 255, 255, 0.1);
  --text: #f5f8ff;
  --muted: #afbbd0;
  --accent: #6fa8ff;
  --accent-2: #9b7cff;
  --danger: #ff6b87;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  --radius: 26px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(111, 168, 255, 0.18), transparent 30%),
    radial-gradient(circle at right bottom, rgba(155, 124, 255, 0.18), transparent 25%),
    linear-gradient(180deg, #07111f, #040913 65%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; border: none; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
button:active { transform: scale(.985); }
button[disabled] { cursor: not-allowed; opacity: .45; transform: none; }

select {
  color-scheme: dark;
}

input, select {
  width: 100%;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

select option {
  background: #1a2436;
  color: #f5f8ff;
}

select option:checked {
  background: #2a3b57;
  color: #f5f8ff;
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
  border-color: rgba(111, 168, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.18);
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 6px;
  accent-color: var(--accent);
}
.app-shell { width: min(1080px, 100%); margin: 0 auto; padding: 18px 16px 42px; }
.glass { background: var(--card); border: 1px solid var(--card-border); backdrop-filter: blur(16px); box-shadow: var(--shadow); }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:16px 18px; border-radius:var(--radius); margin-bottom:18px; }
.brand { display:flex; align-items:center; gap:14px; }
.brand h1 { margin:2px 0 0; font-size:28px; }
.brand-badge { width:52px; height:52px; display:grid; place-items:center; border-radius:18px; background:linear-gradient(135deg, var(--accent), var(--accent-2)); font-size:24px; }
.eyebrow { color: var(--muted); font-size:12px; letter-spacing:.12em; text-transform:uppercase; }
.screen { display:none; animation: fadeUp .22s ease; }
.screen.active { display:block; }
@keyframes fadeUp { from { opacity:0; transform:translateY(8px);} to {opacity:1; transform:translateY(0);} }
.grid { display:grid; gap:16px; }
.two-col { grid-template-columns:1fr 1fr; }
.card, .hero-card { border-radius: var(--radius); padding:22px; }
.hero-card { min-height:60vh; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:10px; }
.spinner { width:52px; height:52px; border-radius:50%; border:4px solid rgba(255,255,255,0.12); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg);} }
.card-head { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; margin-bottom:18px; }
.card-head h2, .card-head h3 { margin:0; }
.chip { border-radius:999px; padding:8px 12px; background:rgba(255,255,255,0.08); font-size:12px; white-space:nowrap; }
.profile-main { display:flex; align-items:center; gap:14px; margin-bottom:18px; }
.avatar-xl { width:76px; height:76px; border-radius:22px; object-fit:cover; background: rgba(255,255,255,0.08); }
.profile-name { font-size:24px; font-weight:700; }
.profile-meta,
.muted-link {
  color: var(--muted);
}

.invite-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.invite-link:hover,
.invite-link:focus-visible {
  color: var(--text);
}
.field { display:flex; flex-direction:column; gap:8px; margin-bottom:14px; }
.field span { color: var(--muted); font-size:14px; }
.toggle-row { display:flex; align-items:center; gap:10px; color: var(--muted); margin: 8px 0 10px; }
.actions-stack { display:flex; flex-direction:column; gap:12px; }
.primary-btn, .secondary-btn, .ghost-btn { min-height:48px; padding:14px 18px; border-radius:18px; color: var(--text); }
.primary-btn { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.secondary-btn { background: rgba(255,255,255,0.09); border: 1px solid rgba(255,255,255,0.12); }
.ghost-btn { background: transparent; border: 1px solid rgba(255,255,255,0.12); }
.ghost-btn.danger { border-color: rgba(255, 107, 135, 0.35); }
.large { min-height:56px; font-weight:700; }
.small { min-height:38px; padding:10px 14px; border-radius:14px; }
.join-inline { display:grid; grid-template-columns: 1fr auto; gap:10px; }
.inline-actions { display:flex; gap:10px; flex-wrap:wrap; }
.subcard {
  margin-top: 14px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
.public-rooms-list { display:grid; gap:12px; }
.public-room-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
.public-room-top {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.public-room-meta {
  margin-top: 8px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  color: var(--muted);
  font-size: 14px;
}
.banner {
  margin-top:16px;
  background: rgba(111, 168, 255, 0.12);
  border:1px solid rgba(111, 168, 255, 0.16);
  border-radius:18px;
  padding:14px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.banner-copy { display:grid; gap:4px; }
.banner-text { color: var(--muted); }
.hidden { display:none !important; }
.rules-list { margin:0; padding-left:20px; color:var(--muted); display:grid; gap:10px; }

.field-hint,
.status-box,
.rules-summary-box,
.empty-state {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
}
.field-hint { color: var(--muted); }
.status-box { color: var(--text); }
.status-box.success { border-color: rgba(111, 168, 255, 0.35); }
.status-box.error { border-color: rgba(255, 107, 135, 0.35); }
.status-list,
.rules-summary-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}
.rules-summary-box.compact { margin-top: 16px; }
.empty-state { color: var(--muted); }

.room-head .room-meta-row { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.room-actions-inline { display:flex; gap:10px; flex-wrap:wrap; }

.room-side-card {
  display: grid;
  gap: 14px;
  align-content: start;
}

.room-section {
  margin-top: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h4 {
  margin: 0;
  font-size: 16px;
}

.room-section .rules-summary-box,
.room-side-card .status-box {
  margin-top: 0;
}

.teams-root, .history-root { display:grid; gap:14px; }
.team-card, .summary-box, .history-item, .score-item { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08); border-radius: 20px; padding: 16px; }
.team-title { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; font-weight:700; }
.player-list { display:grid; gap:10px; }
.player-row { display:grid; grid-template-columns:auto 1fr auto; gap:10px; align-items:center; padding:10px; border-radius:16px; background: rgba(255,255,255,0.04); }
.player-row img { width:42px; height:42px; border-radius:14px; object-fit:cover; background: rgba(255,255,255,0.08); }
.player-meta { display:flex; flex-direction:column; gap:4px; }
.player-sub { color:var(--muted); font-size:13px; }
.player-you {
  display:inline-flex;
  align-items:center;
  margin-left:8px;
  padding:2px 8px;
  border-radius:999px;
  background: rgba(111, 168, 255, 0.16);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  vertical-align: middle;
}
.player-actions {
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.team-select-label {
  display:grid;
  gap:6px;
  min-width:158px;
  color: var(--muted);
  font-size:12px;
}
.team-select {
  min-width:0;
  padding:10px 12px;
  border-radius:12px;
}

.settings-grid { display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
.toggles-grid { display:grid; gap:4px; margin:0; }
.extra-rules-grid { display:grid; gap:4px; margin:0; }
.packs-field { grid-column: 1 / -1; }

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.packs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.packs-grid::-webkit-scrollbar {
  width: 8px;
}

.packs-grid::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
}

.pack-option {
  display:flex;
  align-items:flex-start;
  gap:10px;
  padding:12px 14px;
  border-radius:16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  min-height: 72px;
}

.difficulty-option {
  align-items: center;
}

.pack-option input {
  margin-top: 2px;
  flex: 0 0 auto;
}

.difficulty-option input {
  margin-top: 0;
}

.pack-option-text {
  display:flex;
  flex-direction:column;
  gap:4px;
  min-width: 0;
}

.pack-option-text strong {
  line-height: 1.2;
}

.pack-option-text small {
  color: var(--muted);
  line-height: 1.35;
}

.pack-option-empty { color: var(--muted); }
.game-top { display:grid; grid-template-columns:1fr 1.2fr 1fr; gap:16px; align-items:center; }
.scoreboard { display:grid; gap:10px; }
.score-value { font-size:28px; font-weight:800; }
.round-center { text-align:center; }
.round-word { font-size: clamp(30px, 5vw, 52px); font-weight:900; line-height:1.04; margin:12px 0; }
.round-subtitle { color:var(--muted); }
.turn-hint { color: var(--muted); min-height: 20px; margin-top: 10px; }
.game-room-meta { color: var(--muted); margin-top: 12px; font-size: 14px; }
.timer-box { text-align:right; }
.timer-value { font-size:58px; font-weight:900; }
.action-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap:12px; }
.action { min-height:86px; font-size:18px; font-weight:800; }
.toast {
  position:fixed;
  left:50%;
  bottom:24px;
  transform:translateX(-50%);
  background: rgba(7, 17, 31, 0.96);
  border:1px solid rgba(255,255,255,0.12);
  padding:14px 18px;
  border-radius:16px;
  box-shadow: var(--shadow);
  z-index:1000;
  max-width: min(92vw, 560px);
  cursor: pointer;
}
.toast.error { border-color: rgba(255, 107, 135, 0.35); }
@media (max-width: 920px) {
  .two-col, .settings-grid, .action-grid, .game-top { grid-template-columns: 1fr; }
  .difficulty-grid,
  .packs-grid { grid-template-columns: 1fr; }

  #homeScreen .two-col > :first-child { order: 2; }
  #homeScreen .two-col > :last-child { order: 1; }
  .banner { align-items: stretch; }
  .timer-box { text-align:left; }
  .player-row { grid-template-columns: auto 1fr; }
  .player-actions { grid-column: 1 / -1; justify-content: stretch; }
  .team-select-label { min-width: 0; width: 100%; }
}
.summary-editor {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
}

.summary-editor-note {
  font-size: 13px;
  line-height: 1.45;
  color: rgba(235, 242, 255, 0.76);
}

.summary-words-list {
  display: grid;
  gap: 10px;
}

.summary-word-row {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 10px;
  align-items: center;
}

.summary-word-label {
  min-width: 0;
  color: var(--text);
  word-break: break-word;
}

.summary-word-select {
  width: 100%;
}

@media (max-width: 720px) {
  .summary-word-row {
    grid-template-columns: 1fr;
  }
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 10, 18, 0.72);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(100%, 560px);
  max-height: min(80vh, 760px);
  overflow: auto;
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}