:root {
  --bg: #05060F;
  --panel: #0B0E1E;
  --line: #1C2340;
  --cyan: #00E5FF;
  --mag: #FF3DFF;
  --grn: #2BFF88;
  --red: #FF3D6E;
  --ylw: #FFEA00;
  --org: #FF9100;
  --text: #E8ECFF;
  --sub: #7A85B0;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: #02030A; color: var(--text); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none;
}

/* 세로 9:16 고정, 화면에 맞춰 스케일만 조정 (레터박스) */
#frame {
  position: relative; overflow: hidden; background: var(--bg);
  width: min(100vw, calc(100dvh * 0.5625));
  height: min(100dvh, calc(100vw / 0.5625));
  touch-action: none;
}
#gl { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; }
.hud-top {
  display: flex; align-items: center; gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 12px 6px;
  font-weight: 800; font-size: .95rem;
  text-shadow: 0 0 8px rgba(0, 229, 255, .8);
}
#btnPause {
  pointer-events: auto; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(11, 14, 30, .7); color: var(--sub);
  font-size: .9rem; font-weight: 800; cursor: pointer;
}
.hud-stage { color: var(--cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44%; }
.hud-score { flex: 1; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* 발사 버튼 — 우측 하단, 남은 공 개수 표시 */
.launch {
  pointer-events: auto; position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 72px; height: 72px; border-radius: 50%;
  border: 2px solid var(--cyan); background: rgba(0, 229, 255, .14);
  color: var(--text); font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 0 24px rgba(0, 229, 255, .5), inset 0 0 14px rgba(0, 229, 255, .18);
}
.launch b { font-size: 1.15rem; font-weight: 900; text-shadow: 0 0 10px var(--cyan); font-variant-numeric: tabular-nums; }
.launch small { font-size: .62rem; color: var(--sub); font-weight: 700; }
.launch:disabled { opacity: .35; box-shadow: none; cursor: default; }
.launch:not(:disabled):active { transform: scale(.94); }
#hudChips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px; }
#hudChips span {
  font-size: .7rem; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  border: 1px solid; background: rgba(11, 14, 30, .75); font-variant-numeric: tabular-nums;
}
.hint {
  position: absolute; left: 0; right: 0; bottom: 15%;
  text-align: center; color: var(--sub); font-size: .82rem;
  text-shadow: 0 0 6px rgba(0, 229, 255, .4);
}

/* ---------- 스크린 공통 ---------- */
.scr {
  position: absolute; inset: 0; display: none; z-index: 5;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; background: rgba(5, 6, 15, .93); text-align: center;
}
.scr.on { display: flex; }
.scr.overlay { background: rgba(5, 6, 15, .82); backdrop-filter: blur(3px); }

.logo {
  font-size: 3rem; line-height: 1.05; font-weight: 900; letter-spacing: .06em; font-style: italic;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--cyan), 0 0 42px var(--cyan), 0 0 80px var(--mag);
}
.logo-sub { color: var(--sub); letter-spacing: .4em; font-size: .85rem; margin-bottom: 8px; }
.hi { color: var(--sub); font-size: .9rem; margin-bottom: 10px; }
.hi b { color: var(--ylw); text-shadow: 0 0 10px rgba(255, 234, 0, .7); }

.scr-title {
  font-size: 1.6rem; font-weight: 900; letter-spacing: .1em; font-style: italic;
  color: #fff; text-shadow: 0 0 6px #fff, 0 0 20px var(--cyan);
  margin-bottom: 8px;
}
.neon-green { text-shadow: 0 0 6px #fff, 0 0 20px var(--grn), 0 0 44px var(--grn); }
.neon-red { text-shadow: 0 0 6px #fff, 0 0 20px var(--red), 0 0 44px var(--red); }
.ov-score { color: var(--sub); margin-bottom: 8px; }
.ov-score b { color: var(--text); }

.nbtn {
  min-width: 210px; min-height: 48px; padding: 0 18px;
  border: 1px solid rgba(0, 229, 255, .55); border-radius: 12px;
  background: rgba(0, 229, 255, .06); color: var(--text);
  font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 229, 255, .22), inset 0 0 10px rgba(0, 229, 255, .08);
  text-shadow: 0 0 8px rgba(0, 229, 255, .6);
  transition: transform .1s;
}
.nbtn:active { transform: scale(.97); }
.nbtn.primary {
  border-color: var(--cyan); background: rgba(0, 229, 255, .16);
  box-shadow: 0 0 22px rgba(0, 229, 255, .45), inset 0 0 14px rgba(0, 229, 255, .15);
}
.nbtn.small { min-width: 0; min-height: 42px; font-size: .85rem; padding: 0 13px; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.tgl-row { display: flex; gap: 8px; margin-top: 10px; }
.tgl {
  min-height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--sub);
  font: inherit; font-size: .82rem; font-weight: 700;
}
.tgl.on { color: var(--grn); border-color: rgba(43, 255, 136, .6); box-shadow: 0 0 10px rgba(43, 255, 136, .3); }
.foot-note { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); color: #4A5375; font-size: .72rem; }
.foot-note a { color: #4A5375; }

/* ---------- 스테이지 선택 ---------- */
.sel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(88%, 340px); }
.sel-card {
  aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.sel-card b { font-size: 1.3rem; font-weight: 900; color: var(--cyan); text-shadow: 0 0 10px rgba(0, 229, 255, .6); }
.sel-card small { font-size: .68rem; color: var(--sub); max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-card.clear { border-color: rgba(43, 255, 136, .5); }
.sel-card.clear b { color: var(--grn); text-shadow: 0 0 10px rgba(43, 255, 136, .6); }
.sel-card.lock { opacity: .38; cursor: default; }
.sel-card.lock b { color: var(--sub); text-shadow: none; }

/* ---------- 편집기 (제작용 도구 — 게임 프레임 밖 전체 화면 사용) ---------- */
.editor {
  position: fixed; inset: 0; z-index: 8; background: var(--bg);
  justify-content: flex-start; padding-top: max(18px, env(safe-area-inset-top));
  gap: 10px; overflow-y: auto;
}
.ed-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.ed-tabs button {
  min-width: 44px; min-height: 34px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--sub);
  font: inherit; font-size: .8rem; font-weight: 700;
}
.ed-tabs button.on { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 229, 255, .35); }
.ed-row { display: flex; gap: 8px; width: min(96vw, 720px); align-items: stretch; }
.ed-name {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font: inherit; font-size: .9rem; padding: 8px 12px; text-align: center;
}
.ed-name:focus { outline: none; border-color: var(--cyan); }
.ed-balls {
  display: flex; align-items: center; gap: 6px; color: var(--sub); font-size: .78rem; font-weight: 700;
}
.ed-balls input {
  width: 58px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--cyan); font: inherit; font-weight: 800; padding: 8px 6px; text-align: center;
}
.ed-balls input:focus { outline: none; border-color: var(--cyan); }
.ed-grid {
  display: grid; grid-template-columns: repeat(18, 1fr); gap: 2px;
  width: min(96vw, 720px); touch-action: none;
}
.ed-grid .cell {
  aspect-ratio: 1; border-radius: 3px; border: 1px solid #141A33;
  background: #080B18; color: #fff; font-weight: 800;
  font-size: clamp(.5rem, 2.4vw, .82rem);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.v1 { background: rgba(0, 229, 255, .30); border-color: var(--cyan) !important; }
.v2 { background: rgba(43, 255, 136, .30); border-color: var(--grn) !important; }
.v3 { background: rgba(255, 234, 0, .30); border-color: var(--ylw) !important; }
.v4 { background: rgba(255, 145, 0, .32); border-color: var(--org) !important; }
.v5 { background: rgba(255, 61, 110, .32); border-color: var(--red) !important; }
.v9 { background: rgba(122, 133, 176, .35); border-color: #9AA5CC !important; }
.vx { background: rgba(255, 61, 255, .35); border-color: var(--mag) !important; }
.va { background: rgba(255, 94, 58, .38); border-color: #FF5E3A !important; }
.vc { color: #0A0D1E !important; font-weight: 900; } /* 커스텀 블럭: 배경/테두리는 인라인 색 */
.vi { background: rgba(0, 229, 255, .10); border: 1px dashed var(--cyan) !important; color: var(--cyan); }
.ed-pal { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.ed-pal button {
  min-width: 46px; min-height: 44px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: #080B18; color: var(--sub);
  font: inherit; font-size: .92rem; font-weight: 800;
}
.ed-pal button.pv1 { color: var(--cyan); } .ed-pal button.pv2 { color: var(--grn); }
.ed-pal button.pv3 { color: var(--ylw); } .ed-pal button.pv4 { color: var(--org); }
.ed-pal button.pv5 { color: var(--red); } .ed-pal button.pv9 { color: #C3CBE8; }
.ed-pal button.pvx { color: var(--mag); } .ed-pal button.pva { color: #FF5E3A; }
.ed-pal button.pvc { color: #fff; }
.ed-pal button.pvi { color: #9AD8FF; border-style: dashed; }
.ed-pal button.on { border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 229, 255, .4); background: rgba(0, 229, 255, .1); }
.ed-ctl {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center;
  color: var(--sub); font-size: .8rem; font-weight: 700;
}
.ed-ctl button {
  min-width: 34px; min-height: 32px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #080B18; color: var(--sub); font: inherit; font-weight: 800;
}
.ed-ctl button.on { color: var(--mag); border-color: var(--mag); box-shadow: 0 0 8px rgba(255, 61, 255, .4); }
.ed-ctl input {
  width: 76px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  color: var(--cyan); font: inherit; font-weight: 800; padding: 6px; text-align: center;
}
.ed-ctl input:focus { outline: none; border-color: var(--cyan); }
.ctl-sub { font-weight: 400; font-size: .72rem; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatches button {
  width: 24px; height: 24px; min-width: 0; min-height: 0; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
}
.swatches button.on { border-color: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, .6); }
.ed-info { color: var(--sub); font-size: .74rem; }
.ed-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.ed-msg { min-height: 1.2em; color: var(--ylw); font-size: .8rem; font-weight: 700; text-shadow: 0 0 8px rgba(255, 234, 0, .5); }

.noscript {
  position: absolute; inset: auto 16px 40%; z-index: 9;
  background: var(--panel); border: 1px solid var(--red); border-radius: 12px;
  padding: 14px 16px; color: var(--red); font-weight: 700; text-align: center;
}
