:root { --bg:#151a2e; --panel:#232a47; --panel2:#2e3760; --ink:#f4f1e6; --sub:#a9b0cc; --acc:#ffcc3a; --ok:#6fe08a; --bad:#ff6a7a; --line:#0a0e1c; }
* { box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
html,body { height:100%; }
body { background:var(--bg); color:var(--ink); font-family:"Malgun Gothic","Apple SD Gothic Neo","Noto Sans KR",sans-serif; line-height:1.45; overflow-x:hidden; }
button,input { font:inherit; color:inherit; }
a { color:inherit; }
.screen { display:none; min-height:100dvh; padding:12px 12px 24px; max-width:960px; margin:0 auto; }
.screen.active { display:block; }
#scr-play.active { display:flex; flex-direction:column; padding:6px 8px 8px; min-height:100dvh; max-width:2000px; }

.homelink { display:inline-block; text-decoration:none; background:var(--panel); border:2px solid var(--line); border-radius:6px; padding:6px 10px; font-size:.9em; box-shadow:2px 2px 0 var(--line); }
.homelink.mini { padding:4px 8px; }
.btn { background:var(--panel2); border:2px solid var(--line); border-radius:6px; padding:9px 14px; cursor:pointer; box-shadow:0 3px 0 var(--line); min-height:40px; font-weight:700; }
.btn:active { transform:translateY(2px); box-shadow:0 1px 0 var(--line); }
.btn.sm { padding:6px 10px; min-height:34px; }
.btn.big { background:var(--acc); color:#2a1d00; font-size:1.15em; padding:12px 28px; }
.btn[disabled] { opacity:.45; cursor:not-allowed; }
.card { background:var(--panel); border:3px solid var(--line); border-radius:10px; padding:16px; box-shadow:5px 5px 0 #0007; }
.small { font-size:.82em; color:var(--sub); } small { color:var(--sub); font-weight:400; }
.err { color:var(--bad); min-height:1.2em; margin-top:6px; font-size:.9em; }
.row { display:flex; gap:10px; justify-content:center; margin-top:12px; flex-wrap:wrap; }

/* 메뉴 */
#scr-menu { text-align:center; }
#scr-menu .homelink { position:absolute; left:12px; top:12px; }
.title { margin:34px 0 18px; }
.pix-sub { color:var(--acc); letter-spacing:.2em; font-size:.85em; }
.title h1 { font-size:2.2em; line-height:1.15; text-shadow:3px 3px 0 var(--line); margin:6px 0 10px; }
#menu-art { width:min(560px,92%); image-rendering:pixelated; border:3px solid var(--line); border-radius:8px; background:#7ec4ee; }
#profile { max-width:420px; margin:0 auto; text-align:left; }
#profile label { display:block; margin-bottom:10px; font-weight:700; }
#profile input { display:block; width:100%; margin-top:4px; padding:10px; border:2px solid var(--line); border-radius:6px; background:#0f1426; font-size:1em; }

/* 스테이지 선택 */
.bar { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.who { flex:1; font-weight:700; text-align:center; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sumline { text-align:center; color:var(--sub); margin-bottom:12px; }
.world { background:var(--panel); border:3px solid var(--line); border-radius:10px; margin-bottom:14px; overflow:hidden; box-shadow:4px 4px 0 #0006; }
.world-head { padding:10px 14px; display:flex; align-items:center; gap:10px; border-bottom:3px solid var(--line); }
.world-head canvas { width:48px; height:48px; image-rendering:pixelated; flex:none; }
.world-head h2 { font-size:1.05em; }
.world-head p { font-size:.82em; color:var(--sub); }
.stage-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; padding:12px; }
.stbtn { background:var(--panel2); border:2px solid var(--line); border-radius:8px; padding:10px 6px; cursor:pointer; text-align:center; box-shadow:0 3px 0 var(--line); }
.stbtn b { display:block; font-size:1.05em; }
.stbtn .nm { font-size:.8em; color:var(--sub); min-height:2.4em; display:block; }
.stbtn .st { color:var(--acc); letter-spacing:2px; }
.stbtn .sc { font-size:.78em; color:var(--sub); }
.stbtn.locked { opacity:.45; cursor:not-allowed; }
.w0 .world-head { background:#3f5a2e; } .w1 .world-head { background:#6a4a2a; } .w2 .world-head { background:#46505e; } .w3 .world-head { background:#2a2060; }

/* 플레이 */
.hud { display:flex; align-items:center; gap:8px; margin-bottom:4px; }
.hud-name { flex:1; font-weight:700; font-size:.95em; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.hud-hp canvas { width:21px; height:18px; image-rendering:pixelated; margin-left:2px; }
.hud-item { background:var(--panel); border:2px solid var(--line); border-radius:6px; padding:3px 8px; font-size:.9em; white-space:nowrap; }
.infoline { font-size:.82em; color:var(--sub); margin-bottom:4px; min-height:1.2em; }
.infoline b { color:var(--acc); font-weight:700; }
.playgrid { display:flex; flex-direction:column; gap:8px; flex:1; }
.stagebox { position:relative; width:100%; border:3px solid var(--line); border-radius:8px; overflow:hidden; background:#000; aspect-ratio:16/9; touch-action:none; }
#cv { width:100%; height:100%; display:block; image-rendering:pixelated; touch-action:none; cursor:crosshair; }
#cv.smooth { image-rendering:auto; }
#floats { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
.fl { position:absolute; transform:translate(-50%,-50%); font-weight:900; font-size:clamp(11px,calc(var(--sw,640px) / 38),30px); text-shadow:2px 2px 0 #000,-1px -1px 0 #000,1px -1px 0 #000,-1px 1px 0 #000; white-space:nowrap; animation:flup 1.4s ease-out forwards; }
.fl.good { color:var(--ok); } .fl.bad { color:var(--bad); } .fl.info { color:#cfe0ff; }
@keyframes flup { 0% { opacity:0; margin-top:6px; } 15% { opacity:1; } 100% { opacity:0; margin-top:-34px; } }
.pausemask { position:absolute; inset:0; background:#0009; display:none; flex-direction:column; align-items:center; justify-content:center; gap:8px; font-size:1.5em; font-weight:900; text-align:center; }
.pausemask.on { display:flex; }
.panel { background:var(--panel); border:3px solid var(--line); border-radius:10px; padding:10px; display:grid; grid-template-columns:1fr 1fr; gap:8px 12px; align-content:start; }
.ctl { min-width:0; }
.ctl-top { display:flex; align-items:baseline; gap:8px; font-weight:700; }
.ctl-top b { color:var(--acc); font-size:1.15em; }
.ctl-top .lock { display:none; margin-left:auto; font-size:.85em; }
.ctl.locked .lock { display:inline; }
.ctl.locked input[type=range], .ctl.locked .btn { opacity:.4; pointer-events:none; }
.ctl-row { display:flex; gap:6px; align-items:center; margin-top:2px; }
.ctl-row.two { gap:8px; } .ctl-row.two .btn { flex:1; }
input[type=range] { flex:1; min-width:0; height:34px; accent-color:var(--acc); }
#ctl-charge { grid-column:1 / -1; display:none; }
#ctl-charge.on { display:block; }
.btn.pos.sel { background:#ff5a6a; } .btn.neg.sel { background:#3a86e8; }
.predict { grid-column:1 / -1; display:flex; justify-content:space-between; align-items:center; font-size:.9em; font-weight:700; gap:8px; }
.predict input { width:84px; padding:7px; border:2px solid var(--line); border-radius:6px; background:#0f1426; text-align:right; }
.panel .row { grid-column:1 / -1; margin-top:0; justify-content:stretch; }
.btn.fire { flex:1; background:#e8334a; font-size:1.25em; padding:12px; min-height:50px; letter-spacing:.05em; }
.hintbox { grid-column:1 / -1; display:none; background:#10162c; border:2px dashed var(--sub); border-radius:6px; padding:8px 10px; font-size:.88em; }
.hintbox.on { display:block; }

/* 모달 */
.modal { position:fixed; inset:0; background:#000b; display:none; align-items:flex-start; justify-content:center; overflow:auto; padding:14px; z-index:50; }
.modal.on { display:flex; }
.modal-card { background:var(--panel); border:3px solid var(--line); border-radius:12px; box-shadow:6px 6px 0 #0008; width:min(560px,100%); padding:16px 16px 18px; margin:auto; }
.modal-card h2 { font-size:1.25em; margin-bottom:6px; }
.modal-card p { margin:6px 0; }
.modal-card .tag { display:inline-block; background:var(--acc); color:#2a1d00; font-weight:900; font-size:.78em; padding:1px 8px; border-radius:4px; margin-right:6px; }
.stars { font-size:2.2em; color:var(--acc); letter-spacing:6px; text-align:center; text-shadow:2px 2px 0 var(--line); }
.stars .off { color:#4a4f6a; }
.brk { width:100%; border-collapse:collapse; margin:8px 0; font-size:.92em; }
.brk td { padding:3px 4px; border-bottom:1px solid #ffffff22; } .brk td:last-child { text-align:right; font-weight:700; }
.brk tr.sum td { border-top:2px solid var(--acc); color:var(--acc); font-size:1.1em; }
.qbox { background:#10162c; border-left:4px solid var(--acc); border-radius:4px; padding:8px 10px; margin:8px 0; font-size:.92em; }
.qbox.n { border-left-color:var(--ok); }
.cmp { width:100%; border-collapse:collapse; font-size:.88em; margin:4px 0; }
.cmp th,.cmp td { border:1px solid #ffffff2a; padding:3px 6px; text-align:center; } .cmp th { background:#10162c; color:var(--sub); font-weight:700; }
.rank-tabs { display:flex; gap:6px; margin:8px 0; }
.rank-tabs .btn.on { background:var(--acc); color:#2a1d00; }
.rk { width:100%; border-collapse:collapse; font-size:.95em; }
.rk td,.rk th { padding:5px 6px; border-bottom:1px solid #ffffff22; text-align:left; } .rk th { color:var(--sub); font-size:.82em; }
.rk td:first-child { width:2.4em; font-weight:900; } .rk td:nth-child(3),.rk td:nth-child(4) { text-align:right; }
.rk tr.me td { background:#ffcc3a30; color:var(--acc); font-weight:900; }
.modal-actions { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; margin-top:12px; }

/* 가로 폰/태블릿 */
@media (orientation:landscape) and (max-height:560px) {
  #scr-play.active { padding:4px 8px; }
  .playgrid { flex-direction:row; align-items:flex-start; }
  .stagebox { flex:1 1 auto; width:auto; max-height:calc(100dvh - 70px); max-width:calc((100dvh - 70px) * 16 / 9); }
  .panel { flex:0 0 300px; grid-template-columns:1fr 1fr; gap:6px 10px; padding:8px; }
  .ctl-top { font-size:.9em; }
  .ctl-row .btn.sm { min-height:30px; padding:4px 8px; }
  .btn.fire { min-height:44px; padding:8px; }
}
@media (min-width:900px) { .playgrid { flex-direction:row; align-items:flex-start; } .stagebox { flex:1; } .panel { flex:0 0 280px; grid-template-columns:1fr; } }
@media (min-width:1500px) { .panel { flex-basis:340px; font-size:1.12em; } .hud, .infoline { font-size:1.08em; } }
@media (max-width:520px) { .title h1 { font-size:1.8em; } .stage-grid { gap:6px; padding:8px; } .stbtn .nm { font-size:.74em; } }
@media (prefers-reduced-motion:reduce) { .fl { animation-duration:.01s; } }

/* 미션(전투 전 연습) · 탐구 노트 */
.mission { position:absolute; left:0; right:0; top:0; z-index:5; background:rgba(10,14,28,.86); border-bottom:2px solid var(--acc); padding:5px 8px; font-size:clamp(11px,calc(var(--sw,640px) / 62),19px); cursor:pointer; }
.mission[hidden], .battle[hidden] { display:none; }
.mission.done { border-bottom-color:var(--ok); background:rgba(14,40,26,.9); }
.m-line { display:flex; flex-wrap:wrap; gap:4px 8px; align-items:center; }
.m-line b { color:var(--acc); } .mission.done .m-line b { color:var(--ok); }
.m-tog { margin-left:auto; color:var(--sub); } .mission.min .m-tog { transform:rotate(90deg); }
.chip { background:#ffffff18; border-radius:10px; padding:0 7px; white-space:nowrap; font-size:.92em; } .chip.on { background:#6fe08a33; color:var(--ok); }
.m-body { margin-top:3px; line-height:1.35; } .mission.min .m-body { display:none; }
.m-msg { margin-top:2px; color:#cfe0ff; line-height:1.3; } .m-msg:empty { display:none; }
.battle { position:absolute; left:0; right:0; margin:0 auto; width:fit-content; top:46%; z-index:6; animation:glow 1.3s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow:0 3px 0 var(--line), 0 0 0 6px #ffcc3a66; } }
.why-opt { display:block; width:100%; text-align:left; margin:6px 0; font-weight:600; line-height:1.35; }
.why-opt.right { background:#2f7d4a; } .why-opt.wrong { background:#8a2f3b; }
#why-after textarea { display:block; width:100%; margin-top:4px; padding:8px; border:2px solid var(--line); border-radius:6px; background:#0f1426; resize:vertical; }
@media (orientation:landscape) and (max-height:560px) { .mission { padding:3px 6px; font-size:11px; } }
@media (prefers-reduced-motion:reduce) { .battle { animation:none; } }
