:root {
  color-scheme: light;
  --paper: rgba(255, 250, 242, 0.86);
  --ink: #1f2b3d;
  --ink-soft: #5d6a7e;
  --line: rgba(31, 43, 61, 0.12);
  --red: #d84b59;
  --red-soft: rgba(216, 75, 89, 0.18);
  --blue: #2f67d8;
  --blue-soft: rgba(47, 103, 216, 0.18);
  --green: #27a56b;
  --green-soft: rgba(39, 165, 107, 0.18);
  --gold: #d8a32f;
  --gold-soft: rgba(216, 163, 47, 0.18);
  --empty: rgba(255, 255, 255, 0.76);
  --empty-border: rgba(31, 43, 61, 0.16);
  --panel-shadow: 0 18px 48px rgba(31, 43, 61, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Instrument Sans", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(216, 75, 89, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(47, 103, 216, 0.16), transparent 36%),
    linear-gradient(180deg, #f5efe5 0%, #efe7d9 100%);
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.14) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.65), transparent 85%);
}

#root {
  position: relative;
  z-index: 1;
}

.dotdot-noscript,
.dotdot-error {
  margin: 24px;
  padding: 16px 18px;
  border-radius: 20px;
  background: #fff1f1;
  color: #8c2f39;
  box-shadow: var(--panel-shadow);
}

.app-shell {
  width: min(1120px, calc(100vw - 24px));
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    0
    max(24px, env(safe-area-inset-bottom));
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(2.1rem, 5vw, 3rem);
  line-height: 1;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(31, 43, 61, 0.08);
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.page-link:hover {
  background: rgba(31, 43, 61, 0.12);
}

.game-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.panel {
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 28px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
}

.controls-panel,
.board-panel {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 20px;
}

.controls-header {
  margin-bottom: 16px;
}

.controls-header h1 {
  margin: 4px 0 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 2rem;
  line-height: 1;
}

.status-label {
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.board-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.status-value {
  margin-top: 4px;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.05;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  background: rgba(31, 43, 61, 0.08);
}

.status-pill.toggle {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.status-pill.toggle:hover {
  background: rgba(31, 43, 61, 0.12);
}

.status-pill.red {
  background: var(--red-soft);
  color: #972d38;
}

.status-pill.blue {
  background: var(--blue-soft);
  color: #1f4ca5;
}

.status-pill.green {
  background: var(--green-soft);
  color: #1f7d53;
}

.status-pill.gold {
  background: var(--gold-soft);
  color: #8a6718;
}

.status-pill.muted {
  color: var(--ink-soft);
}

.board-frame {
  margin: 0 auto;
  width: min(100%, 760px);
  border-radius: 30px;
  background: rgba(31, 43, 61, 0.06);
  padding: 12px;
}

.board-grid {
  display: grid;
  gap: 8px;
}

.board-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--empty-border);
  border-radius: 24px;
  background: var(--empty);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 8px 18px rgba(31, 43, 61, 0.06);
}

.board-cell:hover {
  transform: translateY(-1px);
}

.board-cell:active {
  transform: translateY(1px) scale(0.985);
}

.board-cell:focus-visible {
  outline: 3px solid rgba(31, 43, 61, 0.22);
  outline-offset: 2px;
}

.board-cell.owner-empty {
  border-style: dashed;
}

.board-cell.owner-red {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    var(--red-soft);
  border-color: rgba(216, 75, 89, 0.3);
}

.board-cell.owner-blue {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    var(--blue-soft);
  border-color: rgba(47, 103, 216, 0.3);
}

.board-cell.owner-green {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    var(--green-soft);
  border-color: rgba(39, 165, 107, 0.32);
}

.board-cell.owner-gold {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    var(--gold-soft);
  border-color: rgba(216, 163, 47, 0.32);
}

.board-cell.is-legal {
  box-shadow:
    inset 0 0 0 2px rgba(31, 43, 61, 0.12),
    0 0 0 4px rgba(31, 43, 61, 0.08),
    0 12px 24px rgba(31, 43, 61, 0.12);
}

.dot-cluster {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(36px, 62%, 60px);
  height: clamp(36px, 62%, 60px);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.dot-pip {
  position: absolute;
  width: clamp(6px, 0.9vw, 10px);
  height: clamp(6px, 0.9vw, 10px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 2px 8px rgba(31, 43, 61, 0.16);
  transform: translate(-50%, -50%);
}

.dot-overflow {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 18px;
  min-height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 43, 61, 0.78);
  color: rgba(255, 255, 255, 0.98);
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 4px rgba(31, 43, 61, 0.3);
}

.notice-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(216, 75, 89, 0.12);
  color: #8c2f39;
  line-height: 1.45;
}

.scoreboard-panel {
  margin-top: 18px;
}

.scoreboard-header {
  margin-bottom: 12px;
}

.scoreboard-list {
  display: grid;
  gap: 10px;
}

.scoreboard-title {
  margin-top: 4px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.9rem;
  line-height: 1;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 22px;
  padding: 14px 16px;
}

.score-red {
  background: var(--red-soft);
}

.score-blue {
  background: var(--blue-soft);
}

.score-green {
  background: var(--green-soft);
}

.score-gold {
  background: var(--gold-soft);
}

.score-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.score-row-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-row-label strong {
  font-size: 1rem;
}

.score-row-label span {
  color: var(--ink-soft);
}

.score-row-stats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.score-stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink-soft);
}

.score-stat strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.history-panel {
  margin-top: 18px;
}

.history-header {
  margin-bottom: 12px;
}

.history-title {
  margin-top: 4px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.9rem;
  line-height: 1;
}

.history-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 10px;
}

.history-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.history-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.history-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.56);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.history-entry:disabled {
  cursor: default;
}

.history-entry.active {
  border-color: rgba(31, 43, 61, 0.24);
  background: rgba(31, 43, 61, 0.08);
}

.history-entry-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-entry-text strong {
  font-size: 0.98rem;
}

.history-entry-text span {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.history-entry-current {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.color-dot.red {
  background: var(--red);
}

.color-dot.blue {
  background: var(--blue);
}

.color-dot.green {
  background: var(--green);
}

.color-dot.gold {
  background: var(--gold);
}

.control-group {
  margin-top: 16px;
}

.control-group.stacked {
  display: grid;
  gap: 10px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 700;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.range-row input[type="range"] {
  width: 100%;
}

.range-row span {
  min-width: 56px;
  font-weight: 700;
  text-align: right;
}

.select-control {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  font: inherit;
}

.select-control:disabled {
  opacity: 0.55;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
}

.toggle-row span {
  line-height: 1.35;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.player-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
}

.player-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.95rem;
  font-weight: 700;
}

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

.player-row-controls.with-difficulty {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.player-row-controls.single-control {
  grid-template-columns: 1fr;
}

.player-row-summary {
  color: var(--ink-soft);
  font-weight: 700;
}

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

.setup-summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
}

.setup-summary-item span {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}

.setup-summary-item strong {
  font-size: 1rem;
}

.control-actions {
  margin-top: 18px;
}

.action-button {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.action-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(31, 43, 61, 0.12);
}

.action-button:active {
  transform: translateY(1px);
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100vw - 18px, 760px);
  }

  .page-header {
    margin-bottom: 12px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .board-panel {
    order: 1;
  }

  .controls-panel {
    order: 2;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: calc(100vw - 10px);
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-link {
    width: 100%;
  }

  .controls-panel,
  .board-panel {
    width: 100%;
    padding: 16px;
    border-radius: 22px;
  }

  .board-status {
    flex-direction: column;
    align-items: stretch;
  }

  .status-pills {
    justify-content: flex-start;
  }

  .board-frame {
    padding: 8px;
    border-radius: 22px;
  }

  .board-grid {
    gap: 6px;
  }

  .board-cell {
    border-radius: 18px;
  }

  .dot-pip {
    width: 8px;
    height: 8px;
  }

  .scoreboard-title {
    font-size: 1.7rem;
  }

  .history-title {
    font-size: 1.7rem;
  }

  .score-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .score-row-stats {
    gap: 14px;
  }

  .setup-summary-grid {
    grid-template-columns: 1fr;
  }

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

  .player-row-controls {
    grid-template-columns: 1fr;
  }

  .range-row {
    flex-direction: column;
    align-items: stretch;
  }

  .range-row span {
    text-align: left;
  }
}
