:root {
  color-scheme: dark;
  --felt: #0d6f45;
  --felt-dark: #06422a;
  --line: rgba(255, 255, 255, 0.18);
  --text: #f6f1df;
  --muted: #c8d4ca;
  --card: #fbf7ea;
  --ink: #151515;
  --red: #b92331;
  --accent: #ffd166;
  --turn: #70e1ff;
  --button: #17221d;
  --card-w: clamp(64px, min(6.8vw, 9vh), 92px);
  --card-h: calc(var(--card-w) * 1.4359);
  --stack-peek: calc(var(--card-w) * 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 25%, rgba(255, 255, 255, 0.08), transparent 28rem),
    linear-gradient(135deg, #07341f, #0b5d3a 55%, #072d1d);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  min-height: 2.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled:not(.card) {
  cursor: not-allowed;
  opacity: 0.45;
}

.card:disabled {
  cursor: default;
}

button.card:disabled {
  pointer-events: none;
}

.game-shell {
  width: min(1180px, calc(100vw - 24px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(min-content, 1fr) auto auto;
}

.status-bar,
.options-panel,
.match-panel,
.setup-panel,
.log-panel {
  border: 1px solid var(--line);
  background: rgba(4, 26, 17, 0.74);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

#statusText {
  margin-top: 6px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.2;
}

.human-turn-active #statusText {
  color: var(--turn);
}

.integrity-warning-active #statusText {
  color: #ff8a8a;
}

.status-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.status-actions button,
.controls button,
.setup-panel button {
  padding: 0 14px;
}

.match-panel {
  display: grid;
  grid-template-columns: minmax(180px, auto) 1fr auto;
  gap: 10px 16px;
  align-items: center;
  padding: 10px 16px;
  border-top: 0;
  color: var(--muted);
}

.options-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 180;
  display: grid;
  align-content: start;
  width: min(340px, calc(100vw - 28px));
  padding: 16px;
  gap: 14px;
  color: var(--muted);
  transform: translateX(105%);
  transition: transform 180ms ease;
  visibility: hidden;
  pointer-events: none;
  overflow-y: auto;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.options-panel.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.options-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.options-panel label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
}

.options-panel select {
  min-width: 0;
  max-width: 100%;
  min-height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081a12;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  padding: 0 8px;
}

.rules-panel {
  overflow-y: auto;
}

.training-panel {
  width: min(430px, calc(100vw - 28px));
  overflow-y: auto;
}

.training-block {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.training-block h3 {
  margin: 0;
  color: var(--accent);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.training-panel input {
  min-height: 2.2rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081a12;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  padding: 0 8px;
}

.profile-create {
  display: grid;
  grid-template-columns: 1fr 0.58fr auto;
  gap: 6px;
}

.scenario-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scenario-block p {
  color: var(--muted);
  line-height: 1.3;
}

.scenario-pile,
.scenario-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  min-height: calc(var(--card-h) * 0.72);
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.scenario-card {
  width: calc(var(--card-w) * 0.72);
  height: calc(var(--card-h) * 0.72);
}

.training-status {
  min-height: 1.2rem;
  color: var(--accent);
  font-weight: 800;
}

.rules-copy {
  display: grid;
  gap: 10px;
  line-height: 1.35;
}

.rules-copy h3 {
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.rules-copy p,
.rules-copy ul {
  margin: 0;
}

.rules-copy ul {
  display: grid;
  gap: 6px;
  padding-left: 18px;
}

.rules-copy li {
  color: var(--muted);
}

.rules-copy strong {
  color: var(--text);
}

.match-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.match-panel select {
  min-height: 2.3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081a12;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 0 10px;
}

#matchSummary {
  font-weight: 800;
  color: var(--text);
  text-align: center;
}

#starterSummary {
  text-align: right;
}

.table {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: space-between;
  gap: 8px;
  min-height: 0;
  overflow: visible;
  padding: 10px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    var(--felt);
  background-size: 34px 34px;
}

.player-zone {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
  overflow: visible;
}

.opponents-area {
  display: grid;
  grid-template-columns: repeat(var(--ai-count, 1), minmax(0, 1fr));
  gap: 10px;
  align-content: start;
  min-height: 0;
  overflow: hidden;
}

.opponent-zone {
  --op-card-scale: 0.58;
  grid-template-rows: auto auto auto;
  min-height: 0;
  min-width: 0;
  padding: 8px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.08);
  transition: border-color 160ms ease, background 160ms ease;
}

.opponent-zone.current-opponent {
  border-color: rgba(255, 209, 102, 0.52);
  background: rgba(255, 209, 102, 0.08);
}

.opponent-zone .zone-heading {
  flex-wrap: wrap;
  gap: 4px 8px;
}

.human-zone {
  grid-template-rows: auto auto auto;
  min-width: 0;
  border-radius: 8px;
  transition: box-shadow 160ms ease, background 160ms ease;
}

.human-zone.current-human-turn {
  background: rgba(112, 225, 255, 0.08);
  box-shadow: 0 0 0 2px rgba(112, 225, 255, 0.55), 0 0 30px rgba(112, 225, 255, 0.18);
}

.zone-heading {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.table-cards,
.hand-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  flex-wrap: wrap;
}

.opponent-zone .table-cards,
.opponent-zone .hand-strip {
  min-height: calc(var(--card-h) * 0.64);
  min-width: 0;
  width: 100%;
  gap: 4px;
}

.opponent-zone .card {
  width: calc(var(--card-w) * var(--op-card-scale));
  height: calc(var(--card-h) * var(--op-card-scale));
}

.opponent-zone .hand-strip {
  flex-wrap: nowrap;
  overflow: hidden;
  max-width: 100%;
  min-height: calc(var(--card-h) * var(--op-card-scale) + 8px);
}

.opponent-zone .hand-strip.has-known-cards {
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.hand-strip {
  min-height: calc(var(--card-h) * 0.72);
}

.human-zone .hand-strip {
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: safe center;
  width: 100%;
  /* Reserve selector space for every hand, not only hands with pairs. */
  min-height: calc(var(--card-h) + 50px);
  overflow-x: auto;
  padding: 40px 10px 10px;
  overscroll-behavior-x: contain;
}

.human-zone .table-cards {
  min-height: calc(var(--card-h) * 0.86);
  align-items: start;
}

.human-zone .hand-strip > .card,
.human-zone .hand-strip > .rank-group {
  flex: 0 0 auto;
  margin-left: 0;
}

.human-zone .hand-strip > :first-child {
  margin-left: 0;
}

.human-zone .hand-strip:hover {
  z-index: 20;
}

.middle-zone {
  display: grid;
  grid-template-columns: minmax(100px, 0.75fr) minmax(190px, 1.2fr) minmax(150px, 0.85fr) minmax(150px, 0.85fr);
  align-items: center;
  gap: 10px;
  min-height: 0;
}

.deck-area,
.pile-area,
.toast-slot,
.controls {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
}

.controls {
  grid-template-columns: 1fr;
  align-content: center;
}

.controls .primary-action {
  min-width: 150px;
  min-height: 3.2rem;
  border-color: rgba(255, 209, 102, 0.7);
  background: #3a2b09;
  color: #ffe29a;
  font-size: 1.05rem;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}

.deck-pile,
.play-pile,
.card {
  flex-shrink: 0;
  width: var(--card-w);
  height: var(--card-h);
}

.deck-pile,
.play-pile {
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.deck-pile {
  background:
    linear-gradient(rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.28)),
    url("assets/cards/backs/blue.svg") center / contain no-repeat;
  color: #07141f;
  font-size: 1.5rem;
  border: 0;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}

.play-pile {
  position: relative;
  border: 2px dashed rgba(255, 255, 255, 0.34);
  background: rgba(0, 0, 0, 0.12);
  overflow: visible;
  isolation: isolate;
}

.play-pile .pile-card {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: calc(var(--card-w) / -2);
  margin-top: calc(var(--card-h) / -2);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
  transform: translate(var(--pile-x, 0), var(--pile-y, 0)) rotate(var(--pile-rot, 0deg));
}

.play-pile.pile-peek {
  outline: 2px solid rgba(255, 209, 102, 0.72);
  outline-offset: 5px;
}

.play-pile.pile-peek .pile-card.peek-card {
  transform:
    translate(calc((1 - var(--peek-slot, 0)) * var(--card-w) * 0.58), calc(var(--peek-slot, 0) * -16px))
    rotate(calc((1 - var(--peek-slot, 0)) * 6deg));
}

.play-pile .pile-card.new-pile-card {
  animation: pile-land 260ms ease both;
}

.pile-card:nth-last-child(1) {
  z-index: 20;
}

.pile-depth {
  position: absolute;
  right: -10px;
  bottom: -12px;
  z-index: 30;
  min-width: 2.2rem;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(3, 14, 9, 0.86);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.burn-stage {
  position: absolute;
  inset: -28px;
  z-index: 40;
  pointer-events: none;
}

.burn-stage .burn-card {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: calc(var(--card-w) / -2);
  margin-top: calc(var(--card-h) / -2);
  animation: burn-away 950ms ease-in both;
}

.flame {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: calc(var(--card-w) * 0.95);
  height: calc(var(--card-w) * 0.95);
  transform: translateX(-50%);
  opacity: 0;
  animation: flame-burst 950ms ease-out both;
}

.flame::before,
.flame::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  border-radius: 70% 30% 70% 30%;
  transform: translateX(-50%) rotate(45deg);
}

.flame::before {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #ff3b1f, #ffb703 58%, transparent 60%);
  box-shadow: 0 0 28px rgba(255, 95, 31, 0.75);
}

.flame::after {
  width: 58%;
  height: 58%;
  background: linear-gradient(135deg, #fff0a8, #ff8c00 60%, transparent 62%);
  bottom: 10%;
}

.empty-pile {
  color: rgba(255, 255, 255, 0.54);
  font-size: 0.85rem;
  text-transform: uppercase;
}

.card {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  box-shadow: 0 7px 0 rgba(0, 0, 0, 0.2);
  overflow: visible;
  user-select: none;
}

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

button.card {
  transition: transform 130ms ease, box-shadow 130ms ease, outline-color 130ms ease;
}

button.card:hover:not(:disabled) {
  transform: translateY(-5px);
}

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

.card.ai-suggested::before {
  content: "";
  position: absolute;
  inset: -6px;
  z-index: 3;
  border: 3px solid var(--turn);
  border-radius: 12px;
  box-shadow: 0 0 18px rgba(112, 225, 255, 0.72);
  pointer-events: none;
}

.card.ai-suggested::after {
  content: "AI";
  position: absolute;
  top: -13px;
  right: -10px;
  z-index: 4;
  min-width: 24px;
  padding: 3px 5px;
  border: 2px solid #062d37;
  border-radius: 999px;
  background: var(--turn);
  color: #062d37;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

.card.deal-card {
  animation: deal-in 340ms ease both;
}

.card.illegal {
  opacity: 0.62;
}

.card.illegal:disabled {
  opacity: 0.42;
}

.card.debug-card {
  outline: 2px solid rgba(112, 225, 255, 0.45);
}

.card.known-card {
  z-index: 2;
  outline: 3px solid var(--accent);
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.58), 0 7px 0 rgba(0, 0, 0, 0.2);
}

.card.red {
  color: var(--red);
}

.card-back {
  background: transparent;
  color: transparent;
}

.table-stack {
  --table-scale: 1;
  position: relative;
  width: calc(var(--card-w) * var(--table-scale));
  height: calc((var(--card-h) + var(--stack-peek)) * var(--table-scale));
}

.table-stack.locked-stack {
  --table-scale: 0.78;
}

.table-stack.locked-stack .card {
  width: calc(var(--card-w) * var(--table-scale));
  height: calc(var(--card-h) * var(--table-scale));
}

.stack-back,
.stack-face {
  position: absolute;
  left: 0;
}

.stack-back {
  top: calc(var(--stack-peek) * var(--table-scale, 1) * 0.7);
  z-index: 0;
}

.mystery-slot {
  position: absolute;
  inset: calc(var(--card-w) * -0.06);
  border: 2px dashed rgba(255, 209, 102, 0.62);
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.13), rgba(255, 255, 255, 0.03));
  box-shadow: inset 0 0 0 1px rgba(7, 20, 14, 0.5);
  opacity: 1;
  z-index: 0;
}

.down-stack {
  height: calc(var(--card-h) * var(--table-scale));
}

.down-stack .stack-face {
  z-index: 1;
}

.stack-face {
  top: 0;
  z-index: 1;
}

.opponent-zone .table-stack {
  --table-scale: var(--op-card-scale);
}

.opponent-zone .table-stack.locked-stack {
  --table-scale: var(--op-card-scale);
}

.rank-group {
  position: relative;
  display: grid;
  align-items: end;
  justify-items: center;
  width: calc(var(--card-w) + max(0px, (var(--group-count, 2) - 1) * var(--card-w) * 0.24));
  min-width: calc(var(--card-w) * 0.72);
  height: var(--card-h);
  overflow: visible;
}

.rank-select-all {
  position: absolute;
  top: -36px;
  z-index: 12;
  min-height: 1.45rem;
  padding: 0 7px;
  border-radius: 999px;
  border-color: rgba(255, 209, 102, 0.42);
  background: rgba(7, 20, 14, 0.92);
  color: var(--accent);
  font-size: 0.72rem;
  line-height: 1;
}

.rank-select-all.selected {
  background: var(--accent);
  color: #2b2108;
}

.rank-group-cards {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: var(--card-h);
}

.rank-group-cards .card {
  position: absolute;
  left: calc(var(--group-index, 0) * var(--card-w) * 0.24);
  bottom: 0;
}

.rank-group:hover {
  z-index: 40;
}

@media (hover: hover) and (pointer: fine) {
  .rank-group .card:hover:not(:disabled),
  .human-zone .hand-strip > .card:hover:not(:disabled) {
    transform: translateY(-8px);
    z-index: 10;
  }
}

.rank-group .card.selected {
  transform: translateY(-9px);
}

.event-toast {
  position: static;
  z-index: 1;
  min-width: 180px;
  max-width: min(460px, calc(100% - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 8px;
  background: rgba(4, 18, 12, 0.92);
  color: var(--text);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 900;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.94);
}

.event-toast.show {
  animation: toast-pop 1450ms ease both;
}

.end-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(5px);
  overflow-y: auto;
}

.end-overlay[hidden] {
  display: none;
}

.end-panel {
  width: min(460px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 8px;
  background: rgba(5, 33, 21, 0.96);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
}

#endKicker {
  color: var(--accent);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#endTitle {
  margin-top: 8px;
  font-size: 2.6rem;
  line-height: 1;
}

#endBody {
  margin-top: 10px;
  color: var(--muted);
}

.end-match-mode {
  display: grid;
  gap: 8px;
  width: min(260px, 100%);
  margin: 18px auto 0;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
}

.end-match-mode select {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #081a12;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.end-match-mode[hidden] {
  display: none;
}

#endActionButton {
  margin-top: 18px;
  min-width: 190px;
  min-height: 3.2rem;
  border-color: rgba(255, 209, 102, 0.7);
  background: #3a2b09;
  color: #ffe29a;
  font-size: 1.05rem;
}

@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
  }
}

@keyframes pile-land {
  0% {
    opacity: 0.4;
    transform: translate(calc(var(--pile-x, 0) - 8px), calc(var(--pile-y, 0) - 12px)) rotate(calc(var(--pile-rot, 0deg) - 5deg)) scale(1.04);
  }
  100% {
    opacity: 1;
    transform: translate(var(--pile-x, 0), var(--pile-y, 0)) rotate(var(--pile-rot, 0deg));
  }
}

@keyframes toast-pop {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  12%,
  78% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-4%) scale(0.98);
  }
}

@keyframes burn-away {
  0% {
    opacity: 1;
    transform: translate(var(--burn-x, 0), var(--burn-y, 0)) rotate(var(--burn-rot, 0deg)) scale(1);
    filter: brightness(1);
  }
  68% {
    opacity: 0.9;
    transform: translate(calc(var(--burn-x, 0) * 0.35), calc(var(--burn-y, 0) + 22px)) rotate(calc(var(--burn-rot, 0deg) + 12deg)) scale(0.78);
    filter: sepia(0.5) saturate(1.8);
  }
  100% {
    opacity: 0;
    transform: translate(0, 56px) rotate(calc(var(--burn-rot, 0deg) + 28deg)) scale(0.36);
    filter: blur(2px) brightness(1.8);
  }
}

@keyframes flame-burst {
  0%,
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(0.7);
  }
  18%,
  72% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

.staggered-hand {
  flex-wrap: nowrap;
  min-width: 0;
  justify-content: center;
  overflow: hidden;
}

.staggered-hand .card {
  margin-left: calc(var(--card-w) * var(--op-card-scale) * -0.65);
  transform: none;
}

.staggered-hand .card:first-child {
  margin-left: 0;
}

.debug-hand.staggered-hand .card {
  margin-left: calc(var(--card-w) * var(--op-card-scale) * -0.5);
}

.debug-hand.staggered-hand .card:first-child {
  margin-left: 0;
}

.setup-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  padding: 14px 16px;
}

.setup-panel p {
  color: var(--muted);
}

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

.setup-panel.hidden {
  display: none;
}

.log-panel {
  margin-top: 12px;
  padding: 8px 16px 10px;
  border-radius: 0 0 8px 8px;
}

.log-toggle {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  text-align: left;
}

.log-toggle span:first-child {
  font-size: 0.95rem;
  font-weight: 800;
}

.log-toggle span:last-child {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.log-panel.collapsed {
  padding-bottom: 8px;
}

#gameLog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 6px 18px;
  max-height: 118px;
  margin: 10px 0 0;
  padding-left: 18px;
  overflow: auto;
  color: var(--muted);
}

#gameLog[hidden] {
  display: none;
}

@media (max-width: 760px) {
  :root {
    --card-w: clamp(50px, 13.2vw, 64px);
  }

  .game-shell {
    width: min(100vw - 12px, 1180px);
    padding: max(6px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
  }

  .status-bar,
  .match-panel,
  .options-panel,
  .setup-panel {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  #matchSummary,
  #starterSummary {
    text-align: left;
  }

  .table {
    gap: 6px;
    min-height: 0;
    padding: 8px;
  }

  .player-zone {
    gap: 6px;
    min-height: 0;
  }

  .opponents-area {
    min-height: 112px;
    gap: 4px;
  }

  .opponent-zone {
    --op-card-scale: calc(0.68 - var(--ai-count, 1) * 0.06);
    padding: 5px;
  }

  .opponent-zone .zone-heading {
    gap: 4px;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
  }

  .middle-zone {
    grid-template-columns: 1fr 1fr;
  }

  .controls {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .controls button {
    min-height: 2.35rem;
    padding: 0 8px;
    font-size: 0.9rem;
  }

  .controls .primary-action {
    grid-column: 1 / -1;
    min-width: 0;
    min-height: 2.7rem;
    width: 100%;
  }

  .controls #lockSetupButton:not([hidden]) {
    grid-column: 1 / -1;
    width: 100%;
  }

  .toast-slot {
    grid-column: 1 / -1;
    min-height: 48px;
  }

  .table-cards,
  .hand-strip {
    gap: 5px;
    min-height: 0;
  }

  .hand-strip {
    min-height: calc(var(--card-h) * 0.72);
  }

  .human-zone .hand-strip {
    padding-inline: 4px;
  }

  .human-zone .hand-strip > .card,
  .human-zone .hand-strip > .rank-group {
    margin-left: 0;
  }

  .staggered-hand .card {
    margin-left: calc(var(--card-w) * var(--op-card-scale) * -0.65);
  }

  .opponent-zone .card {
    width: calc(var(--card-w) * var(--op-card-scale));
    height: calc(var(--card-h) * var(--op-card-scale));
  }

  .event-toast {
    min-width: 0;
    width: 100%;
    max-width: none;
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .rank-select-all {
    min-height: 1.25rem;
    font-size: 0.64rem;
  }

  .status-bar { gap: 8px; padding: 8px; }
  .status-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .status-actions button { padding: 0 4px; font-size: 0.8rem; }
  #statusText { font-size: 0.88rem; }
  .match-panel { padding: 8px; gap: 6px; font-size: 0.8rem; }
  .match-panel { grid-template-columns: auto minmax(0, 1fr); }
  #starterSummary { grid-column: 1 / -1; }
  .match-panel select { min-height: 2rem; }
  .setup-panel { padding: 8px; gap: 4px; font-size: 0.85rem; }
  .log-panel { margin-top: 6px; padding: 4px 8px; }
  .opponent-zone .zone-heading { flex-wrap: wrap; }
  .opponent-zone .table-cards { gap: 2px; flex-wrap: nowrap; }
}
