:root {
  --bg-page: #f2efe8;
  --bg-panel: rgba(255, 255, 255, 0.28);
  --bg-board: #dba86d;
  --board-frame: #8c5f2b;
  --board-line: rgba(56, 34, 18, 0.9);
  --text: #241a12;
  --text-soft: #695744;
  --shadow: rgba(22, 16, 10, 0.18);
}

body[data-theme="dark"] {
  --bg-page: #1c252d;
  --bg-panel: rgba(44, 59, 73, 0.72);
  --bg-board: #bf8a4b;
  --board-frame: #6a4326;
  --board-line: rgba(35, 22, 11, 0.9);
  --text: #f2efe8;
  --text-soft: #d8d0c6;
  --shadow: rgba(0, 0, 0, 0.35);
}

body[data-theme="light"] {
  --bg-page: #f7f4ef;
  --bg-panel: rgba(255, 255, 255, 0.7);
  --bg-board: #e9c58c;
  --board-frame: #b87d41;
  --board-line: rgba(65, 47, 24, 0.8);
  --text: #2a211b;
  --text-soft: #675c55;
  --shadow: rgba(75, 58, 40, 0.12);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--bg-page);
  color: var(--text);
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background-image:
    linear-gradient(rgba(255,255,255,0.08), rgba(255,255,255,0.04)),
    radial-gradient(circle at top, rgba(255,255,255,0.15), transparent 30%);
  transition: background 0.25s ease;
}

button,
select {
  font: inherit;
}

.start-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(23, 18, 13, 0.38);
  backdrop-filter: blur(4px);
  z-index: 20;
}

.start-screen.hidden {
  display: none;
}

.start-card {
  width: min(90vw, 490px);
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 22px;
  padding: 34px 28px;
  box-shadow: 0 22px 60px var(--shadow);
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-soft);
}

h1, h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
}

.subtitle {
  margin: 14px 0 22px;
  line-height: 1.7;
  color: var(--text-soft);
}

.rules-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  text-align: left;
}

.rules-panel label,
.theme-picker label,
.theme-inline {
  font-weight: 600;
  color: var(--text-soft);
}

.rules-content {
  min-height: 130px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(125, 97, 67, 0.2);
  border-radius: 12px;
  color: var(--text);
  line-height: 1.7;
}

.rules-content ul {
  margin: 0;
  padding-left: 18px;
}

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  text-align: left;
}

select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(125, 97, 67, 0.35);
  background: rgba(255,255,255,0.34);
  color: var(--text);
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #1b1b1b, #4a3d33);
  color: #fff;
  font-size: 1.02rem;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(26, 18, 13, 0.2);
}

.secondary-btn {
  padding: 10px 16px;
  background: rgba(255,255,255,0.25);
  color: var(--text);
  border: 1px solid rgba(125, 97, 67, 0.22);
  box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.app-shell {
  width: min(92vw, 760px);
  background: rgba(255,255,255,0.06);
  border-radius: 26px;
  padding: 18px 18px 22px;
  box-shadow: 0 18px 42px var(--shadow);
  border: 1px solid rgba(255,255,255,0.12);
}

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

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.theme-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-inline select {
  width: auto;
  min-width: 110px;
  margin-top: 0;
}

.status {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.12);
  border-radius: 12px;
  border: 1px solid rgba(124, 94, 68, 0.12);
  transition: all 0.2s ease;
}

.status[data-turn="black"] {
  background: rgba(25, 25, 30, 0.9);
  color: #f5f5f5;
}

.status[data-turn="white"] {
  background: rgba(245, 245, 245, 0.9);
  color: #1d1d1d;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(124, 94, 68, 0.12);
}

.score-item strong {
  font-size: 1.2rem;
}

.black-score {
  background: rgba(12, 12, 13, 0.92);
  color: #f5f5f5;
}

.white-score {
  background: rgba(244, 245, 247, 0.9);
  color: #1d1d1d;
}

.black-score strong {
  color: #f3f3f3;
}

.white-score strong {
  color: #171717;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  width: min(82vw, 680px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(19, minmax(0, 1fr));
  grid-template-rows: repeat(19, minmax(0, 1fr));
  background: var(--bg-board);
  border: 10px solid var(--board-frame);
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(87, 54, 27, 0.12), 0 8px 18px rgba(20, 14, 9, 0.15);
  overflow: hidden;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08), transparent 30%, rgba(98,68,35,0.12));
  pointer-events: none;
}

.cell {
  position: relative;
  border-right: 1px solid var(--board-line);
  border-bottom: 1px solid var(--board-line);
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
}

.cell:hover::before {
  background: rgba(255,255,255,0.08);
}

.cell:nth-child(19n) {
  border-right: none;
}

.cell:nth-last-child(-n + 19) {
  border-bottom: none;
}

.cell.star::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(26, 19, 12, 0.82);
  z-index: 0;
}

.stone {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72%;
  height: 72%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  box-shadow: inset -4px -4px 10px rgba(0,0,0,0.22), inset 4px 4px 8px rgba(255,255,255,0.12);
  animation: stoneDrop 0.18s ease-out;
}

.cell.black .stone {
  background: radial-gradient(circle at 30% 25%, #3b3b3b 0%, #050505 30%, #000 100%);
}

.cell.white .stone {
  background: radial-gradient(circle at 30% 25%, #ffffff 0%, #dfe3e8 32%, #9da5af 100%);
}

@keyframes stoneDrop {
  0% { transform: translate(-50%, -50%) scale(0.75); opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@media (max-width: 560px) {
  body {
    padding: 16px;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

  .board {
    width: min(88vw, 420px);
  }
}
