:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --player-a: #3b82f6;
  --player-b: #ef4444;
  --accent: #fbbf24;
  --cell-size: min(calc(64vmin / var(--grid-size, 8)), 56px);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at top, #1e3a5f 0%, transparent 55%),
    var(--bg);
  color: var(--text);
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.header > div:first-child {
  flex: 0 0 225px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-width: 0;
}

.player-type-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.setting-control input[type='range'] {
  width: 76px;
  accent-color: var(--accent);
}

.setting-control select {
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  background: #0b1220;
  color: var(--text);
  font: inherit;
}

#tree-count-value,
#grid-size-value {
  min-width: 2.5rem;
  color: var(--text);
  font-weight: 700;
}

.header h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  background: var(--accent);
  color: #1c1917;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.05);
}

.message {
  margin-bottom: 0.75rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  background: #7f1d1d;
  color: #fecaca;
}

.end-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(15, 23, 42, 0.58);
  color: var(--text);
  font-size: clamp(1.6rem, 5vw, 3rem);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}

.end-overlay--show {
  animation: end-overlay-fade 3.6s ease forwards;
}

@keyframes end-overlay-fade {
  0%,
  72% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

.main {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.5rem;
  align-items: start;
}

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

.board-section {
  position: relative;
}

.edge-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.edge-label--top {
  text-align: center;
  margin-bottom: 0.5rem;
}

.board-wrap {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
}

.edge-label--left {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), var(--cell-size));
  grid-template-rows: repeat(var(--grid-size), var(--cell-size));
  gap: 4px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--surface-2);
  width: fit-content;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  border: 2px dashed #475569;
  border-radius: 8px;
  background: #0b1220;
  cursor: default;
}

.cell--target {
  cursor: pointer;
  border-color: var(--accent);
  background: #172554;
}

.cell--target:hover {
  background: #1d4ed8;
  border-style: solid;
}

.cell--filled {
  border-style: solid;
  border-color: transparent;
  background: transparent;
  cursor: default;
  padding: 0;
}

.cell--tree {
  background: transparent;
}

.tile {
  width: 100%;
  height: 100%;
}

.tile--selected {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

.tile-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.tree-tile-frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 2px solid #c4a574;
  background: #ffffff;
}

.tree-mask {
  position: absolute;
  inset: 8%;
  background: #5f8f2e;
  mask: url('../tree.svg') center / contain no-repeat;
  -webkit-mask: url('../tree.svg') center / contain no-repeat;
}

.tree-mask--trunk {
  background: #7a4a24;
  clip-path: inset(72% 0 0 0);
}

.sidebar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.turn-info {
  margin: 0 0 0.35rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.turn-info--player-a {
  color: #93c5fd;
}

.turn-info--player-b {
  color: #fca5a5;
}

.turn-info--winner {
  color: #86efac;
}

.turn-info--draw {
  color: #d6d3d1;
}

.deck-info {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.swatch--a {
  background: var(--player-a);
}

.swatch--b {
  background: var(--player-b);
}

.panel-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.preview {
  width: 100px;
  height: 100px;
  margin-bottom: 0.5rem;
  display: grid;
  place-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  padding: 0;
  cursor: pointer;
}

.preview:not(:has(.preview-tile)) {
  cursor: default;
}

.preview-tile {
  width: 100px;
  height: 100px;
}

.preview-placeholder {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.5rem;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 0.8em;
}

.hand {
  display: grid;
  grid-template-columns: repeat(2, 100px);
  gap: 0.75rem;
}

.hand-card {
  display: flex;
  flex-direction: column;
}

.hand-card .tile {
  width: 100px;
  height: 100px;
  cursor: pointer;
  border-radius: 8px;
}

.hand-card .tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
