/* Shared UI styles for Play and Sandbox. Pixel bevels use the generated ui_* sprites through
   border-image (set by JS as CSS variables); the box-shadow look is the fallback. */
:root {
  --bg: #0d0c17;
  --night: #1a1c33;
  --navy: #26304f;
  --slate: #3b4a6b;
  --ink: #120b17;
  --panel: #161a2c;
  --card: #1d2340;
  --card2: #232a4b;
  --line: #3b4a6b;
  --text: #ecebf3;
  --muted: #9aa3b8;
  --dim: #6b7390;
  --gold: #f8cf45;
  --gold2: #e0962a;
  --stone: #b9bbc6;
  --green: #43a047;
  --green2: #8fdc6a;
  --red: #e5654e;
  --red2: #b8332c;
  --cyan: #5fd6ea;
  --purple: #8a5cc9;
  --metal: #66707f;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 0px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
body { -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--cyan); }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.good { color: var(--green2); }
.bad { color: var(--red); }
.warn { color: var(--gold); }
.info { color: var(--cyan); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; line-height: 1.1; }

/* Pixel icons rendered from content sprites (data URLs) */
.pxi { display: inline-block; width: 24px; height: 24px; background-size: 100% 100%; image-rendering: pixelated; flex: none; vertical-align: middle; }
.pxi.s1 { width: 12px; height: 12px; }
.pxi.s3 { width: 36px; height: 36px; }
img.px, canvas.px { image-rendering: pixelated; image-rendering: crisp-edges; }

/* Buttons */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 4px 12px; cursor: pointer; user-select: none; text-decoration: none; color: var(--text);
  background: var(--metal); border: 2px solid var(--ink);
  box-shadow: inset 2px 2px 0 #98a3b3, inset -2px -2px 0 #3f4554;
  font-weight: 600; letter-spacing: .01em; white-space: nowrap;
}
.has-pixel-ui .btn { border-style: solid; border-width: 6px; border-image: var(--img-btn) 6 fill / 6px stretch; box-shadow: none; padding: 1px 8px; image-rendering: pixelated; }
.btn:hover { background: #7d8899; }
.has-pixel-ui .btn:hover { border-image-source: var(--img-btn-hover); }
.btn:active { box-shadow: inset 2px 2px 0 #3f4554, inset -2px -2px 0 #98a3b3; transform: translateY(1px); }
.has-pixel-ui .btn:active { border-image-source: var(--img-btn-pressed); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn[disabled], .btn.disabled { cursor: not-allowed; color: #8e96ad; background: var(--slate); box-shadow: inset 2px 2px 0 #4a5a7e, inset -2px -2px 0 #26304f; transform: none; }
.has-pixel-ui .btn[disabled], .has-pixel-ui .btn.disabled { border-image-source: var(--img-btn-disabled); }
.btn.primary { background: var(--green); box-shadow: inset 2px 2px 0 var(--green2), inset -2px -2px 0 #23602c; color: #fff; text-shadow: 0 1px 0 #1b4a22; }
.has-pixel-ui .btn.primary { border-image-source: var(--img-pbtn); }
.has-pixel-ui .btn.primary:hover { border-image-source: var(--img-pbtn-hover); }
.has-pixel-ui .btn.primary:active { border-image-source: var(--img-pbtn-pressed); }
.has-pixel-ui .btn.primary[disabled] { border-image-source: var(--img-pbtn-disabled); color: #8e96ad; text-shadow: none; }
.btn.danger { background: var(--red2); box-shadow: inset 2px 2px 0 var(--red), inset -2px -2px 0 #6e1a22; }
.has-pixel-ui .btn.danger { border-image: none; border: 2px solid var(--ink); box-shadow: inset 2px 2px 0 var(--red), inset -2px -2px 0 #6e1a22; }
.btn.mini { min-height: 24px; padding: 0 8px; font-size: 12px; }
.has-pixel-ui .btn.mini { padding: 0 4px; border-width: 4px; border-image-width: 4px; border-image-slice: 6; }
.btn.big { min-height: 38px; padding: 4px 16px; font-size: 15px; }
.btn.icon { min-width: 36px; padding: 2px; }
.btn.flash { animation: btnflash .35s steps(2) 2; }
@keyframes btnflash { 50% { filter: brightness(1.6); } }
.btn.shake { animation: shake .3s steps(3) 1; }
@keyframes shake { 0%,100% { transform: translateX(0); } 33% { transform: translateX(-2px); } 66% { transform: translateX(2px); } }

/* Cards / panels */
.card { background: var(--card); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--line), inset 0 4px 0 var(--card2); padding: 10px 12px; }
.has-pixel-ui .card { border-style: solid; border-width: 6px; border-image: var(--img-panel) 6 fill / 6px stretch; box-shadow: none; padding: 6px 8px; }
.card + .card { margin-top: 8px; }
.card h3 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.card h4 { margin: 8px 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; height: 18px; font-size: 11px; font-weight: 700; background: var(--navy); border: 1px solid var(--ink); color: var(--muted); white-space: nowrap; }
.pill.good { color: #10301a; background: var(--green2); }
.pill.warn { color: #3a2a00; background: var(--gold); }
.pill.bad { color: #fff; background: var(--red2); }
.pill.info { color: #062c33; background: var(--cyan); }
.meter { position: relative; height: 18px; min-width: 60px; background: #0d0c17; border: 2px solid var(--ink); box-shadow: inset 0 0 0 1px #2a3150; overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--green); box-shadow: inset 0 2px 0 var(--green2), inset 0 -2px 0 #23602c; transition: width .12s steps(4); }
.meter.low .fill { background: var(--red2); box-shadow: inset 0 2px 0 var(--red), inset 0 -2px 0 #6e1a22; }
.meter.cargo .fill { background: #84552a; box-shadow: inset 0 2px 0 #b47d40, inset 0 -2px 0 #57341a; }
.meter.full .fill { background: var(--gold2); box-shadow: inset 0 2px 0 var(--gold), inset 0 -2px 0 #a35a14; }
.meter .txt { position: relative; display: block; text-align: center; font: 700 12px/14px var(--mono); color: #fff; text-shadow: 1px 1px 0 var(--ink); white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); }
table.list { width: 100%; border-collapse: collapse; font-size: 12px; }
table.list th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 2px 4px; }
table.list td { padding: 2px 4px; border-bottom: 1px solid #222846; font-family: var(--mono); }
table.list td.l { font-family: var(--font); }

/* Modals */
#modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 7, 14, .72); display: flex; align-items: center; justify-content: center; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); pointer-events: auto; animation: fadein .12s steps(3); }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 24px); overflow: auto; background: var(--panel); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--line), 0 6px 0 #05040a; padding: 14px 16px; animation: popin .14s steps(3); }
.modal.wide { width: min(820px, 100%); }
.modal h2 { margin: 0 0 8px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; position: sticky; bottom: -14px; background: var(--panel); padding: 8px 0 2px; }
@keyframes fadein { from { opacity: 0; } }
@keyframes popin { from { transform: translateY(6px); opacity: .4; } }
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { animation: none !important; transition: none !important; }

/* Toasts */
#toasts { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; width: max-content; max-width: 92%; }
.toast { background: var(--night); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--line); padding: 6px 10px; font-size: 13px; display: flex; align-items: center; gap: 6px; animation: popin .14s steps(3); }
.toast.good { box-shadow: inset 0 0 0 2px #2e7d32; }
.toast.bad { box-shadow: inset 0 0 0 2px var(--red2); }
.toast.warn { box-shadow: inset 0 0 0 2px var(--gold2); }

.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px; padding: 3px 0; }
.field label { color: var(--muted); font-size: 12px; }
input[type=number], input[type=text], input[type=search], select, textarea { background: #0d0c17; border: 2px solid var(--ink); box-shadow: inset 0 0 0 1px var(--line); padding: 3px 6px; min-height: 26px; color: var(--text); }
input[type=number] { width: 96px; font-family: var(--mono); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cyan); outline-offset: 0; }
input.invalid { box-shadow: inset 0 0 0 2px var(--red); }
input[type=range] { accent-color: var(--green); }
input[type=checkbox] { accent-color: var(--green); width: 16px; height: 16px; }
.logo-c { display: block; image-rendering: pixelated; }
[data-logo] { display: inline-flex; align-items: center; line-height: 0; }
