/* style.css */
:root {
  color-scheme: dark;
  --ink: #f7f1dc;
  --muted: #b7d4dc;
  --ocean: #061c2e;
  --panel: rgba(5, 26, 43, 0.8);
  --panel-solid: #09253d;
  --line: rgba(203, 240, 245, 0.2);
  --gold: #ffd261;
  --gold-deep: #b77a1c;
  --coral: #ff7c71;
  --mint: #8ee5bd;
  --danger: #ff887f;
  --shadow: 0 14px 38px rgba(0, 12, 24, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --ink: #102b40;
    --muted: #42677d;
    --panel: rgba(241, 251, 250, 0.83);
    --panel-solid: #effaf9;
    --line: rgba(14, 70, 91, 0.17);
    --shadow: 0 14px 38px rgba(22, 62, 84, 0.18);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #102b40;
  --muted: #42677d;
  --panel: rgba(241, 251, 250, 0.83);
  --panel-solid: #effaf9;
  --line: rgba(14, 70, 91, 0.17);
  --shadow: 0 14px 38px rgba(22, 62, 84, 0.18);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: #061c2e;
  color: var(--ink);
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid #fff0a5;
  outline-offset: 3px;
}

#sea-view {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
  background: linear-gradient(#75cce4 0%, #237fa5 75%, #0c4766 100%);
}

#three-root,
#three-root canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#loading {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: white;
  background: radial-gradient(circle at 50% 35%, #237fa5, #061c2e 70%);
  transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-mark {
  margin: auto;
  color: #ffd261;
  font-size: 48px;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .3));
}
#loading strong { font-size: 21px; letter-spacing: .02em; }
#loading span { color: #cae9ef; font-size: 14px; }

.topbar {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding-top: 3px;
  text-shadow: 0 2px 10px rgba(0, 20, 35, .65);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: #12374e;
  background: var(--gold);
  border-radius: 50%;
  font-size: 22px;
  box-shadow: 0 4px 10px rgba(2, 18, 29, .3);
}
.brand strong { display: block; font-family: Georgia, serif; font-size: 18px; line-height: 1; }
.brand small { display: block; margin-top: 4px; color: #d4f3f4; font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }

.resources {
  display: flex;
  gap: 5px;
  pointer-events: auto;
}
.resource {
  min-width: 55px;
  padding: 7px 8px;
  text-align: center;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  backdrop-filter: blur(9px);
  box-shadow: var(--shadow);
}
.resource span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.resource strong { display: block; margin-top: 2px; font-size: 13px; white-space: nowrap; }
.resource.gold strong { color: var(--gold); }
.resource.hull strong { color: var(--mint); }

.icon-btn,
.close-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--panel);
  backdrop-filter: blur(9px);
  cursor: pointer;
  font-size: 23px;
  pointer-events: auto;
}

.glass {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.ship-card {
  position: absolute;
  z-index: 4;
  top: 81px;
  left: 12px;
  width: min(252px, calc(100% - 24px));
  padding: 11px 12px;
  border-radius: 14px;
  pointer-events: none;
}
.ship-card-top {
  display: flex;
  justify-content: space-between;
  gap: 9px;
  align-items: center;
}
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.ship-card strong { font-size: 14px; }
.status-pill {
  padding: 4px 7px;
  border-radius: 999px;
  color: #defcff;
  background: rgba(49, 147, 182, .35);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.status-pill.docked { color: #fff3c6; background: rgba(185, 119, 30, .46); }
.status-pill.danger { color: #ffe1dd; background: rgba(183, 57, 52, .55); }

.hull-meter,
.enemy-meter {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, .2);
}
.hull-meter { margin-top: 9px; }
.hull-meter i,
.enemy-meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f4a05b, #9de5bb);
  transition: width 180ms ease;
}
.location-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.target-card {
  position: absolute;
  z-index: 4;
  top: 187px;
  left: 12px;
  width: min(208px, calc(100% - 24px));
  padding: 10px 12px;
  border-radius: 13px;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.target-card.hidden {
  opacity: 0;
  transform: translateX(-16px);
}
.target-card strong { display: block; margin: 3px 0 6px; font-size: 13px; }
.target-row { display: flex; align-items: center; gap: 8px; }
.enemy-meter { flex: 1; }
.enemy-meter i { background: linear-gradient(90deg, #ffb86b, #ff706c); }
.target-row span { color: var(--muted); font-size: 10px; white-space: nowrap; }

.message {
  position: absolute;
  z-index: 8;
  top: 48%;
  left: 50%;
  width: max-content;
  max-width: min(88vw, 430px);
  padding: 10px 14px;
  border: 1px solid rgba(233, 249, 250, .25);
  border-radius: 12px;
  color: #efffff;
  background: rgba(4, 23, 38, .83);
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.message.show { opacity: 1; transform: translate(-50%, 0); }
.message.success { border-color: rgba(131, 238, 186, .56); }
.message.warning { border-color: rgba(255, 212, 110, .62); }
.message.danger { border-color: rgba(255, 118, 110, .67); }

.action-bar {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: calc(156px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1.23fr;
  gap: 8px;
}
.action-btn {
  display: flex;
  min-height: 55px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 14px;
  color: #fff;
  background: rgba(5, 29, 45, .82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  cursor: pointer;
  text-align: left;
}
.action-btn:not(:disabled):active { transform: translateY(2px); }
.action-btn:disabled { opacity: .62; cursor: not-allowed; }
.action-btn.fire {
  border-color: rgba(255, 188, 105, .72);
  background: linear-gradient(135deg, rgba(172, 59, 46, .94), rgba(113, 42, 39, .94));
}
.action-btn.dock:not(:disabled) {
  border-color: rgba(255, 219, 120, .55);
  background: rgba(87, 92, 49, .86);
}
.action-symbol {
  font-size: 26px;
  line-height: 1;
}
.action-btn b, .action-btn small { display: block; }
.action-btn b { font-size: 13px; }
.action-btn small { margin-top: 2px; opacity: .76; font-size: 10px; line-height: 1.05; }

.helm {
  position: absolute;
  z-index: 5;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
}
.steering-control,
.speed-control {
  display: flex;
  gap: 8px;
  align-items: center;
}
.helm-btn,
.speed-btn {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid rgba(235, 255, 255, .25);
  border-radius: 17px;
  color: #fff;
  background: rgba(5, 29, 45, .75);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  cursor: pointer;
  font-size: 20px;
  touch-action: none;
}
.helm-btn:active,
.speed-btn:active { background: rgba(35, 108, 134, .95); transform: scale(.96); }
.speed-control { gap: 5px; }
.speed-btn { width: 44px; height: 44px; border-radius: 13px; font-size: 15px; }
.speed-readout {
  min-width: 55px;
  padding: 6px 5px;
  color: white;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .4);
}
.speed-readout span { display: block; color: #d2eff3; font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.speed-readout strong { display: block; color: var(--gold); font-size: 15px; }

.help-hint {
  position: absolute;
  z-index: 4;
  right: 13px;
  bottom: calc(169px + env(safe-area-inset-bottom));
  color: rgba(233, 255, 255, .84);
  font-size: 10px;
  text-shadow: 0 1px 3px rgba(0, 25, 41, .9);
}
kbd {
  display: inline-block;
  min-width: 15px;
  margin-left: 2px;
  padding: 1px 3px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 3px;
  background: rgba(6, 34, 51, .55);
  font: inherit;
  text-align: center;
}

.modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  align-items: end;
  transition: visibility 200ms, opacity 200ms;
}
.modal.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 12, 20, .62);
  backdrop-filter: blur(3px);
}
.port-sheet {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: min(84dvh, 740px);
  margin: 0 auto;
  overflow: auto;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 0%, rgba(46, 139, 154, .18), transparent 33%),
    var(--panel-solid);
  box-shadow: 0 -12px 42px rgba(0, 0, 0, .34);
}
.port-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 18px 13px;
}
.port-header h1 {
  margin: 3px 0 5px;
  font-family: Georgia, serif;
  font-size: 28px;
  line-height: 1;
}
.port-header p {
  max-width: 480px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.close-btn { flex: 0 0 auto; color: var(--muted); font-size: 27px; }

.market-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 0 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}
.market-stats div { padding: 9px 7px; background: rgba(5, 28, 45, .18); text-align: center; }
.market-stats span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.market-stats strong { display: block; margin-top: 4px; font-size: 13px; color: var(--gold); }

.market-note {
  margin: 12px 18px;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  background: rgba(255, 207, 98, .1);
}
.market-note span { display: block; color: var(--gold); font-size: 9px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.market-note strong { display: block; margin-top: 4px; font-size: 12px; line-height: 1.35; }

.market-tabs {
  display: flex;
  gap: 18px;
  margin: 0 18px;
  border-bottom: 1px solid var(--line);
}
.market-tab {
  min-height: 42px;
  padding: 0 2px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}
.market-tab.active { border-color: var(--gold); color: var(--ink); }

.market-list {
  display: grid;
  gap: 8px;
  padding: 13px 18px;
}
.goods-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(14, 65, 81, .12);
}
.goods-info { display: flex; min-width: 0; gap: 10px; align-items: center; }
.goods-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 35px;
  height: 35px;
  border-radius: 10px;
  color: #153c50;
  background: #f3d884;
  font-size: 20px;
}
.goods-info strong,
.goods-info small { display: block; }
.goods-info strong { font-size: 13px; }
.goods-info small {
  max-width: 220px;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trade-controls { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.price { color: var(--gold); font-size: 12px; font-weight: 800; white-space: nowrap; }
.buy-btn,
.sell-btn,
.repair-btn,
.leave-btn {
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  color: #183242;
  background: var(--gold);
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}
.sell-btn { color: #123d39; background: var(--mint); }
.buy-btn:disabled,
.sell-btn:disabled { opacity: .42; cursor: not-allowed; }

.empty-hold {
  display: grid;
  min-height: 140px;
  place-content: center;
  gap: 7px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}
.empty-hold strong { color: var(--ink); font-size: 15px; }
.empty-hold span { max-width: 300px; font-size: 12px; line-height: 1.4; }

.port-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel-solid);
}
.repair-btn {
  color: #ffecc7;
  background: rgba(176, 102, 54, .88);
}
.leave-btn { color: #143542; background: #cae9e8; }

@media (min-width: 700px) {
  .topbar { top: 20px; left: 20px; right: 20px; }
  .ship-card { top: 89px; left: 20px; }
  .target-card { top: 195px; left: 20px; }
  .action-bar {
    right: auto;
    bottom: 24px;
    left: 20px;
    width: 340px;
  }
  .helm { right: 20px; bottom: 22px; left: auto; gap: 12px; }
  .help-hint { right: 22px; bottom: 100px; }
  .port-sheet { margin-bottom: 0; border-radius: 24px 24px 0 0; }
}

@media (max-width: 385px) {
  .brand small { display: none; }
  .brand strong { font-size: 16px; }
  .resource { min-width: 48px; padding: 6px 5px; }
  .resource span { font-size: 8px; }
  .resource strong { font-size: 11px; }
  .topbar { gap: 5px; }
  .help-hint { display: none; }
  .action-btn { padding: 7px; }
  .action-btn small { font-size: 9px; }
}
