:root {
  --bg: #eef2f0;
  --panel: #ffffff;
  --text: #1d2b2a;
  --muted: #61706d;
  --line: #d6dedb;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --board: #d6a75f;
  --board-dark: #5c3b1d;
  --shadow: 0 18px 40px rgba(22, 38, 36, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.1), transparent 32%),
    linear-gradient(315deg, rgba(214, 167, 95, 0.18), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.game-panel {
  width: min(100%, 1040px);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.1;
  letter-spacing: 0;
}

.status-text {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.score-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 170px;
}

.score-strip span {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  color: var(--muted);
  white-space: nowrap;
}

.score-strip strong {
  color: var(--text);
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) repeat(2, minmax(128px, 1fr)) repeat(5, minmax(74px, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  font-size: 13px;
}

.field legend {
  padding: 0;
}

.segmented-options {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6f5;
}

.segmented-option {
  position: relative;
  min-width: 0;
}

.segmented-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.segmented-option input:checked + span {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(22, 38, 36, 0.14);
}

.segmented-option input:not(:disabled) + span:hover {
  color: var(--accent-dark);
}

.segmented-option input:focus-visible + span {
  outline: 3px solid rgba(15, 118, 110, 0.48);
  outline-offset: 1px;
}

.segmented-option input:disabled + span {
  cursor: not-allowed;
  opacity: 0.48;
}

button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.48);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.ghost {
  background: #fff;
  color: var(--danger);
  border-color: #f1c4bd;
}

button.ghost:hover:not(:disabled) {
  background: #fff5f3;
  border-color: #df9a90;
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button.secondary:hover:not(:disabled) {
  background: #f3f6f5;
  color: var(--accent-dark);
  border-color: #a8bbb6;
}

.result-dialog,
.notice-dialog {
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(22, 38, 36, 0.3);
}

.result-dialog {
  width: min(calc(100% - 32px), 440px);
}

.notice-dialog {
  width: min(calc(100% - 32px), 380px);
}

.result-dialog::backdrop,
.notice-dialog::backdrop {
  background: rgba(20, 31, 30, 0.56);
  backdrop-filter: blur(3px);
}

.result-dialog-content {
  padding: 28px;
  text-align: center;
}

.result-eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.result-dialog h2 {
  margin: 0;
  font-size: clamp(26px, 6vw, 34px);
  line-height: 1.2;
}

.result-message {
  margin: 12px 0 24px;
  color: var(--muted);
  line-height: 1.6;
}

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

.notice-dialog-content {
  padding: 24px;
  text-align: center;
}

.notice-message {
  margin: 0 0 20px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

.notice-actions {
  display: flex;
  justify-content: center;
}

.notice-actions button {
  min-width: 140px;
}

.board-wrap {
  width: min(100%, 720px);
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--board);
  box-shadow:
    inset 0 0 0 1px rgba(92, 59, 29, 0.38),
    0 14px 28px rgba(92, 59, 29, 0.22);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: crosshair;
}

canvas[aria-disabled="true"] {
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  button,
  .segmented-option span {
    transition: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    align-items: flex-start;
    padding: 14px;
  }

  .game-panel {
    padding: 16px;
  }

  .top-bar {
    flex-direction: column;
    gap: 12px;
  }

  .score-strip {
    justify-content: flex-start;
  }

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

@media (max-width: 620px) {
  .option-field {
    grid-column: 1 / -1;
  }
}

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

  .score-strip {
    width: 100%;
  }

  .score-strip span {
    flex: 1;
    text-align: center;
  }

  .result-dialog-content {
    padding: 22px 18px 18px;
  }

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