:root {
  --bg: #070c12;
  --panel: #111a23;
  --panel-2: #18232e;
  --line: #2a3846;
  --ink: #ece4d2;
  --muted: #95a1ac;
  --lamp: #f0b84a;
  --lamp-hi: #ffd98a;
  --brass: #c8963a;
  --paper: #efe3c4;
  --paper-ink: #2a2016;
  --good: #8fd3a0;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --hand: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
#app { min-height: 100dvh; }

.ico { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 20px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink);
  font-weight: 600; letter-spacing: .01em;
  transition: transform .12s, background .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #f5c661, #d99a2b); border-color: #f6d488; color: #2a1a06; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 15px; }
.btn.round { width: 46px; min-height: 46px; padding: 0; border-radius: 50%; }
.btn.danger { color: #f0a090; border-color: #5a2c25; }
.btn.big { flex-direction: column; gap: 2px; padding: 14px 20px; font-size: 18px; }
.btn.big small { font-weight: 500; font-size: 13px; opacity: .75; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 12px; border: 0; background: transparent; color: var(--ink);
  position: relative;
}
.icon-btn:active { background: #ffffff14; }

/* ---------- title ---------- */
.title {
  max-width: 520px; margin: 0 auto;
  padding: calc(28px + var(--safe-t)) 16px calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 16px;
  min-height: 100dvh;
  background: radial-gradient(120% 60% at 50% 0%, #1a2a3a 0%, transparent 70%);
}
.logo { text-align: center; padding: 8px 0 6px; }
.logo-mark { width: 92px; margin: 0 auto 4px; filter: drop-shadow(0 0 22px #ffcf6e55); }
.logo h1 {
  margin: 0; font: 800 46px/1 var(--serif); letter-spacing: .01em;
  background: linear-gradient(180deg, #fff1cc, #e3a63c); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo p { margin: 8px 0 0; color: var(--muted); }
.pick { margin: 10px 0 0; font: 600 13px/1 var(--sans); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.setting {
  position: relative; text-align: left;
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px; border-radius: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 18%, var(--panel)), var(--panel));
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--line));
  color: var(--ink);
}
.setting svg { width: 46px; height: 42px; color: var(--c); margin-bottom: 4px; }
.setting b { font: 700 18px/1.15 var(--serif); }
.setting span { font-size: 14px; color: var(--muted); line-height: 1.35; }
button.setting:active { transform: scale(.98); }
.setting.soon { opacity: .55; }
.setting.soon em {
  position: absolute; top: 12px; right: 12px;
  font: 700 10px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; font-style: normal;
  padding: 5px 7px; border-radius: 6px; background: #ffffff12; color: var(--muted);
}
.foot { text-align: center; color: var(--muted); font-size: 14px; margin: auto 0 0; }

/* ---------- game ---------- */
.game {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  background: #05080c;
}
.hud {
  display: flex; align-items: center; gap: 2px;
  padding: calc(6px + var(--safe-t)) 8px 6px;
  background: linear-gradient(180deg, #0c141c, #0a1118);
  border-bottom: 1px solid #ffffff0d;
}
.where { flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.where span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.where b { display: block; font: 700 17px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journal .count {
  position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--lamp); color: #2a1a06;
  font: 700 11px/18px var(--sans); font-style: normal; display: none;
}
.journal .count.show { display: block; animation: pop .35s; }
.stage { position: relative; min-height: 0; overflow: hidden; }
.scene { display: block; width: 100%; height: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.scene.from-right { animation: slide-r .32s ease-out; }
.scene.from-left { animation: slide-l .32s ease-out; }
@keyframes slide-r { from { transform: translateX(14%); opacity: .2; } }
@keyframes slide-l { from { transform: translateX(-14%); opacity: .2; } }
.turn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px; border-radius: 14px; border: 1px solid #ffffff1c;
  background: #0a1118b3; display: grid; place-items: center; color: var(--ink);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.turn.left { left: 4px; } .turn.right { right: 4px; }
.turn:active { background: #1a2633; }
.dots { display: flex; justify-content: center; gap: 8px; padding: 10px 0 calc(12px + var(--safe-b)); background: #0a1118; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: #ffffff26; transition: background .2s, transform .2s; }
.dots i.on { background: var(--lamp); transform: scale(1.2); }

.hot { cursor: pointer; outline: none; }
.hot .obj { transition: filter .15s; }
.hot:hover .obj, .hot:focus-visible .obj { filter: brightness(1.15) drop-shadow(0 0 6px #ffd98a66); }
.hot:active .obj { filter: brightness(1.3); }
.rain { animation: rain .55s linear infinite; }
@keyframes rain { from { transform: translate(6px, -44px); } to { transform: translate(-6px, 44px); } }
.swell { animation: swell 4s ease-in-out infinite alternate; }
@keyframes swell { to { transform: translateX(22px); } }
.flash { opacity: 0; animation: flash 11s infinite; }
.room-flash { opacity: 0; animation: room-flash 11s infinite; }
@keyframes flash { 0%, 86% { opacity: 0; } 87% { opacity: .9; } 88% { opacity: .1; } 89.5% { opacity: .7; } 92% { opacity: 0; } }
@keyframes room-flash { 0%, 86% { opacity: 0; } 87% { opacity: .1; } 88% { opacity: 0; } 89.5% { opacity: .07; } 92% { opacity: 0; } }
.flicker { animation: flicker 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes flicker { 0%, 100% { opacity: .95; } 30% { opacity: .78; } 55% { opacity: 1; } 70% { opacity: .85; } }

/* ---------- sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-back { position: absolute; inset: 0; background: #000a; opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto;
  max-width: 560px; max-height: 92dvh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #16212c, #0f171f);
  border: 1px solid #ffffff14; border-bottom: 0; border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px #000a;
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .25, 1);
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.open .sheet-back { opacity: 1; }
.sheet header { display: flex; align-items: center; gap: 8px; padding: 12px 10px 4px 20px; }
.sheet header h2 { flex: 1; margin: 0; font: 700 21px/1.2 var(--serif); }
.sheet-body { padding: 6px 16px calc(20px + var(--safe-b)); overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 14px; }
.sheet h4 { margin: 4px 0 -4px; font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.lede { margin: 0; color: #d4cbb8; }
.puzzle { display: flex; flex-direction: column; gap: 14px; }
.closeup { display: flex; justify-content: center; }
.closeup .solo { width: auto; height: 120px; filter: drop-shadow(0 10px 18px #0009); }
.closeup.big .solo { height: 210px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .btn { flex: 1; }
.menu .btn, .sheet.menu .btn { width: 100%; }

.sheet.solved .puzzle { animation: unlock .7s ease; }
.sheet.solved .wheels, .sheet.solved .lens-grid, .sheet.solved .clock-ctl { pointer-events: none; }
.sheet.solved .wheel-val { border-color: var(--good); box-shadow: 0 0 0 2px #8fd3a055, inset 0 2px 8px #0008; color: var(--good); }
.sheet.solved .lens.on { box-shadow: 0 0 26px #ffd98a; }
@keyframes unlock { 0% { transform: none; } 15% { transform: translateX(-5px); } 30% { transform: translateX(5px); } 45% { transform: translateX(-3px); } 60% { transform: none; } }
.opened.fresh .closeup { animation: rise .5s ease-out; }
@keyframes rise { from { transform: scale(.9); opacity: 0; } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.2); } }

/* lock wheels */
.wheels { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.wheel { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wheel-head { height: 30px; display: grid; place-items: center; color: var(--lamp-hi); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.wheel-head .sym { width: 28px; height: 28px; }
.wheel-head .pair { display: flex; align-items: center; gap: 0; margin: 0 -4px; }
.wheel-head .pair .sym { width: 24px; height: 24px; }
.wheel-head .pair i { font: 800 14px/1 var(--sans); font-style: normal; color: var(--ink); }
.wheel-btn { width: 58px; height: 38px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.wheel-btn:active { background: #24323f; }
.wheel-val {
  width: 58px; height: 66px; display: grid; place-items: center;
  border-radius: 12px; border: 2px solid #b8862f;
  background: linear-gradient(180deg, #0b0f13, #1d252d 50%, #0b0f13);
  box-shadow: inset 0 2px 8px #0008;
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: border-color .3s, color .3s;
}
.glyph { font: 800 34px/1 var(--serif); }
.tick-up .glyph, .tick-up .dir { animation: tick-up .18s ease-out; }
.tick-down .glyph, .tick-down .dir { animation: tick-down .18s ease-out; }
@keyframes tick-up { from { transform: translateY(40%); opacity: 0; } }
@keyframes tick-down { from { transform: translateY(-40%); opacity: 0; } }
.dir { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.dir svg { width: 30px; height: 30px; fill: var(--lamp); }
.dir b { font: 700 13px/1 var(--sans); color: var(--muted); }
.wheels:has(.dir) .wheel-val { width: 64px; height: 72px; }

/* lens panel */
.lens-grid {
  --n: 3; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 10px;
  width: min(100%, calc(var(--n) * 78px), 58dvh); margin: 0 auto; padding: 14px;
  border-radius: 20px; background: linear-gradient(135deg, #f0d48c, #9a6c22); box-shadow: inset 0 0 0 4px #5a3d10, 0 10px 24px #0008;
}
.lens {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid #7a5418;
  background: radial-gradient(circle at 35% 30%, #4a6676, #0e1820 70%);
  box-shadow: inset 0 3px 8px #000a; transition: background .2s, box-shadow .2s, transform .1s;
}
.lens:active { transform: scale(.94); }
.lens.on { background: radial-gradient(circle at 38% 32%, #fff8dc, #ffc85a 45%, #c97a16); box-shadow: 0 0 18px #ffc85a99, inset 0 -3px 6px #a0600f; }
.lens-reset { align-self: center; }

/* tide clock */
.clock-ctl { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; }
.clock-ctl > div { display: flex; align-items: center; gap: 8px; }
.clock-ctl span { font-size: 14px; color: var(--muted); min-width: 56px; text-align: right; }

/* tools in a device sheet */
.tools { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid #ffffff10; padding-top: 14px; }
.tools h4 { margin-bottom: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 6px 12px; border-radius: 20px;
  border: 1px solid #d9c38a55; background: #efe3c412; color: var(--paper);
  font-size: 14px; white-space: nowrap;
}
.chip .ico { width: 18px; height: 18px; color: var(--lamp); }
.hint-list { display: flex; flex-direction: column; gap: 8px; }
.hint-list:empty { display: none; }
.hint-line { margin: 0; display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: #f0b84a14; border: 1px solid #f0b84a33; color: #f1e2bd; }
.hint-line .ico { color: var(--lamp); margin-top: 1px; }
.hint-line.new { animation: rise .35s ease-out; }
.hint-btn { align-self: flex-start; color: var(--lamp-hi); }

/* loot and tokens */
.loot { display: flex; flex-direction: column; gap: 8px; }
.loot-item {
  display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 56px; padding: 10px 14px; border-radius: 14px;
  background: linear-gradient(180deg, #f3e8cc, #e4d3a9); color: var(--paper-ink); border: 0;
  box-shadow: 0 4px 12px #0006;
}
.loot-item .ico { width: 26px; height: 26px; color: #7a5418; }
.loot-item span { flex: 1; font: 700 17px/1.2 var(--serif); }
.loot-item em { font-style: normal; font-size: 13px; font-weight: 700; color: #7a5418; text-transform: uppercase; letter-spacing: .08em; }
.loot-item em.new { color: #a8432f; }
.loot-item.token-item { background: linear-gradient(180deg, #2a2216, #1d170f); color: var(--ink); border: 1px solid #c8963a66; }
.loot-item.token-item em { color: var(--muted); }
.tokens { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; min-height: 44px; }
.token {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 8px; border-radius: 22px;
  background: radial-gradient(circle at 30% 30%, #f6dc93, #b8862f 70%); color: #2a1a06;
  box-shadow: inset 0 -2px 3px #5a3d10, 0 3px 8px #0008;
}
.token .sym { width: 24px; height: 24px; }
.token b { font: 800 20px/1 var(--serif); }

/* ---------- clue papers ---------- */
.viewer { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; }
.viewer-back { position: absolute; inset: 0; background: #000c; opacity: 0; transition: opacity .25s; }
.viewer-card {
  position: relative; width: min(100%, 460px); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; align-items: stretch;
  transform: translateY(20px) scale(.97); opacity: 0; transition: transform .25s, opacity .25s;
}
.viewer.open .viewer-back { opacity: 1; }
.viewer.open .viewer-card { transform: none; opacity: 1; }
.viewer-card > .btn { position: sticky; bottom: 0; flex: none; box-shadow: 0 -10px 24px #000a; }
.hint-card { display: flex; gap: 12px; padding: 18px; border-radius: 16px; background: var(--panel-2); border: 1px solid #f0b84a44; }
.hint-card .ico { color: var(--lamp); width: 26px; height: 26px; }
.hint-card p { margin: 0; font-size: 17px; }

.paper {
  background: linear-gradient(180deg, #f4ead0, #e6d6ad); color: var(--paper-ink);
  border-radius: 6px; padding: 18px 18px 20px;
  box-shadow: 0 18px 40px #000b, inset 0 0 40px #b4955a33;
}
.paper h3 { margin: 0 0 4px; font: 800 22px/1.15 var(--serif); }
.paper .intro { margin: 0 0 12px; font-size: 15px; color: #5a4a35; font-style: italic; }
.hand { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.hand li { font: 600 25px/1.2 var(--hand); color: #24324a; padding-left: 22px; position: relative; }
.hand li::before { content: ''; position: absolute; left: 4px; top: .55em; width: 7px; height: 7px; border-radius: 50%; background: #24324a88; }
.flagkey { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 10px; }
.flagkey div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.flagkey b { font: 800 20px/1 var(--serif); }
.flagsvg { width: 100%; max-width: 60px; height: auto; display: block; box-shadow: 0 2px 4px #0004; }
.bunting { width: 100%; height: auto; display: block; }
.lens-card { --n: 3; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 10px; width: calc(var(--n) * 52px); margin: 6px auto 0; padding: 12px; border: 2px solid #8a6a3a; border-radius: 12px; }
.lens-card span { aspect-ratio: 1; border-radius: 50%; border: 2px solid #6b5230; }
.lens-card span.on { background: radial-gradient(circle at 35% 30%, #fff1b8, #e1a02f); border-color: #9a6a1a; }
table.tides { width: 100%; border-collapse: collapse; font-size: 16px; }
.tides th, .tides td { padding: 7px 8px; border-bottom: 1px solid #b49a6a66; text-align: left; }
.tides thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: #6a5338; }
.tides tbody th { font: 700 16px/1 var(--serif); }
.tides td { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart { width: 100%; height: auto; display: block; border-radius: 6px; }
.chart text { font: 600 8.5px var(--sans); fill: #3a2c1c; }
.chart text.north { font: 800 13px var(--serif); fill: #b8321f; }
.chart text.cap { font: italic 9px var(--serif); fill: #6a5338; }
.paper.wide { padding: 14px; }
.chart-wrap { overflow: auto; border-radius: 6px; cursor: zoom-in; -webkit-overflow-scrolling: touch; }
.chart-wrap.zoomed { cursor: zoom-out; max-height: 62dvh; }
.chart-wrap.zoomed .chart { width: 210%; max-width: none; }
.zoom-tip { margin: 8px 0 0; font-size: 13px; color: #6a5338; text-align: center; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: #02050acc; opacity: 0; transition: opacity .35s; }
.overlay.open { opacity: 1; }
.overlay-card {
  width: min(100%, 440px); padding: 26px 22px 22px; border-radius: 22px;
  background: linear-gradient(180deg, #17222e, #0e151d); border: 1px solid #ffffff14;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 30px 80px #000;
  transform: translateY(16px); transition: transform .35s;
}
.overlay.open .overlay-card { transform: none; }
.overlay-card h2 { margin: 0; font: 800 30px/1.1 var(--serif); color: #fff1cc; }
.overlay-card p { margin: 0; color: #cfc6b4; }
.overlay-card .btn { margin-top: 6px; }
.overlay-card .btn + .btn { margin-top: 0; }
.kicker { font: 600 12px/1 var(--sans) !important; letter-spacing: .16em; text-transform: uppercase; color: var(--lamp) !important; }
.stats { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.stats span { padding: 6px 10px; border-radius: 10px; background: #ffffff0f; font-size: 14px; }
.beam { width: 100%; border-radius: 14px; display: block; }
.beam .sweep { transform-origin: 160px 46px; animation: sweep 3.6s ease-in-out infinite alternate; }
@keyframes sweep { from { transform: rotate(-8deg); } to { transform: rotate(32deg); } }
.beam .boat { animation: boat 3s ease-in-out infinite alternate; }
@keyframes boat { to { transform: translate(-8px, 2px); } }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; background: #1d2a36; border: 1px solid #ffffff1a;
  transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Short screens (iPhone SE with Safari's bars): smaller art, keep controls up. */
@media (max-height: 620px) {
  .closeup .solo { height: 84px; }
  .closeup.big .solo { height: 160px; }
  .sheet-body { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .flash, .room-flash { display: none; }
}
