:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --surface: #f1eadc;
  --panel: #fffaf0;
  --panel-2: #ffffff;
  --panel-3: #f4ead8;
  --line: #d2c6b3;
  --line-soft: #e8decd;
  --text: #211f1a;
  --muted: #746f66;
  --gold: #9b6a12;
  --gold-soft: rgba(191, 141, 49, 0.22);
  --green: #3c8b54;
  --red: #b24e43;
  --blue: #3f76a8;
  --ink: #211f1a;
  --card: #f0d391;
  --focus: #b47a16;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 8%, rgba(237, 197, 118, 0.38), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff7e8;
  color: var(--text);
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: #f7ead5;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

button.primary {
  border-color: #b9872e;
  background: #b67b1a;
  color: #ffffff;
}

button.primary:hover {
  background: #9f6812;
}

button.ghost {
  background: transparent;
}

#startButton:not(:disabled) {
  border-color: #4f9a61;
  background: #78c36f;
  color: #ffffff;
}

#startButton:not(:disabled):hover {
  background: #68b962;
}

#newGameButton,
#lobbyNewGameButton {
  border-color: #b98d86;
  background: transparent;
  color: #6e2f2a;
}

#newGameButton:hover,
#lobbyNewGameButton:hover {
  background: #dfc0b9;
}

#newGameButton.confirm-reset,
#lobbyNewGameButton.confirm-reset {
  border-color: #9f2e28;
  background: #c84038;
  color: #ffffff;
}

#newGameButton.confirm-reset:hover,
#lobbyNewGameButton.confirm-reset:hover {
  background: #b7342e;
}

input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
}

input[readonly] {
  color: var(--muted);
  background: #f7f0e2;
}

label {
  display: block;
  margin: 10px 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  font-size: 21px;
}

h2 {
  font-size: 14px;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.94);
  backdrop-filter: blur(8px);
}

.brand {
  display: grid;
  gap: 4px;
  min-width: 0;
}

#status,
.muted {
  color: var(--muted);
  font-size: 12px;
}

#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status:empty {
  display: none;
}

.layout {
  height: calc(100vh - 68px);
  overflow: hidden;
}

.lobby {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-title button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.join-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(74, 54, 24, 0.14);
}

.join-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.join-title h2 {
  font-size: 22px;
}

.join-title span {
  color: var(--gold);
  font-size: 13px;
  white-space: nowrap;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 9px;
}

.join-card input,
.join-card button {
  min-height: 44px;
}

.lobby-reset {
  margin-top: 14px;
}

.join-card p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.prejoin-players {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
}

.prejoin-players strong {
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
}

.prejoin-player,
.prejoin-empty {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 9px;
  background: var(--panel-2);
  color: var(--text);
}

.prejoin-player {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.prejoin-empty {
  color: var(--muted);
}

.role-avatar {
  width: 42px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid #d0c3ae;
  background: #f7efe1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  color: #6c6154;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
}

.role-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.role-avatar.unknown {
  background: #eee5d7;
}

.player-info,
.player-body {
  min-width: 0;
}

.player-info strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wide {
  grid-column: 1 / -1;
}

.hidden {
  display: none !important;
}

.table {
  height: 100%;
  display: grid;
  grid-template-columns: 292px minmax(420px, 1fr) 324px;
  background: var(--surface);
}

.side,
.hand-panel {
  overflow: auto;
  padding: 10px;
  background: #eee4d3;
}

.side {
  border-right: 1px solid var(--line);
}

.hand-panel {
  border-left: 1px solid var(--line);
}

.compact {
  margin-bottom: 10px;
}

.room-head {
  display: flex;
  align-items: start;
}

.room-actions,
.table-buttons {
  display: flex;
  gap: 7px;
}

#roomLink {
  margin: 10px 0 8px;
  font-size: 12px;
}

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

.room-list {
  display: grid;
  gap: 8px;
}

.room-row,
.player,
.empty-state,
.selected-card,
.selected-empty {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 10px;
}

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

.room-summary {
  min-width: 0;
}

.room-summary strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-badge {
  border: 1px solid #bed0bb;
  border-radius: 999px;
  padding: 4px 8px;
  color: #345b3d;
  background: #e9f3e6;
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

.player {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin-bottom: 8px;
  cursor: default;
}

.player.me {
  border-color: #b9872e;
}

.player.active::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 4px;
  border-radius: 7px 0 0 7px;
  background: var(--gold);
}

.player.targetable {
  cursor: pointer;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

.player strong {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.badge {
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  background: #ece2d1;
  color: var(--text);
}

.badge.good {
  background: #dcefdc;
  color: #255b32;
}

.badge.bad {
  background: #f2d7d2;
  color: #88352e;
}

.badge.gold {
  background: #f3dfac;
  color: #76520d;
}

.board-wrap {
  min-width: 0;
  overflow: auto;
  background: #e5dac7;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.board-wrap.dragging {
  cursor: grabbing;
}

.table-info {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.94);
  backdrop-filter: blur(5px);
}

#turnInfo {
  font-weight: 700;
}

#actionPrompt {
  max-width: 720px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.table-stats {
  display: grid;
  gap: 3px;
  min-width: 82px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

#phaseInfo {
  color: var(--gold);
  font-weight: 700;
}

.board {
  position: relative;
  width: 1520px;
  height: 2394px;
  margin: 18px;
  background:
    linear-gradient(rgba(122, 93, 52, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122, 93, 52, 0.1) 1px, transparent 1px),
    #f6eedf;
  background-size: 80px 126px;
  box-shadow: inset 0 0 0 1px #dacbb4;
}

.cell {
  position: absolute;
  width: 72px;
  height: 117px;
  margin: 6px 4px;
  border: 1px solid transparent;
  border-radius: 7px;
}

.cell.available {
  border-color: rgba(180, 122, 22, 0.42);
}

.cell.targetable {
  cursor: pointer;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft), 0 0 16px rgba(214, 163, 63, 0.18);
}

.cell.targetable::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px dashed rgba(126, 89, 35, 0.38);
  border-radius: 5px;
  pointer-events: none;
}

.cell.occupied.targetable::after {
  inset: -4px;
  border-color: var(--focus);
}

.card {
  position: relative;
  width: 72px;
  height: 117px;
  border-radius: 7px;
  border: 1px solid #564b36;
  background: var(--card);
  color: var(--ink);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px;
  font-size: 12px;
  line-height: 1.15;
  user-select: none;
  box-shadow: 0 2px 0 rgba(99, 73, 35, 0.16);
}

.card strong {
  overflow-wrap: anywhere;
}

.card span {
  color: #4f3a19;
  font-size: 11px;
  font-weight: 700;
}

.card.has-image {
  padding: 0;
  overflow: hidden;
  background: #fffaf0;
}

.card.has-image .card-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  pointer-events: none;
}

.card.has-image strong,
.card.has-image span {
  display: none;
}

.card.path {
  background-color: #d8bd84;
}

.card.action {
  background-color: #b9c7d8;
  border-color: #4d647a;
}

.card.goal {
  background-color: #c9aa66;
}

.card.back {
  background-color: #8c7048;
  color: #fffaf0;
}

.card.back span {
  color: var(--muted);
}

.card.selected {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.card.marked-discard {
  box-shadow: 0 0 0 3px rgba(168, 64, 64, 0.38);
}

.discard-mark {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(95, 56, 30, 0.28);
  background: rgba(255, 250, 240, 0.92);
  color: #7a4630;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow: 0 2px 6px rgba(67, 43, 24, 0.16);
}

.discard-mark:hover {
  background: #f3d7d7;
  color: #8f2f2f;
}

.card.marked-discard .discard-mark {
  background: #a64040;
  border-color: #a64040;
  color: #fff;
}

.card.rotated,
.card.pending-rotate {
  transform: rotate(180deg);
}

.hand {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 10px;
  margin-top: 10px;
}

.hand .card {
  cursor: pointer;
}

.hand .card:hover {
  outline: 2px solid rgba(180, 122, 22, 0.5);
  outline-offset: 2px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

#role {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
  min-height: 238px;
  text-align: center;
}

.role-copy {
  min-width: 0;
}

.role-copy span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.role-copy strong {
  display: block;
  margin-top: 3px;
  color: var(--gold);
  font-size: 16px;
}

.role-mini-card {
  flex: 0 0 auto;
  width: 144px;
  height: 234px;
  display: grid;
  place-items: center;
  border: 1px solid #d0c3ae;
  border-radius: 6px;
  background: #f7efe1;
  color: #6c6154;
  font-size: 54px;
  font-weight: 700;
  overflow: hidden;
}

.role-mini-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.role-mini-card.unknown {
  background: #eee5d7;
}

#hint {
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

#selectedDetails {
  margin: 8px 0 10px;
}

.selected-card {
  display: grid;
  gap: 4px;
  border-color: #dfc58f;
  background: #fff7e8;
}

.selected-card span,
.selected-empty {
  color: var(--muted);
  font-size: 12px;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.status-actions button {
  min-height: 28px;
  padding: 0 9px;
  border-color: #d4b879;
  background: #fffaf0;
  color: #715022;
  font-size: 12px;
}

.status-actions button:hover {
  background: #f4e4bd;
}

.log-panel,
.chat-panel {
  max-height: 360px;
}

#log,
#chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#log {
  max-height: 220px;
  overflow: auto;
}

#chat {
  max-height: 180px;
  overflow: auto;
  margin-bottom: 8px;
}

#chat strong {
  color: var(--text);
}

@media (max-width: 1120px) {
  .table {
    grid-template-columns: 246px minmax(330px, 1fr);
  }

  .hand-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .hand {
    grid-template-columns: repeat(6, 72px);
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 68px;
    padding: 10px;
  }

  .layout {
    height: calc(100vh - 68px);
  }

  .lobby {
    padding: 10px;
  }

  .table {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .side,
  .hand-panel,
  .board-wrap {
    overflow: visible;
  }

  .side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .board-wrap {
    min-height: 440px;
    overflow: auto;
  }

  .table-info {
    min-width: 560px;
  }

  .hand {
    grid-template-columns: repeat(4, 72px);
  }
}
