:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f7f2;
  --panel: #ffffff;
  --ink: #17211c;
  --muted: #667268;
  --line: #dbe3da;
  --teal: #127c76;
  --teal-dark: #0d5e59;
  --coral: #dd574c;
  --yellow: #f2c94c;
  --cell: #fbfcf8;
  --shadow: 0 18px 55px rgba(24, 41, 32, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(18, 124, 118, 0.12), transparent 42%),
    linear-gradient(280deg, rgba(221, 87, 76, 0.11), transparent 40%),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 750;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(18, 124, 118, 0.14);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 42px);
  display: grid;
  place-items: center;
}

.panel {
  width: min(100%, 520px);
  border: 1px solid rgba(219, 227, 218, 0.95);
  border-radius: 8px;
  padding: clamp(20px, 4vw, 34px);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.masthead {
  display: grid;
  gap: 6px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 8vw, 4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.room-form,
.connection-settings {
  display: grid;
  gap: 16px;
}

.connection-settings {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.connection-settings summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.connection-settings[open] summary {
  margin-bottom: 14px;
}

.primary-action {
  width: 100%;
  padding: 0 18px;
  background: var(--teal);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(18, 124, 118, 0.22);
}

.primary-action:hover:not(:disabled) {
  background: var(--teal-dark);
}

.secondary-action,
.small-action {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.secondary-action {
  width: 100%;
  padding: 0 18px;
}

.small-action {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.message-line {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.game-view {
  display: grid;
  gap: 18px;
}

.game-view[hidden],
.lobby-view[hidden] {
  display: none;
}

.game-header,
.room-code-row,
.status-bar,
.game-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-code-row h1 {
  font-size: clamp(2rem, 8vw, 3.4rem);
}

.status-bar {
  min-height: 54px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.status-bar p {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 850;
}

#roleBadge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff5d6;
  color: #6b5014;
  font-size: 0.84rem;
  font-weight: 850;
}

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

.seat {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.seat .mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  font-size: 1.35rem;
  font-weight: 950;
}

.x-seat .mark {
  background: var(--teal);
}

.o-seat .mark {
  background: var(--coral);
}

.seat strong,
.seat small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat small {
  margin-top: 2px;
  color: var(--muted);
  font-weight: 750;
}

.board {
  width: min(100%, 420px);
  margin: 4px auto 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: clamp(8px, 2vw, 12px);
}

.cell {
  aspect-ratio: 1;
  min-height: 72px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
  color: var(--ink);
  font-size: clamp(2.4rem, 15vw, 5rem);
  font-weight: 950;
  line-height: 1;
  box-shadow: inset 0 -8px 0 rgba(23, 33, 28, 0.04);
}

.cell.x {
  color: var(--teal);
}

.cell.o {
  color: var(--coral);
}

.cell.win {
  border-color: var(--yellow);
  background: #fff8df;
}

.game-actions {
  align-items: flex-start;
}

.game-actions .primary-action {
  width: auto;
  min-width: 136px;
}

@media (max-width: 560px) {
  .app-shell {
    align-items: stretch;
  }

  .panel {
    width: 100%;
  }

  .game-header,
  .status-bar,
  .game-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .room-code-row {
    align-items: center;
  }

  .seats {
    grid-template-columns: 1fr;
  }

  .game-actions .primary-action {
    width: 100%;
  }
}
