:root {
  color-scheme: dark;
  --bg: #02040a; --glass: rgba(9, 15, 28, .74); --glass-strong: rgba(8, 13, 24, .92); --line: rgba(140, 190, 255, .16); --line-strong: rgba(140, 190, 255, .32);
  --text: #e7f0ff; --muted: #8fa3c2; --accent: #36e0ff; --accent-2: #8b7bff; --ok: #6ff0a6; --warn: #ffc35a; --bad: #ff6b7d; --pink: #ff9ad5;
  --radius: 14px; --font: "Segoe UI Variable", "Segoe UI", Inter, system-ui, -apple-system, sans-serif; --mono: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, monospace;
  --left-w: 338px; --right-w: 372px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; user-select: none; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
canvas#view:active { cursor: grabbing; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 12px; margin: 6px 0; }
.warning { color: var(--warn); white-space: pre-wrap; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
h2 { font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 650; margin: 0; color: #cfe0ff; }
h3 { margin: 10px 0 6px; font-size: 13.5px; color: #dbe8ff; }
h4 { margin: 10px 0 4px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
a { color: var(--accent); }

/* glass panels */
.panel, #topbar { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); box-shadow: 0 10px 40px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .04); }

#topbar { position: fixed; top: 10px; left: 10px; right: 10px; height: 50px; border-radius: var(--radius); display: flex; align-items: center; gap: 10px; padding: 0 8px 0 12px; z-index: 10; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; }
.brand b { font-weight: 700; background: linear-gradient(90deg, #9fe7ff, #a99bff); -webkit-background-clip: text; background-clip: text; color: transparent; }
#modes { display: flex; gap: 2px; background: rgba(255, 255, 255, .04); padding: 3px; border-radius: 10px; }
#modes button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#modes button[aria-selected="true"] { background: rgba(54, 224, 255, .14); color: var(--text); box-shadow: inset 0 0 0 1px rgba(54, 224, 255, .25); }
.tag { font-size: 8.5px; letter-spacing: .08em; color: var(--accent); border: 1px solid rgba(54, 224, 255, .4); border-radius: 5px; padding: 0 4px; line-height: 1.5; }
.tag.premium { color: #d3c8ff; border-color: rgba(169, 155, 255, .55); }
body[data-tier="pro"] .tag:not(.premium), body[data-tier="premium"] .tag { display: none; }
.clock { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
#clock { font-family: var(--mono); font-size: 12px; min-width: 150px; text-align: right; white-space: nowrap; }
#time-slider { width: 130px; accent-color: var(--accent); }
#time-speed { background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 7px; padding: 2px 4px; font-size: 11px; }
.right { display: flex; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line-strong); background: rgba(255, 255, 255, .04); border-radius: 999px; padding: 3px 10px; font-size: 11px; font-weight: 700; letter-spacing: .05em; white-space: nowrap; }
#tier-badge.pro { color: var(--accent); border-color: rgba(54, 224, 255, .5); }
#tier-badge.premium { color: #d3c8ff; border-color: rgba(169, 155, 255, .6); background: rgba(139, 123, 255, .14); }
.icon { border: 0; background: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.icon svg { width: 18px; height: 18px; }

/* side panels */
#left { position: fixed; top: 70px; left: 10px; bottom: 86px; width: var(--left-w); border-radius: var(--radius); padding: 12px 14px; overflow: auto; z-index: 5; }
#right { position: fixed; top: 70px; right: 10px; bottom: 86px; width: var(--right-w); border-radius: var(--radius); padding: 12px 14px; overflow: auto; z-index: 5; user-select: text; }
#right.collapsed { width: auto; bottom: auto; }
#right.collapsed #right-body { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-head .icon { width: 24px; height: 24px; }

/* forms */
#left-body label, .dialog label { display: grid; gap: 3px; color: var(--muted); font-size: 12px; margin: 6px 0; }
label.check { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; }
label.inline { grid-template-columns: 1fr auto; align-items: center; }
.lbl { font-size: 11.5px; }
.hint { font-size: 11px; color: var(--muted); opacity: .8; }
input:not([type=checkbox]):not([type=range]):not([type=color]), select, textarea { background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; color: var(--text); outline: none; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--line-strong); }
input[type=range] { accent-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.row label, .row3 label { margin: 4px 0; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px 10px; display: grid; gap: 2px; margin: 8px 0; min-width: 0; }
legend { color: var(--accent); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; padding: 0 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.btn { border: 1px solid var(--line-strong); background: rgba(255, 255, 255, .05); border-radius: 9px; padding: 6px 11px; font-weight: 600; white-space: nowrap; }
.btn:hover { background: rgba(255, 255, 255, .1); }
.btn.primary { background: linear-gradient(135deg, #22b5e8, #6f5cff); border-color: transparent; color: #fff; }
.btn.primary.premium { background: linear-gradient(135deg, #7c6cff, #c35cff); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 11.5px; }
.btn .tier, .tier { font-size: 9px; letter-spacing: .08em; margin-left: 5px; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.link { border: 0; background: none; color: var(--accent); padding: 0; }
.seg { display: flex; background: rgba(255, 255, 255, .04); border-radius: 9px; padding: 3px; margin: 6px 0 10px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: none; padding: 5px 6px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.seg button.active { background: rgba(54, 224, 255, .14); color: var(--text); }

/* results */
.stats { display: grid; gap: 6px; margin: 8px 0; }
.stats.c2 { grid-template-columns: 1fr 1fr; } .stats.c3 { grid-template-columns: 1fr 1fr 1fr; } .stats.c1 { grid-template-columns: 1fr; }
.stat { background: rgba(255, 255, 255, .035); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; min-width: 0; }
.stat dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.stat dd { margin: 2px 0 0; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.stat.big dd { font-size: 19px; color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-family: var(--mono); overflow-wrap: anywhere; }
table.grid { width: 100%; border-collapse: collapse; font-size: 11.5px; margin: 6px 0; }
table.grid th { text-align: left; color: var(--muted); font-weight: 600; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; padding: 4px 5px; border-bottom: 1px solid var(--line); }
table.grid td { padding: 4px 5px; border-bottom: 1px solid rgba(140, 190, 255, .08); font-family: var(--mono); font-size: 11.5px; vertical-align: top; }
table.grid td:first-child { font-family: var(--font); }
table.grid tr.selected td { background: rgba(54, 224, 255, .1); }
table.grid tr.clickable { cursor: pointer; } table.grid tr.clickable:hover td { background: rgba(255, 255, 255, .05); }
table.grid input { padding: 2px 5px; font-size: 11.5px; font-family: var(--mono); }
.gate { border: 1px dashed rgba(54, 224, 255, .45); border-radius: 12px; padding: 12px; margin: 10px 0; background: rgba(54, 224, 255, .05); }
.gate p { margin: 0 0 8px; color: #c8dbf5; }
.gate.premium { border-color: rgba(169, 155, 255, .5); background: rgba(139, 123, 255, .07); }
.notice { border-left: 3px solid var(--warn); padding: 6px 10px; margin: 8px 0; color: #ffe2b0; background: rgba(255, 195, 90, .07); border-radius: 0 8px 8px 0; font-size: 12px; }
.notice.ok { border-color: var(--ok); color: #c9ffe0; background: rgba(111, 240, 166, .07); }
.notice.bad { border-color: var(--bad); color: #ffd0d6; background: rgba(255, 107, 125, .08); }
.list { display: grid; gap: 6px; }
.item { border: 1px solid var(--line); background: rgba(255, 255, 255, .025); border-radius: 11px; padding: 9px 11px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item .title { font-weight: 650; }
.item .sub { color: var(--muted); font-size: 11.5px; }
.lockrow { opacity: .6; }
#porkchop { width: 100%; aspect-ratio: 1.08; border-radius: 10px; display: block; cursor: crosshair; background: #060a16; }
.readout { font-family: var(--mono); font-size: 11.5px; color: #cfe0ff; min-height: 34px; margin: 6px 0; white-space: pre-wrap; }
#histogram { width: 100%; height: 110px; display: block; border-radius: 8px; background: rgba(0, 0, 0, .3); }
.body-option.locked { color: var(--muted); }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.manoeuvre-row { display: grid; grid-template-columns: 22px 1fr 24px 24px; gap: 4px; align-items: center; margin: 6px 0 2px; }
.manoeuvre-sub { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-left: 26px; }
.manoeuvre-sub label { margin: 0 !important; grid-template-columns: auto 1fr; gap: 6px; }
.manoeuvre-row input, .manoeuvre-row select { padding: 3px 6px; font-size: 11.5px; }
.manoeuvre-row .order { color: var(--muted); font-family: var(--mono); font-size: 11px; text-align: center; }
.manoeuvre-row .icon { width: 24px; height: 24px; }
.manoeuvre-row .icon svg { width: 14px; height: 14px; }
.manoeuvre-details { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; margin: -2px 0 6px 26px; }
.manoeuvre-details input, .manoeuvre-details select { padding: 3px 6px; font-size: 11px; }

/* labels on the 3D view */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.label { position: absolute; left: 0; top: 0; font-size: 11px; font-weight: 600; color: #eaf6ff; text-shadow: 0 1px 3px #000, 0 0 8px #000; white-space: nowrap; }
.label.craft { color: var(--accent); }
.label.marker { color: var(--pink); font-size: 10px; }
.label.centre { color: #fff; font-size: 12px; }

/* timeline strip */
#bottom { position: fixed; left: 10px; right: 10px; bottom: 10px; height: 68px; border-radius: var(--radius); padding: 8px 14px; z-index: 5; }
.timeline-head { display: flex; justify-content: space-between; font-size: 11px; color: #cfe0ff; }
.timeline { position: relative; height: 34px; margin-top: 4px; cursor: pointer; }
.timeline .track { position: absolute; left: 0; right: 0; top: 14px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .1); }
#timeline-cursor { position: absolute; top: 8px; width: 2px; height: 16px; background: var(--accent); box-shadow: 0 0 8px var(--accent); transform: translateX(-1px); }
#timeline-marks .mark { position: absolute; top: 0; transform: translateX(-50%); font-size: 9.5px; color: var(--muted); white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
#timeline-marks .mark::after { content: ''; position: absolute; left: 50%; top: 13px; width: 2px; height: 10px; background: var(--pink); }
#timeline-marks .mark.low { top: 20px; } #timeline-marks .mark.low::after { top: -7px; }
#timeline-marks .mark span { visibility: hidden; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30; display: grid; gap: 8px; pointer-events: none; }
#toast .t { background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 11px; padding: 9px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: rise .25s ease-out; pointer-events: auto; max-width: 560px; }
#toast .t.error { border-color: rgba(255, 107, 125, .5); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* dialogs */
.dialog { border: 1px solid var(--line-strong); border-radius: 18px; padding: 0; background: #070c18; color: var(--text); width: min(720px, 94vw); max-height: 88vh; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); user-select: text; }
.dialog.wide { width: min(900px, 94vw); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(4px); }
.dialog-body { padding: 20px 22px; display: grid; gap: 10px; }
.dialog h2 { font-size: 16px; text-transform: none; letter-spacing: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.help-body { max-height: 62vh; overflow: auto; padding-right: 6px; font-size: 13px; line-height: 1.55; }
.help-body p { margin: 6px 0; } .help-body ul { margin: 4px 0 8px; padding-left: 18px; }
.help-body code, .formula { font-family: var(--mono); font-size: 12px; color: #bfe9ff; }
.formula { display: block; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 6px 0; white-space: pre-wrap; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: rgba(255, 255, 255, .05); }
.tiers-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tiers-table th, .tiers-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: center; }
.tiers-table td:first-child, .tiers-table th:first-child { text-align: left; }
.tiers-table th { color: var(--accent); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.tiers-table th .price { display: block; color: var(--text); font-size: 13px; letter-spacing: 0; text-transform: none; }
.tiers-table .yes { color: var(--ok); } .tiers-table .no { color: rgba(255, 255, 255, .25); }

/* loading */
#loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: radial-gradient(circle at 50% 45%, #0b1830, #02040a 60%); z-index: 50; transition: opacity .6s; }
#loading.done { opacity: 0; pointer-events: none; }
.ring { width: 54px; height: 54px; border-radius: 50%; border: 2px solid rgba(54, 224, 255, .15); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* printable report */
.report { position: fixed; inset: 0; overflow: auto; background: #fff; color: #111; padding: 32px 40px; z-index: 60; font: 12.5px/1.5 Georgia, "Times New Roman", serif; user-select: text; }
.report h1 { font-size: 22px; margin: 0 0 4px; } .report h2 { font-size: 14px; color: #333; margin: 18px 0 6px; text-transform: none; letter-spacing: 0; }
.report table { width: 100%; border-collapse: collapse; font-size: 12px; } .report th, .report td { border-bottom: 1px solid #ccc; padding: 4px 6px; text-align: left; }
.report .report-actions { position: sticky; top: 0; display: flex; gap: 8px; justify-content: flex-end; background: #fff; padding-bottom: 8px; }
.report .report-actions button { font: 13px system-ui, sans-serif; padding: 6px 12px; border: 1px solid #888; border-radius: 6px; background: #f3f3f3; color: #111; }
@media print { body > *:not(#report) { display: none !important; } #report { position: static; padding: 0; } .report .report-actions { display: none; } }

@media (max-width: 1180px) { :root { --left-w: 300px; --right-w: 330px; } .brand span { display: none; } #time-slider { width: 100px; } #modes button { padding: 5px 7px; } .tag { display: none; } }
@media (max-width: 1040px) { #clock { display: none; } #time-speed { display: none; } }
::-webkit-scrollbar { width: 9px; } ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }
