:root {
  color-scheme: dark;
  --ink: #10282b;
  --panel: rgba(18, 42, 44, .94);
  --paper: #f4f1e7;
  --muted: #bdc9c4;
  --line: rgba(244, 241, 231, .2);
  --red: #e4444e;
  --teal: #25a8b5;
  --gold: #efb63e;
  --violet: #7a65c7;
  --green: #7fa65a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button,
a,
canvas,
input { touch-action: manipulation; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.game-shell {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  color: var(--paper);
  background: #15373b;
  isolation: isolate;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.top-bar {
  position: absolute;
  z-index: 10;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  width: min(1120px, calc(100% - 20px));
  min-height: 58px;
  display: grid;
  grid-template-columns: 42px minmax(150px, 1fr) minmax(130px, auto) 42px 42px 42px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 34, 36, .92);
  box-shadow: 0 9px 30px rgba(0, 0, 0, .3);
  backdrop-filter: blur(10px);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--paper);
  background: rgba(255, 255, 255, .045);
  font-size: 1.02rem;
  font-weight: 850;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible,
.tool-button:hover,
.tool-button:focus-visible,
.start-button:focus-visible,
button:focus-visible,
a:focus-visible {
  border-color: var(--gold);
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.brand-block,
.level-block {
  min-width: 0;
  display: grid;
}

.brand-block small,
.level-block small,
.mission-metric small,
.time-metric small,
.fleet-controls small,
.game-dialog > small,
.intro-scene > small,
.result-copy > small {
  color: var(--gold);
  font-size: .56rem;
  font-weight: 900;
}

.brand-block strong {
  overflow: hidden;
  margin-top: 2px;
  font-family: Georgia, serif;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-block { text-align: right; }

.level-block button {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  border: 0;
  color: var(--paper);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.level-block b {
  color: var(--gold);
  letter-spacing: 1px;
}

.mission-bar {
  position: absolute;
  z-index: 9;
  top: calc(max(10px, env(safe-area-inset-top)) + 68px);
  left: 50%;
  width: min(720px, calc(100% - 20px));
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) 94px;
  gap: 1px;
  transform: translateX(-50%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 34, 36, .92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .24);
  backdrop-filter: blur(8px);
}

.mission-metric,
.time-metric {
  min-width: 0;
  display: grid;
  align-content: center;
  padding: 8px 12px;
  border-right: 1px solid var(--line);
}

.mission-metric span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mission-metric b,
.time-metric b { font-size: .83rem; }

progress {
  width: 100%;
  height: 5px;
  overflow: hidden;
  border: 0;
  border-radius: 2px;
  color: var(--teal);
  background: rgba(255, 255, 255, .12);
}

progress::-webkit-progress-bar { background: rgba(255, 255, 255, .12); }
progress::-webkit-progress-value { background: currentColor; transition: width .3s ease; }
progress::-moz-progress-bar { background: currentColor; }
.satisfaction-metric progress { color: var(--green); }
.time-metric { border-right: 0; text-align: center; }
.time-metric.danger b { color: #ff777e; }

.map-status {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 98px);
  max-width: min(580px, calc(100% - 28px));
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  transform: translateX(-50%);
  border-radius: 5px;
  color: #edf1e8;
  background: rgba(10, 29, 31, .83);
  font-size: .72rem;
  font-weight: 750;
  text-align: center;
  pointer-events: none;
}

.route-dock {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(940px, calc(100% - 20px));
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto auto minmax(150px, auto);
  align-items: center;
  gap: 10px;
  padding: 10px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 34, 36, .94);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .28);
  backdrop-filter: blur(10px);
}

.route-tabs { display: flex; gap: 7px; }

.route-tab {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 7px;
  color: #fff;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}

.route-tab::before {
  content: "";
  width: 30px;
  height: 8px;
  border-radius: 4px;
  background: var(--route-color);
  box-shadow: 0 0 12px color-mix(in srgb, var(--route-color) 70%, transparent);
}

.route-tab b {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: .57rem;
}

.route-tab[aria-selected="true"] {
  border-color: var(--route-color);
  background: rgba(255, 255, 255, .11);
}

.fleet-controls {
  min-width: 178px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.icon-button.small { width: 36px; height: 36px; }
.clear-button { margin-left: 2px; color: #ff9297; }
.fleet-controls span { min-width: 50px; display: grid; text-align: center; }
.fleet-controls b { font-size: .75rem; }

.tool-button,
.start-button,
.game-dialog button,
.game-dialog a {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--paper);
  background: rgba(255, 255, 255, .055);
  font-size: .72rem;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

.tool-button { padding: 0 13px; white-space: nowrap; }
.tool-button span { color: var(--gold); }

.start-button,
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 16px;
  color: #132b2d !important;
  border-color: var(--gold) !important;
  background: var(--gold) !important;
}

.start-button:disabled {
  color: var(--muted) !important;
  border-color: var(--line) !important;
  background: rgba(255, 255, 255, .06) !important;
  cursor: not-allowed;
  opacity: .72;
}

.toast {
  position: absolute;
  z-index: 30;
  top: 132px;
  left: 50%;
  max-width: calc(100% - 28px);
  padding: 9px 13px;
  transform: translate(-50%, -12px);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--paper);
  background: rgba(12, 31, 33, .96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  font-size: .73rem;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.game-dialog {
  width: min(620px, calc(100% - 24px));
  max-height: calc(100svh - 24px);
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(244, 241, 231, .28);
  border-radius: 8px;
  color: var(--paper);
  background: #182f31;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .68);
}

.game-dialog::backdrop {
  background: rgba(5, 15, 16, .78);
  backdrop-filter: blur(6px);
}

.intro-dialog { width: min(820px, calc(100% - 24px)); grid-template-columns: 1fr 1fr; overflow: hidden; }
.intro-dialog[open] { display: grid; }

.intro-scene {
  position: relative;
  min-height: 470px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 38px;
  overflow: hidden;
  background-color: #27575b;
  background-image: url("assets/faroese-sea.png");
  background-size: cover;
  background-position: center;
}

.intro-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(8, 29, 31, .42);
}

.intro-scene > * { position: relative; z-index: 2; }
.intro-scene h1 { max-width: 100%; margin: 8px 0 11px; overflow-wrap: normal; white-space: nowrap; font: 600 1.8rem/1.02 Georgia, serif; letter-spacing: 0; }
.intro-scene p { max-width: 35ch; margin: 0; color: #e0e8e2; font-size: .88rem; line-height: 1.5; }

.intro-map { position: absolute; z-index: 1; inset: 10% 8% auto; height: 48%; opacity: .9; }
.intro-map span,
.intro-map i,
.intro-map b { position: absolute; height: 8px; border-radius: 5px; transform-origin: left center; }
.intro-map span { width: 62%; top: 32%; left: 10%; background: var(--red); transform: rotate(18deg); }
.intro-map i { width: 48%; top: 52%; left: 35%; background: var(--teal); transform: rotate(-25deg); }
.intro-map b { width: 42%; top: 64%; left: 18%; background: var(--gold); transform: rotate(-4deg); }
.intro-map span::before, .intro-map span::after, .intro-map i::before, .intro-map i::after, .intro-map b::before, .intro-map b::after { content: ""; position: absolute; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); border: 4px solid #fff; border-radius: 50%; background: currentColor; }
.intro-map span::before, .intro-map i::before, .intro-map b::before { left: -5px; }
.intro-map span::after, .intro-map i::after, .intro-map b::after { right: -5px; }

.briefing { min-width: 0; display: flex; flex-direction: column; padding: 36px; }
.briefing-progress { display: grid; gap: 7px; color: var(--muted); font-size: .65rem; font-weight: 800; }
.briefing dl, .result-copy dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; margin: 28px 0; background: var(--line); border: 1px solid var(--line); }
.briefing dl div, .result-copy dl div { min-height: 68px; display: grid; align-content: center; gap: 4px; padding: 10px 13px; background: #182f31; }
.briefing dt, .result-copy dt { color: var(--muted); font-size: .6rem; font-weight: 800; text-transform: uppercase; }
.briefing dd, .result-copy dd { margin: 0; font-size: .96rem; font-weight: 850; }
.briefing > p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.dialog-actions { display: grid; grid-template-columns: auto 1fr; gap: 9px; margin-top: auto; padding-top: 28px; }
.dialog-actions button { padding: 0 16px; }

.text-dialog,
.pause-dialog,
.levels-dialog { position: relative; padding: 31px; }
.text-dialog h2, .pause-dialog h2, .levels-dialog h2, .result-copy h2 { margin: 7px 0 14px; font: 600 2rem/1.05 Georgia, serif; letter-spacing: 0; }
.text-dialog > p, .pause-dialog > p { color: var(--muted); font-size: .84rem; line-height: 1.55; }
.text-dialog ol { margin: 22px 0; padding-left: 1.4rem; color: #e1e8e3; font-size: .82rem; line-height: 1.55; }
.text-dialog li + li { margin-top: 12px; }
.text-dialog li::marker { color: var(--gold); font-weight: 900; }
.dialog-close { position: absolute; top: 14px; right: 14px; width: 40px; min-height: 40px !important; padding: 0; font-size: 1.3rem !important; }

.settings-dialog label { display: grid; gap: 8px; padding: 16px 0; border-top: 1px solid var(--line); font-size: .82rem; font-weight: 750; }
.settings-dialog label > span { display: flex; justify-content: space-between; }
.settings-dialog output { color: var(--gold); }
.settings-dialog input[type="range"] { width: 100%; accent-color: var(--gold); }
.settings-dialog .toggle-row { grid-template-columns: 1fr auto; align-items: center; }
.toggle-row input { width: 42px; height: 24px; accent-color: var(--gold); }

.pause-dialog { width: min(430px, calc(100% - 24px)); text-align: center; }
.stack-actions { display: grid; gap: 9px; margin-top: 24px; }
.stack-actions button { justify-content: center; }

.result-dialog { width: min(840px, calc(100% - 24px)); grid-template-columns: minmax(270px, .9fr) minmax(360px, 1.1fr); overflow: hidden; }
.result-dialog[open] { display: grid; }
.result-photo { position: relative; min-height: 500px; background: #315c4a; }
.result-photo::after { content: ""; position: absolute; inset: 0; background: rgba(5, 20, 19, .18); pointer-events: none; }
.result-photo img { width: 100%; height: 100%; display: block; object-fit: cover; }
.result-photo span { position: absolute; z-index: 2; left: 18px; bottom: 18px; padding: 7px 9px; border-left: 3px solid var(--gold); background: rgba(12, 31, 31, .9); font-size: .72rem; font-weight: 900; }
.result-copy { min-width: 0; display: flex; flex-direction: column; padding: 32px; }
.result-stars { color: var(--gold); font-size: 1.75rem; word-spacing: 4px; }
.result-copy > p { margin: 17px 0 5px; color: #dce5df; font-size: .85rem; line-height: 1.55; }
.result-copy > a { align-self: flex-start; min-height: 0; border: 0; color: var(--muted); background: transparent; font-size: .66rem; text-decoration: underline; }
.result-copy dl { grid-template-columns: repeat(3, 1fr); margin: 22px 0; }
.result-copy dl div { min-height: 62px; padding: 8px; text-align: center; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }
.result-actions button { padding: 0 13px; }
.result-actions .primary { grid-column: 1 / -1; }

.levels-dialog { width: min(720px, calc(100% - 24px)); }
.chapter-tabs { display: flex; gap: 6px; margin: 20px 0 16px; overflow-x: auto; scrollbar-width: thin; }
.chapter-tab { min-width: 44px; height: 42px; padding: 0 12px; white-space: nowrap; }
.chapter-tab[aria-selected="true"] { color: #142d2f; border-color: var(--gold); background: var(--gold); }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.level-cell { min-width: 0; height: 58px; display: grid; place-items: center; align-content: center; gap: 2px; padding: 0; }
.level-cell b { font-size: .84rem; }
.level-cell span { min-height: 10px; color: var(--gold); font-size: .52rem; letter-spacing: 1px; }
.level-cell:disabled { opacity: .32; cursor: not-allowed; }
.level-cell.current { border-color: var(--gold); }

@media (max-width: 760px) {
  .game-shell { min-height: 480px; }
  .top-bar { grid-template-columns: 38px minmax(100px, 1fr) auto 38px 38px; min-height: 54px; }
  .top-bar .icon-button { width: 38px; height: 38px; }
  #helpButton { display: none; }
  .brand-block small { display: none; }
  .brand-block strong { font-size: .94rem; }
  .level-block small { display: none; }
  .level-block button { font-size: .68rem; }
  .mission-bar { top: calc(max(10px, env(safe-area-inset-top)) + 64px); grid-template-columns: 1fr 1fr 76px; }
  .mission-metric, .time-metric { padding: 7px 8px; }
  .mission-metric small, .time-metric small { font-size: .48rem; }
  .mission-metric b, .time-metric b { font-size: .7rem; }
  .route-dock { grid-template-columns: 1fr auto; min-height: 92px; gap: 7px; }
  .route-tabs { min-width: 0; }
  .route-tab { width: 44px; height: 44px; }
  .route-tab::before { width: 26px; }
  .fleet-controls { min-width: 0; justify-self: end; }
  .fleet-controls .icon-button { width: 32px; height: 32px; }
  .fleet-controls span { min-width: 44px; }
  .tool-button { justify-self: stretch; min-height: 38px; }
  .start-button { min-height: 38px; }
  .map-status { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 114px); font-size: .65rem; }
  .intro-dialog[open], .result-dialog[open] { display: block; }
  .intro-scene { min-height: 205px; padding: 24px; }
  .intro-scene h1 { font-size: 1.5rem; }
  .intro-scene p { font-size: .76rem; }
  .intro-map { inset: 0 5% auto; height: 25%; }
  .briefing { padding: 22px; }
  .briefing dl { margin: 18px 0; }
  .briefing dl div { min-height: 56px; }
  .dialog-actions { padding-top: 20px; }
  .text-dialog, .pause-dialog, .levels-dialog { padding: 24px 19px; }
  .text-dialog h2, .pause-dialog h2, .levels-dialog h2, .result-copy h2 { font-size: 1.55rem; }
  .result-photo { min-height: 175px; max-height: 210px; }
  .result-copy { padding: 22px; }
  .result-copy > p { margin-top: 10px; }
  .result-copy dl { margin: 16px 0; }
  .result-actions { margin-top: 8px; }
  .level-grid { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .level-cell { height: 50px; }
}

@media (max-width: 390px) {
  .brand-block strong { font-size: .82rem; }
  .route-tab { width: 40px; }
  .fleet-controls { gap: 4px; }
  .clear-button { display: none; }
  .tool-button, .start-button { padding: 0 9px; font-size: .65rem; }
  .dialog-actions, .result-actions { grid-template-columns: 1fr; }
  .result-actions .primary { grid-column: auto; grid-row: 1; }
}

@media (max-height: 610px) and (orientation: landscape) {
  .top-bar { left: 10px; width: 54px; height: calc(100% - 20px); grid-template-columns: 1fr; grid-template-rows: 42px 1fr auto 42px 42px 42px; transform: none; }
  .brand-block { writing-mode: vertical-rl; align-self: center; justify-self: center; }
  .brand-block small { display: none; }
  .level-block { text-align: center; }
  .level-block small, #levelStars { display: none; }
  .level-block button { writing-mode: vertical-rl; }
  .mission-bar { top: 10px; left: calc(50% + 32px); width: min(630px, calc(100% - 90px)); }
  .route-dock { left: calc(50% + 32px); width: min(800px, calc(100% - 90px)); }
  .map-status { left: calc(50% + 32px); }
}

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