:root {
  --bg: #0f1012;
  --panel: #15171b;
  --board: #deb068;
  --ink: rgba(0, 0, 0, 0.75);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.7);
  --line: rgba(255, 255, 255, 0.08);
  --btn: #2a2f38;
  --btnHover: #343b47;
  --focus: rgba(255, 255, 255, 0.22);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1000px 600px at 30% 0%, rgba(222, 176, 104, 0.15), transparent 60%),
    radial-gradient(800px 500px at 90% 20%, rgba(255, 255, 255, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(15, 16, 18, 0.78);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, #bbb 55%, #666 100%);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

.title {
  font-weight: 800;
  letter-spacing: 0.3px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 28px 8px 10px;
  position: relative;
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

.stage {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.canvasWrap {
  padding: 10px;
}

#gameCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  background: radial-gradient(1200px 800px at 30% 20%, rgba(255, 255, 255, 0.18), transparent 60%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.12)),
    var(--board);
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
}

.scoreRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scoreCard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.score {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.stoneIcon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  position: relative;
}

.stoneIcon[data-stone="black"] {
  background: radial-gradient(circle at 30% 30%, #666, #222 55%, #111 100%);
}

.stoneIcon[data-stone="white"] {
  background: radial-gradient(circle at 30% 30%, #fff, #dedede 60%, #bababa 100%);
}

.ops {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--btn);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover { background: var(--btnHover); }
.btn:active { transform: translateY(1px); }
.btn:focus { outline: none; box-shadow: 0 0 0 3px var(--focus); }

.status {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  min-height: 44px;
}

.rules {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
}

.rules summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
}

.rules ol {
  margin: 10px 0 0 18px;
  padding: 0;
}

.audioRow {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  user-select: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modalCard {
  width: min(520px, 100%);
  background: rgba(21, 23, 27, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.modalTitle {
  font-size: 18px;
  font-weight: 900;
  margin-bottom: 6px;
}

.modalBody {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.modalOps {
  display: flex;
  justify-content: flex-end;
}

@media (min-width: 920px) {
  .layout {
    grid-template-columns: 1.4fr 0.6fr;
    align-items: start;
  }

  .panel {
    position: sticky;
    top: 58px;
  }
}
