:root {
  --bg: #071a2c; --panel: #102a40; --panel2: #17364f; --line: rgba(125, 211, 252, 0.18);
  --text: #eef7ff; --dim: #93b2c9; --accent: #38bdf8; --accent2: #bae6fd; --bad: #f87171; --gold: #facc15; --ok: #4ade80;
  --r: 16px;
  /* 판 꾸미기 */
  --sea: #1d6fa5; --sea2: #185f8f; --grid: rgba(255, 255, 255, 0.13); --frame: #0b3557; --isl: #c9a66b; --isl2: #6b8f3a;
  --ship: #94a3b8; --ship2: #64748b; --miss: rgba(255, 255, 255, 0.75); --hit: #f97316; --sunk: #7f1d1d; --clr: rgba(255, 255, 255, 0.1); --lbl: #93c5fd;
}
body.t-sunset { --sea: #7c3a62; --sea2: #6a2f55; --frame: #3b1530; --grid: rgba(255, 220, 200, 0.16); --ship: #fcd9b6; --ship2: #c2876a; --lbl: #fbcfe8; }
body.t-night { --sea: #0f1d3d; --sea2: #0b1631; --frame: #050b1c; --grid: rgba(147, 197, 253, 0.16); --ship: #64748b; --ship2: #334155; --miss: rgba(191, 219, 254, 0.7); --lbl: #a5b4fc; }
body.t-arctic { --sea: #a9d6ea; --sea2: #94c8df; --frame: #4b7f99; --grid: rgba(15, 50, 80, 0.2); --isl: #f8fafc; --isl2: #cbd5e1; --ship: #334155; --ship2: #1e293b; --miss: rgba(15, 40, 70, 0.6); --clr: rgba(15, 50, 80, 0.1); --lbl: #e0f2fe; }
body.t-radar { --sea: #04210f; --sea2: #031a0c; --frame: #021008; --grid: rgba(74, 222, 128, 0.28); --isl: #166534; --isl2: #14532d; --ship: #22c55e; --ship2: #15803d; --miss: rgba(134, 239, 172, 0.75); --hit: #facc15; --lbl: #86efac; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #0f3a5e 0%, var(--bg) 60%, #030b14 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.3); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.22); }
.total { margin-left: auto; font-weight: 800; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.screen > * { max-width: 680px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 2px auto 12px; }
.logo-art { display: inline-flex; gap: 2px; padding: 6px 10px; border-radius: 12px; background: #1d6fa5; font-size: 1.6rem; }
.logo-art .sh { animation: bob 2.4s ease-in-out infinite; }
.logo-art .bm { animation: boom 3s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-3px) rotate(3deg); } }
@keyframes boom { 0%, 60%, 100% { transform: scale(0.6); opacity: 0.2; } 70% { transform: scale(1.2); opacity: 1; } }
h1 { margin: 10px 0 2px; font-size: 1.6rem; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tab { padding: 9px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #04263b; border-color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.btn { padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 800; }
.btn.go { background: var(--accent); color: #04263b; border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.continue {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 12px;
  border-radius: var(--r); border: 1px solid rgba(56, 189, 248, 0.5); background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(56, 189, 248, 0.05));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #04263b; }
.continue b { display: block; } .continue small { color: var(--dim); }
.sea-h { display: flex; align-items: baseline; gap: 8px; margin: 14px 2px 6px; }
.sea-h b { font-size: 1.02rem; } .sea-h small { color: var(--dim); }
.mission {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 8px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
}
.mission .mi { font-size: 1.8rem; width: 40px; text-align: center; flex: none; }
.mission .mt { flex: 1; min-width: 0; }
.mission .mt b { display: block; } .mission .mt small { color: var(--dim); font-size: 0.75rem; }
.mission .ms { color: var(--gold); font-size: 0.95rem; letter-spacing: 1px; white-space: nowrap; }
.mission.lock { opacity: 0.45; }
.mission.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chip { font-style: normal; font-size: 0.68rem; padding: 1px 6px; border-radius: 999px; background: var(--panel2); color: var(--accent2); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 8px 0; }
.kpis div { background: var(--panel2); border-radius: 12px; padding: 8px 2px; }
.kpis b { display: block; font-size: 1.2rem; } .kpis small { color: var(--dim); font-size: 0.72rem; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal span { aspect-ratio: 1; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; font-size: 0.7rem; color: var(--dim); }
.cal .w { background: #1d6fa5; color: #fff; font-weight: 800; } .cal .t { outline: 2px solid var(--accent); }
.seg { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 10px; }
.seg button { flex: 1; min-width: 56px; padding: 8px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; font-size: 0.82rem; }
.seg button.on { background: var(--accent); color: #04263b; border-color: var(--accent); }
.lbl { font-size: 0.8rem; color: var(--dim); margin-top: 6px; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach div { background: var(--panel2); border-radius: 10px; padding: 8px; font-size: 0.78rem; opacity: 0.45; }
.ach div.got { opacity: 1; border: 1px solid rgba(250, 204, 21, 0.4); }
.ach b { display: block; font-size: 0.85rem; }
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.themes button { padding: 8px 2px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.75rem; font-weight: 700; }
.themes button.on { outline: 2px solid var(--accent); }
.themes i { display: block; height: 22px; border-radius: 6px; margin-bottom: 4px; }
.opt { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.opt button { min-width: 64px; }

/* ── 배치·전투 공통 ── */
#place, #battle { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
.p-head { display: flex; align-items: center; gap: 10px; max-width: 900px; width: 100%; margin: 0 auto 4px; }
.p-title { flex: 1; min-width: 0; }
.p-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title small { color: var(--dim); font-size: 0.78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shots { font-weight: 800; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; white-space: nowrap; }
.board-wrap { position: relative; display: flex; justify-content: center; }
.board {
  display: grid; gap: 1px; background: var(--grid); padding: 1px; border-radius: 8px; border: 3px solid var(--frame);
  touch-action: manipulation; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
.cell { position: relative; background: var(--sea); display: grid; place-items: center; font-weight: 800; overflow: visible; }
.cell.alt { background: var(--sea2); }
.cell.lab { background: transparent !important; color: var(--lbl); font-size: 0.62em; opacity: 0.8; }
.cell.isl { background: radial-gradient(circle at 40% 40%, var(--isl2) 0 35%, var(--isl) 36% 100%) !important; }
.cell.ship::before { content: ''; position: absolute; inset: 12%; background: linear-gradient(160deg, var(--ship), var(--ship2)); border-radius: 2px; }
.cell.ship.el::before { left: 6%; border-top-left-radius: 50%; border-bottom-left-radius: 50%; }
.cell.ship.er::before { right: 6%; border-top-right-radius: 50%; border-bottom-right-radius: 50%; }
.cell.ship.et::before { top: 6%; border-top-left-radius: 50%; border-top-right-radius: 50%; }
.cell.ship.eb::before { bottom: 6%; border-bottom-left-radius: 50%; border-bottom-right-radius: 50%; }
.cell.ship.h:not(.el)::before { left: -1px; } .cell.ship.h:not(.er)::before { right: -1px; }
.cell.ship.v:not(.et)::before { top: -1px; } .cell.ship.v:not(.eb)::before { bottom: -1px; }
.cell.ship.sk::before { background: linear-gradient(160deg, #7f1d1d, #3f0d0d); }
.cell.miss::after { content: ''; width: 26%; height: 26%; border-radius: 50%; background: var(--miss); }
.cell.hit::after, .cell.sk::after { content: ''; position: relative; width: 56%; height: 56%; border-radius: 50%; background: radial-gradient(circle, #fde047 0 25%, var(--hit) 45%, rgba(220, 38, 38, 0.6) 70%, transparent 72%); }
.cell.sk::after { background: radial-gradient(circle, #f87171 0 22%, #7f1d1d 55%, transparent 60%); }
.cell.clr { box-shadow: inset 0 0 0 100px var(--clr); }
.cell.clr::after { content: '·'; color: var(--miss); opacity: 0.6; }
.cell.mk { color: #fff; text-shadow: 0 1px 2px #000; }
.cell.mk span { position: relative; z-index: 2; background: rgba(56, 189, 248, 0.85); border-radius: 50%; width: 1.5em; height: 1.5em; display: grid; place-items: center; font-size: 0.8em; }
.cell.last { outline: 2px solid #fde047; outline-offset: -2px; z-index: 1; }
.cell.reveal::before { opacity: 0.55; }
.cell.ghost { box-shadow: inset 0 0 0 100px rgba(255, 255, 255, 0.35); }
.cell.ghost.no { box-shadow: inset 0 0 0 100px rgba(248, 113, 113, 0.45); }
.cell.sel::before { outline: 2px solid #fde047; }
.cell.aim { box-shadow: inset 0 0 0 100px rgba(253, 224, 71, 0.25); }
.cell.boom::after { animation: boom2 0.45s ease-out; }
@keyframes boom2 { 0% { transform: scale(0.2); } 60% { transform: scale(1.5); } 100% { transform: scale(1); } }
.cell.drop::after { animation: drop 0.35s ease-out; }
@keyframes drop { 0% { transform: scale(2.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#foeBoard .cell:not(.lab):not(.isl):not(.miss):not(.hit):not(.sk) { cursor: crosshair; }
.board.busy .cell { cursor: wait !important; }
.board.shake { animation: shake 0.35s; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translate(-3px, 1px); } 50% { transform: translate(3px, -1px); } 75% { transform: translate(-2px, 0); } }

.toast { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #f1f5f9; color: #0f172a; padding: 8px 14px; border-radius: 10px; font-weight: 800; font-size: 0.88rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); z-index: 3; max-width: calc(100% - 24px); text-align: center; pointer-events: none; }
.toast.bad { background: #fee2e2; color: #7f1d1d; }
.toast.good { background: #fef9c3; color: #713f12; }

/* 배치 */
.dock { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 4px auto 8px; max-width: 900px; }
.dock button { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 0.8rem; font-weight: 700; }
.dock button i { display: inline-flex; gap: 1px; }
.dock button i b { width: 9px; height: 9px; border-radius: 2px; background: var(--ship); }
.dock button.on { border-color: #fde047; box-shadow: 0 0 0 1px #fde047 inset; }
.dock button.done { opacity: 0.5; }
#plWrap { flex: 1; align-items: center; min-height: 0; }
.ctrl { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.cbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 70px; padding: 8px 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 1.1rem; }
.cbtn span { font-size: 0.72rem; font-weight: 700; color: var(--dim); }
.cbtn.go:not(:disabled) { background: var(--accent); color: #04263b; border-color: var(--accent); }
.cbtn.go:not(:disabled) span { color: #04263b; }

/* 전투 */
.status { text-align: center; font-weight: 800; padding: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); max-width: 900px; width: 100%; margin: 0 auto 6px; font-size: 0.92rem; }
.status.ai { background: rgba(248, 113, 113, 0.15); border-color: rgba(248, 113, 113, 0.4); }
.status.me { background: rgba(56, 189, 248, 0.15); border-color: rgba(56, 189, 248, 0.45); }
.arena { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.arena.wide { flex-direction: row; justify-content: center; align-items: flex-start; gap: 18px; }
.side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.side.me { flex-direction: row; align-items: flex-start; gap: 8px; }
.arena.wide .side.me { flex-direction: column; align-items: center; }
.fleet { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; font-size: 0.72rem; }
.side.me .fleet { flex-direction: column; flex-wrap: nowrap; align-items: flex-start; }
.arena.wide .side.me .fleet { flex-direction: row; flex-wrap: wrap; }
.fleet span { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); white-space: nowrap; }
.fleet span i { display: inline-flex; gap: 1px; font-style: normal; }
.fleet span i b { width: 6px; height: 6px; border-radius: 1px; background: var(--ship); }
.fleet span i b.x { background: var(--hit); }
.fleet span.dead { opacity: 0.45; text-decoration: line-through; }
.items { display: flex; gap: 6px; justify-content: center; }
.item { display: flex; align-items: center; gap: 5px; padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1rem; }
.item span { font-size: 0.78rem; font-weight: 700; }
.item.on { background: var(--accent); color: #04263b; border-color: var(--accent); }
.board.small .cell.lab { font-size: 0.55em; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(2, 8, 16, 0.72); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.25rem; }
.modal-box p { line-height: 1.5; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal-btns .btn { flex: 1; white-space: nowrap; padding: 10px 8px; }
.big-stars { color: var(--gold); text-align: center; font-size: 2.2rem; letter-spacing: 6px; margin: 4px 0; }
.big-stars .off { opacity: 0.2; }
.res-line { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.quote { background: var(--panel2); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; }
.opp { text-align: center; font-size: 3rem; }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #020a12; padding: 8px; border-radius: 8px; white-space: pre-wrap; color: #fecaca; max-height: 140px; overflow: auto; user-select: text; -webkit-user-select: text; }
.ach-pop { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #fef9c3; color: #713f12; padding: 10px 16px; border-radius: 14px; font-weight: 800; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4); z-index: 20; animation: pop 0.3s ease-out; max-width: calc(100% - 32px); }
@keyframes pop { from { transform: translate(-50%, 20px); opacity: 0; } }
.noscript { padding: 20px; text-align: center; }
@media (max-width: 420px) {
  .back-txt { display: none; }
  .cbtn { min-width: 60px; padding: 7px 6px; }
  .item { padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
