/* Acrylic Beacon: cartographic direction. A nautical chart of an invented cove.
   Chart cream #F2EEDB, ink #2F3B2F, contour brown #8C5A2B, water tint #D5E2E2.
   The two acrylic colours carry the light: terracotta #D9552B (warm, also the one lit control) and glacier #3F97AE. */
:root {
  --paper: #F2EEDB; --ink: #2F3B2F; --brown: #8C5A2B; --water: #D5E2E2; --warm: #D9552B; --cold: #3F97AE;
  --land: #E8DCBC; --muted: #5B6457;
  --sans: 'Alegreya Sans', 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --sc: 'Alegreya Sans SC', 'Alegreya Sans', 'Noto Sans TC', system-ui, sans-serif;
  --ital: 'Alegreya', 'Noto Serif TC', Georgia, serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.4;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sc { font-family: var(--sc); font-weight: 500; letter-spacing: 0.08em; }

.mast {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  max-width: 540px; margin: 0 auto; padding: 6px 12px 0; border-bottom: 1px solid var(--ink);
}
.word { margin: 0; font-family: var(--sc); font-weight: 700; font-size: 17px; letter-spacing: 0.18em; text-transform: lowercase; }
.mast-nav { display: flex; gap: 2px; }
.link {
  background: none; border: 0; min-height: 44px; min-width: 44px; padding: 0 10px; cursor: pointer;
  font-family: var(--sc); font-weight: 500; letter-spacing: 0.08em; font-size: 15px; color: var(--ink);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px;
}

main { max-width: 540px; margin: 0 auto; padding: 0 12px 24px; position: relative; }
.cove-line { display: flex; align-items: baseline; gap: 10px; margin: 10px 2px 2px; min-height: 26px; }
.cove-no { font-size: 13px; color: var(--muted); white-space: nowrap; }
.cove-name { font-family: var(--ital); font-style: italic; font-size: 21px; line-height: 1.15; }
.say { margin: 2px 2px 6px; min-height: 2.7em; font-size: 16px; line-height: 1.35; max-width: 34em; }
.say.fail { color: #8E2A12; font-weight: 500; }
.say.tip { color: var(--muted); }

.chart { position: relative; width: 100%; max-width: 440px; margin: 0 auto; overflow: hidden; }
.status { position: relative; max-width: 440px; margin: 8px auto 0; }
.status .night { margin-top: 0; }
.preview-note { position: absolute; inset: 0; margin: 0; background: var(--paper); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 15px; line-height: 1.3; text-align: center; }
#board *:focus { outline: none; }
#board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#board .boat, #board .bat { transition: transform 0.3s ease; }
#board .boat > g { transition: transform 0.3s ease; }
#board .boat-bob { transform-origin: center; animation: boat-bob 1.6s ease-in-out infinite; }
@keyframes boat-bob { 0%, 100% { transform: translateY(-0.02px); } 50% { transform: translateY(0.02px); } }
#board .dock-figure { opacity: 0; }
#board .boat.home .dock-figure { opacity: 1; }
#board .boat.home .dock-wave { transform-origin: -0.1px -0.42px; animation: dock-wave 0.5s steps(2, end) 2; }
@keyframes dock-wave { 50% { transform: rotate(-22deg); } }
#board .bat-eye, #board .bat-smile { opacity: 0; }
#board .bat.dark .bat-eye, #board .bat.dark .bat-smile { opacity: 1; }
#board .bat.dark .bat-eye { transform: scaleY(0.24); transform-origin: center; }
#board .bat.seen .bat-eye { opacity: 1; transform: scale(1.35); transform-origin: center; }
#board .bat.seen .bat-wing { transform: scaleY(1.35); transform-origin: center; }
#board .bat.gone { opacity: 0.35; transition: transform 0.3s ease, opacity 0.6s; }
#board .bat.seen path { fill: #8E2A12; }
#board .cube-rot { transition: transform 0.3s ease; }
#board .litcell { transition: fill-opacity 0.2s; }
#board .light .route-light { fill-opacity: 0.42; stroke: var(--paper); stroke-width: 0.035; }
#board.instant .boat, #board.instant .bat, #board.instant .boat > g, #board.instant .cube-rot { transition: none; }
#board .cube.can { cursor: pointer; }
#board .cube .pulse { opacity: 0; }
#board .cube.lit-thing .pulse, #board .cube.hinted .pulse { opacity: 1; animation: pulse 1.4s ease-in-out infinite; transform-origin: 3.5px 3.5px; }
#board .open-label { letter-spacing: 0.02em; paint-order: stroke; stroke: var(--paper); stroke-width: 0.04px; stroke-linejoin: round; }
#board .cube.previewing .open-label { opacity: 0; }
#board .preview-key { filter: drop-shadow(0 1px 0 rgba(47, 59, 47, 0.18)); }
#board .preview-label { letter-spacing: 0.035em; }
#board .preview-dim { pointer-events: none; }
#board .preview-open { letter-spacing: 0.02em; paint-order: stroke; stroke: var(--paper); stroke-width: 0.04px; stroke-linejoin: round; }
@keyframes pulse { 0%, 100% { transform: scale(1); stroke-opacity: 0.9; } 50% { transform: scale(1.18); stroke-opacity: 0.35; } }
#board .badge.danger { stroke: var(--warm); }
#board .nextcell.dock-lit { filter: drop-shadow(0 0 1.5px var(--warm)); }
.ghost-light { pointer-events: none; }
.ghost-boat { opacity: 0.38; pointer-events: none; }
.ghost-bat { opacity: 0.75; pointer-events: none; }
.demo-art { opacity: 0; animation: demo-light 3s ease-in-out infinite; }
.demo-art .demo-light { opacity: 0.32; }
.demo-art .demo-boat { animation: demo-boat 3s ease-in-out infinite; }
@keyframes demo-light { 0%, 15% { opacity: 0; } 26%, 76% { opacity: 1; } 100% { opacity: 0; } }
@keyframes demo-boat { 0%, 20% { opacity: 0; transform: translate(5.5px,3.5px); } 32%, 76% { opacity: 1; } 100% { opacity: 0; } }

.tip {
  position: absolute; z-index: 5; max-width: 190px; padding: 6px 9px; font-size: 14px; line-height: 1.3;
  background: var(--paper); border: 1px solid var(--ink); box-shadow: 2px 2px 0 rgba(47, 59, 47, 0.25); pointer-events: none;
}
.hand { position: absolute; z-index: 6; width: 34px; height: 40px; pointer-events: none; animation: tap 1.2s ease-in-out infinite; }
.hand svg { width: 100%; height: 100%; }
.demo-hand { position: absolute; z-index: 7; width: 42px; height: 49px; pointer-events: none; left: 45%; top: 45%; transform: translate(-72%, -82%); animation: demo-tap 3s ease-in-out infinite; }
.demo-hand svg { width: 100%; height: 100%; }
.demo-hand.still { animation: none; }
@keyframes demo-tap { 0%, 12% { opacity: 0; transform: translate(-72%, -100%); } 22%, 76% { opacity: 1; transform: translate(-72%, -82%); } 88%, 100% { opacity: 0; transform: translate(-72%, -100%); } }
.sunrise { position: absolute; z-index: 4; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(242,161,95,0) 0%, rgba(242,161,95,0.42) 50%, rgba(242,161,95,0.08) 100%); clip-path: inset(0 0 0 100%); animation: sunrise 0.6s ease-out forwards; mix-blend-mode: multiply; }
@keyframes sunrise { to { clip-path: inset(0 0 0 0); } }
@keyframes tap { 0%, 100% { transform: translate(0, 6px); } 50% { transform: translate(0, -2px); } }

.night { display: flex; align-items: center; gap: 4px; max-width: 440px; margin: 0 auto; padding: 0 2px; }
.night .tick { flex: 1 1 0; height: 9px; border: 1px solid var(--ink); background: transparent; max-width: 48px; }
.night .tick.past { background: var(--ink); }
.night .tick.now { border-width: 2px; border-color: var(--warm); }
.night .dawn { font-size: 13px; margin-left: 6px; color: var(--muted); }

.tally { display: flex; flex-wrap: wrap; gap: 2px 14px; max-width: 440px; margin: 6px auto 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.tally .t-marks { margin-left: auto; font-weight: 500; }
.tally .t-bat { color: var(--brown); }

.controls { max-width: 440px; margin: 10px auto 0; }
.controls.done { display: none; }
.controls .row { display: flex; gap: 6px; margin-top: 6px; }
.controls .row:empty { display: none; }
.ctl {
  flex: 1 1 0; min-height: 52px; min-width: 44px; padding: 6px 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--paper); border: 1px solid var(--ink); border-radius: 0; font-size: 16px; line-height: 1.1;
  box-shadow: 0 2px 0 var(--ink);
}
.ctl:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
.ctl svg { width: 22px; height: 22px; flex: none; }
.ctl.small { min-height: 44px; font-size: 15px; box-shadow: none; flex: 0 1 auto; padding: 6px 12px; }
.sub-row { justify-content: flex-end; }
.ctl { position: relative; }
.ctl .rose { width: 32px; height: 32px; pointer-events: none; flex: none; }
.main-row .ctl, .lamp-row .ctl { flex-direction: column; gap: 3px; min-height: 66px; padding: 5px 4px; }
.ctl .lbl { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.main-row .ctl .lbl { font-weight: 500; }
.ctl .rose svg { width: 32px; height: 32px; display: block; }
.ctl.small .rose { display: none; }
.ctl.colour { justify-content: center; }
.ctl.colour { flex: 1.4 1 0; }
.ctl.colour .dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid var(--ink); }
.ctl.colour .dot.warm { background: var(--warm); }
.ctl.colour .dot.cold { background: var(--cold); opacity: 0.35; margin-left: -10px; }
.ctl.colour.is-cold .dot.warm { opacity: 0.35; }
.ctl.colour.is-cold .dot.cold { opacity: 1; }
.ctl.hinted, .ctl.cta { border-color: var(--warm); box-shadow: 0 2px 0 var(--warm); outline: 2px solid var(--warm); outline-offset: 1px; }
.ctl.hinted { animation: glow 1.2s ease-in-out infinite; }
.ctl.guided { border-color: var(--warm); box-shadow: inset 0 0 0 2px rgba(217, 85, 43, 0.35), 0 2px 0 var(--warm); }
@keyframes glow { 50% { outline-color: rgba(217, 85, 43, 0.25); } }
.controls.bare .sub-row, .controls.bare .lamp-row { display: none; }
.lamp-row:not(:has(.ctl:not([hidden]))) { display: none; }

.result { max-width: 440px; margin: 12px auto 0; border-top: 2px solid var(--ink); padding-top: 8px; }
.res-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.res-title { font-family: var(--ital); font-style: italic; font-size: 22px; }
.res-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.res-num b { font-size: 26px; font-weight: 700; }
.res-line { margin: 4px 0 8px; }
.res-btns { display: flex; gap: 6px; }
.legend {
  max-width: 440px; margin: 14px auto 0; padding: 6px 10px; border: 1px solid var(--ink); position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; line-height: 1.25;
}
.legend::before { content: attr(aria-label); position: absolute; top: -9px; left: 8px; padding: 0 4px; background: var(--paper); font-family: var(--sc); font-size: 11px; letter-spacing: 0.12em; }
.legend .lg { display: flex; align-items: center; gap: 6px; }
.legend svg { width: 22px; height: 13px; flex: none; }
.legend .sw { width: 18px; height: 12px; flex: none; display: inline-block; border: 1px solid var(--ink); }
.legend .sw.warm { background: rgba(217, 85, 43, 0.45); }
.legend .sw.cold { background: rgba(63, 151, 174, 0.45); }
.legend .sw.hatch { background: repeating-linear-gradient(45deg, rgba(47, 59, 47, 0.55) 0 1px, transparent 1px 4px); }

.map { max-width: 440px; margin: 12px auto 0; }
.map-head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--ink); }
.map-head h2 { margin: 0; font-family: var(--ital); font-style: italic; font-weight: 400; font-size: 22px; }
.map ol { list-style: none; margin: 0; padding: 0; }
.map .chap { margin: 14px 0 2px; font-size: 13px; color: var(--muted); }
.maprow {
  width: 100%; min-height: 48px; display: grid; grid-template-columns: 2.4em 1fr auto; align-items: center; gap: 8px;
  background: none; border: 0; border-bottom: 1px solid rgba(47, 59, 47, 0.3); text-align: left; cursor: pointer; padding: 4px 2px;
}
.maprow .mn { font-variant-numeric: tabular-nums; color: var(--muted); }
.maprow .mname { font-family: var(--ital); font-style: italic; font-size: 18px; }
.maprow .mbest { font-variant-numeric: tabular-nums; font-size: 15px; }
.maprow.locked { color: rgba(47, 59, 47, 0.45); }
.maprow.current .mn { color: var(--warm); font-weight: 700; }

.foot { max-width: 440px; margin: 22px auto 0; font-size: 13px; color: var(--muted); border-top: 1px solid rgba(47, 59, 47, 0.3); }

@media (min-width: 900px) {
  main { max-width: 900px; display: block; }
  .play { display: grid; grid-template-columns: 460px 1fr; grid-template-areas: 'line line' 'say say' 'chart side'; column-gap: 28px; }
  .mast { max-width: 900px; }
  .play > .cove-line { grid-column: 1 / -1; }
  .play > .say { grid-column: 1 / -1; }
  .play > .chart { grid-column: 1; grid-row: 3 / span 6; margin: 0; }
  .play > .status, .play > .controls, .play > .result, .play > .legend { grid-column: 2; margin-left: 0; width: 100%; max-width: 400px; }
  .foot { max-width: 900px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .sunrise { clip-path: inset(0); }
}
@media (max-width: 360px) {
  body { font-size: 16px; }
  .ctl { font-size: 15px; gap: 4px; }
  .ctl svg { width: 17px; height: 17px; }
  .ctl .rose, .ctl .rose svg { width: 26px; height: 26px; }
  .cove-name { font-size: 19px; }
}

.source-credit { max-width: 440px; margin: 14px auto 0; font-size: 12px; line-height: 1.45; color: var(--muted); }

/* 2026-10-19 sea chart: the harbour stamp lands with a thump (reduced motion: it simply appears). */
#board .arrived{opacity:.85;transform-box:fill-box;transform-origin:center;animation:stampIn .32s cubic-bezier(.2,1.6,.4,1) both}
@keyframes stampIn{from{opacity:0;scale:1.8}to{opacity:.85;scale:1}}
@media (prefers-reduced-motion: reduce){#board .arrived{animation:none}}

/* the game's own logo and title, top-left; opens the game's menu */
.brand { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 4px 0 0; background: none; border: 0; cursor: pointer; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; }
.brand img { display: block; flex: none; }
/* controls: no page pan or zoom steals a press; the preview line keeps its space so nothing jumps under the finger */
.ctl, #board { touch-action: none; }
.preview-note[hidden] { display: none !important; }
.word, .link { white-space: nowrap; }
@media (max-width: 360px) { .word { font-size: 13px; letter-spacing: 0.08em; } .brand img { width: 22px; height: 22px; } .link { padding: 0 6px; font-size: 14px; letter-spacing: 0.04em; } }

/* short phones: the three turn buttons and the lamp switch share one row, and the chart gives up height (see fitChart) */
@media (max-height: 700px) {
  .controls:has(#colourBtn[hidden]) { display: flex; flex-wrap: wrap; gap: 6px; }
  .controls:has(#colourBtn[hidden]) .main-row, .controls:has(#colourBtn[hidden]) .lamp-row { display: contents; }
  .controls:has(#colourBtn[hidden]) .main-row .ctl, .controls:has(#colourBtn[hidden]) .lamp-row .ctl { margin-top: 0; padding: 5px 2px; min-width: 0; }
  .controls:has(#colourBtn[hidden]) .main-row .lbl svg { display: none; }
  .controls:has(#colourBtn[hidden]) .sub-row { flex: 0 0 100%; }
  .controls:has(#colourBtn[hidden]) .row { margin-top: 0; }
  .controls.done:has(#colourBtn[hidden]) { display: none; }
  main { padding-bottom: 8px; }
}

/* the 'Why this exists' link lives on the menu (Levels) screen, not under the controls while playing */
body:has(#play:not([hidden])) .why-exists-foot { display: none; }

/* first screen words, goal line, tally */
.wordbox { display: flex; flex-direction: column; line-height: 1.05; }
.tag { font-family: var(--body, inherit); font-size: 13px; letter-spacing: 0.02em; text-transform: none; font-weight: 500; opacity: .8; }
.goal { margin: 2px 2px 2px; font-size: 18px; line-height: 1.3; max-width: 34em; }
.say { min-height: 1.4em !important; margin: 0 2px 6px !important; font-size: 15px !important; }

.say[hidden] { display: none !important; }
.tally .t-say { flex: 1 1 0; min-width: 0; }
.goal { font-size: 18px; }
/* Short phones: rose beside the label, no turn arrow, everything inside its button, 44 px targets. */
@media (max-height: 640px) {
  .controls:not(:has(#colourBtn[hidden])) .main-row .ctl, .controls:not(:has(#colourBtn[hidden])) .lamp-row .ctl { flex-direction: row; min-height: 48px; gap: 3px; padding: 4px 3px; min-width: 0; }
  .controls:not(:has(#colourBtn[hidden])) .main-row .ctl .lbl svg { display: none; }
  .controls:not(:has(#colourBtn[hidden])) .main-row .ctl .rose, .controls:not(:has(#colourBtn[hidden])) .main-row .ctl .rose svg { width: 22px; height: 22px; }
  .ctl .lbl { min-width: 0; }
}
