:root {
  --navy: #13324a;
  --navy-2: #1d4a66;
  --teal: #2f8f9d;
  --sand: #f3e6c4;
  --cream: #fff8e6;
  --coral: #e8604c;
  --gold: #f2b84b;
  --ink: #1d2a33;
  --muted: #6b7b85;
  --good: #3c9a63;
  --bad: #c2453a;
  --panel: rgba(255, 248, 230, 0.96);
  --radius: 0.625rem;
  --shadow: 0 0.5rem 1.75rem rgba(8, 24, 36, 0.35);
  /* Type: a pirate blackletter for the big moments, old-print serifs for headings and
     reading, small caps for controls, and a quick hand for the log. */
  --font-display: 'Pirata One', 'IM Fell English SC', Georgia, serif;
  --font-head: 'IM Fell English SC', Georgia, serif;
  --font-old: 'IM Fell English', Georgia, serif;
  --font-body: 'Alegreya', Georgia, 'Palatino Linotype', serif;
  --font-ui: 'Alegreya Sans SC', 'Alegreya', system-ui, sans-serif;
  --font-hand: 'Caveat', 'Segoe Print', cursive;
  font-family: var(--font-body);
  color: var(--ink);
}
* { box-sizing: border-box; }
/* Everything is sized in rem, so this one rule scales the whole UI with the window.
   The vw cap keeps the three-column port layout from overflowing on tall, narrow windows. */
html { font-size: clamp(15px, min(0.6vw + 1.1vh, 1.2vw), 28px); }
html, body { margin: 0; height: 100%; background: var(--navy); }
body { overflow-x: hidden; }
button, input, select { font: inherit; }
button { font-family: var(--font-ui); font-weight: 500; letter-spacing: 0.02em; }
.gold, table.market td, .stat, .kv b, .bar em { font-variant-numeric: lining-nums tabular-nums; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 1.375rem; flex-wrap: wrap;
  padding: 0.5rem 1.125rem; background: linear-gradient(var(--navy), var(--navy-2));
  color: var(--cream); border-bottom: 2px solid rgba(242, 184, 75, 0.5);
}
#hud[hidden] { display: none; }
.brand { font-family: var(--font-display); font-size: 1.9rem; letter-spacing: 1px; color: var(--gold); margin-right: 0.5rem; }
.stat { display: flex; flex-direction: column; font-size: 1.1rem; line-height: 1.15; }
.stat label { font-family: var(--font-ui); font-size: 0.75rem; text-transform: lowercase; letter-spacing: 1.5px; opacity: 0.65; }
.stat small { font-size: 0.75rem; opacity: 0.75; }
.stat.bad .gold { color: #ff9b8c; }
.hud-btns { margin-left: auto; display: flex; gap: 0.375rem; }
.hud-btns button { background: rgba(255,255,255,0.1); color: var(--cream); border: 1px solid rgba(255,255,255,0.2); border-radius: 0.5rem; width: 2.5rem; height: 2.4rem; font-size: 1.05rem; cursor: pointer; }
.hud-btns button:hover { background: rgba(255,255,255,0.2); }
.gold::after { content: ' g'; opacity: 0.6; font-size: 0.85em; }

/* ---------- Generic UI ---------- */
#screen { flex: 1; position: relative; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.125rem 1.375rem; }
h1, h2, h3 { font-weight: normal; margin: 0 0 0.625rem; font-family: var(--font-head); }
h1 { font-family: var(--font-display); }
h2 { font-size: 1.9rem; color: var(--navy); }
h3 { font-size: 1.2rem; color: var(--navy-2); margin-top: 0.875rem; border-bottom: 1px solid rgba(19,50,74,0.15); padding-bottom: 0.25rem; }
.row { display: flex; gap: 0.625rem; align-items: center; margin-top: 0.75rem; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 0.75rem; align-items: center; }
.hint { color: var(--muted); font-size: 0.95rem; }
.muted { color: var(--muted); }
.bad { color: var(--bad); }
.up { color: var(--good); }
.down { color: var(--bad); }
.cheap { color: var(--good); font-weight: bold; }
.dear { color: var(--bad); font-weight: bold; }

button {
  background: var(--teal); color: white; border: none; border-radius: 0.5rem;
  padding: 0.5rem 0.875rem; cursor: pointer; transition: transform 0.08s, background 0.15s;
}
button:hover:not(:disabled) { background: #277c88; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }
button.big { background: var(--coral); font-size: 1.125rem; padding: 0.75rem 1.625rem; }
button.big:hover:not(:disabled) { background: #d4503d; }
button.ghost { background: transparent; color: var(--navy); border: 1px solid rgba(19,50,74,0.35); }
button.ghost:hover:not(:disabled) { background: rgba(19,50,74,0.08); }
input, select { border: 1px solid rgba(19,50,74,0.3); border-radius: 0.4375rem; padding: 0.4375rem 0.5625rem; background: white; }

/* ---------- Title / new game ---------- */
.title-art { position: absolute; inset: 0; background: linear-gradient(#5fb3b8, #f4c27a 60%, #2f8f9d 60%) center/cover; background-size: cover; background-position: center; }
.title-art.dim::after { content: ''; position: absolute; inset: 0; background: rgba(10, 30, 45, 0.45); }
.screen-title, .screen-newgame, .screen-end { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.title-box { position: relative; text-align: center; margin-top: -24vh; }
.title-box h1 {
  font-size: clamp(3.5rem, 10vw, 7.5rem); color: var(--cream); letter-spacing: 0.25rem;
  text-shadow: 0 0.25rem 0 rgba(19,50,74,0.55), 0 0.625rem 1.875rem rgba(19,50,74,0.4); margin: 0;
}
.title-box .tag { font-family: var(--font-old); color: var(--navy); font-size: 1.5rem; font-style: italic; margin: 0.375rem 0 1.625rem; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.title-box button.ghost { background: rgba(255,248,230,0.85); }

/* Title motion: looping video backdrop, ambient canvas, letters that rise in then ride the swell */
.title-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 1.2s ease; }
.title-video.ready { opacity: 1; }
.title-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.title-box h1 span {
  display: inline-block;
  animation: letter-in 0.9s cubic-bezier(0.2, 0.8, 0.25, 1.15) both, swell 4.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 70ms), calc(1.2s + var(--i) * 140ms);
}
.title-box .tag { animation: fade-up 0.8s ease-out 0.9s both; }
.title-box .col > * { animation: fade-up 0.7s ease-out both; }
.title-box .col > :nth-child(1) { animation-delay: 1.2s; }
.title-box .col > :nth-child(2) { animation-delay: 1.35s; }
.title-box .col > :nth-child(3) { animation-delay: 1.5s; }
.title-box button.big:not(.ghost) { animation: fade-up 0.7s ease-out 1.2s both, glow 2.8s ease-in-out 2.2s infinite; }
/* Cold-load "click to begin": an invisible full-screen button catches the first click,
   while the visible prompt sits in the menu's own spot so it can never overlap the title. */
.press-start {
  position: absolute; inset: 0; z-index: 5; width: 100%; border-radius: 0; background: transparent; padding: 0; cursor: pointer;
}
.press-start:hover:not(:disabled) { background: transparent; }
.menu-area { display: grid; justify-items: center; }
.menu-area > * { grid-area: 1 / 1; }   /* prompt and menu share one cell, so nothing shifts on reveal */
.press-hint {
  align-self: start; pointer-events: none;
  font-family: var(--font-display); font-size: 2rem; color: var(--cream); letter-spacing: 0.05em; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(19,50,74,0.6);
  animation: fade-up 0.8s ease-out 1.2s both, beckon 2.4s ease-in-out 2s infinite;
}
.press-hint span { display: inline-block; background: rgba(19, 50, 74, 0.62); padding: 0.35rem 1.6rem 0.5rem; border-radius: 999px; border: 2px solid rgba(242, 184, 75, 0.7); }
@keyframes beckon { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.title-box.gated .col { visibility: hidden; }
/* After the first click the menu rises in; a new animation name restarts it. */
.title-box.revealed .col > * { animation: reveal 0.6s ease-out both; }
.title-box.revealed .col > :nth-child(2) { animation-delay: 0.12s; }
.title-box.revealed .col > :nth-child(3) { animation-delay: 0.24s; }
.title-box.revealed button.big:not(.ghost) { animation: reveal 0.6s ease-out both, glow 2.8s ease-in-out 1s infinite; }
@keyframes reveal { from { opacity: 0; transform: translateY(14px); } }
@keyframes letter-in { from { opacity: 0; transform: translateY(2.5rem) rotate(-6deg) scale(0.8); } }
@keyframes swell { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-6px) rotate(-1deg); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(0.875rem); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(232, 96, 76, 0.55); } 50% { box-shadow: 0 0 0 0.625rem rgba(232, 96, 76, 0); } }
@media (prefers-reduced-motion: reduce) {
  .title-box h1 span, .title-box .tag, .title-box .col > *, .title-box button.big, .press-hint { animation: none !important; }
  .title-video { display: none; }
  .city-scene::before, .city-scene::after { animation: none; }
}
.newgame { position: relative; width: min(28.75rem, calc(100vw - 2rem)); display: flex; flex-direction: column; gap: 0.75rem; }
.newgame label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.875rem; color: var(--muted); }
.newgame .row { justify-content: space-between; }
.end .score { font-size: 1.5rem; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 0.625rem; padding: 0.25rem 0; font-size: 0.95rem; }

/* ---------- Port: city view ---------- */
.screen-port { padding: 1rem; background: radial-gradient(circle at 30% 0%, #23597a, var(--navy) 70%); min-height: calc(100vh - 3.75rem); }
.city { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.city-scene {
  position: relative; width: min(100%, calc((100vh - 10.5rem) * 16 / 9)); aspect-ratio: 16 / 9;
  background: #7cc1c9 center / 100% 100% no-repeat; border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; border: 3px solid #d9c38f;
  isolation: isolate; /* keep building/sign z-indexes inside the scene, under popups */
}
/* Harbor water glints: soft horizontal sparkles in two layers drifting opposite ways,
   each fading in and out, feathered at every edge so there are no hard bands.
   --water-top is set per port from where its quay ends. */
.city-scene::before, .city-scene::after {
  content: ''; position: absolute; left: 0; right: 0; top: var(--water-top, 82%); bottom: 0; pointer-events: none; z-index: 1;
  background-repeat: repeat-x; background-size: 50% 100%;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 70%, transparent);
          mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 70%, transparent);
}
.city-scene::before {
  background-image:
    radial-gradient(3.5rem 0.3rem at 18% 30%, rgba(255, 252, 230, 0.55), transparent 70%),
    radial-gradient(2.5rem 0.25rem at 62% 62%, rgba(255, 252, 230, 0.45), transparent 70%),
    radial-gradient(4.5rem 0.35rem at 85% 22%, rgba(255, 252, 230, 0.40), transparent 70%);
  animation: water-drift 70s linear infinite, water-glint 5.5s ease-in-out infinite alternate;
}
.city-scene::after {
  background-image:
    radial-gradient(3rem 0.28rem at 35% 75%, rgba(255, 252, 230, 0.45), transparent 70%),
    radial-gradient(5rem 0.32rem at 72% 40%, rgba(255, 252, 230, 0.35), transparent 70%),
    radial-gradient(2.2rem 0.22rem at 8% 55%, rgba(255, 252, 230, 0.50), transparent 70%);
  animation: water-drift-back 95s linear infinite, water-glint 7.5s ease-in-out -3s infinite alternate;
}
@keyframes water-drift { to { background-position: 100% 0; } }
@keyframes water-drift-back { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes water-glint { from { opacity: 0.25; } to { opacity: 0.9; } }
.city-sign {
  position: absolute; top: 4%; left: 50%; transform: translateX(-50%); z-index: 200; text-align: center;
  background: linear-gradient(#5b3a22, #46301e); color: var(--cream); padding: 0.35rem 1.6rem 0.5rem; border-radius: 0.4rem;
  box-shadow: 0 0.35rem 0.9rem rgba(0,0,0,0.35); border: 2px solid #c9a46a;
}
.city-sign span { display: block; font-family: var(--font-display); font-size: 2.4rem; line-height: 1.05; }
.city-sign small { font-family: var(--font-old); font-style: italic; font-size: 1rem; color: #f2dcaf; }
.bld {
  position: absolute; transform: translateX(-50%); background: none; padding: 0; border: 0; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; cursor: pointer; transition: transform 0.18s ease, filter 0.18s ease;
  filter: drop-shadow(0 0.4rem 0.4rem rgba(20, 30, 40, 0.25));
}
.bld:hover:not(:disabled) { background: none; transform: translateX(-50%) translateY(-3%) scale(1.04); filter: drop-shadow(0 0 0.6rem rgba(255, 214, 120, 0.95)) brightness(1.06); }
.bld:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
.bld img { height: 100%; width: auto; display: block; pointer-events: none; user-select: none; }
.bld-sign {
  position: absolute; bottom: -0.9rem; white-space: nowrap; font-family: var(--font-ui); font-weight: 700; font-size: 0.95rem;
  background: var(--cream); color: var(--navy); padding: 0.1rem 0.6rem; border-radius: 0.3rem; border: 2px solid #8a6a3e;
  box-shadow: 0 0.2rem 0.4rem rgba(0,0,0,0.25); transition: background 0.18s, color 0.18s;
}
.bld:hover .bld-sign { background: var(--gold); }
.city-bar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; justify-content: center; width: min(100%, calc((100vh - 10.5rem) * 16 / 9)); }
.city-bar .mini { display: flex; gap: 1rem; color: var(--cream); font-size: 1.05rem; margin-right: auto; flex-wrap: wrap; }
.city-bar .mini b { font-family: var(--font-head); color: var(--gold); }
.city-bar button.ghost { color: var(--cream); border-color: rgba(255,248,230,0.4); }
.sail { background: var(--coral); font-family: var(--font-display); font-size: 1.6rem; padding: 0.5rem 1.6rem; }
.sail:hover:not(:disabled) { background: #d4503d; }

/* ---------- Port: inside a building ---------- */
.bld-view { display: grid; grid-template-columns: 20rem 1fr 17.5rem; gap: 1rem; align-items: start; }
.keeper { display: flex; flex-direction: column; gap: 0.6rem; position: sticky; top: 1rem; }
.keeper-art {
  height: 15rem; border-radius: var(--radius); background: #3a2a1d center / cover; box-shadow: var(--shadow);
  position: relative; display: flex; align-items: flex-end; justify-content: center;
}
.portrait {
  width: 12rem; height: 12rem; padding: 0; border-radius: 50%; overflow: hidden; margin-bottom: -2.5rem;
  border: 0.3rem solid #d9c38f; box-shadow: 0 0.4rem 1rem rgba(0,0,0,0.45); background: var(--sand);
  animation: keeper-in 0.5s cubic-bezier(0.2, 0.8, 0.25, 1.2) both;
}
.portrait:hover:not(:disabled) { background: var(--sand); transform: scale(1.03); }
.portrait { position: relative; }
.portrait img { position: relative; width: 100%; height: 100%; object-fit: cover; display: block; }
.monogram { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-size: 4rem; color: var(--navy); }
@keyframes keeper-in { from { transform: translateY(2rem) scale(0.9); opacity: 0; } }
.keeper-name { margin-top: 2.2rem; text-align: center; color: var(--gold); font-family: var(--font-display); font-size: 1.9rem; line-height: 1; }
.keeper-name small { display: block; font-family: var(--font-old); font-style: italic; color: #e9dcc0; font-size: 1rem; margin-top: 0.3rem; }
.speech {
  position: relative; background: var(--cream); border-radius: 0.8rem; padding: 0.9rem 1.1rem; box-shadow: var(--shadow); min-height: 6.5rem;
}
.speech::before { content: ''; position: absolute; top: -0.7rem; left: 50%; margin-left: -0.7rem; border: 0.7rem solid transparent; border-top: 0; border-bottom-color: var(--cream); }
.speech-text { margin: 0; font-family: var(--font-old); font-size: 1.2rem; line-height: 1.4; color: #2b2419; }
.keeper .back { color: var(--cream); border-color: rgba(255,248,230,0.4); }
.threat { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; border-radius: 0.5rem; color: white; font-size: 1.1rem; }
.threat b { font-family: var(--font-display); font-size: 1.6rem; font-weight: normal; }
.threat.t0 { background: #3c9a63; } .threat.t1 { background: #c79a2e; } .threat.t2 { background: #d4673d; } .threat.t3 { background: #8e2b25; }
.checks { list-style: none; padding: 0; margin: 0.4rem 0 1rem; font-size: 1.1rem; }
.checks li { padding: 0.3rem 0; }
.checks li.warn { color: var(--bad); }
.modal-log { max-height: 60vh; overflow: auto; }
.port-main { align-self: start; }
.port-side { display: flex; flex-direction: column; gap: 0.75rem; }
.card { padding: 0.875rem 1rem; }
.card h3 { margin-top: 0; }
.bar { position: relative; height: 1.25rem; background: rgba(19,50,74,0.15); border-radius: 0.625rem; overflow: hidden; margin: 0.375rem 0; }
.bar span { position: absolute; inset: 0 auto 0 0; background: var(--good); }
.bar span.low { background: var(--bad); }
.bar.cargo span { background: var(--teal); }
.bar em { position: relative; font-style: normal; font-size: 0.75rem; padding-left: 0.5rem; line-height: 1.25rem; color: var(--ink); }
.cargo-list { margin-top: 0.5rem; font-size: 0.95rem; display: flex; flex-direction: column; gap: 3px; }
.cargo-list small { color: var(--muted); }
.log p { font-family: var(--font-hand); font-size: 1.2rem; margin: 0 0 0.5rem; line-height: 1.15; color: #3a3226; }
.log small { font-family: var(--font-ui); display: block; color: var(--muted); font-size: 0.6875rem; }

table.market { width: 100%; border-collapse: collapse; font-size: 1.1rem; }
table.market th { text-align: left; font-weight: normal; font-family: var(--font-ui); color: var(--muted); font-size: 0.85rem; text-transform: lowercase; letter-spacing: 1px; padding: 0.25rem 0.375rem; }
table.market td { padding: 0.8rem 0.5rem; border-top: 1px solid rgba(19,50,74,0.1); white-space: nowrap; }
table.market tr.locked td { color: var(--muted); font-style: italic; }
table.market .trade { display: flex; gap: 0.25rem; align-items: center; }
table.market .trade input { width: 5rem; padding: 0.4rem 0.5rem; height: 2.5rem; }
table.market .trade button { padding: 0.4rem 0.75rem; font-size: 0.95rem; background: #5d7f8f; height: 2.5rem; }
/* Buy/Sell show the order total under the label while a quantity is typed. */
table.market .trade button.buy, table.market .trade button.sell {
  min-width: 5.4rem; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
table.market .trade button small { font-family: var(--font-body); font-weight: 700; font-size: 0.8rem; letter-spacing: 0; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
table.market .trade button small:empty { display: none; }
table.market .trade button.buy.short { background: #9a4a3a; }
table.market .trade button.buy { background: var(--good); }
table.market .trade button.sell { background: var(--coral); }
.tagx { font-size: 0.625rem; text-transform: uppercase; letter-spacing: 1px; margin-left: 0.375rem; padding: 1px 0.375rem; border-radius: 0.375rem; color: white; vertical-align: middle; }
.tagx.shortage { background: var(--bad); }
.tagx.glut { background: var(--good); }
.rumor { background: #3a2a1d; color: #f6e2bb; padding: 1.125rem 1.25rem; border-radius: 0.5rem; font-family: var(--font-old); font-style: italic; font-size: 1.2rem; line-height: 1.5; margin: 0.625rem 0; min-height: 4rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.ship-offer { display: flex; gap: 0.625rem; align-items: center; padding: 0.5rem 0; border-top: 1px solid rgba(19,50,74,0.1); font-size: 0.875rem; }
.ship-offer canvas { width: 6rem; height: 3.375rem; background: linear-gradient(#bfe0e4, #6fb0bb); border-radius: 0.375rem; flex: none; }
.ship-offer.locked { opacity: 0.6; }
.ship-offer button { margin-top: 0.25rem; padding: 0.3125rem 0.625rem; font-size: 0.8125rem; }

/* ---------- Map ---------- */
.screen-map { display: flex; flex-direction: column; align-items: center; gap: 0.625rem; padding: 0.875rem; }
.map-wrap { position: relative; width: min(100%, calc((100vh - 8.75rem) * 1.975)); }
#map { width: 100%; height: auto; display: block; border-radius: var(--radius); box-shadow: var(--shadow); border: 3px solid #d9c38f; }
.map-tip { position: absolute; z-index: 5; pointer-events: none; background: var(--panel); border-radius: 0.5rem; padding: 0.625rem 0.75rem; width: 14.375rem; font-size: 0.8125rem; box-shadow: var(--shadow); }
.tip-prices { margin-top: 0.375rem; }
.tip-prices div { display: flex; justify-content: space-between; }
.map-bar { display: flex; gap: 1rem; align-items: center; color: var(--cream); font-family: var(--font-old); font-size: 1.15rem; }
.map-bar button.ghost { color: var(--cream); border-color: rgba(255,248,230,0.4); }

/* ---------- Combat ---------- */
.screen-combat { display: flex; flex-direction: column; align-items: center; gap: 0.625rem; padding: 0.875rem; }
.combat-wrap { width: min(100%, calc((100vh - 9.375rem) * 1.777)); }
#combat { width: 100%; display: block; border-radius: var(--radius); box-shadow: var(--shadow); cursor: crosshair; }
.combat-bar { display: flex; gap: 0.625rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.combat-bar .hint { color: #b8cad3; }
.combat-bar .n { background: rgba(0,0,0,0.25); border-radius: 0.375rem; padding: 0 0.375rem; margin-left: 0.25rem; }
.combat-bar button.ghost { color: var(--cream); border-color: rgba(255,248,230,0.5); font-size: 1.0625rem; padding: 0.5rem 1.375rem; }

/* ---------- Modal & toasts ---------- */
#modal { position: fixed; inset: 0; background: rgba(8, 20, 30, 0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
#modal[hidden] { display: none; }
.modal-box { width: min(32.5rem, 100%); animation: pop 0.18s ease-out; }
.modal-box p { line-height: 1.5; }
.modal-box .row { flex-wrap: wrap; justify-content: flex-end; }
.fleet { margin: 0.375rem 0; padding-left: 1.25rem; }
.modal-box.wide { width: min(54rem, 100%); max-height: 90vh; overflow-y: auto; }
.help-row { display: grid; grid-template-columns: 16rem 1fr; gap: 1.1rem; align-items: center; padding: 0.75rem 0; border-top: 1px solid rgba(19,50,74,0.12); }
.help-row > * { min-width: 0; }  /* let grid columns shrink below the screenshots' natural width */
.help-row h3 { margin: 0 0 0.3rem; border: 0; padding: 0; }
.help-row p { margin: 0; line-height: 1.45; }
.help-shot {
  width: 100%; padding: 0; border-radius: 0.5rem; overflow: hidden; border: 2px solid #d9c38f; background: var(--navy);
  box-shadow: 0 0.3rem 0.8rem rgba(8,24,36,0.25); cursor: zoom-in; transition: transform 0.15s;
}
.help-shot:hover:not(:disabled) { background: var(--navy); transform: scale(1.02); }
.help-shot img { width: 100%; aspect-ratio: 16 / 9; display: block; object-fit: cover; }
.help-row.zoomed { grid-template-columns: 1fr; }
.help-row.zoomed .help-shot { cursor: zoom-out; transform: none; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
#toasts { position: fixed; bottom: 1.125rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.375rem; z-index: 1100; align-items: center; pointer-events: none; }
.toast { background: var(--navy); color: var(--cream); padding: 0.5625rem 1rem; border-radius: 0.5rem; box-shadow: var(--shadow); font-size: 0.9375rem; transition: opacity 0.5s, transform 0.5s; }
.toast.good { background: #24694a; }
.toast.bad { background: #8e3329; }
.toast.out { opacity: 0; transform: translateY(0.5rem); }

/* ---------- Narrow screens ---------- */
@media (max-width: 1279px) {
  .bld-view { grid-template-columns: 16rem 1fr; }
  .port-side { grid-column: 2; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .portrait { width: 10rem; height: 10rem; }
}
@media (max-width: 900px) {
  .bld-view { grid-template-columns: 1fr; }
  .port-side { grid-column: auto; grid-template-columns: 1fr; }
  .keeper { position: static; }
  .city-sign span { font-size: 1.5rem; }
  .bld-sign { font-size: 0.75rem; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  #hud { gap: 0.75rem; padding: 0.5rem 0.75rem; }
  .brand { display: none; }
  .port-main { overflow-x: auto; }
  .screen-port { padding: 0.75rem 1rem; }
  .city-bar .mini { width: 100%; justify-content: center; }
  .press-hint { font-size: 1.3rem; }
  .help-row { grid-template-columns: 1fr; }
  .city-sign { top: 2%; padding: 0.15rem 0.7rem 0.25rem; }
  .city-sign span { font-size: 1.15rem; }
  .city-sign small { font-size: 0.7rem; }
  .bld-sign { font-size: 0.6rem; padding: 0 0.3rem; bottom: -0.6rem; }
}
