:root {
  color-scheme: light dark;
  --bg: #15120e;
  --panel: #231a13;
  --panel-2: #2d2118;
  --line: #d0a463;
  --line-soft: rgba(208, 164, 99, 0.38);
  --text: #f7ead9;
  --muted: #cbb89f;
  --black-1: #111317;
  --black-2: #2d3138;
  --black-rim: #4a505a;
  --white-1: #fefefe;
  --white-2: #dadce2;
  --white-rim: #8f96a3;
  --empty: #7b613e;
  --accent: #f2c777;
  --good: #6dd28c;
  --danger: #f08a7a;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(242, 199, 119, 0.12), transparent 38rem),
    linear-gradient(135deg, #120e0b, #24170f 55%, #120e0b);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(1120px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0;
}

.layout {
  min-height: calc(100vh - 44px);
  min-height: calc(100dvh - 44px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: center;
}

.board-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.board-wrap {
  width: min(100%, 690px, calc(100dvh - 44px));
  aspect-ratio: 1;
  border-radius: 22px;
  background:
    radial-gradient(circle at 35% 25%, rgba(255,255,255,.10), transparent 18rem),
    linear-gradient(135deg, #5b3b22, #2a1b12);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 18px 36px var(--shadow);
  padding: clamp(8px, 2vw, 18px);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  touch-action: manipulation;
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: center;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.card {
  background: rgba(35, 26, 19, 0.88);
  border: 1px solid var(--line-soft);
  border-radius: 22px;
  box-shadow: 0 18px 36px var(--shadow);
  padding: 15px;
}

.status {
  display: flex;
  align-items: center;
  min-height: 38px;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(242, 199, 119, 0.12);
  border: 1px solid var(--line-soft);
  color: var(--accent);
  font-weight: 650;
}

.message {
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--muted);
}

.message:empty { display: none; }

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

.checkline {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--muted);
  line-height: 1.35;
  margin: 8px 0 14px;
}

.checkline input { margin-top: 4px; }

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.buttons button:last-child { grid-column: 1 / -1; }

button {
  cursor: pointer;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  background: #3a2a1d;
  font: inherit;
  font-weight: 650;
}

button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }

.line { stroke: var(--line); stroke-width: 5; stroke-linecap: round; opacity: .88; }
.node { fill: var(--empty); stroke: rgba(255,255,255,.25); stroke-width: 3; }
.target { fill: rgba(242, 199, 119, .32); stroke: var(--accent); stroke-width: 5; cursor: pointer; }
.piece { cursor: pointer; filter: drop-shadow(0 8px 5px rgba(0,0,0,.35)); }
.stone-shadow { fill: rgba(0,0,0,.20); }
.piece-black-main { fill: url(#stoneBlackGrad); stroke: var(--black-rim); stroke-width: 2.2; }
.piece-black-highlight { fill: rgba(255,255,255,.14); }
.piece-white-main { fill: url(#stoneWhiteGrad); stroke: var(--white-rim); stroke-width: 1.8; }
.piece-white-highlight { fill: rgba(255,255,255,.72); }
.selected-ring { fill: none; stroke: var(--accent); stroke-width: 7; stroke-dasharray: 10 8; pointer-events: none; }
.last-ring { fill: none; stroke: var(--good); stroke-width: 5; opacity: .95; pointer-events: none; }
.hint-ring { fill: none; stroke: var(--danger); stroke-width: 6; stroke-dasharray: 4 7; pointer-events: none; }
.coord { fill: var(--muted); font-size: 18px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

@media (max-width: 1024px) and (orientation: portrait), (max-width: 720px) {
  body {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .app {
    width: 100vw;
    padding: 0 0 18px;
  }

  .layout {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
  }

  .board-panel {
    width: 100vw;
  }

  .board-wrap {
    width: 100vw;
    max-width: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 0;
    box-shadow: none;
  }

  .side-panel {
    width: min(100vw - 18px, 520px);
    margin: 0 auto;
    align-content: start;
  }

  h1 {
    text-align: center;
    font-size: clamp(2.2rem, 12vw, 3.6rem);
  }

  .card {
    border-radius: 18px;
  }
}

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

  .buttons button:last-child { grid-column: auto; }
}
