/* ═══════════════════════════════════════════════════════════
   먼지의 여정 — 1비트 픽셀 미니게임 UI
   (index 와 같은 잉크/페이퍼 두 색, Galmuri11 한 종류)
   ═══════════════════════════════════════════════════════════ */
@font-face {
  font-family: 'Galmuri11';
  src: url('../assets/fonts/Galmuri11.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Galmuri11';
  src: url('../assets/fonts/Galmuri11-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --ink:   #0d0d0d;
  --paper: #f2f1ec;
  --fg: var(--paper);
  --bg: var(--ink);
  --m2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h1v1H0zM2 0h1v1H2zM0 2h1v1H0zM2 2h1v1H2z'/%3E%3C/svg%3E");
  --m4: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h1v1H0zM2 0h1v1H2zM1 1h1v1H1zM3 1h1v1H3zM0 2h1v1H0zM2 2h1v1H2zM1 3h1v1H1zM3 3h1v1H3z'/%3E%3C/svg%3E");
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: 'Galmuri11', 'Apple SD Gothic Neo', sans-serif;
  font-size: 22px; line-height: 1.7;
  overflow: hidden; touch-action: manipulation;
  -webkit-font-smoothing: none; font-smooth: never; text-rendering: optimizeSpeed;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-appearance: none; appearance: none; }
a { color: inherit; text-decoration: none; }
canvas { display: block; }

#game-wrap {
  height: 100vh; height: 100svh;
  display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
  max-width: 560px; margin: 0 auto;
}

/* ── 헤더 ── */
#game-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 2px 8px;
}
#back-link {
  font-size: 11px; letter-spacing: 0.14em; border: 2px solid var(--fg); padding: 6px 9px; line-height: 1;
  flex: none; white-space: nowrap;
}
#back-link:active { background: var(--fg); color: var(--bg); }
#game-head h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.18em; line-height: 1; flex: none; white-space: nowrap; }
/* 제목을 가운데로 잡아 두는 여백 — 자리가 모자라면 먼저 줄어든다 */
.head-pad { flex: 0 1 84px; width: 84px; }

/* ── HUD ── */
#hud {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  padding: 7px 11px; margin-bottom: 8px; min-height: 36px;
  border: 2px solid var(--fg);
}
.hud-slot {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--fg);
}
.hud-slot.got { background: var(--fg); }
.hud-slot.ring { margin-left: 8px; }
.hud-sep { width: 2px; height: 16px; background: var(--fg); margin-left: 4px; }

/* ── 캔버스 ── */
#canvas-wrap { position: relative; line-height: 0; }
#game-canvas { image-rendering: pixelated; image-rendering: crisp-edges; border: 2px solid var(--fg); background: var(--bg); }

/* ── 오버레이 ── */
/* 오버레이는 캔버스 위에 절대배치된다. 내용이 캔버스보다 길면 위아래로 삐져나가
   헤더의 '먼지의 여정'과 겹쳐 보였다. overflow 로 가두고, 글자 크기를 11px 그리드에
   맞춰 낮춰 iPhone SE(캔버스 273x315) 에서도 넘치지 않게 했다.
   safe center 는 그래도 넘칠 때 위쪽이 잘려 못 읽는 것을 막는다(미지원 시 무시됨). */
.overlay {
  position: absolute; inset: 0; z-index: 5; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  justify-content: safe center;
  overflow-y: auto; overscroll-behavior: contain;
  text-align: center; line-height: 1.7; padding: 14px;
  background: var(--bg);
}
.overlay.show { display: flex; }
.ov-eyebrow { font-size: 11px; letter-spacing: 0.34em; text-indent: 0.34em; line-height: 1; margin-bottom: 9px; }
.overlay h2 { font-size: 22px; font-weight: 700; letter-spacing: 0.1em; line-height: 1.4; margin-bottom: 12px; }
.ov-desc { font-size: 11px; line-height: 1.9; margin-bottom: 16px; word-break: keep-all; }
.ov-desc b { font-weight: 700; background: var(--fg); color: var(--bg); padding: 0 4px; }
.ov-date { font-size: 11px; letter-spacing: 0.12em; line-height: 1.7; margin-bottom: 16px; }
.ov-hint {
  font-size: 11px; line-height: 2; margin-top: 14px;
  -webkit-mask-image: var(--m4); mask-image: var(--m4);
  -webkit-mask-size: 4px 4px; mask-size: 4px 4px;
}

.gbtn {
  border: 2px solid var(--fg); background: var(--bg); color: var(--fg);
  font-size: 11px; letter-spacing: 0.14em; white-space: nowrap;
  padding: 9px 16px; line-height: 1.4; box-shadow: 5px 5px 0 var(--fg);
}
.gbtn:active { transform: translate(5px, 5px); box-shadow: none; }
@media (hover: hover) { .gbtn:hover { background: var(--fg); color: var(--bg); } }
.ov-back { margin-top: 18px; font-size: 11px; letter-spacing: 0.1em; border-bottom: 1px solid currentColor; }

/* ── 메시지 줄 ── */
#game-msg {
  min-height: 26px; margin-top: 11px; font-size: 11px; letter-spacing: 0.06em;
  text-align: center; opacity: 0; transition: opacity 0.2s steps(2);
}
#game-msg.show { opacity: 1; }

/* ── D-패드 ── */
#dpad { margin-top: auto; display: grid; gap: 8px; grid-template-areas: ". up ." "left down right"; padding: 12px 0 14px; }
.dp {
  width: 58px; height: 50px; font-size: 22px; line-height: 1;
  border: 2px solid var(--fg); background: var(--bg); color: var(--fg);
  box-shadow: 4px 4px 0 var(--fg);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.dp:active { transform: translate(4px, 4px); box-shadow: none; background: var(--fg); color: var(--bg); }
.dp.up { grid-area: up; } .dp.down { grid-area: down; }
.dp.left { grid-area: left; } .dp.right { grid-area: right; }

@media (hover: hover) and (pointer: fine) {
  #dpad { display: none; }
  #game-wrap { justify-content: center; }
  #game-msg { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) { #game-msg { transition: none; } }
