* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --ink: #2e2419;
  --muted: #6f5b46;
  --paper: #f4efe6;
  --wood: #d6b685;
  --wood-dark: #b58b57;
  --accent: #8a3b12;
  --shadow: rgba(46, 36, 25, 0.2);
}

html,
body {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho",
    "Hiragino Kaku Gothic ProN", "Meiryo", serif;
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 18px 22px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f7f1e7, #efe1cd);
  box-shadow: 0 10px 20px var(--shadow);
}

.hero h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: 0.06em;
}

.eyebrow {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.badge {
  padding: 8px 16px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e2d4c2;
  font-size: 12px;
  letter-spacing: 0.2em;
}

.main {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

.panel {
  background: #fffaf2;
  padding: 20px;
  border-radius: 18px;
  box-shadow: 0 12px 22px var(--shadow);
  display: grid;
  gap: 16px;
}

.controls {
  text-align: left;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #f4e6d4;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 6px 12px rgba(124, 91, 65, 0.2);
}

.thinking.hidden {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(138, 59, 18, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status .label,
.form-block .label,
.log .label {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}

.status p {
  margin: 0;
  line-height: 1.6;
  text-align: left;
}

.log ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid #eadbc7;
  border-radius: 12px;
  background: #fffdf8;
  padding: 10px;
  font-size: 13px;
}

.log li {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.log .stone {
  width: 14px;
  height: 14px;
}

.log li span {
  color: var(--muted);
}

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

.scoreboard div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.stone {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.4),
    inset -1px -1px 3px rgba(0, 0, 0, 0.3);
}

.stone.black {
  background: #1b1b1b;
}

.stone.white {
  background: #f7f7f7;
  border: 1px solid #d4c9bb;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px rgba(138, 59, 18, 0.3);
}

.primary:hover:not(:disabled),
.secondary:hover:not(:disabled) {
  transform: translateY(-1px);
}

.secondary {
  background: #f0e2ce;
  color: var(--ink);
  box-shadow: 0 4px 10px rgba(124, 91, 65, 0.2);
}

.large {
  padding: 14px 24px;
  font-size: 15px;
}

.board-wrapper {
  position: relative;
  display: grid;
  place-items: center;
  padding: 16px;
  max-width: 100%;
}

#board {
  background: var(--wood);
  border-radius: 12px;
  box-shadow: 0 16px 30px rgba(102, 75, 45, 0.35);
  width: min(92vw, 620px);
  height: auto;
  touch-action: manipulation;
}

.board-frame {
  position: absolute;
  inset: 14px;
  border-radius: 14px;
  border: 2px solid rgba(120, 86, 52, 0.5);
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 10, 0.72);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay .modal {
  background: #fff8ee;
  border-radius: 18px;
  padding: 26px;
  width: min(92vw, 480px);
  box-shadow: 0 16px 30px rgba(20, 14, 10, 0.4);
  text-align: center;
}

.form-block {
  margin: 18px 0;
  text-align: left;
}

.pill-group {
  display: grid;
  gap: 8px;
}

.pill-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f2e5d3;
  font-size: 14px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 12px;
}

.win {
  background: radial-gradient(circle, rgba(19, 12, 9, 0.9), rgba(8, 5, 3, 0.95));
}

#fireworks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

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

  .panel {
    order: 2;
  }

  .board-wrapper {
    order: 1;
    padding: 10px 6px;
  }
}

@media (max-width: 600px) {
  .page {
    padding: 16px 14px 24px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px 16px;
    margin-bottom: 16px;
  }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .panel {
    padding: 14px;
    gap: 12px;
  }

  .thinking {
    width: fit-content;
  }

  .status,
  .log {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    text-align: left;
  }

  .status .label,
  .log .label {
    margin: 0;
    white-space: nowrap;
  }

  .status p {
    flex: 1;
    text-align: left;
    font-size: 13px;
    min-width: 0;
  }

  .log ul {
    flex: 1;
    max-height: 32px;
    overflow: hidden;
    padding: 6px 8px;
    text-align: left;
  }

  .log li {
    justify-content: flex-start;
    white-space: nowrap;
  }

  .scoreboard div {
    font-size: 14px;
  }

  .scoreboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
  }

  .scoreboard div {
    justify-content: center;
  }

  .board-wrapper {
    padding: 6px 0;
  }

  #board {
    width: min(96vw, 520px);
  }

  .board-frame {
    inset: 8px;
  }

  .overlay .modal {
    padding: 20px;
  }

  .form-block {
    margin: 12px 0;
  }
}
