/* Saltwake: the sea is the page. The HUD stays small, opaque and legible over a bright sunset sky. */
:root {
  --plate: oklch(from var(--inverse) l c h / 0.9);
}
html, body { background: #1b2a3a; }
body { overflow: hidden; overscroll-behavior: none; }

.sea {
  /* a painted stand-in for the first frame while three.js loads */
  background:
    radial-gradient(60% 40% at 72% 38%, oklch(0.86 0.12 65 / 0.9), transparent 70%),
    linear-gradient(180deg, oklch(0.38 0.07 265) 0%, oklch(0.6 0.08 330) 34%, oklch(0.8 0.11 55) 49%, oklch(0.36 0.06 215) 51%, oklch(0.2 0.04 225) 100%);
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#scene:active { cursor: grabbing; }

.k-hud { gap: var(--s-3); }

/* the mark */
.brand {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-4) var(--s-2) var(--s-2);
  background: var(--plate);
  border: var(--line-w) solid var(--line);
  border-radius: var(--r-2);
  color: var(--ink-1);
  text-decoration: none;
}
.brand__wheel { width: 1.9rem; height: 1.9rem; color: oklch(0.82 0.13 70); transition: transform var(--d-4) var(--ease-out); }
.brand:hover .brand__wheel { transform: rotate(45deg); }
.brand__txt { display: grid; gap: 3px; }
.brand__name { font-family: var(--font-display); font-weight: 650; font-size: 1.25rem; letter-spacing: 0.01em; line-height: 1; }
.brand__sub { font-size: 0.75rem; color: var(--ink-2); line-height: 1.2; }

.hud-tr { display: flex; align-items: center; gap: var(--s-2); }
.hud-tr .k-btn--icon, .hud-tr .k-coin { background: var(--plate); }
#sound-btn svg { width: 1.25rem; height: 1.25rem; }
#sound-btn .wave { display: none; }
#sound-btn[aria-pressed="true"] .wave { display: inline; }
#sound-btn[aria-pressed="true"] .mute { display: none; }
#sound-btn[aria-pressed="true"] { color: var(--accent); }
.k-coin__img:empty { background: radial-gradient(circle at 35% 30%, oklch(0.86 0.12 72), oklch(0.62 0.13 55)); }

.deck { display: grid; gap: var(--s-2); justify-items: stretch; }
/* the log: speed and sail set */
.log {
  display: grid; gap: var(--s-2);
  min-width: 10.5rem;
  padding: var(--s-3) var(--s-4);
  background: var(--plate);
  border: var(--line-w) solid var(--line);
  border-radius: var(--r-2);
}
.log__speed { display: flex; align-items: baseline; gap: var(--s-1); }
.log__num { font-family: var(--font-display); font-weight: 600; font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink-1); }
.log__unit { color: var(--ink-2); font-size: var(--t-sm); }
.log__sail { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: var(--s-3); }
.log__label { font-size: var(--t-sm); color: var(--ink-2); }
.log__meter { min-width: 6rem; }

/* controls hint */
.hint {
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s-2) var(--s-5);
  padding: var(--s-2) var(--s-4);
  background: var(--plate);
  border: var(--line-w) solid var(--line);
  border-radius: var(--r-2);
  font-size: var(--t-sm); color: var(--ink-2);
  transition: opacity var(--d-4) var(--ease-out);
}
.hint[data-quiet] { opacity: 0.55; }
.hint__grp { display: inline-flex; align-items: center; gap: var(--s-1); white-space: nowrap; }
kbd {
  display: inline-grid; place-items: center;
  min-width: 1.6rem; height: 1.6rem; padding: 0 0.35rem;
  border: var(--line-w) solid var(--outline);
  border-radius: var(--r-1);
  box-shadow: inset 0 -2px 0 var(--shade, rgb(0 0 0 / 0.3));
  background: var(--surface-2);
  color: var(--ink-1);
  font: inherit; font-weight: var(--text-weight-strong); font-size: 0.8rem;
}
kbd.wide { padding: 0 0.5rem; }

/* sails button */
.sail-btn { gap: var(--s-2); min-width: 10.5rem; }
.sail-btn__ico { width: 1.35rem; height: 1.35rem; transition: transform var(--d-3) var(--ease-out); }
.sail-btn[aria-pressed="false"] { background: var(--surface-2); color: var(--ink-1); }
.sail-btn[aria-pressed="false"] .sail-btn__ico { transform: scaleY(0.45) translateY(-40%); }

/* phone joystick */
.joy { position: relative; width: 8.5rem; height: 8.5rem; touch-action: none; }
.joy__ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, oklch(from var(--inverse) l c h / 0.35) 0 55%, oklch(from var(--inverse) l c h / 0.62) 56% 100%);
  border: 2px solid oklch(from var(--ink-1) l c h / 0.45);
}
.joy__knob {
  position: absolute; left: 50%; top: 50%; width: 3.4rem; height: 3.4rem; margin: -1.7rem 0 0 -1.7rem;
  border-radius: 50%;
  background: var(--surface-3);
  border: 2px solid var(--ink-2);
  box-shadow: inset 0 2px 0 var(--gloss);
  transition: transform var(--d-2) var(--ease-out);
}
.joy[data-active] .joy__knob { transition: none; background: var(--accent); border-color: var(--accent); }
.hint-top {
  justify-self: center;
  padding: var(--s-1) var(--s-3);
  background: var(--plate);
  border-radius: var(--r-2);
  font-size: var(--t-sm); color: var(--ink-2);
  transition: opacity var(--d-4) var(--ease-out);
}
.hint-top[data-gone] { opacity: 0; pointer-events: none; }

.nogl { position: absolute; inset: 0; display: grid; place-content: center; padding: var(--gutter); text-align: center; z-index: 1; }
.nogl > * { max-width: 36ch; }
.nogl__title, .nogl__text { background: oklch(from var(--ground) l c h / 0.82); margin: 0; padding: var(--s-3) var(--s-5); }
.nogl__title { font-family: var(--font-display); font-size: var(--t-xl); color: var(--ink-1); border-radius: var(--r-3) var(--r-3) 0 0; padding-top: var(--s-5); }
.nogl__text { color: var(--ink-1); border-radius: 0 0 var(--r-3) var(--r-3); padding-bottom: var(--s-5); }
body[data-nogl] :is(#joy, .deck, .promptbar, #help-btn, #help) { display: none; }

/* coin sheet */
.sheet-status { color: var(--ink-2); margin-bottom: var(--s-4); }
.coin-stats { margin-bottom: var(--s-4); }
.ca { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-5); }
.ca__label { color: var(--ink-2); font-size: var(--t-sm); }
.sheet-h { font-family: var(--font-display); font-weight: 600; font-size: var(--t-lg); margin: var(--s-2) 0 var(--s-3); }
.split { list-style: none; padding: 0; margin: 0 0 var(--s-4); display: grid; gap: var(--s-2); }
.split li { display: grid; grid-template-columns: 1fr auto; gap: var(--s-2); align-items: center; padding: var(--s-2) 0; border-bottom: var(--line-w) solid var(--line); }
.split .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.split .bar i { display: block; height: 100%; background: var(--accent); }
.split .burn .bar i { background: var(--warn); }
.split .pct { font-variant-numeric: tabular-nums; font-weight: var(--text-weight-strong); }
.sheet-note { color: var(--ink-2); font-size: var(--t-sm); }

.feeline {
  padding: var(--s-1) var(--s-3);
  background: var(--plate);
  border: var(--line-w) solid var(--line);
  border-radius: var(--r-2);
  font-size: 0.75rem; color: var(--ink-2);
}
.joy[data-used] .joy__label { opacity: 0; }
.joy__label {
  transition: opacity var(--d-3) var(--ease-out);
  position: absolute; left: 50%; bottom: calc(100% + var(--s-1)); transform: translateX(-50%);
  padding: 2px var(--s-2); border-radius: var(--r-1);
  background: var(--plate); color: var(--ink-2); font-size: 0.75rem; white-space: nowrap;
}

/* what shows depends on where the pirate is */
#stage[data-mode="foot"] .helm-only { display: none; }
#stage[data-mode="helm"] .foot-only { display: none; }
#help-btn svg { width: 1.3rem; height: 1.3rem; }
#help-btn[aria-expanded="true"] { color: var(--accent); }
.k-hud__tl { display: grid; gap: var(--s-3); justify-items: start; }

/* first-visit controls card */
.help {
  width: min(21.5rem, calc(100vw - 2 * var(--gutter)));
  padding: var(--s-3) var(--s-4) var(--s-4);
  background: var(--plate);
  border: var(--line-w) solid var(--line);
  border-radius: var(--r-2);
  animation: help-in var(--d-4) var(--ease-out) both;
}
.help__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); }
.help__title { font-family: var(--font-display); font-weight: 600; font-size: var(--t-lg); color: var(--ink-1); }
.help__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); font-size: var(--t-sm); color: var(--ink-2); }
.help__list li { display: grid; grid-template-columns: 7.4rem 1fr; align-items: center; gap: var(--s-3); }
.help__list.k-phone-only li { display: block; }
.keys { display: inline-flex; gap: 3px; }
.help__tip { margin-top: var(--s-3); padding-top: var(--s-3); border-top: var(--line-w) solid var(--line); font-size: var(--t-sm); color: var(--ink-1); }
@keyframes help-in { from { opacity: 0; transform: translateY(-6px); } }

/* the contextual prompt: only near the wheel or the rope ladder */
.promptbar { justify-self: center; }
.prompt {
  display: inline-flex; align-items: center; gap: var(--s-3);
  min-height: var(--control-h-lg);
  padding: var(--s-2) var(--s-5) var(--s-2) var(--s-2);
  background: var(--plate);
  border: var(--line-w) solid oklch(from var(--accent) l c h / 0.7);
  border-radius: var(--r-2);
  color: var(--ink-1);
  font: inherit; font-weight: var(--text-weight-strong); font-size: var(--t-md);
  cursor: pointer;
  animation: prompt-in var(--d-3) var(--ease-out) both;
  transition: transform var(--d-2) var(--ease-out), border-color var(--d-2) var(--ease-out);
}
.prompt:hover { transform: translateY(-2px); border-color: var(--accent); }
.prompt:focus-visible { outline: var(--focus-w) solid var(--focus); outline-offset: var(--focus-offset); }
.prompt kbd { background: var(--accent); color: var(--on-accent); border-color: var(--accent); min-width: 2rem; height: 2rem; }
.prompt[hidden] { display: none; }
@keyframes prompt-in { from { opacity: 0; transform: translateY(8px); } }

/* ship buttons: anchor always, sails at the helm */
.shipbtns { display: grid; gap: var(--s-2); }
.anchor-btn { gap: var(--s-2); background: var(--plate); }
.anchor-btn svg { width: 1.2rem; height: 1.2rem; }
.anchor-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.anchor-btn[data-state="busy"] svg { animation: anchor-sway 1.6s var(--ease-inout) infinite; }
@keyframes anchor-sway { 50% { transform: translateY(2px) rotate(8deg); } }

/* phone thumb pad */
.pad { display: grid; grid-template-columns: auto auto; grid-template-areas: "act jump" "run jump"; gap: var(--s-2); align-items: end; }
.padbtn {
  display: grid; place-items: center;
  width: 3.6rem; height: 3.6rem; border-radius: 50%;
  background: var(--plate); color: var(--ink-1);
  border: 2px solid oklch(from var(--ink-1) l c h / 0.4);
  font: inherit; font-size: 0.78rem; font-weight: var(--text-weight-strong);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.padbtn:active { transform: scale(0.94); }
.padbtn--act { grid-area: act; }
.padbtn--act:not(:disabled) { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.padbtn--act:disabled { opacity: 0.55; }
.padbtn--run { grid-area: run; }
.padbtn--run[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.padbtn--jump { grid-area: jump; width: 5rem; height: 5rem; font-size: var(--t-sm); background: oklch(from var(--surface-2) l c h / 0.9); }
#stage[data-mode="helm"] .pad { grid-template-areas: "act"; grid-template-columns: auto; }

@media (max-width: 767.98px) {
  .deck { grid-auto-flow: column; align-items: end; }
  .shipbtns { justify-items: end; }
  .anchor-btn { width: 3.6rem; height: 3.6rem; padding: 0; border-radius: 50%; font-size: 0; }
  .anchor-btn svg { width: 1.5rem; height: 1.5rem; }
  /* on touch the prompt is a small pill under the top bar, clear of the pirate; the action button carries the same verb */
  .promptbar { position: fixed; right: var(--gutter); bottom: calc(env(safe-area-inset-bottom) + 176px + 8.2rem); }
  .prompt { min-height: 2.4rem; padding: var(--s-1) var(--s-4); font-size: var(--t-sm); }
  .help { padding: var(--s-2) var(--s-3); width: min(15.5rem, calc(100vw - 2 * var(--gutter))); }
  .help__head { margin-bottom: 0; }
  .help__title { font-size: var(--t-sm); }
  .help__list { gap: 2px; font-size: 0.8rem; }
  .help__tip { font-size: 0.75rem; color: var(--ink-2); margin-top: var(--s-2); padding-top: var(--s-2); }
  .k-hud__t.feeline { display: none; }
  #help-btn { display: none; }
  /* one family of thumb buttons: dark glass discs with a pale rim; only the live action is filled */
  .anchor-btn, .padbtn { width: 3.25rem; height: 3.25rem; background: var(--plate); border: 1.5px solid oklch(from var(--ink-1) l c h / 0.55); color: var(--ink-1); }
  .padbtn { font-size: 0.72rem; }
  .padbtn--run { width: 3rem; height: 3rem; }
  .padbtn--jump { width: 4.5rem; height: 4.5rem; background: var(--plate); font-size: var(--t-sm); }
  .padbtn--act:not(:disabled) { background: var(--plate); color: var(--accent); border: 2px solid var(--accent); box-shadow: 0 0 0 3px oklch(from var(--accent) l c h / 0.25); }
  .deck { gap: var(--s-2); }
  .joy { width: 7.6rem; height: 7.6rem; }
  .joy__ring { border-color: oklch(from var(--ink-1) l c h / 0.6); }
  .joy__knob { background: oklch(from var(--ink-1) l c h / 0.5); }
  /* the controls sit a thumb's width above the bottom corners, clear of the platform's corner badge */
  .k-hud { padding-bottom: calc(env(safe-area-inset-bottom) + 176px); }
  .k-hud { grid-template-columns: auto minmax(0, 1fr) auto; }
  .k-hud__tl { min-width: 0; }
  .hud-tr .k-coin .k-change { display: none; }
  .brand { padding: var(--s-1) var(--s-3) var(--s-1) var(--s-1); min-height: 2.75rem; }
  .brand__sub { display: none; }
  .brand__wheel { width: 1.6rem; height: 1.6rem; }
  .brand__name { font-size: 1.05rem; }
  .k-hud__t { grid-column: 1 / -1; grid-row: 2; align-self: start; justify-self: start; }
  .sail-btn { min-width: 0; width: 4.6rem; height: 4.6rem; border-radius: 50%; flex-direction: column; gap: 2px; padding: 0; font-size: var(--t-sm); }
  .sail-btn__txt { line-height: 1.1; text-align: center; max-width: 4.6rem; }
  .hud-tr .k-coin .k-coin__img { display: none; }
  .hud-tr .k-coin { padding-left: var(--s-3); max-width: 11.5rem; }
  .hud-tr .k-coin__price { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .brand__name { font-size: 0.98rem; }
}
@media (prefers-reduced-motion: reduce) {
  .brand__wheel, .sail-btn__ico, .joy__knob { transition: none; }
}
