:root {
  --table-dark: #081d17;
  --table-green: #0d3f31;
  --panel-bg: #10291f;
  --panel-alt: #153528;
  --light-text: #f9f2d7;
  --muted-text: #c9bea0;
  --accent: #f4c75b;
  --accent-dark: #b88928;
  --playable-border: #84ef9b;
  --selected-border: #ffd76e;
  --paper: #f4efde;
  --shadow: rgba(0, 0, 0, .78);
  --mono: Menlo, Monaco, Consolas, monospace;
  --ui: 'Trebuchet MS', 'Segoe UI', sans-serif;
  --card-w: 90px;
  --card-h: 126px;
  --lift-top: 12px;
  --lift-bottom: 8px;
  --card-shell-h: calc(var(--card-h) + var(--lift-top) + var(--lift-bottom));
  --card-gap: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--table-dark);
  color: var(--light-text);
  font-family: var(--ui);
  overflow: hidden;
}

.page {
  height: 100dvh;
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
  flex: 0 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1;
  font-weight: 800;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted-text);
  font-size: 12px;
}

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

.top-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-text);
  font-size: 12px;
}

select, button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  outline: none;
}

select {
  background: var(--accent);
  color: #101010;
  padding: 7px 12px;
  font-weight: 700;
}

button {
  background: var(--accent);
  color: #101010;
  padding: 8px 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background .16s ease, transform .16s ease, opacity .16s ease, box-shadow .16s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:focus-visible { box-shadow: 0 0 0 2px rgba(244, 199, 91, .25); }
button:disabled {
  background: #cec5b5;
  color: #6b6b6b;
  cursor: default;
  transform: none;
  box-shadow: none;
}
button.danger { background: #d96b6b; }
button.secondary { background: #91a090; }
button.danger:hover:not(:disabled) { background: #c85e5e; }
button.secondary:hover:not(:disabled) { background: #7f8d7e; }

.meta, .panel {
  border: 2px solid var(--accent-dark);
  border-radius: 18px;
}

.meta {
  background: var(--panel-alt);
  color: var(--muted-text);
  padding: 8px 14px;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
  font-size: 12px;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
}

.panel {
  background: var(--panel-bg);
  min-height: 0;
}

.table-panel {
  background: var(--table-green);
  padding: 10px 16px 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  padding: 12px 12px 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  min-height: 0;
}

.sidebar h2, .table-panel h2 {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.05;
  text-align: center;
}

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

.opponent-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 104px;
}

.card-row {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--card-gap);
  flex-wrap: nowrap;
}

#opponent-hand.card-row,
#human-hand.card-row { min-height: var(--card-shell-h); }
#human-hand.card-row { padding-bottom: 16px; }

.table-center {
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr) 188px;
  align-items: stretch;
  min-height: 0;
  padding-top: 2px;
}

.table-center::after {
  content: '';
  display: block;
  grid-column: 3;
}

.deck-stack {
  grid-column: 1;
  align-self: center;
  justify-self: start;
  width: 176px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
}

.deck-title {
  color: var(--muted-text);
  font-weight: 800;
  letter-spacing: .08em;
  font-size: 11px;
}

.deck-cards {
  position: relative;
  width: 150px;
  height: 174px;
}

.deck-cards .card-shell {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.deck-cards .offset-a { left: 20px; top: 18px; }
.deck-cards .offset-b { left: 28px; top: 10px; }
.deck-cards .offset-c { left: 36px; top: 2px; }

.deck-count {
  min-width: 110px;
  text-align: center;
  padding: 7px 14px;
  border: 2px solid var(--accent-dark);
  border-radius: 12px;
  background: rgba(21, 53, 40, .42);
  font-weight: 800;
}

.status-center {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 8px;
}

.status-chip {
  background: rgba(20, 59, 46, .42);
  padding: 12px 24px 14px;
  min-width: 322px;
  text-align: center;
}

#status {
  font-size: 23px;
  font-weight: 800;
  line-height: 1.15;
}

#turn, #wins {
  font-size: 12px;
  line-height: 1.45;
}

.last-move {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  min-height: 24px;
}

.table-row {
  width: 100%;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.table-row.empty-state {
  color: var(--muted-text);
  font-style: italic;
}

.table-type {
  color: var(--accent);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .04em;
  text-align: center;
}

.table-play-row { min-height: var(--card-shell-h); }

.result {
  min-height: 24px;
  color: var(--accent);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.center-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.selection {
  min-height: 20px;
  text-align: center;
  margin-top: 4px;
}

.human-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 2px;
}

.hint {
  margin: 0;
  font-size: 11px;
}

.moves {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.move {
  background: var(--paper);
  color: #1b1b1b;
  border-radius: 10px;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.move:hover { background: #f8f3e7; }
.move.selected { outline: 2px solid #2d5643; }
.move.disabled { cursor: default; color: #555; }
.move.pass { font-weight: 800; }

.log-wrap {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.log {
  margin: 8px 0 0;
  background: var(--paper);
  color: #1b1b1b;
  border-radius: 16px;
  padding: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre-wrap;
}

.card-shell {
  position: relative;
  width: var(--card-w);
  height: var(--card-shell-h);
  flex: 0 0 auto;
  user-select: none;
}

.card-body,
.card-shadow {
  position: absolute;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
}

.card-body {
  top: var(--lift-top);
  transform: translateY(0);
  transition: transform .14s ease, filter .14s ease;
}

.card-glow,
.card-plate {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
}

.card-glow {
  border-radius: 13px;
  opacity: 0;
  transition: opacity .14s ease, box-shadow .14s ease;
}

.card-shadow {
  top: calc(var(--lift-top) + 8px);
  transform: translateX(4px);
  background: var(--shadow);
  clip-path: polygon(12% 0%, 88% 0%, 100% 10%, 100% 90%, 88% 100%, 12% 100%, 0% 90%, 0% 10%);
  filter: saturate(.7);
}


.card-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.card-shell.playable:not(.selected) .card-glow {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--playable-border), 0 0 14px rgba(132, 239, 155, .16);
}

.card-shell.selected .card-glow {
  opacity: 1;
  box-shadow: 0 0 0 4px var(--selected-border), 0 0 15px rgba(255, 215, 110, .18);
}

.card-shell.clickable:hover .card-body { transform: translateY(-7px); }
.card-shell.selected .card-body { transform: translateY(-6px); }
.card-shell.clickable.selected:hover .card-body { transform: translateY(-8px); }

.card-shell.clickable:hover .card-shadow { transform: translateX(4px) translateY(-2px); }
.card-shell.selected .card-shadow { transform: translateX(4px) translateY(-2px); }

.card-shell.back .card-shadow { opacity: .78; }

.error { color: #ffb6b6; }
code { font-family: var(--mono); }

@media (max-width: 1400px) {
  .layout { grid-template-columns: minmax(0, 1fr) 286px; }
  .status-chip { min-width: 308px; }
}