/* 도토리 포격전 — 숲 빛깔 화면 틀 */
:root {
  --bg: #1d2b1f;
  --bg2: #24362a;
  --panel: #2a3f30;
  --panel2: #33503b;
  --line: #45664e;
  --text: #f1f5e6;
  --dim: #a9bfa6;
  --accent: #f0a23a;
  --accent2: #d97f1f;
  --leaf: #8fd35c;
  --danger: #ff7b6b;
  --star: #ffd45a;
  --radius: 14px;
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(900px 500px at 15% -10%, #35553c 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.in-battle { overflow: hidden; height: 100dvh; display: flex; flex-direction: column; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
small { color: var(--dim); }
h1, h2, h3, p { margin: 0; }

/* ───── 상단 ───── */
.topbar {
  flex: 0 0 auto; position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 6px; min-height: 48px;
  padding: 2px 8px; padding-top: max(2px, env(safe-area-inset-top));
  background: rgba(29, 43, 31, .94); border-bottom: 1px solid var(--line);
}
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; padding: 0 12px; min-width: 44px; min-height: 44px; border-radius: 999px; flex: 0 0 auto;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 13px; white-space: nowrap;
}
.back-btn:hover { border-color: var(--accent); }
/* 좁은 화면에서는 두 줄까지 (판 이름·유형이 잘리지 않게) */
.top-title {
  flex: 1; min-width: 0; font-weight: 700; text-align: center; font-size: 13px; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.tools { display: flex; gap: 4px; align-items: center; flex: 0 0 auto; }
.star-pill { padding: 4px 9px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--star); font-size: 13px; white-space: nowrap; }
.mini { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 15px; display: inline-grid; place-items: center; padding: 0; }
.mini:hover { border-color: var(--accent); }

/* ───── 공용 ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 10px 16px; font-weight: 700; min-height: 44px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #2b1a05; border-color: transparent; }
.btn.big { font-size: 18px; padding: 14px 24px; }
.btn.small { padding: 5px 10px; font-size: 13px; min-height: 34px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.sub { color: var(--dim); font-size: 14px; }

/* ───── 메뉴 ───── */
.screen { padding: 14px 14px calc(28px + var(--sab)); max-width: 880px; margin: 0 auto; }
.hero { display: flex; gap: 14px; align-items: center; padding: 6px 2px 14px; }
.hero canvas { width: 80px; height: 80px; flex: 0 0 auto; }
.hero h1 { font-size: 26px; letter-spacing: -.5px; }
.hero p { color: var(--dim); font-size: 14px; }
.hero b { color: var(--leaf); }
.first-shot { width: 100%; margin-bottom: 14px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(240, 162, 58, .18); } }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tab { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; }
.tab.on { background: var(--panel2); border-color: var(--accent); color: var(--accent); }
.panel { display: flex; flex-direction: column; gap: 12px; }
.zone-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.zone-tabs::-webkit-scrollbar { display: none; }
.zone-tab { flex: 0 0 auto; min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; white-space: nowrap; }
.zone-tab.on { border-color: var(--leaf); color: var(--leaf); }
.zone-tab.locked { opacity: .55; }
.zone-desc { color: var(--dim); font-size: 13px; }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stage-card {
  text-align: left; padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; gap: 4px; min-height: 104px; position: relative;
}
.stage-card:hover:not(:disabled) { border-color: var(--accent); }
.stage-card:disabled { opacity: .5; }
.stage-card .sid { font-size: 12px; color: var(--dim); }
.stage-card .sname { font-weight: 700; }
.stage-card .skind { font-size: 12px; color: var(--dim); }
.stage-card .stars { margin-top: auto; letter-spacing: 2px; color: #58705c; font-size: 16px; }
.stage-card .stars b { color: var(--star); font-weight: 400; }
.stage-card .tag { position: absolute; right: 8px; top: 8px; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #51341a; color: #ffd9a8; }
.stage-card.boss { border-color: #7a5a2a; }
.card { padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 10px; }
.card h3 { font-size: 16px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.opt { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
.opt select, .seat select {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 40px; width: 100%;
}
.seat { display: grid; grid-template-columns: 74px 1fr 1fr; gap: 6px; align-items: center; font-size: 13px; }
.seat .who { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.seat .who i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.stat { padding: 10px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); text-align: center; }
.stat b { display: block; font-size: 20px; color: var(--accent); }
.stat span { font-size: 12px; color: var(--dim); }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.soon { color: var(--dim); font-size: 13px; }
/* 지형 축소 그림·얼굴 (캔버스) */
.thumb { display: block; width: 100%; height: auto; aspect-ratio: 20 / 7; border-radius: 8px; image-rendering: pixelated; }
.face { flex: 0 0 auto; width: 44px; height: 44px; }
.stage-card .skind { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 34px; }
.stage-card .skind .face { width: 34px; height: 34px; }
.stage-card .tag { right: 14px; top: 14px; }
.seat.off { opacity: .6; }
.seat input[type=text] {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-height: 40px; width: 100%; min-width: 0;
}
.seat .face { justify-self: center; }
.opt select:focus-visible, .seat select:focus-visible, .seat input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* 오늘의 한 발 카드 */
.daily-card { border-color: #7a5a2a; }
.daily-head { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.daily-head .thumb { flex: 1 1 180px; max-width: 300px; }
.daily-head > div { flex: 1 1 200px; display: flex; flex-direction: column; gap: 3px; }
.daily-res { font-size: 15px; }
.daily-res .st { color: var(--star); letter-spacing: 2px; font-weight: 400; }
.week { display: flex; flex-wrap: wrap; gap: 4px; }
.week span { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.week span.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.past { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; color: var(--dim); }
.past span { flex: 0 0 100%; }
.past .btn { font-weight: 400; }
/* 생김새·업적 */
.look-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.look { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-weight: 700; font-size: 13px; }
.look .face { width: 60px; height: 60px; }
.look small { font-weight: 400; font-size: 11px; }
.look.on { border-color: var(--accent); background: #4a3a20; }
.look.on small { color: var(--accent); }
.look:disabled { opacity: .5; }
.look:disabled .face { filter: grayscale(1) brightness(.7); }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.ach { display: grid; grid-template-columns: 24px 1fr auto; column-gap: 8px; align-items: center; padding: 7px 10px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); opacity: .62; }
.ach.got { opacity: 1; border-color: #7a5a2a; }
.ach i { grid-area: 1 / 1 / 3 / 2; font-style: normal; font-size: 18px; }
.ach b { grid-area: 1 / 2; font-size: 14px; }
.ach small { grid-area: 1 / 3; font-size: 11px; }
.ach span { grid-area: 2 / 2 / 3 / 4; font-size: 12px; color: var(--dim); }
/* 알림 쪽지 (업적·새 생김새) */
.toasts { position: fixed; left: 0; right: 0; top: calc(56px + env(safe-area-inset-top, 0px)); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast { max-width: 100%; padding: 8px 16px; border-radius: 999px; background: rgba(255, 252, 240, .97); color: #33301f; font-size: 14px; font-weight: 700; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); animation: toastIn .3s ease-out; transition: opacity .45s, transform .45s; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.9); } }

/* ───── 전투 ───── */
#battle { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.status {
  flex: 0 0 auto; height: 32px; display: flex; align-items: center; gap: 8px; padding: 0 8px;
  background: var(--bg2); border-bottom: 1px solid var(--line); font-size: 12px;
}
.teams { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; }
.team { flex: 1 1 0; min-width: 0; max-width: 190px; display: flex; align-items: center; gap: 5px; opacity: .8; padding: 2px 4px; border-radius: 7px; border: 1px solid transparent; }
.team.cur { opacity: 1; border-color: var(--accent); background: rgba(240, 162, 58, .14); }
.team.out { opacity: .35; }
.team .mk { flex: 0 0 auto; font-size: 11px; }
.team .nm { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.team .sn { display: none; flex: 0 0 auto; font-weight: 700; white-space: nowrap; }
.team .hp { flex: 1 1 30px; min-width: 24px; height: 8px; border-radius: 4px; background: #16211a; overflow: hidden; position: relative; }
.team .hp i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; transition: width .25s; }
.team .hp i.ghost { background: #fff; opacity: .7; transition: width .9s .25s; }
.team .hpn { flex: 0 0 auto; font-variant-numeric: tabular-nums; color: var(--dim); min-width: 22px; text-align: right; }
/* 좁은 화면: 이름·체력 숫자를 윗줄에, 체력 막대를 아랫줄에 (이름이 잘리지 않게) */
@media (max-width: 819px) {
  .team { flex-wrap: wrap; align-content: center; row-gap: 2px; padding: 1px 4px; }
  .team .nm { flex: 1 1 0; }
  .team .hp { order: 5; flex: 1 0 100%; height: 5px; }
  /* 포병이 셋 이상이면 이름 대신 짧은 이름(자리 번호)을 쓰고 촘촘하게 */
  .teams.many { gap: 3px; }
  .teams.many .team { gap: 3px; padding: 1px 3px; }
  .teams.many .nm { display: none; }
  .teams.many .sn { display: inline; flex: 1 1 0; font-size: 11px; }
  .teams.many .hpn { min-width: 0; font-size: 11px; }
}
.wind { flex: 0 0 auto; display: flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.wind-arrow { display: inline-block; font-weight: 700; color: #9fd6ff; transition: transform .3s; }
.clock { flex: 0 0 auto; position: relative; width: 26px; height: 26px; display: grid; place-items: center; }
.clock svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.clock b { font-size: 11px; position: relative; }
.ring-bg { fill: none; stroke: #16211a; stroke-width: 4; }
.ring-fg { fill: none; stroke: var(--leaf); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 94.2; }
.clock.low .ring-fg { stroke: var(--danger); }
.round { flex: 0 0 auto; color: var(--dim); white-space: nowrap; }

.field { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; background: #8fd3ff; touch-action: none; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.banner {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); padding: 8px 18px; border-radius: 999px; white-space: nowrap;
  background: rgba(20, 30, 22, .82); color: #fff; font-weight: 800; font-size: 17px; pointer-events: none; animation: pop .25s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.7); opacity: 0; } }
.bubble {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(92%, 420px); padding: 9px 13px; border-radius: 14px;
  background: rgba(255, 252, 240, .95); color: #33301f; font-size: 14px; font-weight: 600; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  pointer-events: none; /* 말풍선 위에서도 끌어 쏘기를 시작할 수 있게 */
}
.curtain { position: absolute; inset: 0; background: rgba(18, 28, 20, .93); display: grid; place-items: center; text-align: center; z-index: 5; cursor: pointer; }
.curtain b { display: block; font-size: 24px; margin-bottom: 6px; }
.curtain span { color: var(--dim); }
.range-bar {
  position: absolute; left: 6px; right: 6px; top: 40px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 5px 8px; border-radius: 12px; background: rgba(20, 30, 22, .78); font-size: 12px;
}
.wind.flip { animation: windFlip .5s ease-out; }
@keyframes windFlip { 30% { transform: scale(1.25); border-color: #9fd6ff; } }
/* 오늘의 한 발 기록 줄 */
.daily-log {
  position: absolute; left: 6px; top: 40px; z-index: 2; margin: 0; padding: 5px 10px; list-style: none; max-width: 72%;
  border-radius: 10px; background: rgba(20, 30, 22, .74); font-size: 12px; line-height: 1.45; pointer-events: none; font-variant-numeric: tabular-nums;
}
.daily-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daily-log li.ok { color: var(--star); font-weight: 700; }
.daily-log.in-box { position: static; max-width: none; background: var(--panel); font-size: 13px; padding: 8px 12px; pointer-events: auto; }
/* 1-1 안내: 당기는 유령 손가락 */
.ghost { position: absolute; left: 56%; top: 44%; width: 0; height: 0; z-index: 2; pointer-events: none; }
.ghost-line { position: absolute; left: 0; top: -2px; width: 110px; height: 0; border-top: 4px dashed rgba(255, 247, 194, .9); transform-origin: 0 50%; transform: rotate(142deg) scaleX(0); animation: ghostLine 1.9s ease-in-out infinite; }
.ghost-dot { position: absolute; left: -17px; top: -17px; width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .55); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); animation: ghostDot 1.9s ease-in-out infinite; }
@keyframes ghostDot { 0% { transform: translate(0, 0) scale(1.25); opacity: 0; } 12% { transform: translate(0, 0) scale(1); opacity: 1; } 70% { transform: translate(-87px, 68px) scale(1); opacity: 1; } 86%, 100% { transform: translate(-87px, 68px) scale(1.3); opacity: 0; } }
@keyframes ghostLine { 0%, 12% { transform: rotate(142deg) scaleX(0); opacity: 1; } 70% { transform: rotate(142deg) scaleX(1); opacity: 1; } 86%, 100% { transform: rotate(142deg) scaleX(1); opacity: 0; } }
.range-bar label { display: flex; align-items: center; gap: 5px; flex: 1 1 110px; min-width: 0; white-space: nowrap; }
.range-bar input { flex: 1; min-width: 44px; accent-color: var(--accent); height: 28px; }
.range-bar b { min-width: 18px; text-align: right; }
.range-bar .btn.small { padding: 5px 8px; font-size: 12px; white-space: nowrap; flex: 0 0 auto; }
@media (max-width: 480px) { .range-bar { flex-wrap: nowrap; gap: 4px; padding: 5px 6px; } .range-bar .btn.small { padding: 5px 6px; } }

.hud { flex: 0 0 auto; background: var(--bg2); border-top: 1px solid var(--line); padding: 4px 8px calc(6px + var(--sab)); display: flex; flex-direction: column; gap: 4px; }
.hud.idle .aimrow, .hud.idle .walk, .hud.idle .fire, .hud.idle #passBtn { opacity: .4; pointer-events: none; }
.hud.nowalk .walk { opacity: .45; }
.aimrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; height: 48px; }
.stepper { display: grid; grid-template-columns: 46px 1fr 46px; align-items: stretch; gap: 4px; }
.step {
  min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 18px; font-weight: 700; padding: 0;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.step:active { background: #40634a; }
.val { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; border-radius: 12px; background: #16211a; border: 1px solid transparent; padding: 0; min-width: 0; }
.val.locked { border-color: var(--accent); background: #3a2d18; }
.val.locked small::after { content: ' 🔒'; }
.val small { font-size: 10px; }
.val b { font-size: 19px; font-variant-numeric: tabular-nums; }
.shellrow { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; height: 48px; align-items: stretch; overscroll-behavior-x: contain; }
.shellrow::-webkit-scrollbar { display: none; }
/* 칩이 넘칠 때: 더 있는 쪽 가장자리를 흐리게 (main.js가 more-l·more-r를 붙인다) */
.shellrow.more-r { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); }
.shellrow.more-l { -webkit-mask-image: linear-gradient(270deg, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(270deg, #000 calc(100% - 26px), transparent); }
.shellrow.more-l.more-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 26px, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(90deg, transparent, #000 26px, #000 calc(100% - 26px), transparent); }
.chip {
  flex: 0 0 auto; min-width: 56px; padding: 2px 8px 2px 4px; display: flex; align-items: center; gap: 2px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); font-size: 12px; font-weight: 700; white-space: nowrap;
}
.chip canvas { width: 34px; height: 34px; }
.chip.on { border-color: var(--accent); background: #4a3a20; }
.chip:disabled { opacity: .35; }
.chip .cn { color: var(--dim); min-width: 14px; text-align: center; }
.actrow { display: flex; gap: 8px; align-items: stretch; height: 64px; }
/* 좁은 화면: 걷기 ◁ ▷ 아래에 연료 막대를 얇게 깔아 보조 버튼 자리를 넓힌다 */
.walk { display: grid; grid-template-columns: 50px 50px; grid-template-rows: 1fr 14px; gap: 4px; align-items: stretch; }
#walkL { grid-area: 1 / 1; }
#walkR { grid-area: 1 / 2; }
.walk .fuel { grid-area: 2 / 1 / 3 / 3; border-radius: 7px; }
.walk .fuel small { font-size: 10px; line-height: 1; }
.fuel { position: relative; border-radius: 10px; background: #16211a; overflow: hidden; display: grid; place-items: center; }
.fuel i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(180deg, #7fc65a, #4f9a3a); width: 100%; }
.fuel small { position: relative; color: #fff; font-weight: 700; font-size: 12px; text-shadow: 0 1px 2px #000; }
.extra { flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.mini2 { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; font-weight: 700; padding: 0 2px; touch-action: none; user-select: none; -webkit-user-select: none; white-space: nowrap; }
.mini2.on, .mini2.armed { border-color: var(--accent); color: var(--accent); }
.fire {
  flex: 0 0 96px; border-radius: 16px; border: 0; font-size: 20px; font-weight: 800; color: #2b1a05;
  background: linear-gradient(180deg, #ffbf5a, var(--accent2)); box-shadow: 0 3px 0 #9a5a12; touch-action: manipulation;
}
.fire:active { transform: translateY(2px); box-shadow: 0 1px 0 #9a5a12; }
body.left-hand .actrow { flex-direction: row-reverse; }

/* PC·태블릿(너비 820px 이상, 높이 501px 이상): 두 줄 — 위 포탄 칩(전체 너비라 8종이 한눈에), 아래 걷기 · 보조 · 각도/세기 · 발사 */
@media (min-width: 820px) and (min-height: 501px) {
  .hud { display: grid; grid-template-columns: auto auto minmax(220px, 1fr) auto; grid-template-areas: 'shell shell shell shell' 'walk extra aim fire'; align-items: center; gap: 8px 12px; padding: 8px 16px calc(10px + var(--sab)); }
  .hud .actrow { display: contents; }
  .hud .walk { grid-area: walk; height: 60px; grid-template-columns: 48px 70px 48px; grid-template-rows: 1fr; }
  .hud #walkL { grid-area: 1 / 1; }
  .hud .walk .fuel { grid-area: 1 / 2; border-radius: 10px; }
  .hud #walkR { grid-area: 1 / 3; }
  .hud .walk .fuel small { font-size: 12px; }
  .hud .extra { grid-area: extra; display: grid; grid-template-columns: 44px 44px 64px; height: 60px; }
  .hud .aimrow { grid-area: aim; height: 60px; width: 100%; max-width: 460px; justify-self: center; }
  .hud .shellrow { grid-area: shell; height: 50px; }
  /* 자리가 남으면 가운데로, 넘치면 왼쪽부터 (가운데 정렬은 넘친 왼쪽이 잘리므로 양 끝 여백으로 맞춘다) */
  .hud .shellrow::before, .hud .shellrow::after { content: ''; margin: auto; }
  .hud .fire { grid-area: fire; flex: none; width: 120px; height: 64px; }
  .chip { min-width: 66px; }
}
/* 아주 넓은 화면(1500px 이상): 한 줄로 (걷기 · 보조 · 각도/세기 · 포탄 · 발사) — 칩 8개(570px)가 다 들어간다 */
@media (min-width: 1500px) and (min-height: 501px) {
  .hud { grid-template-columns: auto auto minmax(300px, 380px) minmax(0, 1fr) auto; grid-template-areas: 'walk extra aim shell fire'; gap: 12px; padding: 12px 16px; height: 96px; }
  .hud .aimrow { max-width: none; }
  .hud .shellrow { height: 60px; }
}
@media (min-width: 820px) { .top-title { font-size: 16px; } }
/* 마우스로 쓰는 화면: 칩 줄이 넘치면 얇은 스크롤 막대를 보여 준다 (휠·끌기로도 넘긴다) */
@media (hover: hover) and (pointer: fine) {
  .shellrow { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
}

/* ───── 창 ───── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(10, 16, 12, .72); display: grid; place-items: center; padding: 14px; overflow-y: auto; }
.box { width: min(100%, 460px); background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100dvh - 28px); overflow-y: auto; }
.box.small { width: min(100%, 340px); text-align: center; }
.box h2 { font-size: 20px; }
.box .big-stars { font-size: 40px; letter-spacing: 6px; color: #58705c; text-align: center; line-height: 1; }
.box .big-stars b { color: var(--star); font-weight: 400; }
.rule { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--dim); }
.rule.got { color: var(--text); }
.rule i { font-style: normal; color: #58705c; }
.rule.got i { color: var(--star); }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.kv div { background: var(--panel); border-radius: 10px; padding: 8px 4px; }
.kv b { display: block; font-size: 18px; color: var(--accent); }
.kv span { font-size: 12px; color: var(--dim); }
.bag { display: flex; flex-wrap: wrap; gap: 6px; }
.bag span { display: inline-flex; align-items: center; gap: 2px; padding: 2px 9px 2px 3px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.bag canvas { width: 26px; height: 26px; }
.newshell { padding: 8px 10px; border-radius: 12px; background: #4a3a20; border: 1px solid #7a5a2a; font-size: 13px; }
.box .thumb { flex: 0 0 auto; }
.foes { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.foe { display: flex; flex-direction: column; align-items: center; font-size: 13px; line-height: 1.3; }
.foe .face { width: 64px; height: 64px; }
.foe.ally b { color: #ffb0a8; }
.cond { font-size: 13px; font-weight: 700; color: #9fd6ff; }
.unlock { text-align: center; font-weight: 700; color: var(--leaf); }
.big-stars.pop b { display: inline-block; animation: starPop .5s cubic-bezier(.3, 1.6, .5, 1) backwards; }
.big-stars.pop b:nth-of-type(2) { animation-delay: .2s; }
.big-stars.pop b:nth-of-type(3) { animation-delay: .4s; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
.rank { display: grid; grid-template-columns: 44px 16px 1fr; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 12px; background: var(--panel); border: 1px solid transparent; }
.rank.got { border-color: var(--star); }
.rank i { font-style: normal; text-align: center; }
.rank b { display: block; font-size: 14px; }
.rank span { font-size: 12px; color: var(--dim); }
.pause-opts { text-align: left; padding: 4px 10px; border-radius: 12px; background: var(--panel); }
.pause-opts .check { min-height: 36px; font-size: 13px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 13px; color: var(--dim); }
#quitBtn.armed { border-color: var(--danger); color: var(--danger); }
.help { display: flex; flex-direction: column; gap: 8px; font-size: 14px; min-height: 250px; }
.help h3 { font-size: 14px; color: var(--leaf); margin-top: 4px; }
.help ul { margin: 0; padding-left: 18px; color: var(--dim); }
.help li b { color: var(--text); }
.help table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help td { padding: 3px 4px; border-top: 1px solid var(--line); vertical-align: middle; color: var(--dim); }
.help td:first-child { width: 30px; }
.help td canvas { width: 26px; height: 26px; display: block; }
.help td b { color: var(--text); white-space: nowrap; }
.err { margin: 0; max-height: 90px; overflow: auto; text-align: left; font-size: 11px; color: var(--dim); background: #16211a; border-radius: 8px; padding: 8px; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 380px) {
  .back-txt { display: none; }
  .fire { flex-basis: 80px; }
}
@media (max-height: 620px) and (max-width: 819px) {
  .aimrow, .shellrow { height: 44px; }
  .actrow { height: 58px; }
}
/* 낮은 가로 화면(가로로 든 휴대폰): 두 줄 — 위 각도/세기 + 포탄 칩, 아래 걷기 · 보조 · 발사 */
@media (max-height: 500px) and (min-width: 560px) {
  .hud { display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); grid-template-areas: 'aim shell' 'act act'; gap: 4px 8px; padding: 4px 8px calc(4px + var(--sab)); }
  .hud .aimrow { grid-area: aim; height: 44px; }
  .hud .shellrow { grid-area: shell; height: 44px; }
  .hud .actrow { grid-area: act; height: 46px; }
  .hud .walk { grid-template-columns: 56px 56px 70px; grid-template-rows: 1fr; }
  .hud #walkL { grid-area: 1 / 1; }
  .hud #walkR { grid-area: 1 / 2; }
  .hud .walk .fuel { grid-area: 1 / 3; border-radius: 10px; }
  .hud .walk .fuel small { font-size: 12px; }
  .hud .fire { flex-basis: 150px; }
  .status { height: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  .first-shot, .banner, .toast, .big-stars.pop b, .wind.flip { animation: none; }
  .ghost-dot, .ghost-line { animation-duration: 4s; }
}
