/* ============================================================
   HARBORLIGHT — style.css
   Warm storybook chrome over a canvas diorama. Parchment
   "driftwood" tray, safe-area aware HUD, inspect cards, and
   milestone toasts. Tokens per ART §5.1. The scene canvas
   fills the viewport; the game paints sky-coloured letterbox
   bars itself, so the page background is neutral.
   ============================================================ */

:root {
  --font-ui: -apple-system, "SF Pro Rounded", "Segoe UI Variable", "Segoe UI",
             Roboto, "Helvetica Neue", Arial, sans-serif;
  --parchment: rgba(252,246,232,0.92);
  --ink: #3A2E22;          --ink-soft: #6E5138;
  --wood: #8A6B4A;         --wood-dk: #6E5138;
  --accent: #E88A54;       --gold: #E0AD4C;
  --shadow: 0 6px 24px rgba(40,28,16,0.35);
  --sky: #2E3A66;          /* live-updated by render's palette tick */
  --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);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.35;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud.hidden { display: none; }

.pill {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 10px);
  height: 40px; border-radius: 20px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px 0 10px;
  background: var(--parchment);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.pill span {
  font-size: 18px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.pill canvas { display: block; }
#driftHud.pop { animation: pillpop 120ms ease-out; }
@keyframes pillpop { 0%{transform:scale(1)} 50%{transform:scale(1.18)} 100%{transform:scale(1)} }

#plentyHud {
  position: absolute;
  top: calc(var(--safe-t) + 12px);
  right: calc(var(--safe-r) + 10px);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  filter: drop-shadow(0 0 var(--plenty-r, 0px) rgba(140,230,190,0.85));
}
#plentyHud.pulse { animation: fishpulse 2.4s ease-in-out infinite; }
@keyframes fishpulse { 0%,100%{ transform:scale(1) } 50%{ transform:scale(1.06) } }
#plentyHud.pop { animation: fishpop 250ms ease-out; }
@keyframes fishpop { 0%{transform:scale(1)} 50%{transform:scale(1.15)} 100%{transform:scale(1)} }

#hudBtns {
  position: absolute;
  top: calc(var(--safe-t) + 58px);
  right: calc(var(--safe-r) + 10px);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: auto;
}
.ghostbtn {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1.5px solid var(--wood);
  background: var(--parchment);
  color: var(--wood-dk);
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.ghostbtn:active { transform: scale(0.94); }

/* ================= Build tray ================= */
#tray {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 12;
  height: calc(88px + max(12px, var(--safe-b)));
  padding: 8px 12px max(12px, var(--safe-b));
  padding-left: calc(12px + var(--safe-l));
  padding-right: calc(12px + var(--safe-r));
  border-radius: 14px 14px 0 0;
  background: var(--parchment);
  border-top: 2px solid rgba(138,107,74,0.4);
  display: flex; gap: 10px; align-items: center; justify-content: center;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
#tray::before {
  content: ''; position: absolute; left: 0; right: 0; top: -34px; height: 34px;
  pointer-events: none;
  background: linear-gradient(transparent, rgba(20,14,10,0.38));
}
#tray.hidden { display: none; }

.trayBtn {
  position: relative; flex: 0 0 auto;
  width: 64px; height: 64px; border-radius: 12px;
  background: rgba(255,255,255,0.28);
  border: 2px solid transparent;
  cursor: pointer; scroll-snap-align: center;
  display: flex; align-items: center; justify-content: center;
  transition: transform 160ms ease-out;
}
.trayBtn canvas { display: block; pointer-events: none; }
.trayBtn.selected {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(232,138,84,0.5);
}
.trayBtn.selected canvas { transform: translateY(-4px); }
.trayBtn.locked canvas { filter: grayscale(1); opacity: 0.45; }
.trayBtn.locked { cursor: default; }
.trayBtn.unaffordable { opacity: 0.7; }
.trayBtn.hintpulse { animation: hintpulse 260ms ease-out; }
@keyframes hintpulse { 0%{transform:scale(1)} 45%{transform:scale(1.12)} 100%{transform:scale(1)} }

.costBadge {
  position: absolute; right: 3px; bottom: 3px;
  min-width: 26px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--wood);
  color: #FCF6E8; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 3px;
}
.costBadge.pricey { background: #B0442E; }
.costBadge .log { width: 8px; height: 5px; border-radius: 2px; background: #C29768; display: inline-block; }
.lockGlyph {
  position: absolute; right: 4px; bottom: 3px;
  font-size: 12px; color: var(--wood-dk);
}
.trayHint {
  position: absolute; left: 0; right: 0; bottom: -14px;
  text-align: center; font-size: 10px; color: var(--ink-soft);
  white-space: nowrap;
}

/* ================= Inspect card ================= */
#card {
  position: fixed; z-index: 14; max-width: 240px;
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 14px;
  background: var(--parchment); box-shadow: var(--shadow);
  pointer-events: none;
  transform-origin: center bottom;
  animation: cardin 200ms cubic-bezier(0.34,1.4,0.64,1);
}
#card.hidden { display: none; }
@keyframes cardin { 0%{opacity:0; transform:scale(0.92)} 100%{opacity:1; transform:scale(1)} }
#cardPortrait { display: block; border-radius: 6px; }
#cardName { font-size: 15px; font-weight: 700; color: var(--ink); }
#cardActivity { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
#cardStat {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--ink-soft); margin-top: 6px;
}

/* ================= Toasts ================= */
#toastWrap {
  position: fixed; z-index: 16; left: 0; right: 0;
  top: calc(var(--safe-t) + 8px);
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none;
}
.toast {
  max-width: 320px; margin-top: 6px;
  padding: 10px 18px; border-radius: 12px;
  background: var(--parchment); border: 2px solid var(--gold);
  box-shadow: var(--shadow); text-align: center;
  animation: toastin 320ms cubic-bezier(0.22,1,0.36,1);
}
.toast.out { animation: toastout 240ms ease-in forwards; }
.toastName { font-size: 15px; font-weight: 700; color: var(--ink); }
.toastFlavor { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
@keyframes toastin { 0%{opacity:0; transform:translateY(-24px)} 100%{opacity:1; transform:translateY(0)} }
@keyframes toastout { 0%{opacity:1; transform:translateY(0)} 100%{opacity:0; transform:translateY(-24px)} }

/* Full-screen milestone wash */
#milestoneWash {
  position: fixed; inset: 0; z-index: 15; pointer-events: none;
  background: rgba(255,240,200,0.12); opacity: 0;
}
#milestoneWash.flash { animation: wash 900ms ease-out; }
@keyframes wash { 0%{opacity:0} 30%{opacity:1} 100%{opacity:0} }

/* Floating +text (collect) */
#floatWrap { position: fixed; inset: 0; z-index: 13; pointer-events: none; }
.floatText {
  position: absolute; font-size: 12px; font-weight: 700; color: #FCF6E8;
  -webkit-text-stroke: 2px var(--wood-dk);
  paint-order: stroke fill;
  animation: floatup 650ms ease-out forwards;
}
@keyframes floatup { 0%{opacity:1; transform:translateY(0)} 100%{opacity:0; transform:translateY(-26px)} }

/* ================= Overlays ================= */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  text-align: center; padding: 24px;
  background: rgba(16,20,38,0.82);
  transition: opacity 400ms ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay h1 {
  font-size: 28px; font-weight: 700; letter-spacing: 0.18em; color: #FCF6E8;
}
.overlay h2 { font-size: 22px; font-weight: 700; color: #FCF6E8; }
.overlay .subtitle { font-size: 13px; color: #D8CCB8; max-width: 320px; }
.beginbtn {
  min-height: 56px; padding: 0 28px; border-radius: 14px; border: none;
  background: var(--parchment); color: var(--ink);
  font-family: var(--font-ui); font-size: 16px; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow);
}
.beginbtn:active { transform: scale(0.97); }
.beginbtn.ghost { background: rgba(252,246,232,0.2); color: #FCF6E8; border: 1.5px solid var(--wood); }
.confirmRow { display: flex; gap: 12px; }
