:root {
  color-scheme: dark;
  --ink: #102327;
  --deep: #173238;
  --water: #789ca0;
  --paper: #e7e4d8;
  --muted: #9cb0ad;
  --mint: #77f2cf;
  --rust: #ef7e60;
  --tray: #13292e;
}

* { box-sizing: border-box; }

html, body { height: 100%; height: 100dvh; margin: 0; overflow: hidden; }

body {
  background: #0b1d21;
  color: var(--paper);
  font-family: "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input { font: inherit; }
button { color: inherit; }

.game-shell {
  width: min(100%, 980px);
  min-width: 0;
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--deep);
  box-shadow: 0 0 50px #0007;
}

.hud {
  min-width: 0;
  min-height: 60px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #bcd2cb29;
  background: #173238f5;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border: 2px solid var(--mint); color: var(--mint); font-weight: 900; font-size: 12px; letter-spacing: .06em; transform: rotate(-4deg); }
h1, h2, p { margin: 0; }
.brand h1 { font-size: clamp(15px, 2.5vw, 21px); line-height: 1; text-transform: uppercase; letter-spacing: .05em; }
.brand small, .panel-head small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .12em; }

.hud-values { display: flex; justify-content: center; gap: clamp(10px, 3.2vw, 32px); }
.hud-values span { display: flex; flex-direction: column; }
.hud-values small { color: var(--muted); font-size: 8px; letter-spacing: .1em; }
.hud-values strong { font-size: 13px; font-variant-numeric: tabular-nums; }
#damageValue { color: #f5a48e; }
#payoutValue { color: var(--mint); }

.hud-actions { display: flex; align-items: center; gap: 7px; }
.wind { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.wind img { width: 20px; height: 20px; transition: transform 1s linear; }
.small-button, .round-button, .close-button { border: 1px solid #bcd2cb55; background: #ffffff0a; font-weight: 800; cursor: pointer; }
.small-button { min-height: 34px; padding: 0 10px; font-size: 10px; letter-spacing: .09em; }
.round-button, .close-button { width: 34px; height: 34px; border-radius: 50%; font-size: 16px; }

.harbor-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--water); }
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; }

.berth-status { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 6px 10px; background: #102327d9; border: 1px solid #77f2cf66; color: var(--mint); font-size: 9px; font-weight: 900; letter-spacing: .11em; white-space: nowrap; pointer-events: none; }
.toast { position: absolute; top: 48px; left: 50%; transform: translate(-50%, -8px); min-width: 190px; max-width: calc(100% - 32px); padding: 10px 14px; background: #102327eb; border-left: 3px solid var(--mint); text-align: center; font-size: 11px; font-weight: 800; letter-spacing: .06em; opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-left-color: var(--rust); }

.first-hint { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: min(420px, calc(100% - 28px)); padding: 12px 12px 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: #102327ef; border: 1px solid #d9e5df55; box-shadow: 0 8px 30px #10232777; }
.first-hint strong { color: var(--mint); font-size: 11px; letter-spacing: .11em; }
.first-hint span { font-size: 11px; line-height: 1.35; color: #e7e4d8cc; }
.first-hint button { grid-row: 1 / 3; grid-column: 2; border: 0; background: var(--mint); color: var(--ink); padding: 0 12px; font-size: 10px; font-weight: 900; cursor: pointer; }

.controls {
  padding: 9px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  background: var(--tray);
  border-top: 1px solid #bcd2cb29;
  touch-action: none;
}
.control-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 5px; }
.control-block { min-width: 0; }
.control-title label { font-size: 10px; font-weight: 900; letter-spacing: .12em; color: var(--muted); }
.control-title output { color: var(--mint); font-size: 11px; font-weight: 900; font-variant-numeric: tabular-nums; }
.range-row { display: grid; grid-template-columns: 44px 1fr 60px 52px; gap: 8px; align-items: center; }
.range-row > span { color: #89a19e; font-size: 8px; font-weight: 800; letter-spacing: .06em; text-align: center; }
.range-row button { height: 34px; border: 1px solid #77f2cf77; background: #77f2cf12; color: var(--mint); font-size: 10px; font-weight: 900; cursor: pointer; }
input[type="range"] { width: 100%; min-width: 0; height: 36px; margin: 0; appearance: none; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: linear-gradient(90deg, #ef7e6099, #9bb1ad55 48%, #e7e4d8 50%, #9bb1ad55 52%, #77f2cf99); border-radius: 10px; }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 20px; height: 28px; margin-top: -11px; border-radius: 3px; border: 2px solid #13292e; background: var(--paper); box-shadow: 0 0 0 1px #e7e4d888; }
input[type="range"]::-moz-range-track { height: 6px; background: #78908d; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 26px; border: 2px solid #13292e; border-radius: 3px; background: var(--paper); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: #071316cc; backdrop-filter: blur(4px); }
.overlay[hidden] { display: none; }
.panel { width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: 18px; background: #e7e4d8; color: var(--ink); box-shadow: 0 18px 70px #0009; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 13px; border-bottom: 2px solid var(--ink); }
.panel-head h2 { text-transform: uppercase; font-size: 24px; }
.panel-head small { color: #456166; }
.close-button { color: var(--ink); border-color: #10232755; }
.panel-copy { margin: 13px 0; color: #3f5558; font-size: 12px; line-height: 1.45; }
.fleet-list { display: grid; gap: 8px; }
.fleet-card { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 12px; padding: 11px; border: 1px solid #1023273b; background: #fff5; }
.fleet-card.active { border: 2px solid #2a8f7f; }
.fleet-card img { width: 56px; height: 56px; object-fit: contain; background: #789ca044; }
.fleet-card h3 { margin: 0 0 3px; font-size: 15px; text-transform: uppercase; }
.fleet-card p { font-size: 10px; color: #536a6e; line-height: 1.4; }
.fleet-card button, .panel-done, .danger-button { min-height: 38px; border: 0; padding: 0 14px; background: var(--ink); color: var(--paper); font-size: 10px; font-weight: 900; letter-spacing: .06em; cursor: pointer; }
.fleet-card button:disabled { opacity: .5; cursor: not-allowed; }
.panel-done { width: 100%; margin-top: 14px; background: #2a8f7f; }
.danger-button { width: 100%; margin-top: 14px; background: #a84f3d; }
.help-panel ol { margin: 16px 0; padding-left: 20px; font-size: 12px; line-height: 1.55; }
.key-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 11px; }
.key-grid span { padding: 8px; background: #10232712; }

@media (max-width: 670px) {
  .hud { min-height: 55px; grid-template-columns: auto 1fr; gap: 6px 10px; }
  .brand-mark { width: 29px; height: 29px; }
  .brand h1 { font-size: 14px; }
  .hud-values { order: 3; grid-column: 1 / -1; justify-content: space-between; padding-top: 4px; border-top: 1px solid #bcd2cb1c; }
  .hud-actions { justify-self: end; }
  .wind span { display: none; }
  .small-button { min-height: 30px; }
  .round-button { width: 30px; height: 30px; }
  .controls { grid-template-columns: 1fr; gap: 7px; padding-top: 7px; }
  .control-title { margin-bottom: 1px; }
  .range-row { grid-template-columns: 42px 1fr 58px 50px; }
  input[type="range"] { height: 30px; }
  .range-row button { height: 30px; }
}

@media (max-width: 420px) {
  .range-row { grid-template-columns: 38px minmax(0, 1fr) 48px 48px; gap: 6px; }
  .range-row > span { font-size: 7px; overflow: hidden; }
  .hud-values { gap: 7px; }
  .hud-values strong { font-size: 12px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .hud { min-height: 45px; padding-block: 5px; }
  .brand small, .hud-values small { display: none; }
  .controls { grid-template-columns: 1fr 1fr; gap: 14px; padding-block: 5px; }
  .control-title { margin-bottom: 0; }
  .range-row { grid-template-columns: 36px 1fr 45px; }
  .range-row > span:nth-of-type(2) { display: none; }
  .first-hint { bottom: 6px; }
}
