:root {
  color-scheme: light;
  --felt: #276048;
  --felt-deep: #1d4738;
  --felt-line: rgba(255, 255, 255, 0.28);
  --paper: #fffaf0;
  --ink: #1a1d20;
  --muted: #677078;
  --rail: #e5dccd;
  --rail-dark: #bda988;
  --hearts: #ba2f3f;
  --spades: #20242a;
  --gold: #d2a84d;
  --sky: #4e89a8;
  --danger: #d55345;
  --ok: #4d8b5f;
  --shadow: 0 18px 50px rgba(26, 29, 32, 0.18);
  --cell-size: clamp(44px, 5.1vw, 72px);
  --gap: clamp(4px, 0.5vw, 8px);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(39, 96, 72, 0.16), rgba(210, 168, 77, 0.08)),
    #f3efe6;
}

button {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 20px;
  width: min(1480px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.game,
.panel {
  border: 1px solid rgba(26, 29, 32, 0.12);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
}

.game {
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(26, 29, 32, 0.1);
  background: rgba(255, 250, 240, 0.72);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 2.6vw, 2.7rem);
  line-height: 1;
}

h2 {
  margin-bottom: 12px;
  font-size: 0.9rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(26, 29, 32, 0.18);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdfa;
  cursor: pointer;
}

.icon-button:hover:not(:disabled),
.icon-button:focus-visible:not(:disabled) {
  border-color: rgba(26, 29, 32, 0.35);
  background: #fff7e7;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.icon-button span {
  font-size: 1.45rem;
  line-height: 1;
}

.status-strip {
  display: flex;
  min-height: 78px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 18px;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(26, 29, 32, 0.1);
}

.status-strip strong {
  display: block;
  margin-top: 5px;
  font-size: 1.05rem;
}

.status-strip p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.turn-badge.hearts {
  background: var(--hearts);
}

.turn-badge.spades {
  background: var(--spades);
}

.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, var(--cell-size)));
  grid-template-rows: repeat(3, minmax(0, calc(var(--cell-size) * 1.28)));
  gap: var(--gap);
  justify-content: center;
  overflow: auto;
  min-height: 0;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(32, 36, 42, 0.14), rgba(32, 36, 42, 0) 28%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent calc(var(--cell-size) + var(--gap))
    ),
    var(--felt);
}

.cell {
  position: relative;
  display: grid;
  min-width: var(--cell-size);
  min-height: calc(var(--cell-size) * 1.28);
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
}

.cell.home-top {
  background: rgba(32, 36, 42, 0.18);
}

.cell.neutral {
  border-color: rgba(255, 255, 255, 0.42);
  background:
    linear-gradient(135deg, rgba(210, 168, 77, 0.18), rgba(78, 137, 168, 0.13)),
    rgba(255, 255, 255, 0.08);
}

.cell.home-bottom {
  background: rgba(186, 47, 63, 0.14);
}

.cell.action-move {
  outline: 3px solid rgba(78, 137, 168, 0.95);
  outline-offset: -3px;
}

.cell.action-capture,
.cell.action-siege {
  outline: 3px solid rgba(213, 83, 69, 0.96);
  outline-offset: -3px;
}

.cell.action-evacuate {
  outline: 3px solid rgba(77, 139, 95, 0.96);
  outline-offset: -3px;
}

.cell.clickable {
  cursor: pointer;
}

.cell.setup-cell:hover,
.cell.setup-cell:focus-visible {
  outline: 3px solid rgba(210, 168, 77, 0.95);
  outline-offset: -3px;
}

.cell.setup-selected-piece {
  box-shadow: inset 0 0 0 3px rgba(78, 137, 168, 0.95);
}

.cell-label {
  position: absolute;
  top: 4px;
  left: 5px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.58rem;
  font-weight: 800;
}

.card {
  position: relative;
  display: grid;
  width: calc(var(--cell-size) * 0.84);
  height: calc(var(--cell-size) * 1.08);
  grid-template-rows: auto 1fr auto;
  padding: 5px;
  border: 1px solid rgba(26, 29, 32, 0.25);
  border-radius: 7px;
  color: var(--ink);
  background:
    linear-gradient(145deg, #fffdfa, #efe6d5);
  box-shadow: 0 5px 12px rgba(26, 29, 32, 0.18);
  user-select: none;
}

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

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

.card.selected {
  border-color: var(--gold);
  box-shadow:
    0 0 0 3px rgba(210, 168, 77, 0.48),
    0 9px 18px rgba(26, 29, 32, 0.2);
}

.card.dimmed {
  opacity: 0.48;
}

.card .rank {
  font-size: clamp(0.78rem, 1.35vw, 1.06rem);
  font-weight: 900;
  line-height: 1;
}

.card .suit {
  display: grid;
  place-items: center;
  font-size: clamp(1.2rem, 2.3vw, 2.2rem);
  line-height: 1;
}

.card .class {
  overflow: hidden;
  color: rgba(26, 29, 32, 0.62);
  font-size: clamp(0.48rem, 0.62vw, 0.58rem);
  font-weight: 800;
  letter-spacing: 0;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.stack-count {
  position: absolute;
  right: -6px;
  bottom: -6px;
  display: grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #fffdfa;
  border-radius: 999px;
  color: #fff;
  background: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
}

.ascended-tag {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #fffdfa;
  border-radius: 999px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(26, 29, 32, 0.18);
}

.ascended-tag.hearts {
  background: var(--hearts);
}

.ascended-tag.spades {
  background: var(--spades);
}

.gap-card {
  width: calc(var(--cell-size) * 0.82);
  height: calc(var(--cell-size) * 1.05);
  border: 1px dashed rgba(255, 255, 255, 0.42);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%) 0 0 / 10px 10px,
    rgba(255, 255, 255, 0.09);
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 8px;
}

.panel-section {
  padding: 18px;
  border-bottom: 1px solid rgba(26, 29, 32, 0.1);
}

.panel-section:last-child {
  border-bottom: 0;
}

.rulebook {
  color: var(--ink);
}

.rulebook summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.rulebook summary::-webkit-details-marker {
  display: none;
}

.rulebook summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-weight: 900;
}

.rulebook[open] summary::after {
  content: "-";
}

.rulebook-body {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.rulebook-body section {
  display: grid;
  gap: 7px;
}

.rulebook h3 {
  margin: 0;
  color: var(--felt-deep);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.rulebook p,
.rulebook ul {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.42;
}

.rulebook ul {
  display: grid;
  gap: 5px;
  padding-left: 18px;
}

.rulebook-table {
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(26, 29, 32, 0.12);
  border-radius: 8px;
  background: #fffdfa;
}

.rulebook-table > div {
  display: grid;
  grid-template-columns: minmax(88px, 0.72fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(26, 29, 32, 0.08);
}

.rulebook-table > div:last-child {
  border-bottom: 0;
}

.rulebook-table strong {
  font-size: 0.78rem;
}

.rulebook-table span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.engine-section {
  display: grid;
  grid-template-columns: auto minmax(420px, 1fr) minmax(160px, 210px) minmax(220px, 1fr);
  align-items: center;
  gap: 10px 12px;
}

.engine-dock {
  border-bottom: 1px solid rgba(26, 29, 32, 0.1);
  background: rgba(255, 250, 240, 0.58);
}

.engine-section h2 {
  margin-bottom: 0;
}

.engine-players {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 10px;
}

.engine-players label {
  display: grid;
  gap: 5px;
}

.engine-players span,
.engine-toggle {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.engine-players select,
.engine-players input {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(26, 29, 32, 0.16);
  border-radius: 8px;
  padding: 0 9px;
  color: var(--ink);
  background: #fffdfa;
}

.engine-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
}

.engine-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--felt);
}

.engine-button {
  min-height: 42px;
  border: 1px solid rgba(26, 29, 32, 0.16);
  border-radius: 8px;
  color: #fff;
  background: var(--felt-deep);
  cursor: pointer;
  font-weight: 850;
}

.engine-button:hover:not(:disabled),
.engine-button:focus-visible:not(:disabled) {
  background: var(--felt);
}

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

.engine-button.secondary {
  min-height: 36px;
  color: var(--ink);
  background: #fffdfa;
  font-size: 0.78rem;
}

.engine-button.secondary:hover:not(:disabled),
.engine-button.secondary:focus-visible:not(:disabled) {
  background: #fff7e7;
}

.engine-button.danger {
  color: #fff;
  background: var(--danger);
}

.engine-button.danger:hover:not(:disabled),
.engine-button.danger:focus-visible:not(:disabled) {
  background: #b94439;
}

.engine-memory-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 8px;
  min-width: 0;
}

.memory-text-panel {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
}

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

.memory-text-panel textarea {
  width: 100%;
  min-height: 180px;
  border: 1px solid rgba(26, 29, 32, 0.18);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: #fffdfa;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.35;
  resize: vertical;
}

.memory-text-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.engine-info {
  min-height: 34px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

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

.setup-controls label {
  display: grid;
  gap: 5px;
}

.setup-controls span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.setup-controls select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(26, 29, 32, 0.16);
  border-radius: 8px;
  padding: 0 9px;
  color: var(--ink);
  background: #fffdfa;
}

.setup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.setup-button {
  min-height: 38px;
  border: 1px solid rgba(26, 29, 32, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdfa;
  cursor: pointer;
  font-weight: 850;
}

.setup-button.primary {
  color: #fff;
  background: var(--sky);
}

.setup-button:hover:not(:disabled),
.setup-button:focus-visible:not(:disabled) {
  border-color: rgba(26, 29, 32, 0.35);
  background: #fff7e7;
}

.setup-button.primary:hover:not(:disabled),
.setup-button.primary:focus-visible:not(:disabled) {
  background: #3f7895;
}

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

.selected-card {
  min-height: 72px;
  padding: 12px;
  border: 1px solid rgba(26, 29, 32, 0.12);
  border-radius: 8px;
  background: #fffdfa;
}

.selected-card.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.selected-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-weight: 900;
}

.selected-meta {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.action-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid rgba(26, 29, 32, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdfa;
  cursor: pointer;
  text-align: left;
}

.action-button:hover,
.action-button:focus-visible {
  border-color: rgba(26, 29, 32, 0.34);
  background: #fff7e7;
}

.action-button span:first-child {
  font-weight: 800;
}

.action-button span:last-child {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.82rem;
}

.captured {
  display: grid;
  gap: 14px;
}

.mini-label {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 900;
}

.hearts-text {
  color: var(--hearts);
}

.spades-text {
  color: var(--spades);
}

.captured-row {
  display: flex;
  min-height: 32px;
  flex-wrap: wrap;
  gap: 5px;
}

.captured-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  border: 1px solid rgba(26, 29, 32, 0.14);
  border-radius: 6px;
  background: #fffdfa;
  font-size: 0.8rem;
  font-weight: 900;
}

.log-section {
  min-height: 0;
  flex: 1;
}

.move-log {
  display: flex;
  max-height: min(360px, 42vh);
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  margin: 0;
  padding-left: 24px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.move-log li::marker {
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 1040px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .engine-section {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .engine-players {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .engine-memory-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .panel {
    min-height: 0;
  }

  .panel-section {
    padding: 15px;
  }
}

@media (max-width: 720px) {
  :root {
    --cell-size: 43px;
    --gap: 4px;
  }

  .shell {
    width: 100vw;
    min-height: 100vh;
    margin: 0;
  }

  .game,
  .panel {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .topbar,
  .status-strip {
    padding-right: 14px;
    padding-left: 14px;
  }

  .board {
    justify-content: start;
    padding: 14px;
  }

  .engine-players {
    grid-template-columns: 1fr;
  }

  .engine-memory-actions {
    grid-template-columns: 1fr;
  }
}
