/* ==========================================================================
   Astral Sovereignty — play.astralsovereignty.com game client
   Single stylesheet. No frameworks, no external fonts, no network requests.
   Tokens mirror astralsovereignty.com (site.css) so the game feels like home.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  --bg-0:      #04050a;
  --bg-1:      #070910;
  --bg-2:      #0b0e17;
  --panel:     #12151d;
  --panel-2:   #171b25;
  --panel-3:   #1e2430;

  --line:      #1e2531;
  --line-soft: #161c26;
  --line-lit:  #2b3648;
  --edge-ui:   #4c5c78;

  --blue:      #2e75f2;
  --blue-lit:  #6ea8ff;
  --blue-deep: #1a3d6b;
  --blue-dim:  rgba(46, 117, 242, .14);

  --amber:     #e8a33d;
  --amber-dim: rgba(232, 163, 61, .13);
  --cyan:      #4fd8e8;
  --cyan-dim:  rgba(79, 216, 232, .12);
  --green:     #5fc88a;
  --green-dim: rgba(95, 200, 138, .13);
  --danger:    #e05a5a;
  --danger-dim: rgba(224, 90, 90, .12);

  --text:      #eaf1ff;
  --text-2:    #b9c8de;
  --text-3:    #8b9bb4;
  --text-4:    #7486a0;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", "Roboto Mono", monospace;

  --t-sm:   .875rem;
  --t-xs:   .765rem;

  --rad:    10px;
  --rad-sm: 7px;

  --shell-max: 1280px;
  --header-h: 3.4rem;
  --tabbar-h: 3.2rem;
}

/* ---------- 2. Reset & base ---------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue-lit); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .92em; }
::selection { background: var(--blue-deep); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden;
      clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; z-index: 100;
        background: var(--blue); color: #fff; padding: .5rem .9rem; border-radius: 0 0 8px 0; }
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--blue-lit); outline-offset: 2px; }

/* Starfield backdrop */
#stars { position: fixed; inset: 0; z-index: -1; opacity: .55; }

/* ---------- 3. App shell -------------------------------------------------- */

#app { display: flex; flex-direction: column; min-height: 100dvh; }

.shell-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .9rem;
  height: var(--header-h);
  padding: 0 clamp(.7rem, 2vw, 1.4rem);
  background: color-mix(in srgb, var(--bg-1) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.shell-header .brand {
  display: flex; align-items: center; gap: .5rem; color: var(--text);
  font-weight: 700; letter-spacing: -.02em; white-space: nowrap;
}
.shell-header .brand img { width: 24px; height: 24px; }
.shell-header .brand span { color: var(--blue-lit); }
.shell-header .spacer { flex: 1; }

.shard-chip {
  font-size: var(--t-xs); color: var(--text-3);
  border: 1px solid var(--line-lit); border-radius: 999px;
  padding: .18rem .65rem; white-space: nowrap; max-width: 12rem;
  overflow: hidden; text-overflow: ellipsis;
}

/* Tick status chip — the game clock, always visible in-game */
.tick-chip {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: var(--mono); font-size: var(--t-xs);
  border: 1px solid var(--line-lit); border-radius: 999px;
  padding: .22rem .7rem; color: var(--text-2); white-space: nowrap;
  background: var(--panel);
}
.tick-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.tick-chip.is-locked .dot { background: var(--danger); }
.tick-chip.is-precompute .dot { background: var(--amber); }
.tick-chip.is-due .dot { background: var(--cyan); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; border-radius: var(--rad-sm);
  background: transparent; border: 1px solid transparent; cursor: pointer;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--line-lit); }
.icon-btn img { width: 18px; height: 18px; }

/* ---------- 4. Tab bar ---------------------------------------------------- */

.tabbar {
  position: sticky; top: var(--header-h); z-index: 39;
  display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--bg-1) 92%, transparent);
  border-bottom: 1px solid var(--line);
  padding: 0 clamp(.4rem, 1.5vw, 1.2rem);
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar a {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .65rem .85rem; color: var(--text-3); white-space: nowrap;
  border-bottom: 2px solid transparent; font-size: var(--t-sm); font-weight: 600;
}
.tabbar a:hover { color: var(--text); text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--text); border-bottom-color: var(--blue); }
.tabbar a img { width: 16px; height: 16px; opacity: .8; }
.tabbar a .badge {
  min-width: 1.15rem; text-align: center;
  background: var(--blue-dim); color: var(--blue-lit);
  border-radius: 999px; font-size: var(--t-xs); padding: 0 .3rem;
}

/* ---------- 5. Main layout ----------------------------------------------- */

main.game-main {
  flex: 1; width: 100%; max-width: var(--shell-max);
  margin: 0 auto; padding: clamp(.8rem, 2vw, 1.5rem);
}
main.game-main.wide { max-width: none; padding: 0; }

.two-col { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .two-col { grid-template-columns: 340px 1fr; } }
.three-col { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 1100px) { .three-col { grid-template-columns: 280px 1fr 320px; } }

/* ---------- 6. Cards & panels --------------------------------------------- */

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--rad); padding: .95rem 1rem; margin-bottom: 1rem;
}
.card > h2, .card > h3 { display: flex; align-items: center; gap: .5rem; }
.card .card-sub { color: var(--text-3); font-size: var(--t-sm); margin-top: -.3rem; }
.card.selectable { cursor: pointer; transition: border-color .12s; }
.card.selectable:hover { border-color: var(--edge-ui); }
.card.is-selected { border-color: var(--blue); background: var(--panel-2); }

.panel-empty {
  border: 1px dashed var(--line-lit); border-radius: var(--rad);
  padding: 1.6rem 1rem; text-align: center; color: var(--text-3);
  font-size: var(--t-sm); margin-bottom: 1rem;
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: .15rem .9rem; margin: .4rem 0; }
.kv dt { color: var(--text-4); font-size: var(--t-sm); }
.kv dd { margin: 0; font-size: var(--t-sm); text-align: right; font-variant-numeric: tabular-nums; }

/* Status pills — mirrors the Godot client's StatusPill */
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .02em;
  border-radius: 999px; padding: .12rem .55rem;
  background: var(--panel-3); color: var(--text-2); white-space: nowrap;
}
.pill.ok, .pill.active, .pill.open, .pill.completed, .pill.applied, .pill.certified, .pill.running
  { background: var(--green-dim); color: var(--green); }
.pill.warn, .pill.pending, .pill.submitted, .pill.precompute, .pill.draft, .pill.building
  { background: var(--amber-dim); color: var(--amber); }
.pill.info, .pill.locked, .pill.reported, .pill.scanning
  { background: var(--cyan-dim); color: var(--cyan); }
.pill.bad, .pill.failed, .pill.cancelled, .pill.closed, .pill.decaying, .pill.rejected
  { background: var(--danger-dim); color: var(--danger); }
.pill.neutral { background: var(--panel-3); color: var(--text-3); }

/* Resource rows */
.res-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .8rem; padding: .3rem 0; border-bottom: 1px solid var(--line-soft);
  font-size: var(--t-sm);
}
.res-row:last-child { border-bottom: 0; }
.res-row .qty { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.res-row .qty small { color: var(--text-4); }

/* Meters (storage, population, build progress) */
.meter { height: 6px; border-radius: 999px; background: var(--panel-3); overflow: hidden; margin: .25rem 0 .1rem; }
.meter > i { display: block; height: 100%; background: var(--blue); border-radius: 999px; }
.meter.warn > i { background: var(--amber); }
.meter.bad > i { background: var(--danger); }
.meter-label { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--text-4); }

/* ---------- 7. Tables ----------------------------------------------------- */

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--rad); margin-bottom: 1rem; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.tbl th {
  text-align: left; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-4); font-weight: 600; padding: .55rem .75rem;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
.tbl td { padding: .5rem .75rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- 8. Buttons & forms -------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border-radius: var(--rad-sm); border: 1px solid var(--line-lit);
  background: var(--panel-2); color: var(--text);
  padding: .5rem .95rem; font-weight: 600; font-size: var(--t-sm);
  cursor: pointer; transition: background .12s, border-color .12s;
  text-decoration: none;
}
.btn:hover { background: var(--panel-3); border-color: var(--edge-ui); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-lit); border-color: var(--blue-lit); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-dim); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--blue-lit); }
.btn--ghost:hover { background: var(--blue-dim); border-color: transparent; }
.btn--sm { padding: .28rem .65rem; font-size: var(--t-xs); }
.btn img { width: 15px; height: 15px; }

.field { margin-bottom: .85rem; }
.field label { display: block; font-size: var(--t-sm); font-weight: 600; color: var(--text-2); margin-bottom: .25rem; }
.field .hint { font-size: var(--t-xs); color: var(--text-4); margin-top: .25rem; }
.field input[type="text"], .field input[type="email"], .field input[type="number"],
.field input[type="url"], .field select, .field textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-lit);
  border-radius: var(--rad-sm); padding: .5rem .65rem; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue); outline: none;
}
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--danger); }
.field .err { color: var(--danger); font-size: var(--t-xs); margin-top: .25rem; }
.field-row { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 9rem; margin-bottom: 0; }

fieldset { border: 1px solid var(--line); border-radius: var(--rad-sm); margin: 0 0 .85rem; padding: .7rem .85rem; }
legend { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-4); padding: 0 .35rem; }

/* ---------- 9. Notices, banners, toasts ----------------------------------- */

.banner {
  display: flex; gap: .6rem; align-items: flex-start;
  border: 1px solid var(--line-lit); border-left: 3px solid var(--blue);
  background: var(--panel); border-radius: var(--rad-sm);
  padding: .6rem .8rem; margin-bottom: 1rem; font-size: var(--t-sm);
}
.banner.warn { border-left-color: var(--amber); }
.banner.bad { border-left-color: var(--danger); }
.banner.ok { border-left-color: var(--green); }

#toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 90;
  display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 24rem);
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line-lit);
  border-left: 3px solid var(--blue); border-radius: var(--rad-sm);
  padding: .6rem .85rem; font-size: var(--t-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: toast-in .18s ease-out;
}
.toast.ok { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 10. Modal ------------------------------------------------------ */

dialog.modal {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-lit); border-radius: var(--rad);
  padding: 0; width: min(94vw, 560px); max-height: 86dvh;
}
dialog.modal::backdrop { background: rgba(2, 3, 6, .7); backdrop-filter: blur(2px); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; overflow-y: auto; max-height: calc(86dvh - 8rem); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: .6rem;
  padding: .8rem 1rem; border-top: 1px solid var(--line);
}
dialog.modal.modal--wide { width: min(96vw, 860px); }

/* ---------- 11. Login & shard select --------------------------------------- */

.auth-wrap {
  min-height: calc(100dvh - var(--header-h));
  display: grid; place-items: center; padding: 1.2rem;
}
.auth-card {
  width: min(94vw, 420px);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--rad); padding: 1.6rem 1.5rem;
}
.auth-card .logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.auth-card .logo img { width: 56px; height: 56px; }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card .sub { text-align: center; color: var(--text-3); font-size: var(--t-sm); margin-bottom: 1.2rem; }

.shard-list { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------- 12. Galaxy map ------------------------------------------------- */

.map-shell { position: relative; height: calc(100dvh - var(--header-h) - var(--tabbar-h)); }
.map-shell canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.map-shell canvas.dragging { cursor: grabbing; }
.map-hud {
  position: absolute; top: .7rem; left: .7rem; z-index: 5;
  display: flex; gap: .4rem; flex-wrap: wrap;
}
.map-hud .btn { backdrop-filter: blur(6px); background: color-mix(in srgb, var(--panel) 80%, transparent); }
.map-side {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 6;
  width: min(94vw, 360px); overflow-y: auto;
  background: color-mix(in srgb, var(--bg-1) 94%, transparent);
  border-left: 1px solid var(--line); padding: .9rem;
  transform: translateX(100%); transition: transform .18s ease-out;
}
.map-side.open { transform: none; }
.map-legend {
  position: absolute; bottom: .7rem; left: .7rem; z-index: 5;
  font-size: var(--t-xs); color: var(--text-3);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  border: 1px solid var(--line); border-radius: var(--rad-sm); padding: .45rem .65rem;
}

/* ---------- 13. Utility ---------------------------------------------------- */

.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.muted { color: var(--text-3); }
.small { font-size: var(--t-sm); }
.xs { font-size: var(--t-xs); }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.mt1 { margin-top: 1rem; } .mb1 { margin-bottom: 1rem; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-3 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 1000px) { .grid-3 { grid-template-columns: 1fr 1fr 1fr; } }

.entity-icon { width: 34px; height: 34px; object-fit: contain; flex: none; }
.entity-icon--lg { width: 56px; height: 56px; }

.loading { display: grid; place-items: center; padding: 3rem 1rem; color: var(--text-3); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line-lit); border-top-color: var(--blue);
  animation: spin .8s linear infinite; margin-bottom: .6rem;
}
@keyframes spin { to { transform: rotate(1turn); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
