: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)) 14px max(16px, env(safe-area-inset-bottom));
  gap: 8px;
}

.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; }
.streak-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; }
.new-btn:active { background: #3d8ae8; }
.message { margin: 0; text-align: center; font-size: 13px; color: #a0a0a0; min-height: 18px; }

#game { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.oni { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }

/* 카드 행 */
.cardrow { display: flex; gap: 8px; justify-content: center; align-items: stretch; flex-wrap: nowrap; }
.card {
  background: #15171d; border: 1px solid #2a2f3a; border-radius: 10px;
  padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  position: relative;
}
.ai-row .card { opacity: 0.9; }
.card.neutral { background: #1c1710; border-color: #4a3c1e; }
.card.you { cursor: pointer; }
.card.you.sel { border-color: #4f9eff; box-shadow: 0 0 0 2px rgba(79,158,255,0.5); background: #16233a; }
.nlabel { position: absolute; top: -8px; left: 50%; transform: translateX(-50%); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #c8a24a; background: #0a0a0a; padding: 0 4px; border-radius: 4px; }
.cn { font-size: 13px; line-height: 1; }

/* 카드 미니 5×5 패턴 */
.mini { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; width: 56px; height: 56px; }
.ai-row .mini, .card.neutral .mini { width: 44px; height: 44px; }
.mc { background: #262c38; border-radius: 2px; }
.mc.center { background: #6b7686; }
.mc.move { background: #4f9eff; }
.card.neutral .mc.move { background: #d2a64e; }
.card.neutral .mc.center { background: #8a7a55; }

/* 보드 5×5 */
.board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  width: min(86vw, 50vh, 360px); aspect-ratio: 1;
  background: #6b4423; border: 3px solid #6b4423; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.sq { background: #d8b787; position: relative; display: flex; align-items: center; justify-content: center; border-radius: 3px; }
.sq.arch-a { background: #c98f6b; }
.sq.arch-p { background: #b6c2d0; }
.sq.arch-a::after, .sq.arch-p::after { content: '⛩'; position: absolute; font-size: 60%; opacity: 0.35; color: #3a2a1a; }
.sq.last { box-shadow: inset 0 0 0 3px rgba(255,200,80,0.55); }
.sq.selp { box-shadow: inset 0 0 0 3px #4f9eff; }
.sq.dest { cursor: pointer; }
.sq.dest::before {
  content: ''; position: absolute; width: 34%; height: 34%; border-radius: 50%;
  background: rgba(79,158,255,0.55); box-shadow: 0 0 6px rgba(79,158,255,0.6);
}

.pc { width: 74%; height: 74%; border-radius: 50%; position: relative; z-index: 1; }
.pc.p { background: radial-gradient(circle at 35% 30%, #6fb0ff, #1d4f8f); box-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.pc.a { background: radial-gradient(circle at 35% 30%, #ff8a8a, #9e2b2b); box-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.pc.mas { border: 2px solid #ffd95e; box-shadow: 0 0 8px rgba(255,206,79,0.65); }
.pc.mas::after { content: '★'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 64%; color: #ffe89a; }

/* 공통 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; border: none; cursor: pointer; font-family: inherit;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.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-score .unit { font-size: 18px; font-weight: 600; color: #c0c0c0; margin-left: 8px; }
.overlay-meta { margin: 0; font-size: 14px; color: #a0a0a0; min-height: 1em; }
.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%; }
.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; }
