:root {
  --ink: #f6f1e6;
  --ink-soft: #d9e6e3;
  --muted: #a9c0bd;
  --glass: rgba(10, 34, 41, .58);
  --glass-strong: rgba(9, 29, 35, .86);
  --line: rgba(255, 255, 255, .16);
  --accent: #ffd38a;
  --accent-ink: #2a1f0c;
  --sea: #3fb7c4;
  --shadow: 0 10px 30px rgba(0, 18, 24, .28);
  --radius: 14px;
  --serif: "Noto Serif KR", "Nanum Myeongjo", serif;
  --sans: "Pretendard", "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0d2a33; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.stage { position: fixed; inset: 0; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
/* Soft scrims keep the type readable over a bright sky or white sand. */
.stage::before, .stage::after { content: ''; position: absolute; left: 0; right: 0; z-index: 2; pointer-events: none; }
.stage::before { top: 0; height: 170px; background: linear-gradient(to bottom, rgba(5, 26, 33, .5), rgba(5, 26, 33, 0)); }
.stage::after { bottom: 0; height: 190px; background: linear-gradient(to top, rgba(5, 26, 33, .5), rgba(5, 26, 33, 0)); }

/* ---- Loading veil ---- */
.veil { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; text-align: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 110%, #f4c98a 0%, #e48f6a 22%, #6f6c8c 48%, #1d3f55 72%, #0d2a33 100%); transition: opacity 1.2s ease, visibility 1.2s; }
.veil.done { opacity: 0; visibility: hidden; }
.veil-kicker { letter-spacing: .32em; font-size: 12px; color: #ffe7c2; margin: 0 0 14px; }
.veil-title { font-family: var(--serif); font-weight: 700; font-size: clamp(34px, 7vw, 64px); margin: 0; letter-spacing: -.01em; text-shadow: 0 4px 30px rgba(0, 0, 0, .25); }
.veil-sub { margin: 12px 0 34px; color: #f7e9d6; font-size: clamp(15px, 2.4vw, 18px); }
.veil-bar { width: min(280px, 70vw); height: 2px; margin: 0 auto; background: rgba(255, 255, 255, .22); border-radius: 2px; overflow: hidden; }
.veil-bar span { display: block; height: 100%; width: 40%; background: #fff4de; border-radius: 2px; animation: slide 1.6s ease-in-out infinite; }
.veil-step { margin: 14px 0 0; font-size: 13px; color: #f3e2cc; min-height: 1.4em; }
.veil.failed .veil-bar { display: none; }
@keyframes slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

/* ---- Brand ---- */
.brand { position: absolute; top: max(18px, env(safe-area-inset-top)); left: var(--gutter); z-index: 5; pointer-events: none; text-shadow: 0 2px 14px rgba(0, 25, 32, .55); }
.brand-kicker { margin: 0; font-size: 11px; letter-spacing: .26em; color: var(--ink-soft); }
.brand-title { margin: 4px 0 2px; font-family: var(--serif); font-weight: 500; font-size: clamp(22px, 3vw, 34px); line-height: 1.15; }
.brand-title em { font-style: normal; font-weight: 700; }
.brand-place { margin: 0; font-size: 14px; color: var(--ink-soft); transition: opacity .4s; }

/* ---- Controls ---- */
.top-tools { position: absolute; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); z-index: 6; display: flex; gap: 8px; align-items: center; }
.pill, .icon-btn, .chip, .place-row button, .place-row select, .field select { border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); box-shadow: var(--shadow); cursor: pointer; }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 999px; font-size: 14px; max-width: 46vw; }
#weather-short { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#weather-mini { display: none; font-weight: 600; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sea); box-shadow: 0 0 0 3px rgba(63, 183, 196, .25); flex: none; }
.pill.off .dot { background: #8a9b99; box-shadow: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path:first-child { fill: currentColor; stroke: none; }
#drawer-btn svg path:first-child, #drawer-close svg path:first-child, #places-close svg path:first-child { fill: none; stroke: currentColor; }
#sound-btn .wave { opacity: .25; }
#sound-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
#sound-btn[aria-pressed="true"] .wave { opacity: 1; }
#sound-btn.waiting { animation: sound-wait 1.8s ease-in-out infinite; }   /* on, waiting for the first touch to be allowed to play */
@keyframes sound-wait { 50% { box-shadow: 0 0 0 7px rgba(255, 255, 255, .18); } }
@media (prefers-reduced-motion: reduce) { #sound-btn.waiting { animation: none; } }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; padding: 0 var(--gutter) max(30px, calc(env(safe-area-inset-bottom) + 26px)); display: grid; gap: 10px; justify-items: center; pointer-events: none; }
.dock > * { pointer-events: auto; }
/* Places: a panel opened from the '장소' button (top right), the shortcuts grouped by area. Closed by default so the scene stays clear. */
.places-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.places-btn[aria-expanded="true"] { background: var(--ink); color: #12333b; border-color: transparent; }
.places { position: absolute; z-index: 8; top: calc(max(16px, env(safe-area-inset-top)) + 50px); right: max(16px, env(safe-area-inset-right)); width: min(440px, calc(100vw - 2 * var(--gutter))); max-height: calc(100% - max(16px, env(safe-area-inset-top)) - 190px); overflow-y: auto; overscroll-behavior: contain;
  padding: 6px 16px 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--glass-strong); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: 0 18px 50px rgba(0, 18, 24, .45); animation: places-in .18s ease-out; }
.places[hidden] { display: none; }
@keyframes places-in { from { opacity: 0; transform: translateY(-6px); } }
.places-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 4px; }
.places-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.places-head .icon-btn { width: 34px; height: 34px; box-shadow: none; background: rgba(255, 255, 255, .08); border-color: transparent; color: var(--ink); }
.place-group { padding: 10px 0 2px; border-top: 1px solid var(--line); }
.place-group:first-child { border-top: 0; }
.place-group h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .12em; color: var(--accent); font-weight: 600; }
.place-row { display: flex; flex-wrap: wrap; gap: 6px; }
.place-row button, .place-row select { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(255, 255, 255, .07); box-shadow: none; }
.place-row button { height: 36px; padding: 0 14px; border-radius: 999px; font-size: 14px; white-space: nowrap; transition: background .2s, color .2s; }
.place-row button:hover { background: rgba(255, 255, 255, .14); }
.place-row button[aria-pressed="true"] { background: var(--ink); color: #12333b; border-color: transparent; font-weight: 600; }
.place-row select, .field select { height: 36px; border-radius: 999px; padding: 0 14px; font-size: 14px; appearance: none; -webkit-appearance: none; }
.place-row select option, .field select option { background: #12333b; color: var(--ink); }
.dive-pick select.active { background: var(--sea); color: #032128; border-color: transparent; font-weight: 600; }

.timebar { display: flex; align-items: center; gap: 10px; width: min(640px, 100%); padding: 8px 10px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.timebar .chip { height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; box-shadow: none; background: rgba(255, 255, 255, .08); flex: none; }
.chip[aria-pressed="true"] { background: var(--accent) !important; color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.slider { flex: 1; min-width: 0; }
.slider input { width: 100%; margin: 0; accent-color: var(--accent); height: 22px; background: transparent; }
input[type=range] { -webkit-appearance: none; appearance: none; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #1b2547, #2b3a63 18%, #f2b07a 25%, #fff1c9 40%, #fff1c9 62%, #ffd38a 70%, #e47a5a 75%, #2b3a63 82%, #1b2547); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #1b2547, #2b3a63 18%, #f2b07a 25%, #fff1c9 40%, #fff1c9 62%, #ffd38a 70%, #e47a5a 75%, #2b3a63 82%, #1b2547); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.ticks { position: relative; height: 13px; font-size: 10px; color: var(--muted); margin: 1px 9px 0; }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#hour-label { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; min-width: 46px; text-align: center; }

.credit { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(6px, env(safe-area-inset-bottom)); z-index: 7; margin: 0; font-size: 10.5px; color: rgba(255, 255, 255, .78); text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.credit a { color: inherit; }

.rehearsal-note { position: absolute; top: 76px; right: max(16px, env(safe-area-inset-right)); z-index: 6; margin: 0; padding: 7px 12px; border-radius: 10px; background: rgba(60, 40, 10, .78); color: #ffe2b0; font-size: 13px; }

/* ---- Dive HUD ---- */
.dive-hud { position: absolute; left: var(--gutter); top: 120px; z-index: 6; width: min(300px, calc(100vw - 32px)); padding: 14px; border-radius: var(--radius); background: rgba(3, 40, 56, .7); border: 1px solid rgba(120, 220, 235, .25); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.dive-depth { margin: 0; font-size: 20px; font-weight: 700; color: #bff3f8; }
.dive-note, .dive-keys { margin: 2px 0 10px; font-size: 12px; color: #8fc7cf; }
.dive-keys { margin: 8px 0 0; }
.dive-hud .field select { width: 100%; }
.fish-info { margin: 6px 0 0; font-size: 12.5px; color: #d6f4f7; min-height: 0; }
.swim { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.swim button { height: 34px; border-radius: 10px; border: 1px solid rgba(160, 230, 240, .25); background: rgba(255, 255, 255, .08); font-size: 13px; cursor: pointer; }
.swim .surface { grid-column: span 2; background: var(--sea); color: #032128; font-weight: 600; border-color: transparent; }

/* ---- Drawer ---- */
.drawer { position: absolute; top: 0; right: 0; bottom: 0; z-index: 20; width: min(400px, 100vw); background: var(--glass-strong); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-left: 1px solid var(--line); display: flex; flex-direction: column; animation: drawer-in .3s ease; }
.drawer[hidden] { display: none; }
@keyframes drawer-in { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: max(18px, env(safe-area-inset-top)) 18px 10px 22px; }
.drawer-head h2 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 21px; }
.drawer-head .icon-btn { box-shadow: none; }
.drawer-body { overflow-y: auto; padding: 0 22px max(28px, env(safe-area-inset-bottom)); }
.drawer section { padding: 16px 0; border-top: 1px solid var(--line); }
.drawer h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .14em; color: var(--accent); font-weight: 600; }
.drawer h4 { margin: 16px 0 6px; font-size: 14px; }
.drawer p, .drawer li { font-size: 14px; line-height: 1.65; color: var(--ink-soft); }
.drawer p { margin: 0 0 10px; }
.readout { margin: 0 0 6px !important; color: var(--ink) !important; }
.muted { color: var(--muted) !important; font-size: 13px !important; }
.note { font-size: 12.5px !important; color: var(--muted) !important; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.drawer .chip { height: 36px; padding: 0 14px; border-radius: 999px; font-size: 13.5px; background: rgba(255, 255, 255, .08); box-shadow: none; }
.field { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-soft); }
.field.wide { display: flex; width: 100%; margin-top: 6px; }
.field.wide input { flex: 1; accent-color: var(--accent); }
#volume::-webkit-slider-runnable-track { background: rgba(255, 255, 255, .22); }
#volume::-moz-range-track { background: rgba(255, 255, 255, .22); }
.drawer .field select { box-shadow: none; height: 36px; }
.howto, .limits, .sources { padding-left: 18px; margin: 0; }
.howto b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; }

/* ---- Phone ---- */
@media (max-width: 640px) {
  .brand { top: max(14px, env(safe-area-inset-top)); }
  .brand-kicker { display: none; }
  .brand-title { font-size: 16.5px; white-space: nowrap; }
  .brand-place { font-size: 12.5px; }
  .top-tools { gap: 6px; }
  .pill { height: 36px; padding: 0 12px; font-size: 13px; }
  #weather-short { display: none; }
  #weather-mini { display: inline; }
  .brand { max-width: calc(100vw - 226px); }
  .places-btn { width: 36px; padding: 0; justify-content: center; }
  .places-btn span { display: none; }   /* icon only on phones: the title keeps its room */
  .icon-btn { width: 36px; height: 36px; }
  .dock { gap: 8px; padding-bottom: max(26px, calc(env(safe-area-inset-bottom) + 22px)); }
  .timebar { gap: 6px; padding: 6px 8px; }
  .timebar .chip { padding: 0 10px; font-size: 12.5px; }
  #hour-label { min-width: 42px; font-size: 14px; }
  .dive-hud { top: auto; bottom: 150px; padding: 12px; }
  .dive-hud .dive-keys { display: none; }
  .drawer { top: auto; width: 100%; max-height: 82vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; animation-name: sheet-in; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
  .rehearsal-note { top: 64px; }
}
@media (prefers-reduced-motion: reduce) { .veil-bar span { animation: none; width: 100%; } .drawer { animation: none; } }
