:root {
  color-scheme: dark;
  --bg: #0b0608;
  --bg2: #140a0d;
  --panel: #1b0f13;
  --panel2: #251218;
  --line: #3a1f27;
  --text: #f6e8ea;
  --dim: #b08a90;
  --muted: #8a666c;
  --red: #ff4d3d;
  --red2: #d11f1f;
  --amber: #ffb347;
  --gold: #ffd36b;
  --green: #4fd18b;
  --blue: #59b8ff;
  --shadow: 0 8px 30px rgba(0,0,0,.5);
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(255,77,61,.10), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(255,120,40,.07), transparent 60%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------------- AUTH ---------------- */
.auth { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px; background: linear-gradient(180deg, var(--panel), var(--bg2));
  border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 18px; }
.sun {
  width: 74px; height: 74px; border-radius: 50%; margin: 0 auto 14px;
  background: radial-gradient(circle at 50% 45%, #ffd98a 0%, #ff7a3d 40%, #d11f1f 72%, #6f0d0d 100%);
  box-shadow: 0 0 50px 12px rgba(255,90,50,.45); animation: pulse 4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{transform:scale(1);box-shadow:0 0 44px 10px rgba(255,90,50,.4)} 50%{transform:scale(1.06);box-shadow:0 0 70px 18px rgba(255,90,50,.6)} }
.brand h1 { font-size: 2.2rem; letter-spacing: .35em; text-indent: .35em;
  background: linear-gradient(180deg,#ffd9a0,#ff5e3a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .sub { color: var(--dim); font-size: .85rem; letter-spacing: .2em; text-transform: uppercase; margin-top: 4px; }
.tabs { display: flex; gap: 8px; margin: 8px 0 16px; }
.tab { flex: 1; padding: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--dim); border-radius: 10px; font-weight: 600; }
.tab.active { color: var(--text); border-color: var(--red); background: rgba(255,77,61,.12); }
#authForm { display: flex; flex-direction: column; gap: 10px; }
input {
  background: #0e0709; border: 1px solid var(--line); color: var(--text);
  padding: 13px 14px; border-radius: 10px; font-size: 1rem; outline: none;
}
input:focus { border-color: var(--red); }
.primary {
  background: linear-gradient(180deg, var(--red), var(--red2)); color: #fff; border: none;
  padding: 14px; border-radius: 10px; font-size: 1.05rem; font-weight: 700; letter-spacing: .05em; margin-top: 4px;
  box-shadow: 0 6px 20px rgba(209,31,31,.4);
}
.primary:active { transform: translateY(1px); }
.error { color: var(--red); font-size: .85rem; min-height: 18px; text-align: center; }
.legal { text-align: center; color: var(--muted); font-size: .72rem; margin-top: 14px; }

/* ---------------- GAME SHELL ---------------- */
.game { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: linear-gradient(180deg, var(--panel), var(--bg2)); border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.tb-brand { font-weight: 800; letter-spacing: .18em; color: var(--gold); font-size: .85rem; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tb-brand .dot { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 40% 40%, #ffd98a, #ff4d3d 70%); box-shadow: 0 0 10px #ff4d3d; }
.tb-stats { display: flex; gap: 14px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tb-stats::-webkit-scrollbar { display: none; }
.stat { display: flex; flex-direction: column; min-width: max-content; }
.stat label { font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stat span { font-weight: 700; font-size: .95rem; }
.stat.energy .ebar { position: relative; width: 90px; height: 18px; background: #0e0709; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.efill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #ff7a3d, #ffd36b); }
.ebar span { position: relative; font-size: .7rem; font-weight: 700; text-shadow: 0 1px 2px #000; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--dim); padding: 8px 12px; border-radius: 9px; font-weight: 600; }

.view { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
.view::-webkit-scrollbar { width: 8px; }
.view::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* ---------------- NAV ---------------- */
.nav {
  display: flex; background: linear-gradient(0deg, var(--panel), var(--bg2)); border-top: 1px solid var(--line);
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}
.navb {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 8px 2px 7px; font-size: .62rem; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-top: 2px solid transparent;
}
.navb span { font-size: 1.15rem; }
.navb.active { color: var(--text); border-top-color: var(--red); background: rgba(255,77,61,.08); }

/* ---------------- CARDS / COMPONENTS ---------------- */
.card { background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 1rem; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: .8rem; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin: 10px 0 6px; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); font-size: .85rem; }
.dim { color: var(--dim); }
.pill { font-size: .65rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim); }
.pill.safe { color: var(--green); border-color: var(--green); }
.pill.danger { color: var(--red); border-color: var(--red); }
.pill.gold { color: var(--gold); border-color: var(--gold); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: .85rem; }
.btn:active { transform: translateY(1px); }
.btn.red { background: linear-gradient(180deg, var(--red), var(--red2)); border: none; color: #fff; }
.btn.green { background: rgba(79,209,139,.15); border-color: var(--green); color: var(--green); }
.btn.gold { background: rgba(255,211,107,.12); border-color: var(--gold); color: var(--gold); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .4; }
.num { width: 70px; background: #0e0709; border: 1px solid var(--line); color: var(--text); padding: 8px; border-radius: 8px; text-align: right; }
select.sel { background: #0e0709; border: 1px solid var(--line); color: var(--text); padding: 9px; border-radius: 8px; flex: 1; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: .7rem; text-transform: uppercase; padding: 6px 6px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 8px 6px; border-bottom: 1px solid rgba(58,31,39,.5); }
table.tbl tr.me td { background: rgba(255,77,61,.08); }

.warpgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 8px; }
.warp { text-align: left; }
.warp .wn { font-weight: 700; font-size: .9rem; }
.warp .wt { font-size: .68rem; color: var(--muted); margin-top: 2px; }

#mapCanvas { width: 100%; height: 260px; display: block; background: radial-gradient(circle at 50% 50%, #160b0e, #0b0608); border: 1px solid var(--line); border-radius: 12px; touch-action: none; }

.trade-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid rgba(58,31,39,.5); }
.trade-row:last-child { border-bottom: none; }
.cname { font-weight: 700; }
.cmeta { font-size: .68rem; color: var(--muted); }

.shipline { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(58,31,39,.5); }

.toast {
  position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--red); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: .85rem; z-index: 50; box-shadow: var(--shadow); max-width: 90%;
  animation: toastin .2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.good { border-color: var(--green); }
.toast.bad { border-color: var(--red); }

.chatwrap { display: flex; flex-direction: column; height: 100%; }
.chatlog { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.chatmsg { font-size: .85rem; }
.chatmsg b { color: var(--gold); }
.chatinput { display: flex; gap: 8px; margin-top: 10px; }
.chatinput input { flex: 1; }

.kv { display: flex; justify-content: space-between; font-size: .85rem; padding: 4px 0; }
.kv span:last-child { font-weight: 700; }

/* ---------------- DESKTOP ---------------- */
@media (min-width: 860px) {
  .game { flex-direction: row; }
  .topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 10; }
  .nav {
    flex-direction: column; width: 96px; border-top: none; border-right: 1px solid var(--line);
    padding-top: 64px; justify-content: flex-start; gap: 2px;
  }
  .navb { border-top: none; border-left: 3px solid transparent; padding: 14px 4px; font-size: .68rem; }
  .navb.active { border-top: none; border-left-color: var(--red); }
  .view { padding: 78px 26px 26px; }
  .view-inner { max-width: 1000px; margin: 0 auto; }
  #mapCanvas { height: 440px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}
@media (min-width: 860px) {
  .game { padding-left: 0; }
  .nav { order: -1; }
}
