/* 대양 항해일지 */
:root {
  --ink: #eaf3fb; --muted: #a9bfd3; --panel: rgba(9, 24, 40, 0.86); --line: rgba(160, 200, 235, 0.25);
  --accent: #ffb340; --accent2: #3fb6ff; --good: #5ad19a; --bad: #ff6b5a;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #06121f; color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

.home-btn { position: fixed; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); z-index: 60; padding: 7px 12px; border-radius: 999px;
  background: rgba(6, 18, 31, 0.65); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 13px; backdrop-filter: blur(6px); }
.home-btn:hover { background: rgba(20, 50, 80, 0.8); }

/* 화면 */
.screen { position: fixed; inset: 0; z-index: 40; display: flex; }
.screen[hidden] { display: none !important; }
.center { align-items: center; justify-content: center; }
.panel-screen { align-items: center; justify-content: center; background: rgba(3, 10, 18, 0.45); backdrop-filter: blur(2px); padding: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; width: min(560px, 100%); max-height: calc(100% - 20px); overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45); }
.panel.wide { width: min(760px, 100%); }
.panel.narrow { width: min(400px, 100%); }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; font-size: 20px; flex: 1; }
.x { background: none; border: 0; font-size: 20px; color: var(--muted); padding: 4px 8px; }
.muted { color: var(--muted); line-height: 1.5; margin: 6px 0; }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row.end { justify-content: flex-end; }

.btn { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(30, 64, 98, 0.7); color: var(--ink); font-size: 16px; font-weight: 600; text-decoration: none; text-align: left; }
.btn small { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.btn:hover { background: rgba(48, 92, 136, 0.85); }
.btn.primary { background: linear-gradient(180deg, #ffbe55, #f08b1f); color: #241302; border-color: #ffd28a; }
.btn.primary small { color: #5a3608; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.sm { padding: 7px 12px; font-size: 14px; align-items: center; }

/* 불러오기 */
#loading { background: radial-gradient(ellipse at 50% 30%, #12406a, #06121f 70%); }
.load-box { text-align: center; }
.load-icon { font-size: 56px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
.load-bar { width: 240px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; margin: 10px auto 0; }
.load-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* 타이틀 */
#title { align-items: flex-end; justify-content: flex-start; padding: calc(60px + var(--safe-t)) 24px calc(28px + var(--safe-b)) calc(36px + var(--safe-l));
  background: linear-gradient(90deg, rgba(3, 12, 22, 0.75) 0%, rgba(3, 12, 22, 0.35) 40%, transparent 70%); }
.title-wrap { max-width: 440px; }
.logo { font-size: clamp(38px, 7vw, 62px); margin: 0 0 4px; letter-spacing: -1px; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5); font-weight: 800; }
.logo span { color: var(--accent); }
.tagline { margin: 0 0 18px; color: #d8e6f3; font-size: 16px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.menu { display: flex; flex-direction: column; gap: 9px; }
.menu .btn { width: 100%; }
.save-info { color: var(--muted); font-size: 13px; margin-top: 12px; text-shadow: 0 1px 6px #000; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud[hidden] { display: none; }
#hud button, #hud canvas#minimap, #hud .touch > * { pointer-events: auto; }
.top-info { position: absolute; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 56vw; }
.chip { padding: 5px 11px; border-radius: 999px; background: rgba(6, 18, 31, 0.6); border: 1px solid var(--line); font-size: 13.5px; white-space: nowrap; backdrop-filter: blur(6px); }
.chip:empty { display: none; }
.chip.gold { color: #ffd27a; }
.objective { position: absolute; top: calc(46px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(480px, 58vw); padding: 9px 13px;
  border-radius: 12px; background: rgba(6, 18, 31, 0.7); border: 1px solid var(--line); font-size: 14px; line-height: 1.45; backdrop-filter: blur(6px); }
.objective b { color: var(--accent); }
.objective .prog { float: right; color: var(--muted); font-size: 12px; }
.objective .sub { color: var(--muted); font-size: 12.5px; }
.hud-btns { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; gap: 6px; }
.hud-btns button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(6, 18, 31, 0.6); font-size: 17px; backdrop-filter: blur(6px); }
#gauge { position: absolute; top: calc(56px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 176px; height: 176px; }
#minimap { position: absolute; bottom: calc(14px + var(--safe-b)); left: calc(14px + var(--safe-l)); width: 180px; height: 180px; border-radius: 50%; cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4); }
.speed-box { position: absolute; bottom: calc(14px + var(--safe-b)); right: calc(14px + var(--safe-r)); padding: 10px 14px; border-radius: 14px; background: rgba(6, 18, 31, 0.62);
  border: 1px solid var(--line); min-width: 170px; backdrop-filter: blur(6px); }
.speed-box b { font-size: 34px; font-variant-numeric: tabular-nums; }
.speed-box small { margin-left: 4px; color: var(--muted); }
.mini-bars { margin-top: 4px; display: grid; gap: 4px; }
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.bar-row span { width: 26px; }
.bar { flex: 1; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); overflow: hidden; position: relative; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent2); }
.bar.heel i { background: var(--good); }
.bar.heel.warn i { background: var(--bad); }
.sail-state { font-size: 12.5px; margin-top: 5px; color: #ffd27a; min-height: 16px; }
.dock-btn { position: absolute; bottom: calc(210px + var(--safe-b)); left: 50%; transform: translateX(-50%); padding: 12px 22px; border-radius: 999px;
  border: 1px solid #ffd28a; background: linear-gradient(180deg, #ffbe55, #f08b1f); color: #241302; font-weight: 700; font-size: 17px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); }
.dock-btn[hidden] { display: none; }
.center-msg { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: clamp(36px, 9vw, 84px); font-weight: 800; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none; opacity: 0; transition: opacity 0.25s; }
.center-msg.show { opacity: 1; }
.center-msg small { display: block; font-size: 18px; font-weight: 600; opacity: 0.9; }
.toasts { position: absolute; top: calc(130px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(460px, 70vw); }
.toast { padding: 8px 14px; border-radius: 10px; background: rgba(6, 18, 31, 0.82); border: 1px solid var(--line); font-size: 14px; animation: tin 0.25s ease-out; text-align: center; }
.toast.good { border-color: rgba(90, 209, 154, 0.6); }
.toast.warn { border-color: rgba(255, 107, 90, 0.7); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }
.keys-help { position: absolute; bottom: calc(14px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--muted); background: rgba(6, 18, 31, 0.5);
  padding: 5px 10px; border-radius: 8px; white-space: nowrap; }

/* 터치 조작 */
.touch { display: none; }
body.touch-ui .touch { display: block; }
body.touch-ui .keys-help { display: none; }
.wheel { position: absolute; left: calc(18px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); width: 136px; height: 136px; border-radius: 50%;
  background: radial-gradient(circle, rgba(6, 18, 31, 0.15) 30%, rgba(6, 18, 31, 0.55) 31%, rgba(6, 18, 31, 0.55) 60%, rgba(6, 18, 31, 0.2) 61%); border: 2px solid rgba(220, 180, 120, 0.7); touch-action: none; }
.wheel-inner { position: absolute; inset: 8px; border-radius: 50%; border: 6px solid #b07a42; transition: transform 0.05s; }
.wheel-inner i { position: absolute; left: 50%; top: -14px; width: 8px; height: 22px; margin-left: -4px; background: #c68e52; border-radius: 4px; transform-origin: 4px 66px; }
.wheel-inner i:nth-child(2) { transform: rotate(90deg); } .wheel-inner i:nth-child(3) { transform: rotate(180deg); } .wheel-inner i:nth-child(4) { transform: rotate(270deg); }
.wheel-inner i:first-child { background: #ffb340; }
.wheel-inner span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; color: #f3d9b5; }
.sheet-ctl { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); display: flex; gap: 8px; align-items: flex-end; }
.sheet-track { position: relative; width: 54px; height: 190px; border-radius: 27px; background: rgba(6, 18, 31, 0.55); border: 2px solid rgba(160, 200, 235, 0.5); touch-action: none; overflow: hidden; }
.sheet-fill { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(0deg, rgba(63, 182, 255, 0.15), rgba(63, 182, 255, 0.55)); }
.sheet-knob { position: absolute; left: 4px; right: 4px; height: 30px; border-radius: 15px; background: #eaf3fb; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }
.sheet-track .lbl { position: absolute; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); z-index: 1; }
.sheet-track .lbl.top { top: 6px; } .sheet-track .lbl.bot { bottom: 6px; }
.auto-btn { width: 50px; height: 50px; border-radius: 12px; border: 1px solid var(--line); background: rgba(6, 18, 31, 0.6); font-size: 11.5px; line-height: 1.15; }
.auto-btn.on { background: rgba(63, 182, 255, 0.55); border-color: #9fd8ff; }
body.touch-ui .speed-box { right: auto; left: calc(14px + var(--safe-l)); bottom: calc(176px + var(--safe-b)); min-width: 0; max-width: 46vw; padding: 6px 11px; }
body.touch-ui .sail-state { font-size: 11.5px; }
body.touch-ui .speed-box b { font-size: 24px; }
body.touch-ui .mini-bars { width: 118px; }
body.touch-ui #minimap { bottom: auto; top: calc(56px + var(--safe-t)); left: calc(10px + var(--safe-l)); width: 112px; height: 112px; }
body.touch-ui #gauge { width: 122px; height: 122px; }
body.touch-ui .dock-btn { bottom: calc(306px + var(--safe-b)); font-size: 15px; white-space: nowrap; padding: 10px 18px; }

/* 레이스 목록 */
.race-list { display: grid; gap: 10px; margin-top: 10px; }
.race-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: rgba(20, 44, 70, 0.6); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.race-card h3 { margin: 0; font-size: 16px; }
.race-card p { margin: 0; color: var(--muted); font-size: 13px; grid-column: 1; }
.race-card .stars { color: #ffd27a; letter-spacing: 2px; }
.race-card .btn { grid-row: 1 / span 3; grid-column: 2; }

/* 항구 */
.deliver:empty { display: none; }
.deliver { background: rgba(90, 209, 154, 0.14); border: 1px solid rgba(90, 209, 154, 0.5); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 14px; line-height: 1.5; }
.tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.tab { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; font-size: 14px; }
.tab.on { background: rgba(63, 182, 255, 0.3); border-color: #9fd8ff; }
.tab[hidden] { display: none; }
.tab-body[hidden] { display: none; }
.job { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 7px; background: rgba(20, 44, 70, 0.5); }
.job .ic { font-size: 24px; }
.job .t { font-weight: 600; }
.job .d { color: var(--muted); font-size: 12.5px; }
.job .pay { color: #ffd27a; font-weight: 700; text-align: right; }
.sec-title { margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
.upg { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 7px; align-items: center; }
.pips { color: var(--accent); letter-spacing: 2px; }
.boats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.boat-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: rgba(20, 44, 70, 0.5); display: flex; flex-direction: column; gap: 5px; }
.boat-card.cur { border-color: var(--accent); }
.boat-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.log-list { font-size: 13.5px; line-height: 1.6; max-height: 320px; overflow: auto; }
.log-list li { margin-bottom: 3px; }

/* 해도 */
.chart-panel { width: min(720px, 100%); }
#chartCanvas { width: 100%; aspect-ratio: 1; border-radius: 10px; display: block; }

/* 설정 */
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.set-row select, .set-row input[type=range] { background: #12304e; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font: inherit; }
.set-row input[type=checkbox] { width: 20px; height: 20px; }

/* 결과 */
.res-body { font-size: 15px; line-height: 1.6; margin-bottom: 12px; }
.res-body .big { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.res-body .stars { font-size: 30px; color: #ffd27a; letter-spacing: 4px; }
.res-body .new { color: var(--good); font-weight: 700; }

/* 세로·작은 화면 */
@media (max-width: 720px) {
  .top-info { max-width: 60vw; top: calc(52px + var(--safe-t)); }
  .objective { top: calc(88px + var(--safe-t)); width: min(420px, 62vw); font-size: 13px; padding: 7px 10px; }
  .toasts { top: calc(170px + var(--safe-t)); }
  .hud-btns button { width: 34px; height: 34px; font-size: 15px; }
  .chip { font-size: 12px; padding: 4px 9px; }
  #title { align-items: flex-end; padding: 70px 16px calc(20px + var(--safe-b)); background: linear-gradient(0deg, rgba(3, 12, 22, 0.85) 0%, rgba(3, 12, 22, 0.4) 55%, transparent 80%); }
  .title-wrap { max-width: none; width: 100%; }
  .btn { font-size: 15px; padding: 10px 14px; }
}
@media (max-width: 720px) and (orientation: portrait) {
  body.touch-ui #gauge { top: calc(52px + var(--safe-t)); }
  /* 세로 화면: 목표 카드는 미니맵과 나침반 사이, 상태 칩은 그 아래 한 줄 */
  .objective { top: calc(54px + var(--safe-t)); width: calc(100vw - 268px); min-width: 140px; }
  .top-info { top: calc(184px + var(--safe-t)); max-width: 96vw; flex-wrap: nowrap; }
  .toasts { top: calc(222px + var(--safe-t)); width: 86vw; }
}
@media (max-height: 500px) and (orientation: landscape) {
  body.touch-ui .speed-box { left: 50%; transform: translateX(-50%); bottom: calc(8px + var(--safe-b)); max-width: 40vw; }
  body.touch-ui .dock-btn { bottom: calc(100px + var(--safe-b)); }
  .sheet-track { height: 140px; }
  .sheet-ctl { bottom: calc(80px + var(--safe-b)); }
  .wheel { width: 112px; height: 112px; }
  .wheel-inner i { transform-origin: 4px 54px; }
  body.touch-ui #gauge { width: 100px; height: 100px; }
  .objective { top: calc(44px + var(--safe-t)); }
}
