:root {
  color-scheme: dark;
  --felt: #17513f;
  --felt-deep: #0e342c;
  --felt-light: #276a55;
  --wood: #6f4026;
  --gold: #e9bd66;
  --paper: #f6efe1;
  --ink: #1f1b16;
  --text: #f8f1e7;
  --muted: #d6c3a3;
  --danger: #d8514d;
  --ok: #62c891;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(233, 189, 102, 0.2), transparent 30%),
    linear-gradient(135deg, #311e18, #142d29 52%, #0a1715);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

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

.table-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar,
.online-panel,
.hand-panel,
.rules {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 23, 21, 0.76);
  box-shadow: var(--shadow);
}

.online-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(180px, 0.6fr);
  gap: 14px;
  padding: 14px 22px;
  border-top: 0;
}

.online-panel[hidden] {
  display: none;
}

.online-room {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.online-state {
  display: grid;
  align-content: center;
  gap: 4px;
  color: var(--muted);
}

.online-state strong {
  color: var(--gold);
  font-size: 18px;
}

.online-players {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
}

.online-player {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
}

.online-player.connected {
  color: var(--text);
  border-color: rgba(98, 200, 145, 0.45);
}

.your-turn .topbar,
.your-turn .online-panel {
  box-shadow:
    0 0 0 2px rgba(233, 189, 102, 0.65),
    var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 8px 8px 0 0;
  padding: 18px 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

#status,
#hint,
.rules li,
label {
  color: var(--muted);
}

#status {
  margin-top: 6px;
  min-height: 24px;
}

.controls,
.hand-actions,
.turn-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  text-transform: uppercase;
}

input,
select {
  min-width: 130px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #14231f;
  color: var(--text);
  padding: 9px 10px;
}

input[type="number"] {
  width: 92px;
  min-width: 92px;
}

input[type="checkbox"] {
  min-width: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--gold);
}

.check-control {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 40px;
  text-transform: none;
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  grid-template-rows: minmax(86px, auto) 144px minmax(88px, auto);
  gap: 14px;
  min-height: 396px;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    radial-gradient(circle at center, var(--felt-light), var(--felt) 48%, var(--felt-deep));
  background-size:
    58px 58px,
    58px 58px,
    auto;
  border-left: 12px solid var(--wood);
  border-right: 12px solid var(--wood);
}

.board > .opponents,
.board > .center-table,
.board > .player {
  grid-column: 1;
}

.scoreboard {
  grid-column: 2;
  grid-row: 1 / -1;
  align-self: start;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(10, 23, 21, 0.72);
  padding: 12px;
}

.scoreboard h2 {
  margin-bottom: 10px;
}

.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.scoreboard th,
.scoreboard td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  text-align: left;
}

.scoreboard th:last-child,
.scoreboard td:last-child {
  text-align: right;
}

.scoreboard .is-positive td:last-child {
  color: var(--ok);
  font-weight: 800;
}

.scoreboard .is-negative td:last-child {
  color: #ffd1cd;
  font-weight: 800;
}

#scoreboardSummary {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.player-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--paper);
  font-size: 15px;
}

.player-title strong {
  color: var(--gold);
}

.opponents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.opponent {
  min-height: 136px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.1);
}

.opponent-hand {
  display: flex;
  align-items: center;
  min-height: 38px;
  margin-bottom: 8px;
}

.mini-card {
  width: 26px;
  height: 36px;
  margin-right: -12px;
  border-radius: 4px;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.22);
}

.mini-card.back {
  border: 1px solid rgba(233, 189, 102, 0.85);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%),
    #253f73;
  background-size: 10px 10px;
}

.hand-count {
  margin-left: 18px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.meld-row,
.hand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 112px;
}

.meld {
  display: flex;
  gap: 4px;
  align-items: center;
  min-height: 110px;
  padding: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
}

.center-table {
  display: grid;
  grid-template-columns: 88px 88px 1fr;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: min(620px, 100%);
  margin: 0 auto;
}

.pile {
  position: relative;
  width: 82px;
  height: 114px;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
}

.stock {
  display: grid;
  place-items: center;
  border: 3px solid rgba(233, 189, 102, 0.85);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%),
    #253f73;
  background-size: 18px 18px;
  color: var(--paper);
  font-size: 32px;
  font-weight: 800;
}

.discard img,
.card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.traditional-card {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(31, 27, 22, 0.28);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 45%, rgba(0, 0, 0, 0.04), transparent 38%),
    #fbf7ee;
  color: #151515;
  font-family: Georgia, "Times New Roman", serif;
  overflow: hidden;
}

.traditional-card.red {
  color: #bf2230;
}

.suit-mark {
  font-size: 38px;
  line-height: 1;
}

.corner {
  position: absolute;
  display: grid;
  justify-items: center;
  font-size: 16px;
  font-weight: 800;
  line-height: 0.95;
}

.corner b {
  font-size: 14px;
  line-height: 1;
}

.corner.top {
  top: 6px;
  left: 7px;
}

.corner.bottom {
  right: 7px;
  bottom: 6px;
  transform: rotate(180deg);
}

.turn-actions {
  align-content: center;
}

.hand-panel {
  border-radius: 0 0 8px 8px;
  padding: 14px 22px 18px;
}

.hand-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.card {
  width: 66px;
  height: 104px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.32);
}

.card.selected {
  outline: 4px solid var(--gold);
  transform: translateY(-12px);
}

.card.borrowable {
  box-shadow:
    0 0 0 2px rgba(98, 200, 145, 0.9),
    0 10px 22px rgba(0, 0, 0, 0.32);
}

.card.pending {
  box-shadow:
    0 0 0 4px var(--ok),
    0 12px 24px rgba(0, 0, 0, 0.36);
}

.card.back {
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%),
    #76322d;
  background-size: 16px 16px;
}

.rules {
  margin-top: 18px;
  border-radius: 8px;
  padding: 18px 22px;
}

.rules ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 20px;
}

.is-error {
  color: #ffd1cd !important;
}

.is-ok {
  color: #d4ffe6 !important;
}

@media (max-width: 820px) {
  .table-shell {
    width: min(100vw - 16px, 720px);
    padding-top: 8px;
  }

  .topbar,
  .hand-header {
    align-items: stretch;
    flex-direction: column;
  }

  .board {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 14px;
    border-left-width: 6px;
    border-right-width: 6px;
    grid-template-rows: auto 300px auto;
  }

  .board > .opponents,
  .board > .center-table,
  .board > .player,
  .scoreboard {
    grid-column: 1;
  }

  .scoreboard {
    grid-row: auto;
  }

  .center-table {
    grid-template-columns: 92px 92px;
    justify-content: start;
  }

  .turn-actions {
    grid-column: 1 / -1;
    align-self: start;
  }

  .turn-actions button {
    width: 148px;
  }

  .pile {
    width: 86px;
    height: 120px;
  }

  .card {
    width: 64px;
    height: 100px;
  }
}
