:root {
  --ink: #18212f;
  --muted: #637083;
  --paper: #f7f4ed;
  --panel: #ffffff;
  --line: #d9dfdc;
  --teal: #087f8c;
  --teal-dark: #075f69;
  --coral: #e45b4f;
  --amber: #f2b84b;
  --mint: #b9e6d3;
  --shadow: 0 18px 50px rgba(24, 33, 47, .12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(8, 127, 140, .10), transparent 34%),
    linear-gradient(315deg, rgba(228, 91, 79, .10), transparent 34%),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.lobby-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  align-items: center;
  gap: 28px;
  padding: 32px 0;
}

.brand-panel,
.lobby-panel,
.side-panel > *,
.score-box,
.waiting-panel {
  background: rgba(255, 255, 255, .88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-panel {
  min-height: 520px;
  padding: 38px;
  display: grid;
  align-content: space-between;
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.8rem, 8vw, 6.4rem);
  line-height: .92;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.15rem;
}

.lead {
  max-width: 520px;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.55;
}

.letter-cloud {
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, 1fr));
  gap: 12px;
}

.letter-cloud span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: clamp(1.8rem, 5vw, 4rem);
  font-weight: 800;
}

.letter-cloud span:nth-child(3n) {
  background: var(--teal);
}

.letter-cloud span:nth-child(4n) {
  background: var(--coral);
}

.lobby-panel {
  padding: 26px;
  display: grid;
  gap: 18px;
}

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

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

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, .15);
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 18px;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  font-weight: 800;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: var(--ink);
  color: #fff;
}

.compact {
  min-height: 40px;
  padding: 0 14px;
}

.error-line {
  min-height: 20px;
  margin: 0;
  color: var(--coral);
  font-weight: 700;
}

.game-shell {
  width: min(1320px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0;
}

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

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.status-pill,
.timer-pill {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 12px;
  background: #e8ecea;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 800;
}

.timer-pill {
  background: var(--ink);
  color: #fff;
  min-width: 78px;
}

.status-pill.online {
  background: var(--mint);
  color: #145542;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.score-box {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  box-shadow: none;
}

.score-box span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.score-box strong {
  font-size: 1.35rem;
}

.score-box small {
  color: var(--muted);
  font-weight: 800;
}

.score-box.self {
  border-left: 6px solid var(--teal);
}

.score-box.opponent {
  border-left: 6px solid var(--coral);
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.board-wrap {
  position: relative;
  min-width: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 12), 1fr);
  gap: clamp(3px, .6vw, 7px);
  width: min(100%, 78vh);
  margin: 0 auto;
  padding: clamp(8px, 1.2vw, 14px);
  border-radius: 8px;
  background: #263241;
  box-shadow: var(--shadow);
  touch-action: none;
}

.board.dimmed {
  opacity: .28;
}

.cell {
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: #fffdf7;
  color: var(--ink);
  font-size: clamp(.9rem, 2.4vw, 1.8rem);
  font-weight: 900;
  display: grid;
  place-items: center;
  user-select: none;
  box-shadow: inset 0 -3px 0 rgba(24, 33, 47, .12);
}

.cell.selected {
  background: var(--amber);
  color: #2c2107;
  transform: translateY(-1px);
}

.cell.found-self {
  background: #b9e6d3;
  color: #123d32;
}

.cell.found-opponent {
  background: #ffd0cb;
  color: #66221b;
}

.cell.found-shared {
  background: #c7d8ff;
  color: #1f3566;
}

.cell.selected,
.cell.found-self.selected,
.cell.found-opponent.selected,
.cell.found-shared.selected {
  background: var(--amber);
  color: #2c2107;
}

.waiting-panel {
  position: absolute;
  inset: 10% 50% auto auto;
  transform: translateX(50%);
  z-index: 2;
  width: min(430px, calc(100% - 28px));
  padding: 22px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.side-panel {
  display: grid;
  gap: 12px;
}

.side-panel > * {
  padding: 16px;
  box-shadow: none;
}

.match-panel p {
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.settings-list {
  margin: 10px 0 0;
  display: grid;
  gap: 7px;
}

.settings-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 7px;
}

.settings-list dt,
.settings-list dd {
  margin: 0;
}

.settings-list dt {
  color: var(--muted);
  font-weight: 700;
}

.settings-list dd {
  font-weight: 900;
  text-align: right;
}

.selection-text {
  min-height: 26px;
  color: var(--ink) !important;
  font-size: 1.25rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.emote-panel {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.emote-panel button {
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.25rem;
}

.chat-panel {
  min-height: 320px;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.words-panel {
  display: grid;
  gap: 8px;
}

.word-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.word-list li {
  padding: 7px 9px;
  border-radius: 8px;
  background: #f0f3f1;
  font-weight: 800;
}

.word-list li.hidden-word {
  color: var(--muted);
  letter-spacing: 0;
}

.word-list li.revealed {
  background: rgba(8, 127, 140, .12);
  color: var(--teal-dark);
}

.word-list li.extra {
  background: rgba(242, 184, 75, .24);
  color: #6d4800;
}

.chat-messages {
  height: 230px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.chat-line {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f0f3f1;
  overflow-wrap: anywhere;
}

.chat-line.own {
  background: rgba(8, 127, 140, .12);
}

.chat-line strong {
  font-size: .82rem;
  color: var(--muted);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 12px;
}

.toast-layer {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.toast.good {
  background: var(--teal);
}

.toast.extra {
  background: #7a4e00;
}

.toast.bad {
  background: var(--coral);
}

.emote-burst {
  position: fixed;
  left: 50%;
  top: 48%;
  z-index: 11;
  font-size: clamp(4rem, 12vw, 8rem);
  transform: translate(-50%, -50%);
  animation: burst 1.1s ease forwards;
  pointer-events: none;
}

@keyframes burst {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.4); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1.25); }
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(24, 33, 47, .72);
  padding: 18px;
}

.result-overlay > div {
  width: min(430px, 100%);
  border-radius: 8px;
  background: #fff;
  padding: 26px;
  text-align: center;
  box-shadow: var(--shadow);
}

.result-overlay h2 {
  font-size: 2rem;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 920px) {
  .lobby-shell,
  .play-layout {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: auto;
    gap: 26px;
  }

  .board {
    width: min(100%, 92vh);
  }
}

@media (max-width: 620px) {
  .lobby-shell {
    width: min(100% - 20px, 1120px);
  }

  .brand-panel,
  .lobby-panel {
    padding: 18px;
  }

  .join-row,
  .settings-grid,
  .score-strip,
  .score-box,
  .chat-form,
  .result-actions {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .emote-panel {
    grid-template-columns: repeat(3, 1fr);
  }

  .cell {
    border-radius: 4px;
  }
}
