:root {
  --wood-light: #c9a06c;
  --wood-mid: #8b6914;
  --wood-dark: #4a3419;
  --wood-shadow: rgba(45, 30, 15, 0.45);
  --ink: #1a1510;
  --paper: #f5efe4;
  --accent: #2d6a4f;
  --danger: #9b2226;
  --font: "Segoe UI", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 80% at 50% 0%, #3d2e22 0%, transparent 55%),
    linear-gradient(165deg, #2a1f18 0%, #1a1410 100%);
}

.app {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.header {
  text-align: center;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--paper);
}

.subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: rgba(245, 239, 228, 0.72);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem 1.5rem;
  margin-bottom: 0.75rem;
}

.mode-fieldset {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-width: min(100%, 14rem);
}

.mode-fieldset legend {
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(245, 239, 228, 0.8);
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.mode-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--paper);
  cursor: pointer;
}

.mode-label input {
  accent-color: var(--accent);
}

.mode-hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: rgba(245, 239, 228, 0.6);
}

.names {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.name-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(245, 239, 228, 0.85);
}

.name-field input {
  width: 11rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--paper);
  font-size: 0.9375rem;
}

.name-field input::placeholder {
  color: rgba(245, 239, 228, 0.4);
}

.name-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.12);
  color: var(--paper);
}

.btn.primary {
  background: var(--accent);
  border-color: #1b4332;
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 2px;
}

.status {
  text-align: center;
  min-height: 1.5rem;
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--paper);
}

.status.winner {
  color: #95d5b2;
}

.status.draw {
  color: #e9c46a;
}

.layer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.layer-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(245, 239, 228, 0.75);
}

.layer-indicator {
  min-width: 4.5rem;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--paper);
}

.layer-btn {
  padding: 0.35rem 0.65rem;
  min-width: 2.25rem;
}

.view-hint {
  width: 100%;
  flex-basis: 100%;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.35;
  color: rgba(245, 239, 228, 0.55);
  max-width: 28rem;
  margin: 0 auto;
}

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.board-frame {
  border-radius: 8px;
  border: 4px solid var(--wood-dark);
  box-shadow:
    0 12px 28px var(--wood-shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  line-height: 0;
  background: var(--wood-dark);
}

#board {
  display: block;
  width: min(90vw, min(90vh - 12rem, 32rem));
  height: min(90vw, min(90vh - 12rem, 32rem));
  max-width: 100%;
  cursor: pointer;
  touch-action: none;
  vertical-align: middle;
}

#board.is-idle {
  cursor: default;
}

#board.is-grab {
  cursor: grab;
}

#board.is-grabbing {
  cursor: grabbing;
}

#board:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 4px;
}

.stats {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  color: var(--paper);
}

.stats h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.stats-sub {
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(245, 239, 228, 0.75);
}

.stats-current table,
.stats-leaderboard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stats-current th,
.stats-current td,
.stats-leaderboard th,
.stats-leaderboard td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stats-current th,
.stats-leaderboard th {
  color: rgba(245, 239, 228, 0.65);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-empty {
  font-size: 0.875rem;
  color: rgba(245, 239, 228, 0.55);
}

@media (max-width: 480px) {
  .name-field input {
    width: 100%;
  }
}
