html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", sans-serif;
  color: #f3e6c8;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-size: 15px;
  text-shadow: 0 1px 3px #000;
}
#hud.hidden { display: none; }
#hud .minimap { position: absolute; left: 16px; bottom: 16px; width: min(190px, 34vw); height: auto; max-height: 24vh; object-fit: contain; opacity: 0.85;
  border: 1px solid #f3e6c855; border-radius: 6px; image-rendering: pixelated; box-shadow: 0 0 12px #0008; }
#hud .minimap.hidden { display: none; }
@media (pointer: coarse) { #hud .minimap { left: auto; right: 16px; bottom: auto; top: 76px; width: min(150px, 34vw); } }
#hud > span { position: absolute; top: 14px; }
#hud .level { left: 16px; font-weight: 600; }
#hud .oil-label { left: 16px; top: 40px; }
#hud .oil {
  left: 52px;
  top: 44px;
  width: 180px;
  height: 12px;
  border: 1px solid #f3e6c899;
  border-radius: 6px;
  overflow: hidden;
}
#hud .oil > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #c46a1b, #ffcf66);
  transition: width 0.15s linear;
}
#hud .oil > i.low { background: linear-gradient(90deg, #8a1f12, #e0533a); }
#hud .buoys { right: 16px; font-weight: 600; color: #9fe8d6; }
#hud .hint { right: 16px; top: auto; bottom: 14px; opacity: 0.6; font-size: 13px; }
#hud .msg {
  position: absolute;
  bottom: 70px;
  /* Stay clear of the minimap in the corner: long tips wrap in the middle instead. */
  left: calc(min(190px, 34vw) + 24px);
  right: calc(min(190px, 34vw) + 24px);
  text-align: center;
  font-size: 22px;
  color: #ffe2a8;
  text-shadow: 0 1px 6px #000c;
}
@media (pointer: coarse) { #hud .msg { left: 16px; right: 16px; } }
#hud .flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(transparent 40%, #6a0d2a);
  opacity: 0;
}

#toast {
  position: fixed; top: 64px; left: 50%; z-index: 20; transform: translate(-50%, calc(-100% - 70px));
  display: flex; gap: 10px; align-items: baseline; padding: 10px 18px; border-radius: 12px;
  background: #1a1408ee; border: 1px solid #ffd27a; box-shadow: 0 0 24px #ffb34766;
  color: #f3e6c8; font: 14px system-ui, sans-serif; transition: transform 0.35s ease; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }
#toast b { color: #ffd27a; }
#toast em { color: #ffc879; font-style: normal; font-weight: 700; }
#screen .stats-line { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin: 4px 0 8px; }
#screen .stats-line span { display: grid; justify-items: center; min-width: 74px; }
#screen .stats-line small { font-size: 11px; opacity: 0.7; }
#screen .stats-line b { color: #ffd27a; }
#screen .awards { list-style: none; padding: 0; margin: 0.5em auto; max-width: 760px; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; text-align: left; max-height: 60vh; overflow-y: auto; }
#screen .awards li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 10px; border-radius: 8px;
  background: #ffffff0d; opacity: 0.55; font-size: 13px; }
#screen .awards li.got { opacity: 1; background: #ffb34722; border: 1px solid #ffd27a55; }
#screen .awards li span { grid-column: 1; font-size: 12px; opacity: 0.8; }
#screen .awards li em { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-style: normal; color: #ffc879; }

#screen .blessings { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
#screen .blessings button { display: grid; gap: 4px; justify-items: center; width: 190px; padding: 12px 10px; cursor: pointer;
  font: 13px system-ui, sans-serif; color: #f3e6c8; background: #10182599; border: 1px solid #ffd27a44; border-radius: 12px; }
#screen .blessings button:hover, #screen .blessings button.sel { border-color: #ffd27a; background: #ffb34726; box-shadow: 0 0 18px #ffb34744; }
#screen .blessings .ico { font-size: 28px; }
#screen .blessings b { color: #ffd27a; }
#screen .blessings small { opacity: 0.85; }
#screen .blessed span { font-size: 18px; margin: 0 2px; cursor: help; }

#screen .menu { display: grid; gap: 8px; margin-top: 14px; min-width: min(300px, 80vw); }
#screen .menu button { padding: 11px 16px; cursor: pointer; text-align: left; font: 600 15px system-ui, sans-serif;
  color: #f3e6c8; background: #10182599; border: 1px solid #ffd27a44; border-radius: 10px; }
#screen .menu button:hover { border-color: #ffd27a; background: #ffb34726; }
#screen .menu button b { display: inline-block; width: 1.6em; color: #ffd27a; }
#screen .modes { display: flex; gap: 1.2em; justify-content: center; flex-wrap: wrap; margin: 0.6em 0 0.2em; }
#screen .modes span { text-decoration: none; cursor: pointer; padding: 0.35em 0.9em; border: 1px solid rgba(255, 200, 120, 0.35);
  border-radius: 999px; background: rgba(255, 170, 80, 0.08); }
#screen .modes span:hover { background: rgba(255, 170, 80, 0.2); }
#screen .modes b { color: #ffc879; }

#screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  background: radial-gradient(#0006, #000d);
}
/* The title menu sits over the live demo, so keep the middle clear and darken the edges. */
#screen[data-screen="title"] { background: radial-gradient(ellipse at center, #0000 20%, #0008 75%, #000c); }
#screen[data-screen="title"] h1, #screen[data-screen="title"] p, #screen[data-screen="title"] li { text-shadow: 0 1px 6px #000, 0 0 2px #000; }
#screen.hidden { display: none; }
#screen[data-screen="photo"] { background: none; justify-content: flex-end; pointer-events: none; }
#screen .photo-hint { pointer-events: auto; cursor: pointer; }
#screen .photo-hint { font-size: 13px; padding: 6px 14px; border-radius: 999px; background: #000a; opacity: 0.85; }
#screen h1 {
  font-size: clamp(36px, 7vw, 64px);
  letter-spacing: 4px;
  color: #ffd27a;
  margin: 0 0 12px;
  text-shadow: 0 0 28px #ffb34777;
}
#screen .sub { max-width: 520px; line-height: 1.5; opacity: 0.9; }
#screen .how { list-style: none; padding: 0; line-height: 1.8; opacity: 0.85; }
#screen .go { margin-top: 18px; font-size: 20px; color: #ffe2a8; animation: pulse 1.6s ease-in-out infinite; }
#screen pre { white-space: pre-wrap; max-width: 600px; font-size: 12px; opacity: 0.7; }

@keyframes pulse {
  50% { opacity: 0.45; }
}

/* Run timer and pause button */
#hud .timer { left: 50%; transform: translateX(-50%); font-variant-numeric: tabular-nums; opacity: 0.85; }
#hud .pause-btn, #hud .photo-btn {
  position: absolute;
  top: 36px;
  right: 16px;
  pointer-events: auto;
  font: 600 13px system-ui, sans-serif;
  color: #f3e6c8;
  background: #0006;
  border: 1px solid #f3e6c855;
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
}

#hud .photo-btn { right: 52px; padding: 2px 7px; }

/* Level select on the title screen */
#screen .pick { margin: 22px 0 6px; opacity: 0.7; font-size: 14px; }
#screen .acts { display: flex; gap: 10px 28px; justify-content: center; flex-wrap: wrap; text-align: left; }
#screen .acts { max-height: 44vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #ffd27a55 transparent; }
#screen .pick .tap-hint { display: none; }
@media (pointer: coarse) { #screen .pick .key-hint { display: none; } #screen .pick .tap-hint { display: inline; } }
#screen .act-name { margin: 0 0 4px 10px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: #ffd27a; opacity: 0.8; }
#screen .act.sealed .act-name { color: #9fe8d6; }
#screen .story { max-width: 560px; margin: 6px auto 10px; font-style: italic; color: #cfe7ff; opacity: 0.9; line-height: 1.5; }
#screen .levels { list-style: none; padding: 0; margin: 0; line-height: 1.7; font-size: 15px; }
#screen .levels li { cursor: pointer; padding: 0 10px; border-radius: 6px; }
#screen .levels li:hover { background: #ffd27a22; }
#screen .levels li b { color: #ffd27a; margin-right: 6px; }
#screen .levels li.locked { opacity: 0.35; cursor: default; }
#screen .levels li span { opacity: 0.7; }
#screen .levels li span.all { opacity: 1; color: #ffd27a; }
#screen .levels li.locked:hover { background: none; }
#screen .best { color: #9fe8d6; }

/* Touch controls (shown after the first touch) */
#touch { position: fixed; inset: auto 0 0 0; display: flex; align-items: flex-end; justify-content: space-between; padding: 18px; pointer-events: none; }
#touch.hidden { display: none; }
#touch .pad { display: flex; gap: 14px; }
/* The dash button sits above the flare button, so the right pad stays two buttons wide. */
#touch .pad.right { display: grid; grid-template-columns: auto auto; align-items: end; }
#touch .pad.right [data-k="dash"] { grid-column: 1; grid-row: 1; width: 52px; height: 52px; justify-self: center; font-size: 22px; }
#touch .pad.right [data-k="flare"] { grid-column: 1; grid-row: 2; }
#touch .pad.right [data-k="forward"] { grid-column: 2; grid-row: 2; }
#touch button {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid #f3e6c866;
  background: #0007;
  color: #ffe2a8;
  font-size: 26px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#touch button.down { background: #ffd27a44; }
#screen { z-index: 2; } /* menus sit above the touch buttons */
@media (pointer: coarse) {
  #hud .hint { display: none; }
}

/* Settings screen */
#screen .settings { list-style: none; padding: 0; margin: 6px 0 0; min-width: min(420px, 90vw); }
#screen .settings li {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}
#screen .settings li.sel { background: #ffd27a26; outline: 1px solid #ffd27a66; }
#screen .settings li b { color: #ffd27a; font-weight: 600; letter-spacing: 1px; }
#screen .small { margin-top: 18px; font-size: 13px; opacity: 0.6; cursor: pointer; }
#hud .fps { left: 16px; top: 62px; font-size: 12px; opacity: 0.7; font-variant-numeric: tabular-nums; }
#hud .fps.hidden { display: none; }

/* Ending: lighter backdrop so the fireworks show, and rolling credits */
#screen[data-screen="won"] { background: radial-gradient(#0000 35%, #000b); }
#screen .credits { height: 180px; overflow: hidden; margin-top: 10px; mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent); -webkit-mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent); }
#screen .credits .roll { animation: roll 22s linear infinite; line-height: 1.5; opacity: 0.9; }
#screen .credits p { margin: 0 0 22px; }
#screen .credits b { color: #ffd27a; }
@keyframes roll { from { transform: translateY(180px); } to { transform: translateY(-100%); } }
@media (prefers-reduced-motion: reduce) { #screen .credits .roll { animation-duration: 60s; } }

/* Wind arrow on storm levels */
#hud .wind { left: 50%; top: 36px; font-size: 22px; color: #bcd4ff; transform-origin: 50% 50%; transition: transform 0.2s linear; }
#hud .wind.hidden { display: none; }

/* Level editor */
#editor {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #050811ee;
  overflow: auto;
}
#editor.hidden { display: none; }
#editor .bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
#editor .bar b { color: #ffd27a; font-size: 18px; margin-right: 8px; }
#editor button {
  font: 600 13px system-ui, sans-serif;
  color: #f3e6c8;
  background: #1a2233;
  border: 1px solid #f3e6c844;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
#editor button:hover { border-color: #ffd27a99; }
#editor .tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 900px; }
#editor .tools button { display: flex; align-items: center; gap: 6px; }
#editor .tools button.sel { background: #ffd27a33; border-color: #ffd27a; }
#editor .tools small { opacity: 0.5; font-weight: 400; }
#editor .tools i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
#editor .grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  width: min(960px, 100%, (100vh - 280px) * 2);
  aspect-ratio: 2 / 1;
  border: 1px solid #f3e6c833;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
#editor .grid > div { display: flex; align-items: center; justify-content: center; font-size: 11px; color: #bfe6ff; border: 1px solid #0003; }
#editor .water, #editor .tools .twater i { background: #17394a; }
#editor .wall, #editor .tools .twall i { background: #6b5f57; }
#editor .buoy, #editor .tools .tbuoy i { background: radial-gradient(#9fe8d6 35%, #17394a 40%); }
#editor .tools .tbuoy i { background: #9fe8d6; }
#editor .oil, #editor .tools .toil i { background: radial-gradient(#ffb347 35%, #17394a 40%); }
#editor .tools .toil i { background: #ffb347; }
#editor .shadow, #editor .tools .tshadow i { background: radial-gradient(#8a4fd1 40%, #17394a 45%); }
#editor .tools .tshadow i { background: #8a4fd1; }
#editor .boat, #editor .tools .tboat i { background: #d9a05b; }
#editor .light, #editor .tools .tlight i { background: #fff1b8; box-shadow: 0 0 8px #ffd27a; }
#editor .cur, #editor .tools .tcur i { background: #1d5770; }
#editor .wisp, #editor .tools .twisp i { background: radial-gradient(#9fd8ff 30%, #17394a 38%); }
#editor .brute, #editor .tools .tbrute i { background: radial-gradient(#b0303a 48%, #17394a 54%); }
#editor .tools .twisp i { background: #9fd8ff; }
#editor .tools .tbrute i { background: #b0303a; }
#editor .whirl, #editor .tools .twhirl i { background: radial-gradient(#04080c 25%, #bfe6ff 32%, #17394a 45%); }
#editor .shard, #editor .tools .tshard i { background: radial-gradient(#ffe39a 30%, #17394a 38%); }
#editor .gate, #editor .tools .tgate i { background: repeating-linear-gradient(90deg, #5a3d22 0 3px, #2a2a2e 3px 5px); box-shadow: inset 0 0 0 2px #3f9c8a; }
#editor .tools .tshard i { background: #ffd27a; }
#editor .settings-row, #editor .modes-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; font-size: 13px; }
#editor .settings-row input, #editor .settings-row select {
  font: 13px system-ui, sans-serif; color: #f3e6c8; background: #1a2233; border: 1px solid #ffd27a44;
  border-radius: 6px; padding: 4px 8px; margin-left: 4px;
}
#editor .settings-row input { width: 170px; }
#editor .modes-row button.sel { background: #ffd27a33; border-color: #ffd27a; }
#editor button:disabled { opacity: 0.35; cursor: default; }
#editor .grid > div.pre { outline: 2px solid #ffd27acc; outline-offset: -2px; }
#editor .grid > div.axis { box-shadow: inset 2px 0 0 #ffd27a88; }
#editor .guide { margin: 0; padding: 8px 16px 8px 36px; max-width: 720px; font-size: 13px; line-height: 1.5;
  background: #0d1420e6; border: 1px solid #ffd27a44; border-radius: 8px; }
#editor .guide.hidden { display: none; }
#editor .stats { margin: 0; font-size: 12px; opacity: 0.85; text-align: center; }
#editor .stats em { color: #ffd27a; font-style: normal; }
#editor .status { margin: 0; color: #9fe8d6; font-weight: 600; }
#editor .status.bad { color: #ffb38a; }
#editor .help { margin: 0; font-size: 12px; opacity: 0.6; text-align: center; }
#screen span[data-action] { cursor: pointer; text-decoration: underline dotted; }

/* Touch screens and narrow (phone) layouts */
.touch-only { display: none; }
@media (pointer: coarse) {
  .touch-only { display: list-item; }
  .keys-only { display: none; }
  #hud .msg { bottom: 120px; }
}
@media (max-width: 600px) {
  #hud { font-size: 13px; }
  #hud .timer { left: 16px; top: 62px; transform: none; }
  #hud .oil { width: 120px; }
  #hud .wind { top: 58px; }
  #hud .fps { top: 82px; }
  #hud .msg { font-size: 17px; padding: 0 12px; box-sizing: border-box; }
  #screen h1 { letter-spacing: 2px; }
  #touch button { width: 64px; height: 64px; }
}

/* Title: Embers and the Boatyard link */
#screen .embers-line { margin: 14px 0 0; cursor: pointer; color: #ffd27a; }
#screen .embers-line b { color: #f3e6c8; }
#screen .earned { color: #ffd27a; font-weight: 700; font-size: 18px; margin: 6px 0; }

/* Boatyard: list on the left, details on the right, the live 3D boat in between */
#shop {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr minmax(300px, 400px);
  grid-template-rows: auto 1fr;
  pointer-events: none;
  background: linear-gradient(90deg, #050811dd 0, #05081100 30%, #05081100 62%, #050811e6 100%);
}
#shop.hidden { display: none; }
#shop > * { pointer-events: auto; }
#shop header { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: #050811cc; }
#shop header b { font-size: 22px; color: #ffd27a; letter-spacing: 2px; }
#shop header .embers { margin-left: auto; font-size: 18px; color: #ffd27a; font-weight: 700; }
#shop button { font: 600 13px system-ui, sans-serif; color: #f3e6c8; background: #1a2233; border: 1px solid #f3e6c844; border-radius: 6px; padding: 6px 10px; cursor: pointer; }
#shop button:hover { border-color: #ffd27a99; }
#shop button.poor { opacity: 0.55; }
#shop .list { overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
#shop .list button { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 9px 12px; }
#shop .list button small { color: #ffd27a; font-weight: 600; }
#shop .list button.own small { color: #9fe8d6; }
#shop .list button.sel { background: #ffd27a2e; border-color: #ffd27a; }
#shop .detail { grid-column: 3; overflow-y: auto; padding: 4px 16px 16px; }
#shop h2 { margin: 6px 0 2px; color: #ffd27a; }
#shop h3 { margin: 14px 0 6px; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; opacity: 0.7; }
#shop .blurb { margin: 0 0 10px; opacity: 0.85; line-height: 1.4; }
#shop .bars { list-style: none; padding: 0; margin: 0; }
#shop .bars li { display: grid; grid-template-columns: 105px 1fr 16px; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
#shop .bars i { height: 8px; border-radius: 4px; background: #ffffff1a; overflow: hidden; }
#shop .bars i b { display: block; height: 100%; background: linear-gradient(90deg, #c46a1b, #ffcf66); }
#shop .bars em { font-style: normal; font-size: 11px; }
#shop .bars em.up { color: #8be38b; }
#shop .bars em.down { color: #ff8a7a; }
#shop .numbers { font-size: 12px; opacity: 0.6; margin: 6px 0; }
#shop .main-act { margin: 10px 0; }
#shop .big { font-size: 16px; padding: 9px 18px; background: #6a4a17; border-color: #ffd27a; }
#shop .eq { color: #9fe8d6; font-weight: 700; }
#shop .ups { list-style: none; padding: 0; margin: 0; }
#shop .ups li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; margin: 6px 0; font-size: 13px; }
#shop .ups small { display: block; opacity: 0.6; font-size: 11px; }
#shop .pips { color: #ffd27a; letter-spacing: 2px; }
#shop .paints { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: 6px 0; }
#shop .paints > span { width: 40px; font-size: 13px; opacity: 0.8; }
#shop .sw { width: 24px; height: 24px; padding: 0; border-radius: 50%; background: var(--c); border: 2px solid #0008; font-size: 10px; }
#shop .sw.on { border-color: #fff; box-shadow: 0 0 0 2px #ffd27a; }
#shop .sw.locked { opacity: 0.55; }
#shop .sw.glow { box-shadow: 0 0 8px var(--c); }
#shop .hint, #shop .msg { font-size: 13px; opacity: 0.8; }
#shop .msg { color: #ffd27a; min-height: 1em; }
@media (max-width: 800px) {
  #shop { grid-template-columns: 1fr; grid-template-rows: auto 30vh auto 1fr; background: #050811e6; }
  #shop .list { grid-row: 3; flex-direction: row; overflow-x: auto; }
  #shop .list button { flex: 0 0 auto; }
  #shop .detail { grid-column: 1; grid-row: 4; }
}

#shop .trait { margin: 0 0 10px; color: #9fe8d6; font-weight: 600; font-size: 13px; }
