:root {
  --bg: #070b1a;
  --ink: #eaf0ff;
  --muted: #9fb0d3;
  --dim: #6c7ca3;
  --glass: rgba(14, 22, 48, 0.62);
  --glass-2: rgba(24, 36, 74, 0.72);
  --line: rgba(150, 185, 255, 0.22);
  --line-2: rgba(150, 185, 255, 0.4);
  --nova: #ff8a2a;
  --nova-2: #ff3d7f;
  --cyan: #4fd8ff;
  --good: #5be38f;
  --bad: #ff5468;
  --warn: #ffc94a;
  --radius: 14px;
  --tap: 46px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --head: 'Orbitron', 'Exo 2', system-ui, sans-serif;
  --body: 'Exo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; }
body { overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
input, select, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; }
p { margin: 0 0 0.7em; line-height: 1.45; }
h1, h2, h3 { font-family: var(--head); font-weight: 700; letter-spacing: 0.04em; margin: 0; }

/* The screen art IS the play area, as in the iPhone original: full brightness, exactly between the
   top bar and the tabs, behind the controls (a scroll container's own background stays put). */
#app {
  position: relative; height: 100%; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
@media (min-width: 600px) {
  body { background: radial-gradient(ellipse at center, #121a36 0%, #05070f 75%); }
  #app { box-shadow: 0 0 0 1px var(--line), 0 0 80px rgba(0, 0, 0, 0.8); }
}

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 56px;
  background: linear-gradient(180deg, #1b2547, #0d1430);
  border-bottom: 1px solid rgba(255, 255, 255, 0.18); z-index: 2; position: relative;
}
#topbar[hidden], #tabs[hidden] { display: none; }
.icon-btn { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--glass); display: grid; place-content: center; gap: 4px; cursor: pointer; }
.icon-btn span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }
#where { flex: 1; min-width: 0; }
#where-name { font-family: var(--head); font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#where-sub, #cash-sub { font-size: 12px; color: var(--muted); }
#cash { text-align: right; }
#cash-val { font-family: var(--head); font-size: 15px; color: var(--warn); }

/* ---- screen ---- */
#screen { background: #000 center top / cover no-repeat; flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 14px 12px 20px; position: relative; z-index: 1; }
#screen.full { padding: 0; }
body.no-tabs #screen { padding-bottom: calc(12px + var(--safe-b)); }
.screen-title { font-size: 20px; margin: 4px 2px 12px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8); }
.screen-title small { display: block; font-family: var(--body); font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 3px; }

.panel { background: rgba(4, 7, 18, 0.38); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
#screen { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.7); }
.sheet, .paper { text-shadow: none; }
.panel h3 { font-size: 13px; color: var(--cyan); text-transform: uppercase; letter-spacing: 0.12em; margin: 0 0 8px; }
.panel.tight { padding: 4px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.note { color: var(--muted); font-size: 14px; }
.lines p { margin: 0 0 0.35em; }

/* rows (cargo, equipment, ships ...) */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; min-height: 52px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name.bold { color: var(--good); }
.row .sub { font-size: 13px; color: var(--muted); }
.row .price { font-family: var(--head); font-size: 14px; text-align: right; min-width: 74px; }
.row .price.na { color: var(--dim); font-family: var(--body); font-size: 13px; }
.row .thumb { width: 52px; height: 52px; object-fit: contain; flex: none; }
.row.disabled .name { color: var(--dim); }

/* buttons */
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.55); color: #fff;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.18) 50%, rgba(255, 255, 255, 0.1) 51%, rgba(255, 255, 255, 0.22) 100%);
  font-weight: 700; font-size: 15px; letter-spacing: 0.01em; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 2px 6px rgba(0, 0, 0, 0.45);
  transition: transform 0.06s, filter 0.15s;
}
.btn:active { transform: scale(0.97); filter: brightness(1.25); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.primary { border-color: rgba(255, 190, 120, 0.85); background: linear-gradient(180deg, rgba(255, 190, 110, 0.6) 0%, rgba(255, 120, 60, 0.4) 50%, rgba(230, 70, 60, 0.35) 51%, rgba(255, 110, 70, 0.45) 100%); }
.btn.danger { border-color: rgba(255, 120, 130, 0.85); background: linear-gradient(180deg, rgba(255, 110, 120, 0.6) 0%, rgba(200, 40, 60, 0.45) 50%, rgba(160, 20, 40, 0.4) 51%, rgba(210, 50, 70, 0.5) 100%); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.round { width: var(--tap); padding: 0; border-radius: 50%; font-size: 22px; }
.btn.wide { width: 100%; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.btn-col { display: grid; gap: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* ---- bottom tabs ---- */
#tabs {
  display: grid; grid-template-columns: repeat(5, 1fr); z-index: 2;
  padding: 6px 6px calc(6px + var(--safe-b));
  background: linear-gradient(180deg, #161d38, #070b1a); position: relative;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0 4px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; cursor: pointer; border-radius: 10px; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--ink); background: rgba(79, 216, 255, 0.1); }
.tab.on svg { color: var(--nova); }

/* sub navigation (segmented) */
.seg { display: flex; gap: 6px; margin: 0 0 12px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(4, 7, 18, 0.5); color: #dfe7ff; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.on { color: var(--ink); border-color: var(--nova); background: rgba(255, 138, 42, 0.18); }

/* ---- overlays ---- */
#overlays { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.overlay { position: absolute; inset: 0; pointer-events: auto; background: rgba(2, 4, 12, 0); transition: background 0.16s; display: flex; justify-content: center; padding: 16px; padding-top: calc(16px + var(--safe-t)); padding-bottom: calc(16px + var(--safe-b)); }
.overlay.in { background: rgba(2, 4, 12, 0.6); }
.overlay.center { align-items: center; }
.overlay.bottom { align-items: flex-end; }
.sheet {
  width: 100%; max-width: 480px; max-height: 100%; display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(30, 44, 88, 0.96), rgba(12, 18, 40, 0.97));
  border: 1px solid var(--line-2); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  transform: translateY(14px) scale(0.98); opacity: 0; transition: transform 0.16s, opacity 0.16s;
}
.overlay.in .sheet { transform: none; opacity: 1; }
.overlay.out .sheet { transform: translateY(14px); opacity: 0; }
.overlay.tall .sheet { max-height: 92%; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 6px; }
.sheet-head h2 { font-size: 17px; line-height: 1.25; }
.sheet-body { padding: 8px 18px 6px; overflow-y: auto; font-size: 16px; }
.sheet-body.scroll { flex: 1; }
.sheet-buttons { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.sheet-buttons .btn { flex: 1 1 30%; }
.sheet-buttons .help-btn { flex: 0 0 var(--tap); padding: 0; }
.alert-icon { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-family: var(--head); font-weight: 900; background: rgba(79, 216, 255, 0.2); color: var(--cyan); border: 1px solid var(--cyan); }
.alert-warning .alert-icon { background: rgba(255, 201, 74, 0.18); color: var(--warn); border-color: var(--warn); }
.alert-error .alert-icon { background: rgba(255, 84, 104, 0.18); color: var(--bad); border-color: var(--bad); }
.alert-confirm .alert-icon { background: rgba(255, 138, 42, 0.18); color: var(--nova); border-color: var(--nova); }
.field { width: 100%; min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line-2); background: rgba(0, 0, 0, 0.35); color: var(--ink); font: 600 18px var(--body); padding: 0 14px; margin: 6px 0; }
.field.num { text-align: center; font-family: var(--head); }
.field:focus { outline: 2px solid var(--nova); outline-offset: 1px; }
.field-label { display: block; color: var(--muted); font-size: 13px; margin-top: 8px; }
.stepper { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.stepper .field { flex: 1; margin: 0; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--nova); flex: none; }
.modal-form { padding-bottom: 6px; }
.modal-form > .inner { overflow-y: auto; padding: 14px 14px 8px; }

/* ---- title ---- */
.title-screen { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 10px; padding: 0 24px calc(28px + var(--safe-b)); }
.title-screen .spacer { flex: 1; }
.title-screen .btn { min-height: 52px; font-size: 17px; }
.title-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; }
.title-foot a { color: var(--muted); }

/* ---- encounter ---- */
.enc { display: flex; flex-direction: column; min-height: 100%; gap: 8px; position: relative; }
.enc-ships { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 4px; padding: 12px 0 6px; }
.ship-pic { position: relative; width: 100%; max-width: 230px; aspect-ratio: 1; justify-self: center; }
.ship-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform: scale(1.35); }
.ship-pic.them { transform: scaleX(-1); }
.enc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.enc-stats .info { display: grid; gap: 3px; align-content: start; }
.enc-stats .who { display: flex; flex-direction: column; }
.enc-stats .who .name { font-family: var(--head); font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--good); transition: width 0.3s; }
.bar.mid i { background: var(--warn); }
.bar.low i { background: var(--bad); }
.bar.shield i { background: linear-gradient(90deg, #2d7dff, var(--cyan)); }
.bar.empty { opacity: 0.4; }
.enc-text { min-height: 64px; margin: 4px 0 0; padding: 0 2px; font-size: 16px; }
.enc-text p { margin: 0 0 0.3em; }
.enc-text .result p { color: var(--warn); }
.enc-text .next { color: #fff; }
.enc-actions { position: sticky; bottom: 0; padding: 8px 0 4px; display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-top: auto; }
.enc-actions .btn { min-height: 52px; }
.flash { animation: flash 0.35s; }
@keyframes flash { 0% { filter: brightness(2.5) saturate(0.4); } 100% { filter: none; } }
.shake { animation: shake 0.3s; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.tribbles { position: absolute; inset: 0; pointer-events: none; }
.tribble { position: absolute; width: 34px; height: 34px; border-radius: 50%; border: 0; pointer-events: auto; background: radial-gradient(circle at 35% 35%, #f6d59a, #b77b3c 60%, #6d4220); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }

/* ---- charts ---- */
.chart-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: rgba(3, 6, 18, 0.82); touch-action: manipulation; }
.chart-wrap canvas { display: block; width: 100%; height: auto; }
.chart-info { margin-top: 10px; }

/* ---- news ---- */
.paper { background: #efe7d2; color: #1d1a14; border-radius: 6px; padding: 16px 16px 10px; font-family: Georgia, 'Times New Roman', serif; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.paper h2 { font-family: 'Times New Roman', Georgia, serif; font-size: 26px; text-align: center; letter-spacing: 0.02em; border-bottom: 3px double #1d1a14; padding-bottom: 6px; margin-bottom: 10px; }
.paper p { font-size: 16px; padding-left: 14px; text-indent: -14px; }
.paper p::before { content: '• '; }

/* misc */
.pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid var(--line-2); color: var(--muted); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); } .cyan { color: var(--cyan); }
.center { text-align: center; }
.mt { margin-top: 12px; }
.hidden { display: none !important; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--glass-2); border: 1px solid var(--line-2); border-radius: 20px; padding: 8px 16px; font-size: 14px; z-index: 20; pointer-events: none; }
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list button { width: 100%; text-align: left; min-height: 50px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink); font-size: 16px; padding: 0 6px; cursor: pointer; }
.menu-list li:first-child button { border-top: 0; }
.menu-list h3 { margin: 14px 6px 6px; font-size: 12px; color: var(--cyan); letter-spacing: 0.14em; text-transform: uppercase; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
