:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(60px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  gap: 16px;
}

/* 점수바: SCORE | BEST | New 버튼 */
.score-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.score-box {
  flex: 1;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0a0a0;
}

.score-val,
.best-val {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  margin-top: 2px;
  line-height: 1.1;
}

.new-btn {
  flex: 0 0 auto;
  font: inherit;
  color: #fff;
  background: #4f9eff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 56px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.new-btn:active { background: #3d8ae8; }

/* 게임 영역 — 보드/캠버스/그리드 등을 여기에 */
#game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 chrome */
.home-link,
.hof-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 10;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.home-link { left:  max(12px, env(safe-area-inset-left)); }
.hof-link  { right: max(12px, env(safe-area-inset-right)); }

@media (hover: hover) {
  .home-link:hover,
  .hof-link:hover {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* 오버레이 (게임 종료 / 완료 시 점수 + 저장 버튼) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 18px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  min-width: 240px;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay-score {
  margin: 0;
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.overlay-card button {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.overlay-card button:active {
  background: rgba(255, 255, 255, 0.18);
}

.overlay-card .save-btn {
  background: #4f9eff;
  border-color: #4f9eff;
}

.overlay-card .save-btn:active {
  background: #3d8ae8;
}

.overlay-sub { margin: 0; font-size: 13px; color: #b8b8b8; line-height: 1.4; }

/* ─── Dara ─────────────────────────────────────────────── */
#game {
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.dr-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
}
.dr-side { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.dr-side b { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: center; }
.dr-chip {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto;
}
.dr-side.me .dr-chip { background: radial-gradient(circle at 35% 30%, #fffdf6, #e9dcc0 55%, #b9a57e); }
.dr-side.foe .dr-chip { background: radial-gradient(circle at 35% 30%, #8a8f9c, #3a3d46 55%, #14151a); box-shadow: 0 0 0 1px #5a5e6a; }
.dr-hand { display: inline-grid; grid-template-columns: repeat(6, 6px); gap: 2px; }
.dr-hand i { width: 6px; height: 6px; border-radius: 50%; background: #262626; transition: background .2s; }
.dr-hand.me i.on { background: #efe3c8; }
.dr-hand.foe i.on { background: #7d828f; }
#game.moving .dr-hand { display: none; }
.dr-mid { display: flex; flex-direction: column; align-items: center; gap: 1px; text-align: center; min-width: 0; }
.dr-phase { font-weight: 700; color: #e8d6a8; font-size: 12px; white-space: nowrap; }
.dr-phase.warn { color: #ffb454; }
.dr-lv { font-size: 11px; color: #9a9a9a; }

.dr-wrap { position: relative; width: min(100%, calc((100dvh - 330px) * 1.2)); }
.dr-board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  aspect-ratio: 6 / 5;
  width: 100%;
  padding: 3.5%;
  border-radius: 16px;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255,240,205,.35), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(120,80,40,.25), transparent 60%),
    repeating-radial-gradient(circle at 30% 40%, rgba(255,255,255,.035) 0 2px, transparent 2px 5px),
    linear-gradient(160deg, #d9b679, #c39a5c 60%, #a87f45);
  box-shadow: inset 0 0 0 3px #6e4b23, inset 0 0 18px rgba(60,35,10,.45), 0 8px 22px rgba(0,0,0,.5);
}

.dr-h {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
/* the scooped hole */
.dr-h::before {
  content: '';
  position: absolute;
  width: 74%; aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 62%, #8a6331, #6a4720 60%, #553818);
  box-shadow: inset 0 3px 5px rgba(40,22,5,.75), 0 1px 0 rgba(255,235,190,.45);
  transition: box-shadow .15s;
}
/* stones */
.dr-st {
  position: relative;
  width: 66%; aspect-ratio: 1;
  border-radius: 50%;
  transform: scale(0);
  transition: transform .18s cubic-bezier(.3,1.6,.5,1), opacity .2s;
  pointer-events: none;
}
.dr-h.me .dr-st, .dr-h.foe .dr-st { transform: scale(1); }
.dr-h.me .dr-st {
  background: radial-gradient(circle at 34% 30%, #fffef9, #f1e6cc 45%, #c9b48a 85%, #a8916a);
  box-shadow: 0 2px 3px rgba(40,22,5,.6);
}
.dr-h.foe .dr-st {
  background: radial-gradient(circle at 34% 30%, #9ca1ad, #474b55 40%, #22242b 80%, #101115);
  box-shadow: 0 2px 3px rgba(20,10,0,.7);
}

/* drop hints */
.dr-h.open::before { box-shadow: inset 0 3px 5px rgba(40,22,5,.75), 0 0 0 2px rgba(255,248,220,.35); }
.dr-h.no::after {
  content: '×';
  position: absolute;
  color: rgba(255,226,190,.78);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  font-size: clamp(18px, 6vw, 28px);
  font-weight: 800;
  line-height: 1;
}

/* move phase */
.dr-h.can .dr-st { box-shadow: 0 2px 3px rgba(40,22,5,.6), 0 0 0 2px rgba(255,255,255,.55); }
.dr-h.sel .dr-st { transform: scale(1.1) translateY(-2px); box-shadow: 0 5px 8px rgba(40,22,5,.6), 0 0 0 3px #ffd34d; }
.dr-h.to::after {
  content: '';
  position: absolute;
  width: 30%; aspect-ratio: 1; border-radius: 50%;
  background: #7dffa0;
  box-shadow: 0 0 10px #7dffa0;
  animation: dr-pulse 1s ease-in-out infinite;
}
.dr-h.tgt .dr-st { box-shadow: 0 0 0 3px #ff5a4f, 0 0 12px #ff5a4f; animation: dr-wob .7s ease-in-out infinite; }
.dr-h.line::before { box-shadow: inset 0 3px 5px rgba(40,22,5,.75), 0 0 0 3px #ffd34d, 0 0 14px #ffcf3d; }
.dr-h.last .dr-st { outline: 2px solid rgba(80,200,255,.9); outline-offset: 2px; }
.dr-h.from::after {
  content: ''; position: absolute; width: 16%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(80,200,255,.8);
}
.dr-h.gone::after {
  content: ''; position: absolute; width: 66%; aspect-ratio: 1; border-radius: 50%;
  border: 3px dashed #ff5a4f;
  animation: dr-gone 1.6s ease-out forwards;
}

@keyframes dr-pulse { 50% { transform: scale(.7); opacity: .6; } }
@keyframes dr-wob { 50% { transform: scale(.92); } }
@keyframes dr-gone { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.25); opacity: .35; } }

.dr-banner {
  position: absolute;
  left: 0; right: 0; top: -8px;
  transform: translateY(-100%);
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(20,14,6,.88);
  border: 1px solid #ffd34d;
  color: #fff3cc;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
}
.dr-banner.show { animation: dr-banner 4.4s ease forwards; }
@keyframes dr-banner { 0% { opacity: 0; transform: translateY(-80%); } 10%, 85% { opacity: 1; transform: translateY(-100%); } 100% { opacity: 0; transform: translateY(-100%); } }

.dr-msg {
  margin: 0;
  min-height: 2.8em;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  color: #d0d0d0;
}
.dr-msg.ok { color: #6ee787; }
.dr-msg.bad { color: #ff8a80; }
