*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #e6e9ef;
  --hi: #ffffff;
  --lo: #c3c9d4;
  --ink: #4a5161;
  --ink-soft: #8990a0;
  --hl: #e6b545;     /* 선택 가능한 점 */
  --lock: #e0646c;   /* 보호 / 방금 먹힌 점 */
  --p1: #a3db85;
  --p2: #94d6ff;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2a2d34;
    --hi: #353942;
    --lo: #1d1f24;
    --ink: #d4d9e3;
    --ink-soft: #8b92a2;
    --hl: #e9bf5c;
    --lock: #e8737a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #2a2d34; --hi: #353942; --lo: #1d1f24;
  --ink: #d4d9e3; --ink-soft: #8b92a2;
  --hl: #e9bf5c; --lock: #e8737a;
  color-scheme: dark;
}

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--ink);
  font-family: "Gowun Dodum", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.game {
  width: min(90vw, 520px);
  padding: 28px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

/* ── 플레이어 ── */
.players {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
}

.player {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  border-radius: 999px;
  opacity: .62;
  box-shadow: inset 3px 3px 6px var(--lo), inset -3px -3px 6px var(--hi);
  transition: box-shadow .25s ease, opacity .25s ease;
}
.player[data-player="2"] { flex-direction: row-reverse; padding: 8px 8px 8px 14px; }
.player[data-player="1"] { --pc: var(--p1); }
.player[data-player="2"] { --pc: var(--p2); }

.player.active {
  opacity: 1;
  box-shadow: 6px 6px 14px var(--lo), -6px -6px 14px var(--hi);
}

.swatch {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--pc);
  box-shadow: 3px 3px 6px var(--lo), -3px -3px 6px var(--hi),
              inset 1px 1px 2px rgba(255,255,255,.35);
  cursor: pointer;
}
.swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}
.swatch:focus-within { outline: 2px solid var(--ink-soft); outline-offset: 3px; }

.name {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  padding: 6px 8px;
  border-radius: 10px;
}
.player[data-player="2"] .name { text-align: right; }
.name:focus-visible {
  box-shadow: inset 2px 2px 4px var(--lo), inset -2px -2px 4px var(--hi);
}

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

/* ── 보드 ── */
.board {
  --cur: var(--p1);
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 44px;
  background: var(--bg);
  box-shadow: 14px 14px 30px var(--lo), -14px -14px 30px var(--hi);
}
.board[data-turn="2"] { --cur: var(--p2); }

.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.lines line { stroke-width: 1.5; stroke-linecap: round; }
.lines .p1 { stroke: var(--p1); }
.lines .p2 { stroke: var(--p2); }

.pt {
  position: absolute;
  z-index: 1;
  width: 15%;
  height: 15%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: default;
}
.pt.playable { cursor: pointer; }
.pt:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: -2px; }
.pt.p1 { --pc: var(--p1); }
.pt.p2 { --pc: var(--p2); }

.dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 2px 2px 4px var(--lo), inset -2px -2px 4px var(--hi);
  transition: width .2s ease, height .2s ease, background-color .2s ease, transform .2s ease;
}

.pt.own .dot {
  width: 58%;
  height: 58%;
  background: radial-gradient(circle at 34% 30%,
              color-mix(in srgb, var(--pc) 55%, #fff) 0%, var(--pc) 60%);
  box-shadow: 4px 4px 9px var(--lo), -4px -4px 9px var(--hi);
}

.pt.empty.playable:hover .dot,
.pt.empty.playable:focus-visible .dot,
.pt.target .dot {
  width: 40%;
  height: 40%;
  background: color-mix(in srgb, var(--cur) 35%, var(--bg));
}
.pt.own.playable:hover .dot,
.pt.own.playable:focus-visible .dot { transform: scale(1.07); }

/* 링 표시 */
.pt::after {
  content: "";
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  border: 2.5px solid transparent;
  pointer-events: none;
  transition: border-color .2s ease;
}
.pt.locked::after { border-color: var(--lock); }
.pt.source::after { border-color: var(--hl); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  50% { transform: scale(1.1); opacity: .55; }
}

/* ── 결과 ── */
.result {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.result[hidden] { display: none; }
#result-text {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  color: var(--ink);
}

/* ── 버튼 ── */
.btn, .icon-btn {
  border: 0;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 6px 6px 12px var(--lo), -6px -6px 12px var(--hi);
  transition: box-shadow .15s ease;
}
.btn { padding: 12px 28px; border-radius: 999px; font-size: 1rem; }
.icon-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}
.btn:active, .icon-btn:active {
  box-shadow: inset 4px 4px 8px var(--lo), inset -4px -4px 8px var(--hi);
}
.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: 3px; }

@media (max-width: 420px) {
  .players { gap: 8px; }
  .icon-btn { width: 42px; height: 42px; }
  .name { font-size: .95rem; padding: 6px 4px; }
  .board { border-radius: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
