*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ui-text-dim: #666666;
  --black:       #101010;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Press Start 2P', monospace;
  image-rendering: pixelated;
}

/* ── SCENE ── */
.scene { position: fixed; inset: 0; }

.sky {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, #c8e8f8, #a8d0f0);
}
#sky-tile {
  position: absolute; left: 0; right: 0; top: 0;
  height: 28%;
  background-image: url('/img/sky-tile.svg');
  background-repeat: repeat;
  background-size: 5px 8px;
  pointer-events: none;
  opacity: 0.18;
}

.sea {
  position: absolute; left: 0; right: 0; bottom: 0; height: 72%;
  background: linear-gradient(to bottom, #6878d0, #5060b8);
  z-index: 2;
}
#sea-canvas {
  position: absolute; left: 0; right: 0; top: 28%; bottom: 0;
  width: 100%; height: 72%;
  pointer-events: none; z-index: 3;
}

.horizon-line {
  position: absolute; left: 0; right: 0; top: 28%; height: 2px;
  background: #8898e0; opacity: 0.6;
}

/* ── DEPTH ── */
.depth-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: rgba(255,255,255,0.12); pointer-events: none; z-index: 4;
}
.depth-label {
  position: absolute; left: 10px; font-size: 6px;
  color: rgba(255,255,255,0.35); pointer-events: none;
  transform: translateY(-50%); z-index: 4;
}

/* ── CELESTIALS ── */
.celestial {
  position: absolute; border-radius: 50%; pointer-events: none;
  opacity: 0;
  transition: opacity 4s linear, top 120s linear, left 120s linear;
}
#sun {
  width: 32px; height: 32px;
  margin: -16px 0 0 -16px;
}
#sun img {
  width: 32px; height: 32px;
  image-rendering: pixelated;
  display: block;
}
#moon {
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
}
#moon img {
  width: 22px; height: 22px;
  image-rendering: pixelated;
  display: block;
}

/* ── CANVAS ── */
#stars-canvas { position: absolute; inset: 0; pointer-events: none; }
#clouds-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }

/* ── VIEWPORT ── */
.viewport {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  z-index: 5; pointer-events: none;
}

/* ── SHIP MARKERS ── */
.ship-marker {
  position: absolute;
  transform: translate(-50%, -100%);
  cursor: pointer; pointer-events: all; z-index: 4;
  transition: top 8s linear, left 8s linear;
}
.ship-marker:hover .ship-tooltip { opacity: 1; }
.ship-marker.panel-hover .ship-tooltip { opacity: 1; }
.ship-marker.highlighted .ship-svg { filter: drop-shadow(0 0 6px #ffd840); }

.ship-tooltip {
  position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%);
  background: #f4f0d0; border: 2px solid #2a1408;
  padding: 3px 6px; font-size: 6px; color: #2a1408;
  white-space: nowrap; opacity: 0;
  transition: opacity 0.15s; pointer-events: none;
}
.vessel-row.cross-highlight { background: rgba(200,160,64,0.25); }
.ship-pin {
  position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  pointer-events: none; display: none;
  image-rendering: pixelated;
}
.ship-pin.active {
  display: block;
  animation: pinbounce 1.2s ease-in-out infinite;
}
@keyframes pinbounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%       { transform: translateX(-50%) translateY(-5px); }
}

/* ── FOREGROUND ── */
.foreground {
  position: absolute; bottom: 28px; left: 0; right: 0;
  z-index: 5; pointer-events: none;
}

/* ── FOOTER ── */
.footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 28px; background: linear-gradient(to bottom, #e8d8a0, #d8c880);
  border-top: 2px solid #c8a060;
  display: flex; align-items: center; padding: 0 12px; z-index: 10;
}

/* ── WEATHER ── */
/* ── PIXEL PANEL (shared SNES-style box) ── */
/* Border is an absolutely-positioned SVG overlay generated by pixel-border.js  */
/* corner.svg (7×7 top-left) + edge.svg (7×2 left) tiled + mirrored for all 4  */
#weather-widget, #wx-location-panel, #bino-btn, #settings-btn {
  position: relative;
  background: linear-gradient(to bottom, #f4f0d0, #e8d8a0);
}
#vessel-panel {
  position: relative;
  background: linear-gradient(to bottom, #f4f0d0, #e8d8a0);
  border: none;
  box-shadow: none;
}

/* ── TOP-RIGHT UI COLUMN ── */
#ui-top-right {
  position: absolute; top: 12px; right: 12px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  z-index: 10;
}

/* ── WEATHER ── */
#wx-panels {
  display: flex; flex-direction: column; align-items: stretch;
}
#wx-location-panel {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; min-width: 280px;
}
.wx-crosshair { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; }
.wx-location-name { font-size: 12px; color: #3a2008; }
.wx-updated { font-size: 8px; color: #8a6030; margin-top: 4px; }

/* Horizontal arm connector between location panel and weather body */
.wx-h-connector {
  display: flex; justify-content: space-between;
  height: 36px; /* 14px bottom border + 8px gap + 14px top border */
}
.wx-arm { width: 14px; background: #503818; }

#weather-widget {
  padding: 20px 18px 24px; min-width: 280px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.wx-main-icon { width: 48px; height: 48px; image-rendering: pixelated; display: block; }
.wx-stats { display: flex; width: 100%; justify-content: space-around; }
.wx-stat { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.wx-stat-val { font-size: 18px; color: #3a2008; line-height: 1; }
.wx-unit { font-size: 9px; vertical-align: top; }
.wx-stat-label { font-size: 8px; color: #8a6030; }

/* Vertical arm connector from weather body to settings button */
.wx-v-arm {
  width: 14px; height: 20px;
  background: #503818;
  align-self: flex-end;
}

/* ── SETTINGS BUTTON ── */
#settings-btn {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-family: inherit;
}
#settings-btn:hover { background: linear-gradient(to bottom, #ece8c0, #dcc890); }

/* ── EASTER EGG MENU ── */
#easter-egg-menu {
  display: none;
  flex-direction: row; gap: 4px;
}
#easter-egg-menu.visible { display: flex; }
.egg-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 16px; cursor: pointer;
  font-family: inherit; font-size: 9px; color: #3a2008;
  background: linear-gradient(to bottom, #f4f0d0, #e8d8a0);
  min-width: 76px;
}
.egg-tile:hover { background: linear-gradient(to bottom, #ece8c0, #dcc890); }
.egg-tile img { width: 48px; height: 24px; image-rendering: pixelated; display: block; }

/* ── SETTINGS MODAL ── */
#settings-overlay {
  display: none;
  position: absolute; inset: 0; z-index: 25;
  background: rgba(0,0,0,0.35);
  align-items: center; justify-content: center;
}
#settings-overlay.visible { display: flex; }
#settings-modal {
  position: relative;
  background: linear-gradient(to bottom, #f4f0d0, #e8d8a0);
  padding: 28px 36px; min-width: 360px;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.settings-title {
  font-size: 16px; color: #3a2008;
}
#settings-close {
  background: none; border: none; font-family: inherit;
  font-size: 8px; color: #8a6030; cursor: pointer; padding: 4px;
}
#settings-close:hover { color: #3a2008; }
.settings-hr {
  height: 1px; background: #c8a060; margin-bottom: 20px;
}
.settings-row {
  display: flex; align-items: center; gap: 20px;
  font-size: 12px; color: #3a2008; cursor: pointer;
  padding: 10px 0;
}
.settings-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px; flex-shrink: 0;
  border: 3px solid #3a2008; background: #f4f0d0;
  cursor: pointer; image-rendering: pixelated;
}
.settings-row input[type="checkbox"]:checked {
  background: #3a2008;
  box-shadow: inset 0 0 0 3px #f4f0d0;
}
.settings-credit {
  margin-top: 20px; padding-top: 16px;
  border-top: 2px dashed #c8a060;
  font-size: 7px; color: #8a6030; line-height: 2.2;
}
.settings-credit a { color: #c89020; text-decoration: none; }
.settings-credit a:hover { color: #3a2008; text-decoration: underline; }

#last-updated { color: #8a6030; margin-left: 4px; }

/* ── BINOCULARS ── */
#bino-btn {
  position: absolute; bottom: 42px; left: 50%;
  transform: translateX(-50%); z-index: 10; cursor: pointer;
  padding: 16px 24px;
  display: flex; align-items: center; gap: 18px;
  white-space: nowrap;
  display: none; /* temporarily pulled (product decision) — change to flex to restore */
}
#bino-btn:hover { background: linear-gradient(to bottom, #ece8c0, #dcc890); }
#bino-btn img { width: 52px; height: 40px; image-rendering: pixelated; flex-shrink: 0; }
.bino-label { font-size: 10px; color: #3a2008; }

/* ── VESSEL PANEL ── */
#vessel-panel {
  position: absolute; bottom: 28px; left: 0; right: 0;
  height: 0; overflow: hidden;
  border-top: 3px solid #c8a858;
  box-shadow: none;
  z-index: 11; transition: height 0.3s cubic-bezier(0.2,0,0,1);
}
#vessel-panel.open { height: 280px; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; height: 36px;
  background: #e8d8a0; border-bottom: 1px solid #c8a858;
}
.panel-lhs { display: flex; align-items: center; gap: 8px; }
.panel-title { font-size: 7px; color: #3a2008; }
.panel-count {
  font-size: 6px; color: #3a2008;
  border: 1px solid #c8a060; padding: 1px 5px;
}
.panel-close {
  font-size: 7px; color: #8a6030; cursor: pointer;
  background: none; border: none; font-family: inherit; padding: 4px;
}
.panel-close:hover { color: #c03010; }

.vessel-list { overflow-y: auto; max-height: 244px; }
.vessel-list::-webkit-scrollbar { width: 4px; }
.vessel-list::-webkit-scrollbar-thumb { background: #8a6030; }
.vessel-list::-webkit-scrollbar-track { background: transparent; }

.vessel-row {
  display: grid;
  grid-template-columns: 44px 1fr 72px;
  gap: 8px; padding: 8px 10px;
  border-bottom: 2px solid rgba(0,0,0,0.08);
  cursor: pointer; align-items: center; min-height: 48px;
}
.vessel-row:nth-child(even) { background: rgba(0,0,0,0.04); }
.vessel-row:hover { background: rgba(80,144,216,0.14); }

.vr-icon {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.vr-ship-img {
  width: 32px; height: 20px; object-fit: contain;
  image-rendering: pixelated;
}
.vr-type {
  font-size: 5px; padding: 1px 3px; text-align: center;
  border: 1px solid var(--black); line-height: 1.4;
}
.vr-identity { min-width: 0; }
.vr-name {
  font-size: 8px; color: #3a2008;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.vr-sub {
  display: flex; align-items: center; gap: 5px;
  font-size: 6px; color: #8a6030;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vr-flag {
  width: 15px; height: 10px; flex-shrink: 0;
  image-rendering: pixelated;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}
.vr-stats {
  text-align: right; display: flex;
  flex-direction: column; align-items: flex-end; gap: 4px;
}
.vr-dist { font-size: 8px; color: #c89020; }
.vr-motion { font-size: 6px; color: var(--ui-text-dim); }

.vt-cargo   { background: #a0b8f8; color: #101040; }
.vt-tanker  { background: #f8c080; color: #402000; }
.vt-sail    { background: #80e8a0; color: #004020; }
.vt-ferry   { background: #f8e880; color: #404000; }
.vt-fishing { background: #d8a8f8; color: #300040; }
.vt-vessel  { background: #d0d0d0; color: #303030; }

.empty-panel {
  padding: 32px 24px; text-align: center;
  font-size: 7px; color: var(--ui-text-dim); line-height: 2;
}

/* ── INFO CARD ── */
#info-card {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 20;
  background: linear-gradient(to bottom, #f4f0d0, #e8d8a0);
  padding: 16px; display: none;
  width: min(400px, 90vw);
}
#info-card.visible { display: block; }

.card-close {
  margin-left: auto; flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 7px; letter-spacing: 1px;
  color: #8a6030; padding: 4px 0 4px 4px;
}
.card-close:hover { color: #3a2008; }

.card-body { display: flex; gap: 14px; align-items: center; }

.card-art {
  flex: 0 0 96px; width: 96px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.08);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
}
.card-ship-img {
  width: 84%; height: 84%; object-fit: contain;
  image-rendering: pixelated;
}

.card-info { min-width: 0; flex: 1; }

.card-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 2px solid #2a1408;
}
.card-title {
  font-size: 10px; color: #3a2008; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-flag {
  width: 24px; height: 16px; flex-shrink: 0;
  image-rendering: pixelated;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

.card-rows { display: flex; flex-direction: column; gap: 8px; }
.card-rows-dist { margin-top: 14px; padding-top: 10px; border-top: 2px dashed #c8a060; }

.card-row {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  font-size: 8px; white-space: nowrap;
}
.card-row .lbl { color: #8a6030; }
.card-row .val { color: #3a2008; }
.card-rows-dist .val { color: #c89020; font-size: 9px; }

/* ── TITLE SCREEN ── */
/* 3x3 grid: the centre cell holds the window (untouched, scene shows
   through); the other 8 cells are covered by 4 wash panels (2 full-width
   top/bottom + 2 that fill the middle row's sides) so the "room" wash
   surrounds the window exactly, with no reliance on box-shadow/mask hacks.
   Window fills 95% of the viewport in whichever axis binds first, holding
   windowFrame.svg's native 1772:1229 aspect ratio. */
#title-screen {
  --win-w: min(95vw, calc(95vh * 1772 / 1229));
  --win-h: calc(var(--win-w) * 1229 / 1772);
  position: absolute; inset: 0; z-index: 30;
  display: grid;
  grid-template-columns: 1fr var(--win-w) 1fr;
  grid-template-rows: 1fr var(--win-h) 1fr;
  pointer-events: all; cursor: pointer;
  transition: opacity 0.8s ease;
}
#title-screen.hidden { opacity: 0; pointer-events: none; }

/* Translucent, and each of the 4 panels stays inside its own grid cell
   (no overlap) — overlapping translucent layers compound into visibly
   darker patches. The unpainted frame-edge strips are covered separately
   by .side-patch, below. */
.wash { background: rgba(42, 51, 66, 0.78); }
.wash-top    { grid-column: 1 / 4; grid-row: 1; }
.wash-bottom { grid-column: 1 / 4; grid-row: 3; }
.wash-left   { grid-column: 1; grid-row: 2; }
.wash-right  { grid-column: 3; grid-row: 2; }

.window-wrap {
  grid-column: 2; grid-row: 2;
  position: relative;
}

/* windowFrame.svg's frame body only spans x=32–1740 of its 1772px canvas —
   the outer 32px column each side is unpainted (it exists so the sill can
   flare out at the bottom), so raw scene would leak through as a bright
   strip between frame and wash. These two strips fill that column with the
   same wash tint. They sit under .window-frame-img (DOM order), so the
   painted sill steps at the bottom still draw over them, and they never
   overlap the .wash-* panels (which stop at the grid cell boundary) —
   overlapping translucent layers would compound into darker patches. */
.side-patch {
  position: absolute; top: 0; bottom: 0;
  width: calc(100% * 32 / 1772);
  background: rgba(42, 51, 66, 0.78);
}
.side-patch-left  { left: 0; }
.side-patch-right { right: 0; }

.window-frame-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  pointer-events: none; user-select: none;
}

.title-box {
  position: absolute; left: 50%; top: 61%;
  transform: translate(-50%, -50%);
  width: 76%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none;
}

.title-text {
  /* Scales with the window so the composition holds at any viewport
     (0.0625 × win-w ≈ the 40px the old fixed-max design used at 640px) */
  font-size: calc(var(--win-w) * 0.0625);
  color: #171512; text-align: center; line-height: 1.35; letter-spacing: 0.5px;
  text-shadow:
    2px 0 0 #fdf8ec, -2px 0 0 #fdf8ec, 0 2px 0 #fdf8ec, 0 -2px 0 #fdf8ec,
    2px 2px 0 #fdf8ec, -2px -2px 0 #fdf8ec, 2px -2px 0 #fdf8ec, -2px 2px 0 #fdf8ec;
  animation: titlebob 2s ease-in-out infinite;
}
@keyframes titlebob {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.title-sub {
  font-size: calc(var(--win-w) * 0.019);
  color: #171512;
  text-shadow: 1px 0 0 #fdf8ec, -1px 0 0 #fdf8ec, 0 1px 0 #fdf8ec, 0 -1px 0 #fdf8ec;
  animation: blinksub 1.2s step-end infinite;
}
@keyframes blinksub {
  0%,100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── MOBILE ── */
@media (max-width: 599px) {
  #wx-location-panel, #weather-widget { min-width: 0; }
  #wx-location-panel { padding: 8px 10px; }
  #weather-widget { padding: 12px 10px 16px; gap: 12px; }
  .wx-stat-val { font-size: 14px; }
}

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  .title-text    { animation: none; }
  .title-sub     { animation: none; opacity: 0.7; }
  .ship-pin.active { animation: none; }
}
