/* Deep Drift — all layout is screen-space over a full-bleed canvas, so there is
   no letterboxed stage and viewport units mean what they look like they mean. */

:root {
  --ink: #e8e6f0;
  --dim: #9a97ab;
  --panel: rgba(16, 15, 24, 0.94);
  --edge: rgba(255, 255, 255, 0.12);
  --amber: #e0a33c;
  --good: #7fe0a0;
  --bad: #ff7b7b;
  --font: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b0a10;
  color: var(--ink);
  font-family: var(--ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ------------------------------------------------------------------- HUD */

#hud {
  position: fixed;
  inset: 0;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-family: var(--font);
  font-size: 12px;
}

.hud-left { display: flex; flex-direction: column; gap: 5px; }

.gauge { display: flex; align-items: center; gap: 7px; }
.gauge .tag { width: 34px; color: var(--dim); font-size: 10px; letter-spacing: 0.09em; }
.gauge .track {
  width: clamp(90px, 17vw, 170px);
  height: 11px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--edge);
  border-radius: 2px;
  overflow: hidden;
}
.gauge .fill { display: block; height: 100%; transition: width 0.12s linear; }
.gauge .val { font-size: 10px; color: var(--dim); min-width: 62px; }

#bar-fuel .fill  { background: linear-gradient(90deg, #4aa3d8, #8fd8ff); }
#bar-hull .fill  { background: linear-gradient(90deg, #4fbf7a, #a8f0c0); }
#bar-cargo .fill { background: linear-gradient(90deg, #c98a2c, #ffd88a); }
.gauge.low .fill { background: linear-gradient(90deg, #b4342f, #ff8a7a) !important; }
.gauge.low .val  { color: var(--bad); }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.stat { display: flex; gap: 8px; align-items: baseline; }
.stat .k { color: var(--dim); font-size: 10px; letter-spacing: 0.09em; }
.stat .v { font-size: 15px; font-weight: 700; }
.stat.sub .v { font-size: 11px; color: var(--dim); font-weight: 400; }
#money { color: var(--amber); }
.stat.core .v { color: #d9a8ff; font-size: 12px; }
.stat.core .k { color: #d9a8ff; }

.tools { display: flex; gap: 6px; margin-top: 6px; pointer-events: auto; }
.tools button {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--edge);
  color: var(--ink);
  border-radius: 5px;
  width: 30px; height: 26px;
  cursor: pointer;
  font-size: 13px;
}
.tools button:hover { background: rgba(255, 255, 255, 0.12); }

.hud-items {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  font-size: 11px;
}
.item {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--edge);
  border-radius: 5px;
  padding: 4px 8px;
  color: var(--ink);
}
.item b { color: var(--amber); margin-right: 5px; }
.item .count { color: var(--dim); margin-left: 5px; }
.item.empty { opacity: 0.38; }

#prompt {
  position: fixed;
  left: 50%;
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 74px));
  transform: translateX(-50%);
  background: rgba(10, 9, 16, 0.9);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
  font-family: var(--font);
  pointer-events: none;
  white-space: nowrap;
}
#prompt b { color: var(--amber); }

#toasts {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  margin: 0; padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
  pointer-events: none;
  max-width: min(380px, 68vw);
}
.toast {
  background: rgba(10, 9, 16, 0.92);
  border-left: 3px solid var(--edge);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11.5px;
  line-height: 1.4;
  animation: slide 0.18s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.bad  { border-left-color: var(--bad); }
@keyframes slide { from { opacity: 0; transform: translateX(14px); } }

/* --------------------------------------------------------------- panels */

#panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 94vw);
  max-height: 84vh;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(7px);
  z-index: 20;
}
#panel header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--edge);
}
#panel h2 { margin: 0; font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; flex: 1; }
#panel-money { font-family: var(--font); color: var(--amber); font-weight: 700; }
#panel-close {
  background: none; border: none; color: var(--dim);
  font-size: 15px; cursor: pointer; padding: 2px 4px;
}
#panel-close:hover { color: var(--ink); }
#panel-body { padding: 12px 16px; overflow-y: auto; }
#panel footer {
  padding: 9px 16px;
  border-top: 1px solid var(--edge);
  font-size: 11px;
  color: var(--dim);
  font-family: var(--font);
}
#panel footer b { color: var(--amber); }

.rows { display: flex; flex-direction: column; gap: 7px; }
.row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.row.small { font-size: 11.5px; color: var(--dim); }
.grow { flex: 1; }
.num { font-family: var(--font); color: var(--amber); }
.row.small .num { color: var(--dim); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.muted { color: var(--dim); font-size: 12px; line-height: 1.55; }

.foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 13px;
  padding-top: 11px;
  border-top: 1px solid var(--edge);
}
.total { flex: 1; font-family: var(--font); font-size: 15px; font-weight: 700; color: var(--amber); }

.pricelist { margin-top: 16px; }
.pricelist h4 {
  margin: 0 0 7px;
  font-size: 10px;
  letter-spacing: 0.11em;
  color: var(--dim);
  text-transform: uppercase;
}

.btn {
  background: var(--amber);
  color: #17130a;
  border: none;
  border-radius: 5px;
  padding: 6px 13px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--ui);
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { background: rgba(255, 255, 255, 0.1); color: var(--dim); cursor: not-allowed; }

.upgrade {
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.025);
}
.uhead { display: flex; align-items: baseline; gap: 10px; }
.uname { font-weight: 700; font-size: 13px; flex: 1; }
.pips { color: var(--amber); font-size: 10px; letter-spacing: 2px; }
.ublurb { color: var(--dim); font-size: 11.5px; margin: 3px 0 6px; line-height: 1.45; }
.ucur { font-family: var(--font); font-size: 11px; color: var(--dim); margin-bottom: 8px; }
.maxed { font-size: 11.5px; color: var(--good); font-family: var(--font); }

/* ------------------------------------------------------------- screens */

.screen {
  position: fixed;
  inset: 0;
  background: rgba(6, 5, 11, 0.86);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}
.card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 28px 30px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  max-height: 92vh;
  overflow-y: auto;
}
.card.wide { max-width: 720px; text-align: left; }
.card h1 {
  margin: 0 0 8px;
  font-size: clamp(30px, 7vw, 46px);
  letter-spacing: 0.12em;
  font-weight: 800;
}
.card h1 span { color: var(--amber); }
.card h1.won { color: var(--amber); font-size: clamp(26px, 6vw, 38px); }
.card h2 { margin: 0 0 12px; font-size: 19px; letter-spacing: 0.05em; }
.card h3 {
  margin: 16px 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--amber);
}
.tagline { color: var(--dim); font-size: 13.5px; line-height: 1.65; margin: 0 0 22px; }
.credit { color: var(--dim); font-size: 11px; margin: 18px 0 0; font-family: var(--font); }

.buttons { display: flex; flex-direction: column; gap: 9px; }
.buttons button, .card > button {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--edge);
  color: var(--ink);
  border-radius: 7px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
}
.buttons button:hover, .card > button:hover { background: rgba(255, 255, 255, 0.14); }
button.primary { background: var(--amber); color: #17130a; border-color: transparent; }
button.primary:hover { filter: brightness(1.12); background: var(--amber); }
button .sub { font-size: 10.5px; font-weight: 400; opacity: 0.75; font-family: var(--font); }
.card > button.primary { margin-top: 20px; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.cols p { color: var(--dim); font-size: 12.5px; line-height: 1.6; margin: 0 0 10px; }
.keys, .bullets { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.keys li { display: flex; gap: 10px; margin-bottom: 7px; align-items: baseline; }
.keys b {
  font-family: var(--font);
  color: var(--amber);
  min-width: 92px;
  font-size: 11px;
  flex: none;
}
.keys span { color: var(--dim); }
.bullets li { color: var(--dim); margin-bottom: 6px; line-height: 1.5; }
.bullets b { color: var(--ink); }

.stats { list-style: none; margin: 0 0 4px; padding: 0; font-family: var(--font); font-size: 12.5px; }
.stats li {
  display: flex;
  justify-content: space-between;
  padding: 7px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.stats span { color: var(--dim); }
.stats b { color: var(--amber); }

/* ------------------------------------------------------- touch controls */

#touch { display: none; }
body.touch #touch {
  display: flex;
  position: fixed;
  inset: auto 0 0 0;
  justify-content: space-between;
  padding: 0 max(14px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  pointer-events: none;
  z-index: 15;
}
body.touch .hud-items { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); }
body.touch #prompt { bottom: max(200px, calc(env(safe-area-inset-bottom) + 200px)); }
body.touch #toasts { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); max-width: 55vw; }

#touch .pad { display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
#touch button {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(20, 19, 30, 0.72);
  border: 1px solid var(--edge);
  color: var(--ink);
  font-size: 20px;
  touch-action: none;
}
#touch button:active { background: rgba(224, 163, 60, 0.5); }
#touch .thrust { width: 78px; height: 78px; background: rgba(224, 163, 60, 0.28); }

@media (max-width: 620px) {
  .cols { grid-template-columns: 1fr; gap: 6px; }
  .gauge .val { display: none; }
  .card { padding: 22px 20px; }
}

/* --------------------------------------------------- depth gauge & floaters */

#gauge {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  top: 20%;
  height: 58%;
  width: 12px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.45));
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.07);
}
#gauge .tick {
  position: absolute;
  left: 1px; right: 1px;
  height: 1px;
  background: rgba(255, 255, 255, 0.17);
}
#gauge-best {
  position: absolute;
  left: -3px; right: -3px;
  height: 2px;
  margin-top: -1px;
  background: rgba(255, 255, 255, 0.33);
  transition: top 0.2s linear;
}
#gauge-now {
  position: absolute;
  left: -5px;
  margin-top: -5px;
  border: 5px solid transparent;
  border-left-color: var(--amber);
  filter: drop-shadow(0 0 4px rgba(224, 163, 60, 0.6));
  transition: top 0.1s linear;
}

#floaters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}
.floater {
  position: absolute;
  top: 0;
  left: 0;
  font: 700 12px var(--ui);
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.7);
  will-change: transform, opacity;
}

body.touch #gauge { top: 16%; height: 44%; }
