:root {
  --ink: #eef1f4;
  --dim: #9aa6b2;
  --gold: #f2c879;
  --red: #ff6a52;
  --glass: rgba(8, 14, 24, 0.62);
  --line: rgba(255, 255, 255, 0.1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #04070d; color: var(--ink); font-family: var(--sans); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ov { touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--serif); color: var(--dim); }

/* HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
  display: grid; gap: 6px; pointer-events: none;
  background: linear-gradient(rgba(2, 5, 10, 0.75), rgba(2, 5, 10, 0));
}
#hud button { pointer-events: auto; }
.dawn { display: flex; align-items: center; gap: 8px; color: var(--dim); }
.dawn svg { width: 14px; height: 14px; stroke: none; flex: none; }
.dawn svg.sun { fill: none; color: var(--gold); }
.dawn svg.sun circle { fill: var(--gold); stroke: none; }
.track { flex: 1; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #5d6f99, var(--gold)); }
.row { display: flex; align-items: center; gap: 14px; }
.oil { display: flex; align-items: center; gap: 6px; color: var(--gold); }
.oil svg { width: 14px; height: 14px; stroke: none; }
.gauge { width: 72px; height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; }
.gauge i { display: block; height: 100%; background: var(--gold); transition: width 0.3s; }
.gauge i.low { background: var(--red); animation: blink 0.9s infinite alternate; }
@keyframes blink { to { opacity: 0.45; } }
.buoys { display: flex; gap: 5px; }
.buoy { width: 13px; height: 13px; border-radius: 50%; border: 3.5px solid #f4f1ea; box-shadow: inset 0 0 0 0 transparent; background: transparent; position: relative; }
.buoy::after { content: ""; position: absolute; inset: -3.5px; border-radius: 50%; background: conic-gradient(var(--red) 0 12.5%, transparent 0 25%, var(--red) 0 37.5%, transparent 0 50%, var(--red) 0 62.5%, transparent 0 75%, var(--red) 0 87.5%, transparent 0); -webkit-mask: radial-gradient(circle, transparent 3px, #000 3.2px); mask: radial-gradient(circle, transparent 3px, #000 3.2px); }
.buoy.gone { opacity: 0.18; }
.score { margin-left: auto; font-family: var(--serif); font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
#hud .round { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); display: grid; place-items: center; padding: 0; }
#btnPause svg { width: 14px; height: 14px; stroke: none; }
#btnSound svg { width: 16px; height: 16px; }
#btnSound .mute, #btnSound.off .wave { display: none; }
#btnSound.off .mute { display: inline; }
#btnSound.off { color: var(--dim); }
#nightName { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }

#coach {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translateX(-50%);
  width: min(360px, calc(100% - 32px)); padding: 12px 14px; border-radius: 14px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 14px; line-height: 1.4; pointer-events: none; animation: rise 0.35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* DOCK */
#dock {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; justify-content: center; gap: 14px; pointer-events: none;
  background: linear-gradient(rgba(2, 5, 10, 0), rgba(2, 5, 10, 0.7));
}
#dock button {
  pointer-events: auto; position: relative; overflow: hidden; display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-radius: 999px; border: 1px solid rgba(242, 200, 121, 0.35);
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: var(--gold); font-weight: 600; font-size: 15px;
}
#dock button svg { width: 22px; height: 22px; }
#dock button:disabled { color: var(--dim); border-color: var(--line); cursor: default; }
#btnHorn::after { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, 0.08); transform-origin: left; transform: scaleX(var(--cd, 0)); }
#btnFlare.armed { background: rgba(255, 106, 82, 0.25); border-color: var(--red); color: #fff; }

/* CARDS */
#modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 60%, rgba(2, 5, 10, 0.2), rgba(2, 5, 10, 0.65)); }
.card {
  width: min(420px, 100%); max-height: calc(100% - 20px); overflow: auto; padding: 26px 22px 20px; border-radius: 20px;
  background: rgba(8, 14, 24, 0.78); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: rise2 0.35s ease-out;
}
@keyframes rise2 { from { opacity: 0; transform: translateY(10px); } }
.card h1, .card h2 { font-family: var(--serif); font-weight: 600; margin: 4px 0 10px; letter-spacing: 0.01em; }
.card h1 { font-size: 40px; color: var(--gold); text-shadow: 0 0 24px rgba(242, 200, 121, 0.35); }
.card h2 { font-size: 28px; }
.kicker { margin: 0; color: var(--dim); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; }
.lede { color: #c9d1da; line-height: 1.5; margin: 0 0 18px; }
.nights { display: grid; gap: 8px; }
.night {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04);
}
.night b { font-family: var(--serif); color: var(--gold); font-size: 18px; }
.night:disabled { opacity: 0.4; cursor: default; }
.night:not(:disabled):hover { background: rgba(242, 200, 121, 0.08); }
.stars { display: inline-flex; gap: 2px; font-style: normal; }
.stars i { font-style: normal; color: rgba(255, 255, 255, 0.18); font-size: 15px; }
.stars i.on { color: var(--gold); }
.card > .stars { display: flex; justify-content: center; margin: 0 0 14px; }
.card > .stars i { font-size: 34px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 18px; }
.chips span { padding: 4px 10px; border-radius: 999px; font-size: 12px; color: var(--gold); border: 1px solid rgba(242, 200, 121, 0.3); }
.actions { display: grid; gap: 8px; }
.actions button { padding: 13px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-weight: 600; }
.actions button.primary { background: var(--gold); color: #1a1206; border-color: var(--gold); }
.tally { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 18px; }
.tally dt { color: var(--dim); }
.tally dd { margin: 0; font-family: var(--serif); font-size: 17px; text-align: right; font-variant-numeric: tabular-nums; }
.fine { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin-top: 16px; font-size: 12px; color: var(--dim); }
.fine a { color: var(--dim); }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { accent-color: var(--gold); width: 16px; height: 16px; margin: 0; }
.coins { margin: 0; color: var(--gold); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.coins b { font-family: var(--serif); font-size: 18px; }
.coins::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe7a8, #c9922f); }
.upgrade-row { grid-template-columns: 1fr auto; align-items: center; margin-top: 12px; }
.lede.small { font-size: 13px; margin-bottom: 12px; color: var(--dim); }
.upgrades { display: grid; gap: 8px; margin-bottom: 16px; }
.upgrade { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); }
.up-text { display: grid; gap: 2px; }
.up-text b { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.up-text small { color: var(--dim); font-size: 12px; line-height: 1.35; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.pips i.on { background: var(--gold); }
.upgrade button { min-width: 72px; padding: 9px 12px; border-radius: 10px; border: 1px solid rgba(242, 200, 121, 0.5); background: rgba(242, 200, 121, 0.12); color: var(--gold); font-weight: 600; }
.upgrade button:disabled { opacity: 0.4; cursor: default; }
.maxed { color: var(--dim); font-size: 13px; padding: 0 8px; }
