:root {
  --bg: #efe3cf;
  --bg-top: #fbf5ec;
  --panel: rgba(255, 250, 242, 0.94);
  --ink: #171411;
  --muted: #6d655a;
  --line: rgba(23, 20, 17, 0.1);
  --accent: #e86635;
  --green: #16695e;
  --soft: #f5d687;
  --shadow: 0 16px 40px rgba(58, 35, 17, 0.12);
  --glow-accent: rgba(232, 102, 53, 0.2);
  --glow-green: rgba(22, 105, 94, 0.16);
  --field-bg: rgba(255, 255, 255, 0.85);
  --card-solid: #fff;
  --texture: url("/img/white.webp");
}

body[data-theme="dark"] {
  --bg: #171b21;
  --bg-top: #232831;
  --panel: rgba(30, 35, 43, 0.92);
  --ink: #f5efe6;
  --muted: #b9b1a6;
  --line: rgba(245, 239, 230, 0.12);
  --accent: #ff8a4c;
  --green: #2d9f90;
  --soft: #5a4830;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  --glow-accent: rgba(255, 138, 76, 0.16);
  --glow-green: rgba(45, 159, 144, 0.18);
  --field-bg: rgba(18, 22, 29, 0.9);
  --card-solid: rgba(21, 26, 33, 0.96);
  --texture: url("/img/black.webp");
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    var(--texture) 0 0 / 420px 420px repeat,
    radial-gradient(circle at top left, var(--glow-accent), transparent 28%),
    radial-gradient(circle at bottom right, var(--glow-green), transparent 28%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
  transition: background 0.22s ease, color 0.22s ease;
}

.app-shell {
  width: min(1280px, calc(100% - 24px));
  margin: 0 auto;
  padding: 72px 0 24px;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.theme-toggle span:first-child {
  font-size: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.auth-view,
.panel--inner,
.panel--sidebar,
.panel--game,
.topbar {
  padding: 16px;
}

.compact-hero,
.room-line,
.team-tile__head,
.game-header,
.feed__head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  display: grid;
  gap: 10px;
  padding: 18px 22px;
}

.topbar__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
}

.topbar__identity {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  align-self: center;
}

.eyebrow,
.panel__kicker {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Rubik Mono One", monospace;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  line-height: 0.95;
}

.auth-hero-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 620px;
}

.hero-note,
.topbar__subtitle,
.auth-status,
.word-card__hint,
.score-row__meta,
.team-tile__members,
.status-pill {
  color: var(--muted);
}

.auth-grid,
.compact-layout,
.team-lobby,
.scoreboard,
.event-log,
.stack-sm,
.mini-grid,
.inline-field,
.controls,
.status-strip,
.panel--sidebar,
.panel--game {
  display: grid;
  gap: 10px;
}

.auth-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel--inner {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel--inner button {
  justify-self: start;
  min-width: 148px;
}

.compact-layout {
  grid-template-columns: 340px 1fr;
  margin-top: 14px;
  align-items: start;
}

.room-line {
  justify-content: flex-start;
  flex-wrap: nowrap;
  row-gap: 10px;
  column-gap: 10px;
}

#room-code {
  margin: 0;
  display: inline-flex;
  align-items: center;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 18px;
  background: var(--card-solid);
  border: 1px solid rgba(23, 20, 17, 0.08);
  box-shadow: inset 0 -1px 0 rgba(23, 20, 17, 0.04);
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.03em;
  width: fit-content;
}

.topbar__subtitle {
  font-size: 0.95rem;
  line-height: 1.35;
  max-width: 56ch;
  margin: 0;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(23, 20, 17, 0.12);
  background: var(--field-bg);
  color: var(--ink);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
  text-align: center;
  line-height: 1;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #ff8c56);
  color: #fff;
}

.accent-button {
  background: var(--green);
  color: #fff;
}

.ghost-button,
.text-button,
.ghost-link {
  background: rgba(23, 20, 17, 0.06);
  color: var(--ink);
}

.icon-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(23, 20, 17, 0.08);
  border-radius: 14px;
  background: rgba(23, 20, 17, 0.06);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(23, 20, 17, 0.04);
  font-size: 1.1rem;
  font-weight: 800;
  overflow: hidden;
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.icon-chip svg {
  width: 20px;
  height: 20px;
  transition: transform 0.18s ease;
}

.icon-chip::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  opacity: 0;
  transform: scale(0.55);
}

.icon-chip--success {
  background: var(--green);
  border-color: rgba(22, 105, 94, 0.72);
  color: #fff;
  box-shadow:
    0 0 0 6px rgba(22, 105, 94, 0.14),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  animation: icon-chip-pop 0.42s ease;
}

.icon-chip--success svg {
  animation: icon-chip-hide 1.2s ease forwards;
}

.icon-chip--success::after {
  animation: icon-chip-check 1.2s ease forwards;
}

@keyframes icon-chip-pop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes icon-chip-hide {
  0%,
  18% {
    opacity: 1;
    transform: scale(1);
  }

  30%,
  100% {
    opacity: 0;
    transform: scale(0.7);
  }
}

@keyframes icon-chip-check {
  0%,
  20% {
    opacity: 0;
    transform: scale(0.55);
  }

  35%,
  82% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.78);
  }
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  white-space: nowrap;
  padding: 0 16px;
  border-radius: 14px;
  text-decoration: none;
  font-weight: 800;
}

.auth-status:empty {
  display: none;
}

.ghost-button--sm {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 0.95rem;
}

.text-button {
  padding: 8px 0 0;
  text-align: left;
}

#leave-room {
  min-height: 44px;
  padding-inline: 20px;
  border-radius: 16px;
  white-space: nowrap;
}

#leave-room {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(23, 20, 17, 0.04);
}

.team-tile,
.score-row,
.status-strip article,
.feed,
.word-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.team-tile,
.feed,
.status-strip article,
.word-card,
.words-panel {
  padding: 12px;
}

.team-tile__title,
.score-row__name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.team-tile__head {
  align-items: center;
}

.team-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(23, 20, 17, 0.1);
  background: rgba(23, 20, 17, 0.06);
  font-size: 1.1rem;
  flex: 0 0 auto;
}

button.team-icon {
  cursor: pointer;
}

.team-icon--static {
  width: 32px;
  height: 32px;
  font-size: 1rem;
}

.team-name-input {
  min-width: 0;
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(23, 20, 17, 0.12);
  background: rgba(255, 255, 255, 0.9);
  font: inherit;
  font-weight: 800;
  color: var(--ink);
}

.team-tile__members {
  margin-top: -2px;
  line-height: 1.45;
  min-height: 24px;
}

.team-member--self {
  font-weight: 800;
  color: var(--ink);
}

.team-join {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(23, 20, 17, 0.1);
  background: rgba(23, 20, 17, 0.06);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
  flex: 0 0 auto;
}

.team-join--leave {
  background: rgba(195, 64, 52, 0.12);
  border-color: rgba(195, 64, 52, 0.16);
  color: #8c3028;
}

.mini-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-field {
  grid-template-columns: 1fr auto;
}

.timer {
  min-width: 108px;
  padding: 10px 12px;
  border-radius: 16px;
  text-align: center;
  background: rgba(23, 20, 17, 0.94);
  color: #fff;
  font-family: "Rubik Mono One", monospace;
  font-size: 1rem;
}

.word-card {
  min-height: 180px;
  align-content: center;
  justify-items: center;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 241, 222, 0.86)),
    linear-gradient(135deg, rgba(232, 102, 53, 0.08), rgba(22, 105, 94, 0.08));
}

.word-card__topline {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 800;
  text-align: center;
}

.word-card__team {
  color: var(--ink);
  font-size: 1.5rem;
}

.word-card__player {
  color: var(--muted);
  font-size: 1rem;
}

.word-card__word {
  text-align: center;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 800;
}

.word-card__hint {
  text-align: center;
}

#current-word[data-private="true"] {
  letter-spacing: 0.08em;
  color: var(--muted);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.controls > button {
  width: min(240px, 100%);
}

.event-log {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
}

.event-log li,
.score-row {
  padding: 10px 12px;
}

.event-log__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.event-log__item--correct {
  background: rgba(22, 105, 94, 0.14);
  border-color: rgba(22, 105, 94, 0.28);
}

.event-log__item--skip {
  background: rgba(195, 64, 52, 0.12);
  border-color: rgba(195, 64, 52, 0.24);
}

.event-log__item--challenged {
  box-shadow: inset 0 0 0 2px rgba(237, 133, 32, 0.95);
  border-color: rgba(237, 133, 32, 0.9);
}

.event-log__word {
  font-weight: 800;
}

.event-log__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-log__status {
  font-size: 0.9rem;
  color: var(--muted);
}

.event-log__button {
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(23, 20, 17, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.winner-banner {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(245, 214, 135, 0.3);
  border: 1px solid rgba(245, 214, 135, 0.6);
  font-weight: 800;
}

.words-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.words-panel__status {
  color: var(--muted);
  line-height: 1.35;
}

.words-panel__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

#open-words-packs {
  grid-column: 1 / -1;
}

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

.packs-list__item {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid rgba(23, 20, 17, 0.1);
  border-radius: 16px;
  background: rgba(23, 20, 17, 0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.packs-list__item--active {
  background: rgba(22, 105, 94, 0.14);
  border-color: rgba(22, 105, 94, 0.28);
  color: var(--green);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 20, 17, 0.34);
  backdrop-filter: blur(3px);
}

.modal__card {
  position: relative;
  width: min(760px, 100%);
  max-height: min(85vh, 920px);
  padding: 20px;
  border-radius: 22px;
  border: 1px solid rgba(23, 20, 17, 0.1);
  background: rgba(255, 250, 242, 0.98);
  box-shadow: 0 24px 60px rgba(23, 20, 17, 0.2);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal__body {
  display: grid;
  gap: 10px;
  max-height: calc(85vh - 110px);
  overflow-y: auto;
  padding-right: 4px;
}

.modal__body p {
  line-height: 1.45;
}

.help-intro {
  display: grid;
  gap: 8px;
}

.help-section {
  border: 1px solid rgba(23, 20, 17, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  overflow: hidden;
}

.help-section summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  font-weight: 800;
}

.help-section summary::-webkit-details-marker {
  display: none;
}

.help-section summary::after {
  content: "+";
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(23, 20, 17, 0.08);
  font-size: 18px;
  line-height: 1;
}

.help-section[open] summary::after {
  content: "−";
}

.help-section__content {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
}

.help-rule {
  display: grid;
  gap: 6px;
}

.help-rule strong {
  font-size: 15px;
}

.help-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 8px;
}

body[data-theme="dark"] #room-code,
body[data-theme="dark"] .team-tile,
body[data-theme="dark"] .score-row,
body[data-theme="dark"] .status-strip article,
body[data-theme="dark"] .feed,
body[data-theme="dark"] .words-panel,
body[data-theme="dark"] .packs-list__item,
body[data-theme="dark"] .modal__card,
body[data-theme="dark"] .help-section {
  background: rgba(34, 40, 49, 0.92);
  border-color: rgba(245, 239, 230, 0.1);
  box-shadow: none;
}

body[data-theme="dark"] .word-card {
  background:
    linear-gradient(135deg, rgba(34, 40, 49, 0.98), rgba(28, 33, 41, 0.96)),
    linear-gradient(135deg, rgba(255, 138, 76, 0.06), rgba(45, 159, 144, 0.08));
  border-color: rgba(245, 239, 230, 0.1);
}

body[data-theme="dark"] .word-card__team,
body[data-theme="dark"] .word-card__word,
body[data-theme="dark"] .feed__head strong,
body[data-theme="dark"] .team-tile__title,
body[data-theme="dark"] .score-row__name,
body[data-theme="dark"] .winner-banner,
body[data-theme="dark"] .modal__head h3,
body[data-theme="dark"] .help-rule strong {
  color: #f5efe6;
}

body[data-theme="dark"] .word-card__player,
body[data-theme="dark"] .word-card__hint,
body[data-theme="dark"] .event-log__status,
body[data-theme="dark"] .words-panel__status,
body[data-theme="dark"] .team-tile__members,
body[data-theme="dark"] .score-row__meta,
body[data-theme="dark"] .topbar__subtitle,
body[data-theme="dark"] .hero-note,
body[data-theme="dark"] .auth-status,
body[data-theme="dark"] .modal__body p,
body[data-theme="dark"] .help-list {
  color: #b9b1a6;
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] .team-name-input {
  background: rgba(19, 24, 31, 0.96);
  border-color: rgba(245, 239, 230, 0.12);
  color: #f5efe6;
}

body[data-theme="dark"] .ghost-button,
body[data-theme="dark"] .text-button,
body[data-theme="dark"] .ghost-link,
body[data-theme="dark"] .icon-chip,
body[data-theme="dark"] .team-icon,
body[data-theme="dark"] .team-join,
body[data-theme="dark"] .event-log__button,
body[data-theme="dark"] .packs-list__item {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(245, 239, 230, 0.1);
  color: #f5efe6;
  box-shadow: none;
}

body[data-theme="dark"] .theme-toggle {
  background: rgba(30, 35, 43, 0.96);
  border-color: rgba(245, 239, 230, 0.12);
}

body[data-theme="dark"] .timer {
  background: #11151b;
  color: #fff3e7;
}

body[data-theme="dark"] .event-log__item {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(245, 239, 230, 0.1);
}

body[data-theme="dark"] .event-log__item--correct {
  background: rgba(45, 159, 144, 0.18);
  border-color: rgba(45, 159, 144, 0.34);
}

body[data-theme="dark"] .event-log__item--skip {
  background: rgba(195, 64, 52, 0.18);
  border-color: rgba(195, 64, 52, 0.3);
}

body[data-theme="dark"] .winner-banner {
  background: rgba(255, 190, 92, 0.14);
  border-color: rgba(255, 190, 92, 0.34);
}

body[data-theme="dark"] .team-join--leave {
  background: rgba(195, 64, 52, 0.18);
  border-color: rgba(195, 64, 52, 0.3);
  color: #ffd7d1;
}

body[data-theme="dark"] #current-word[data-private="true"] {
  color: #8f9aa6;
}

@media (max-width: 920px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    padding: 10px 14px;
  }

  .auth-grid,
  .compact-layout,
  .controls,
  .mini-grid,
  .compact-hero,
  .topbar__row,
  .topbar__actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .room-line {
    flex-wrap: wrap;
  }

  .topbar__identity {
    display: grid;
    gap: 10px;
  }

  .auth-hero-actions {
    justify-content: flex-start;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar__actions {
    justify-content: stretch;
    align-self: stretch;
  }

  #compact-status,
  #leave-room {
    width: 100%;
    justify-content: center;
  }
}
