/* OVERCHARGE — 기획서 5장 값(색 · 크기 · 레이아웃) 그대로. 기획서에 없는 연출은 같은 팔레트 안에서 최소로. */
:root {
  --bg: #0F172A;
  --tile-bg: #1E293B;
  --red: #FF3B5C;
  --blue: #00D2FF;
  --yellow: #FFD600;
  --green: #00E676;
  --rock: #475569;
  --text: #E2E8F0;
  --muted: #94A3B8;
  --line: #334155;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;          /* 모바일 터치 스크롤 방지(기획서 1장) */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  max-width: 440px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* 1. 상단 헤더 80px */
.hud-top {
  height: 80px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
}
.stage-name { font-size: 17px; font-weight: 800; line-height: 1.3; }
.stage-name b { color: var(--yellow); letter-spacing: .04em; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--tile-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.small { padding: 6px 9px; font-size: 12px; }
.btn.primary { background: var(--yellow); color: var(--bg); border-color: transparent; }

/* 2. 상태 바 60px */
.status {
  height: 60px;
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 0 16px;
}
.status-left { font-size: 12px; color: var(--muted); }
.turns { font-size: 24px; font-weight: 900; letter-spacing: .06em; }
.turns.danger { color: var(--red); animation: blink .9s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
.stage-nav { justify-self: end; display: flex; align-items: center; gap: 4px; }
.stage-count { min-width: 26px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); }

/* 3. 메인 보드 — 정사각형, 화면 너비 92%(높이가 모자라면 main.js가 줄인다) */
.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board { position: relative; --tile: 60px; }

.tiles {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
}
.tile { margin: 3px; background: var(--tile-bg); border-radius: 12px; }

/* 드래그 연결선(5.3) — 구슬 아래 */
.link { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#linkLine {
  fill: none;
  stroke: currentColor;
  stroke-width: 8px;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px currentColor);
}

.orbs { position: absolute; inset: 0; pointer-events: none; }

/* 구슬 — 에너지 단계별 지름(5.2): Lv.1 42% · Lv.2 62% · Lv.3 82% */
.orb {
  --k: .42;
  --s: 1;
  position: absolute;
  left: calc((var(--c) + .5) * var(--tile));
  top: calc((var(--r) + .5) * var(--tile));
  width: calc(var(--k) * var(--tile));
  height: calc(var(--k) * var(--tile));
  transform: translate(-50%, -50%) scale(var(--s));
  transition: width .12s ease-out, height .12s ease-out, transform .12s ease-out, left .15s ease-in, top .15s ease-in, opacity .15s;
}
.orb.lv-1 { --k: .42; }
.orb.lv-2 { --k: .62; }
.orb.lv-3 { --k: .82; }
.orb.lv-4 { --k: .92; }
.orb.t-ROCK { --k: .82; }

.orb .body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.c-RED .body    { background: var(--red);    box-shadow: 0 0 12px rgba(255, 59, 92, .6); }
.c-BLUE .body   { background: var(--blue);   box-shadow: 0 0 12px rgba(0, 210, 255, .6); }
.c-YELLOW .body { background: var(--yellow); box-shadow: 0 0 12px rgba(255, 214, 0, .6); }
.c-GREEN .body  { background: var(--green);  box-shadow: 0 0 12px rgba(0, 230, 118, .6); }
.c-PRISM .body  { background: conic-gradient(#FF3B5C, #FFD600, #00E676, #00D2FF, #FF3B5C); box-shadow: 0 0 12px rgba(255, 255, 255, .5); }
.t-ROCK .body   { background: var(--rock); border-radius: 24%; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25); }

.num {
  position: relative;
  z-index: 1;
  font-size: calc(var(--tile) * .26);
  font-weight: 900;
  line-height: 1;
  color: var(--bg);
}
.lv-1 .num { font-size: calc(var(--tile) * .2); }
.c-PRISM .num { text-shadow: 0 0 3px #fff, 0 0 6px #fff; }

/* 레이저 화살표 · 바위 X 표시 */
.glyph { position: absolute; inset: 0; width: 100%; height: 100%; }
.glyph polygon { fill: rgba(15, 23, 42, .8); }
.t-ROCK .glyph path { fill: none; stroke: #1E293B; stroke-width: 8; stroke-linecap: round; }
.t-ROCK .glyph path.crack { stroke-width: 4; opacity: .8; }

/* Lv.3 — 곧 터질 듯 미세하게 떨림(5.2 pulse-shake) */
.lv-3 .body { animation: pulse-shake .45s ease-in-out infinite; }
@keyframes pulse-shake {
  0%, 100% { transform: scale(1) translate(0, 0) rotate(0); }
  20% { transform: scale(1.04) translate(-1px, 0) rotate(-2deg); }
  40% { transform: scale(.98) translate(1px, -1px) rotate(2deg); }
  60% { transform: scale(1.05) translate(-1px, 1px) rotate(-1deg); }
  80% { transform: scale(.99) translate(1px, 0) rotate(1deg); }
}

/* 드래그 중 고른 구슬 · 합이 4 이상이면 마지막 구슬이 크게 부풂(5.3) */
.orb.sel { --s: 1.1; }
.orb.sel::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .9);
}
.orb.t-ROCK.sel::after { border-radius: 28%; }
.orb.inflate { --s: 1.35; }

/* 합체 — 끝 칸으로 빨려 들어감(150ms) */
.orb.merging { opacity: .7; }

/* 폭발 · 바위 부서짐(220ms) */
.orb.boom { animation: boom .22s ease-out forwards; }
@keyframes boom {
  0% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; filter: brightness(1.8); }
  100% { transform: translate(-50%, -50%) scale(1.9); opacity: 0; filter: brightness(2.4); }
}
.orb.crumble { animation: crumble .22s ease-in forwards; }
@keyframes crumble {
  100% { transform: translate(-50%, -50%) scale(.35) rotate(28deg); opacity: 0; }
}

/* 이펙트 레이어(충격파 · 레이저) — 구슬 위 */
.fx { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 4; }
.fx * { transform-box: fill-box; transform-origin: center; }

/* 합산 미리보기 말풍선(5.3) */
.tip {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -100%);
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .92);
  border: 1px solid rgba(255, 255, 255, .3);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
}
.tip.boom {
  color: var(--yellow);
  border-color: var(--yellow);
  box-shadow: 0 0 14px rgba(255, 214, 0, .55);
  font-size: 17px;
}
.tip[hidden] { display: none; }

/* 콤보 팝업 */
.popups { position: absolute; inset: 0; z-index: 5; pointer-events: none; display: flex; justify-content: center; }
.combo {
  margin-top: 6%;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: .04em;
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(255, 214, 0, .75), 0 2px 0 #000;
  white-space: nowrap;
}

/* 4. 하단 힌트 바 60px */
.hint {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

/* 결과 창 */
.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, .7);
}
.modal.hidden { display: none; }
.card {
  width: min(320px, 86%);
  padding: 24px 20px 20px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #111C33;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.m-title { font-size: 28px; font-weight: 900; letter-spacing: .04em; }
.modal.clear .m-title { color: var(--green); text-shadow: 0 0 14px rgba(0, 230, 118, .6); }
.modal.over .m-title { color: var(--red); text-shadow: 0 0 14px rgba(255, 59, 92, .6); }
.m-text { margin: 10px 0 18px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.m-btns { display: flex; justify-content: center; gap: 8px; }
.m-btns .btn { padding: 10px 16px; font-size: 15px; }
.m-btns .btn[hidden] { display: none; }
