:root {
  color-scheme: light;
  --felt: #1f5f4a;
  --felt-dark: #184635;
  --ink: #1d2528;
  --muted: #667277;
  --paper: #f8faf8;
  --line: #d9dfda;
  --accent: #b73d32;
  --gold: #d1a441;
  --blue: #356b9a;
  --shadow: 0 12px 30px rgba(18, 31, 25, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
}

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

button.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
}

button.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.85rem;
}

button.active {
  background: var(--accent);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.25rem, 6vw, 5.25rem);
  line-height: 0.95;
}

h2 {
  font-size: 1rem;
}

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

.lobby-shell {
  display: grid;
  gap: 28px;
  padding: 40px 0;
}

.lobby-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 32px;
  align-items: end;
  min-height: 48vh;
  padding: 42px;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(13, 42, 31, 0.92), rgba(27, 95, 74, 0.62)),
    url("../img/table-texture.svg");
  background-size: cover;
}

.lede {
  max-width: 640px;
  margin-top: 16px;
  font-size: 1.15rem;
  color: rgba(255,255,255,0.82);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.lobby-actions,
.join-section,
.list-section {
  display: grid;
  gap: 16px;
}

.lobby-actions {
  padding: 18px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
}

.lobby-actions input {
  border-color: transparent;
}

.section-header,
.inline-form {
  display: flex;
  gap: 12px;
  align-items: end;
  justify-content: space-between;
}

.section-header.compact {
  align-items: center;
}

.section-status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.inline-form label {
  flex: 1;
}

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

.game-list-item,
.empty-state,
.join-section {
  padding: 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.game-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.game-list-item span,
.game-list-item p {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.error-text,
.notice.error {
  color: #9a211b;
}

.game-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 24px;
  padding: 22px;
  color: #fff;
  background: var(--felt-dark);
}

.brand-link {
  color: #fff;
  font-size: 1.25rem;
  font-weight: 800;
  text-decoration: none;
}

.connection {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  color: #d7f2e7;
  background: rgba(255,255,255,0.12);
}

.side-panel h2 {
  margin-bottom: 10px;
  color: #d7f2e7;
}

.host-controls {
  display: grid;
  gap: 10px;
}

.host-status {
  color: #d7f2e7;
  font-size: 0.88rem;
}

.host-inline {
  align-items: center;
}

.players,
.event-log {
  display: grid;
  gap: 8px;
}

.player-row,
.log-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
}

.player-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.player-row.self {
  outline: 2px solid var(--gold);
}

.player-row span,
.log-row {
  color: rgba(255,255,255,0.72);
  font-size: 0.85rem;
}

.table-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf3ee, #f8faf8);
}

.table-header {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.table-header h1 {
  font-size: 1.8rem;
}

.turn-pill {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.turn-pill.my-turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(209, 164, 65, 0.22);
}

.notice {
  margin: 14px 22px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.waiting-room {
  padding: 22px;
}

.waiting-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  max-width: 720px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.waiting-summary h2 {
  margin-bottom: 6px;
  font-size: 1.2rem;
}

.waiting-summary p {
  color: var(--muted);
}

.waiting-count {
  display: grid;
  place-items: center;
  min-width: 62px;
  min-height: 62px;
  border-radius: 999px;
  color: #fff;
  background: var(--felt);
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.territories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-content: start;
  padding: 22px;
  overflow: auto;
}

.territory {
  min-height: 174px;
  padding: 14px;
  border: 1px solid rgba(31, 95, 74, 0.24);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.territory.target-valid {
  border-color: var(--felt);
  box-shadow: 0 0 0 3px rgba(31, 95, 74, 0.16), var(--shadow);
}

.territory.target-invalid {
  opacity: 0.62;
}

.territory.drag-over {
  transform: translateY(-2px);
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(209, 164, 65, 0.24), var(--shadow);
}

.territory:focus-visible,
.house-card:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(53, 107, 154, 0.35);
  outline-offset: 2px;
}

.territory-head {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.territory-head span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: #fff;
  background: var(--felt);
  font-weight: 800;
}

.territory p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.territory .target-hint {
  color: var(--felt-dark);
  font-weight: 700;
}

.effects {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  margin-top: 10px;
}

.effects span,
.card-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--felt-dark);
  background: #e8f1ec;
  font-size: 0.78rem;
}

.stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.abilities .card-chip {
  color: #68470d;
  background: #fff3cf;
}

.hand-panel {
  display: grid;
  gap: 12px;
  padding: 16px 22px 22px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.92);
}

.hand-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

#mode-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-card-panel {
  min-height: 58px;
}

.selection-summary {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.selection-summary span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.hand-row,
.keep-row {
  display: flex;
  gap: 10px;
  min-height: 78px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.house-card {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  flex: 0 0 132px;
  min-height: 172px;
  padding: 12px;
  color: var(--ink);
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: pan-y;
}

.house-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(183, 61, 50, 0.18);
}

.house-card.playable {
  cursor: grab;
}

.house-card.dragging-source {
  opacity: 0.45;
}

.house-card span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

.house-card small {
  color: var(--muted);
}

.keep-card,
.keep-empty {
  display: grid;
  place-items: center;
  flex: 0 0 150px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf4;
}

.keep-card.pending {
  border-color: var(--gold);
}

.keep-card.selected-source {
  border-color: var(--felt);
  box-shadow: 0 0 0 3px rgba(31, 95, 74, 0.16);
}

.drag-card-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 150px;
  min-height: 70px;
  padding: 12px;
  pointer-events: none;
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.drag-card-ghost span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

.scoreboard {
  padding: 0 22px 22px;
}

.scoreboard h2 {
  margin-bottom: 12px;
  font-size: 1.4rem;
}

.score-grid {
  display: grid;
  gap: 10px;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.score-row small {
  grid-column: 1 / -1;
  color: var(--muted);
}

dialog {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

@media (max-width: 900px) {
  .lobby-band,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .lobby-band {
    min-height: 42vh;
    padding: 28px;
  }

  .game-layout {
    min-height: 100vh;
  }

  .side-panel {
    position: static;
    grid-template-columns: 1fr;
  }

  .table-panel {
    min-height: auto;
  }

  .table-header,
  .hand-toolbar,
  .section-header,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

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

  .waiting-summary {
    grid-template-columns: 1fr;
  }

  .hand-panel {
    position: sticky;
    bottom: 0;
    z-index: 5;
    max-height: 58vh;
    overflow: auto;
  }

  .selection-summary {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
