:root {
  color-scheme: dark;
  --ink: #e8f3ff;
  --muted: #91a6bd;
  --dim: #5f7690;
  --bg: #070b14;
  --surface: #0c1322;
  --raised: #111c30;
  --line: #263b59;
  --accent: #68d5ff;
  --accent-bright: #a5e9ff;
  --accent-soft: rgba(104, 213, 255, .1);
  --amber: #d5b7ff;
  --danger: #ff8496;
  --shadow: 0 18px 50px rgba(0, 0, 0, .25);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 80% -10%, #152a4c 0, transparent 32rem), var(--bg); }
button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 3px; }
.skip-link { position: fixed; top: -4rem; left: 1rem; z-index: 10; padding: .65rem 1rem; color: var(--bg); background: var(--accent-bright); }
.skip-link:focus { top: 1rem; }
.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.masthead { display: flex; align-items: flex-end; justify-content: space-between; min-height: 88px; padding: 16px 0 14px; border-bottom: 1px solid var(--line); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, 'Times New Roman', serif; font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 400; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 1rem; letter-spacing: -.02em; }
.eyebrow { margin-bottom: .5rem; color: var(--muted); font-size: .67rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.save-status { color: var(--dim); font-size: .69rem; }
.text-button, .icon-button { border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.text-button { padding: .45rem .6rem; border-bottom: 1px solid var(--line); font-size: .75rem; }
.text-button:hover, .icon-button:hover { color: var(--ink); }
.text-button.danger { color: var(--danger); }

.stage-nav { display: grid; grid-template-columns: repeat(var(--stage-count, 1), 1fr); border-bottom: 1px solid var(--line); }
.stage-tab { display: flex; align-items: center; gap: .65rem; padding: .72rem .75rem; border: 0; border-right: 1px solid var(--line); color: var(--dim); background: transparent; cursor: pointer; text-align: left; }
.stage-tab:last-child { border-right: 0; }
.stage-tab span { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border: 1px solid currentColor; border-radius: 50%; font-size: .65rem; }
.stage-tab small { margin-left: auto; color: var(--dim); font-size: .6rem; text-transform: uppercase; }
.stage-tab.active { color: var(--accent-bright); background: linear-gradient(180deg, var(--accent-soft), transparent); box-shadow: inset 0 -2px var(--accent); }
.stage-tab:disabled { cursor: not-allowed; opacity: .65; }

.status-strip { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: minmax(230px, 1.3fr) 2fr; min-height: 72px; border-bottom: 1px solid var(--line); background: rgba(7, 11, 20, .97); box-shadow: 0 8px 18px rgba(0, 0, 0, .2); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.primary-resource { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem .7rem 0; border-right: 1px solid var(--line); }
.resource-icon { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); box-shadow: inset 0 0 14px var(--accent-soft); }
.primary-resource div span, .resource-item span { display: block; margin-bottom: .3rem; color: var(--muted); font-size: .65rem; text-transform: uppercase; }
.primary-resource strong { font-size: 1.4rem; font-weight: 500; }
.rate { margin-left: auto; color: var(--accent); font-size: .7rem; }
.resource-list { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.resource-item { display: flex; flex-direction: column; justify-content: center; padding: .7rem 1rem; border-right: 1px solid var(--line); }
.resource-item:last-child { border-right: 0; }
.resource-item strong { font-size: 1rem; font-weight: 500; }
.resource-rate { margin-top: .25rem; color: var(--accent); font-size: .58rem; white-space: nowrap; }

.mission-panel { display: grid; grid-template-columns: 1.3fr 1fr; gap: 2rem; align-items: end; padding: 1.4rem 0; }
.mission-panel h2 { margin-bottom: .6rem; font-family: Georgia, serif; font-size: clamp(1.5rem, 3vw, 2.25rem); font-weight: 400; }
.mission-panel p { max-width: 650px; margin-bottom: 0; color: var(--muted); font: .88rem/1.65 system-ui, sans-serif; }
.progress-copy { display: flex; justify-content: space-between; margin-bottom: .65rem; color: var(--muted); font-size: .68rem; text-transform: uppercase; }
.progress-copy strong { color: var(--ink); }
.progress-track { height: 5px; overflow: hidden; background: var(--raised); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); box-shadow: 0 0 12px var(--accent); transition: width .35s ease; }
.stage-progress #next-milestone { margin-top: .7rem; font: .7rem/1.4 var(--font, monospace); color: var(--dim); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .85fr); gap: 1rem; }
.panel { border: 1px solid var(--line); background: rgba(12, 19, 34, .82); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; min-height: 58px; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.panel-heading .eyebrow { margin-bottom: .35rem; }
.status-chip, .counter { color: var(--muted); font-size: .64rem; }
.status-chip { padding: .3rem .55rem; border: 1px solid var(--line); border-radius: 999px; text-transform: uppercase; }
.card-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-card { position: relative; min-height: 132px; padding: 1rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.action-card:nth-child(2n) { border-right: 0; }
.action-card h3, .upgrade h3 { margin: 0 0 .5rem; font-size: .82rem; }
.action-card p, .upgrade p { margin-bottom: .8rem; color: var(--muted); font: .72rem/1.4 system-ui, sans-serif; }
.action-card footer { position: absolute; right: 1rem; bottom: .85rem; left: 1rem; display: flex; align-items: center; justify-content: space-between; padding: 0; border: 0; }
.cost { color: var(--amber); font-size: .64rem; }
.primary-button { min-width: 92px; padding: .58rem .8rem; border: 1px solid var(--accent); color: #07101b; background: var(--accent); cursor: pointer; font-size: .7rem; font-weight: 800; user-select: none; -webkit-user-select: none; }
.primary-button:hover { background: var(--accent-bright); }
.primary-button:disabled { border-color: var(--line); color: var(--dim); background: transparent; cursor: not-allowed; }
.primary-button.danger-fill { border-color: var(--danger); background: var(--danger); }
.upgrade-list { padding: .2rem 1rem .8rem; }
.upgrade { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.upgrade:last-child { border-bottom: 0; }
.upgrade-header, .upgrade-footer { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.upgrade-tag { color: var(--accent); font-size: .6rem; text-transform: uppercase; }
.upgrade button { padding: .4rem .65rem; }
.empty-state { padding: 1.5rem 1.2rem; color: var(--dim); font: .76rem/1.6 system-ui, sans-serif; }
.right-rail { display: grid; align-content: start; gap: 1rem; }
.icon-button { padding: .4rem; font-size: .65rem; }
.field-log ol { max-height: 245px; margin: 0; padding: .4rem 1.2rem 1.2rem; overflow: auto; list-style: none; }
.field-log li { display: grid; grid-template-columns: 4.2rem 1fr; gap: .8rem; padding: .7rem 0; border-bottom: 1px dotted var(--line); color: var(--muted); font: .7rem/1.45 system-ui, sans-serif; }
.field-log time { color: var(--dim); font-family: var(--font, monospace); font-size: .62rem; }
.app-shell > footer { display: flex; justify-content: space-between; padding: 2rem 0 3rem; color: var(--dim); font-size: .62rem; letter-spacing: .05em; }
.app-shell > footer b { color: var(--accent); }
dialog { max-width: 440px; padding: 1.6rem; border: 1px solid var(--line); color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(2, 8, 6, .82); backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: .75rem; font-family: Georgia, serif; font-size: 1.5rem; font-weight: 400; }
dialog p:not(.eyebrow) { color: var(--muted); font: .82rem/1.6 system-ui, sans-serif; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.5rem; }
noscript { position: fixed; inset: auto 0 0; padding: 1rem; color: var(--bg); background: var(--danger); text-align: center; }

@media (max-width: 800px) {
  .app-shell { width: min(100% - 24px, 700px); }
  .save-status { display: none; }
  .status-strip, .mission-panel, .workspace { grid-template-columns: 1fr; }
  .status-strip { min-height: 0; }
  .primary-resource { min-height: 58px; padding: .55rem .65rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .resource-icon { width: 2rem; height: 2rem; }
  .primary-resource strong { font-size: 1.15rem; }
  .resource-list { min-height: 58px; overflow-x: auto; }
  .resource-item { padding: .6rem .8rem; }
  .mission-panel { gap: 1.5rem; padding: 2rem 0; }
}
@media (max-width: 520px) {
  .masthead { align-items: center; }
  .header-actions { gap: .15rem; }
  .stage-tab { justify-content: center; padding: .85rem .4rem; font-size: .7rem; }
  .stage-tab span, .stage-tab small { display: none; }
  .resource-list { grid-auto-columns: minmax(105px, 1fr); }
  .card-list { grid-template-columns: 1fr; }
  .action-card { border-right: 0; }
  .app-shell > footer { display: grid; gap: .6rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
