: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: 14px; font-weight: 700; color: #a8a8a8; font-variant-numeric: tabular-nums; line-height: 1.35; }

/* ─── Mū tōrere ────────────────────────────────────────────
   Square board sized to the space left over (container query), star drawn in SVG,
   pieces are buttons positioned in % so they slide with a CSS transition. */
#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
}

.mt-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #cfcfcf;
}
.mt-chip { display: inline-flex; align-items: center; gap: 6px; }
.mt-chip i {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block;
}
.mt-chip.me i  { background: radial-gradient(circle at 35% 30%, #fffaf0, #e7d3ad 60%, #b89a6a); }
.mt-chip.foe i { background: radial-gradient(circle at 35% 30%, #6d7f78, #2b3633 60%, #151b1a); box-shadow: 0 0 0 1px #8a9a94; }
.mt-level {
  font-size: 12px; color: #e9c98a; background: rgba(233, 201, 138, 0.10);
  border: 1px solid rgba(233, 201, 138, 0.28); border-radius: 999px; padding: 3px 10px;
  font-variant-numeric: tabular-nums;
}

.mt-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  container-type: size;
}
.mt-board {
  position: relative;
  flex: 0 0 auto;
  width: min(100cqw, calc(100cqh - 84px - var(--rules-h, 0px)));
  aspect-ratio: 1;
}
.mt-lines { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mt-disc { fill: url(#mtWood); stroke: #8a6440; stroke-width: 0.6; }
.mt-star { fill: rgba(255, 236, 200, 0.07); }
.mt-star-edge { fill: none; stroke: #e6c58f; stroke-width: 1.1; stroke-linejoin: round; }
.mt-spokes line { stroke: #c9a46c; stroke-width: 0.8; stroke-linecap: round; opacity: 0.85; }
.mt-dot { fill: #2a1c11; stroke: #e6c58f; stroke-width: 0.7; transition: fill 0.2s; }
.mt-dot.from { fill: #5a3d22; }

.mt-empty {
  position: absolute;
  width: 15.5%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px dashed rgba(255, 228, 170, 0.0);
  pointer-events: none;
  transition: left 0.28s ease, top 0.28s ease, border-color 0.2s;
}
.mt-empty.on { border-color: rgba(255, 228, 170, 0.75); animation: mtPulse 1.4s ease-in-out infinite; }
@keyframes mtPulse { 50% { transform: translate(-50%, -50%) scale(1.12); } }

.mt-pc {
  position: absolute;
  width: 14.5%; aspect-ratio: 1;
  min-width: 30px;
  transform: translate(-50%, -50%);
  border: none; padding: 0; margin: 0;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: left 0.28s cubic-bezier(.3,.7,.3,1), top 0.28s cubic-bezier(.3,.7,.3,1);
  -webkit-tap-highlight-color: transparent;
}
.mt-board.instant .mt-pc, .mt-board.instant .mt-empty { transition: none; }
.mt-pc::before {           /* bigger invisible hit area */
  content: ''; position: absolute; inset: -12%; border-radius: 50%;
}
.mt-pc span {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.55), inset 0 -3px 4px rgba(0, 0, 0, 0.25);
}
.mt-pc.me span  { background: radial-gradient(circle at 35% 30%, #fffaf0, #ead8b4 55%, #b4955f); }
.mt-pc.foe span { background: radial-gradient(circle at 35% 30%, #77897f, #2d3a36 58%, #141a19); box-shadow: 0 3px 6px rgba(0,0,0,0.55), inset 0 0 0 1.5px rgba(160, 182, 172, 0.55); }
.mt-pc.last span::after {
  content: ''; position: absolute; inset: 36%; border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
}
.mt-pc.foe.last span::after { background: rgba(255, 255, 255, 0.16); }
.mt-pc.can span { outline: 3px solid #ffd27a; outline-offset: 2px; animation: mtGlow 1.4s ease-in-out infinite; }
@keyframes mtGlow { 50% { outline-color: rgba(255, 210, 122, 0.35); } }
.mt-pc.nope { animation: mtNope 0.32s; }
@keyframes mtNope {
  25% { transform: translate(-58%, -50%); } 75% { transform: translate(-42%, -50%); }
}
.mt-pc:disabled { cursor: default; }
.mt-pc.warned span { outline: 3px solid #ff7a66; outline-offset: 2px; animation: none; }
.mt-pc.stuck span { filter: saturate(0.5) brightness(0.8); }
.mt-pc.stuck::after { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid #ff7a66; pointer-events: none; }
.mt-pc:focus-visible span { outline: 3px solid #4f9eff; outline-offset: 3px; }

.mt-msg {
  margin: 0;
  min-height: 2.7em;
  width: 100%;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-size: 15px; font-weight: 700; line-height: 1.3;
  color: #f0f0f0;
}
.mt-msg.ok { color: #9be39b; }
.mt-msg.bad { color: #ff9b8f; }
.mt-msg.hint { color: #ffd27a; font-size: 14px; }
.mt-sub {
  margin: 0;
  text-align: center;
  font-size: 12px; font-weight: 600; color: #9a9a9a;
  font-variant-numeric: tabular-nums;
}
.mt-sub.warn { color: #ffb35c; }

@media (max-height: 600px) {
  #game { gap: 4px; }
  .mt-msg { font-size: 14px; min-height: 2.6em; }
}

/* Rule legend — only where there is room for it below a full-size board. */
.mt-rules {
  display: none;
  margin: 4px 0 0; padding: 10px 12px; list-style: none;
  width: min(100%, 360px);
  border: 1px solid rgba(233, 201, 138, 0.18); border-radius: 12px;
  background: rgba(233, 201, 138, 0.05);
  font-size: 12.5px; line-height: 1.35; color: #c9c2b4;
}
.mt-rules li { display: flex; align-items: center; gap: 9px; padding: 2px 0; }
.mt-rules i { flex: 0 0 28px; height: 18px; position: relative; font-style: normal; }
.mt-rules i::before { content: ''; position: absolute; left: 3px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #e7d3ad; }
.mt-rules .r-rim::after, .mt-rules .r-out::after, .mt-rules .r-in::after {
  content: '→'; position: absolute; left: 15px; top: -1px; font-size: 13px; color: #ffd27a; font-style: normal;
}
.mt-rules .r-out::before { background: #e7d3ad; box-shadow: 0 0 0 2px #6b4a2f, 0 0 0 3px #c9a46c; }
.mt-rules .r-in::before { background: #e7d3ad; box-shadow: -7px 0 0 -2px #2d3a36; }
.mt-rules .r-end::before { background: #2d3a36; box-shadow: 0 0 0 2px rgba(255, 120, 100, 0.8); }
@media (min-height: 760px) {
  .mt-rules { display: block; }
  .mt-wrap { --rules-h: 112px; }
}
