:root {
  --bg: #0d1117; --panel: #161b22; --line: #2a313c; --text: #e6edf3; --muted: #8b949e;
  --accent: #4f8cff; --warn: #ffb020;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
header { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
header .primary { padding: 7px 14px; white-space: nowrap; }
h1 { margin: 0; font-size: 17px; letter-spacing: .02em; }
h1 span { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
.muted { color: var(--muted); font-size: 12px; }

main { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 14px; padding: 14px;
  max-width: 1500px; margin: 0 auto; }
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.phead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

#view { position: relative; height: min(62vh, 640px); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(#1b3358 0%, #3a6aa5 55%, #86a9cf 100%); }
#gl { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.viewbar { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; }
.viewbar button { background: rgba(13,17,23,.6); backdrop-filter: blur(6px); }
.hint { position: absolute; right: 12px; bottom: 8px; font-size: 11px; color: rgba(255,255,255,.7); pointer-events: none; }

button { font: inherit; color: var(--text); background: #21262d; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: #4b5565; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 10px 16px; }
.btns { display: flex; gap: 6px; }

.presets { display: grid; grid-template-columns: 52px 1fr 52px 44px; gap: 8px; align-items: center; }
.arrow { font-size: 34px; line-height: 1; height: 56px; padding: 0 0 6px; }
.dice { font-size: 20px; height: 56px; padding: 0; }
.pname { text-align: center; min-width: 0; }
#presetName { font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.strip { display: grid; grid-template-columns: 38px 26px repeat(9, 1fr) 26px; grid-template-rows: 46px 46px 16px 26px 26px;
  gap: 3px; align-items: stretch; }
.strip .rowlab { font-size: 11px; color: var(--muted); padding: 0; background: none; border: none; text-align: left; }
.strip .rowlab:hover { color: var(--text); }
.strip .z { border-radius: 5px; border: 1px solid rgba(255,255,255,.12); padding: 0; min-width: 0; }
.strip .z.sel { outline: 2px solid #fff; outline-offset: 1px; box-shadow: 0 0 0 4px var(--accent); z-index: 1; }
.strip .stab { grid-row: 1 / span 2; border-radius: 5px 5px 14px 14px; }
.strip .lab { font-size: 10px; color: var(--muted); text-align: center; }
.sel { margin-top: 8px; min-height: 17px; }
.check { color: var(--muted); font-size: 12px; display: flex; gap: 5px; align-items: center; cursor: pointer; }

.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.sw { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 5px; font-size: 11px; position: relative; }
.sw i { display: block; height: 30px; border-radius: 5px; border: 1px solid rgba(255,255,255,.14); }
.sw em { position: absolute; top: 8px; right: 8px; font-style: normal; font-size: 9px; font-weight: 700;
  background: #000; color: #fff; border-radius: 3px; padding: 0 4px; letter-spacing: .05em; }
.warn { margin-top: 10px; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
  background: rgba(255,176,32,.12); border: 1px solid rgba(255,176,32,.5); color: #ffd58a; }

pre { margin: 0 0 12px; padding: 10px; background: #0d1117; border: 1px solid var(--line); border-radius: 8px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
pre.args { margin-bottom: 0; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.gallery:not(:empty) { margin-top: 12px; }
.gallery figure { margin: 0; position: relative; aspect-ratio: 16 / 11; background: #0d1117; border-radius: 8px;
  overflow: hidden; border: 1px solid var(--line); display: grid; place-items: center; }
.gallery img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.gallery figcaption { position: absolute; left: 8px; bottom: 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; text-shadow: 0 1px 3px #000; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #30363d; border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; display: inline-block; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.path { margin-top: 10px; font: 12px ui-monospace, Menlo, monospace; color: var(--muted); word-break: break-all; }

#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 10; cursor: zoom-out; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 96vw; max-height: 94vh; border-radius: 6px; }

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 10px; gap: 10px; }
  .stage, .side { display: contents; }
  #view { height: 42vh; position: sticky; top: 0; z-index: 5; order: 1; }
  #landrep { order: 1; max-height: none; }
  .side > .panel { order: 2; }
  #renderPanel { order: 3; }
  h1 span { display: block; margin: 0; }
  .hint { display: none; }
}

/* ---- fly mode */
body:not(.fly) .flyonly { display: none !important; }
body.fly .designonly { display: none !important; }
body.fly #view { height: min(70vh, 800px); }
#hud { position: absolute; left: 0; right: 0; top: 0; padding: 10px 14px 18px; pointer-events: none;
  background: linear-gradient(rgba(8,12,18,.72), rgba(8,12,18,0)); text-shadow: 0 1px 2px #000; }
#hudMain { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; font-size: 13px; }
#hudMain b { font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 650; }
#hudMain i { font-style: normal; color: #b9c4d0; font-size: 12px; margin-right: 6px; }
#hudMain span { font-size: 10px; letter-spacing: .1em; color: #9fb0c2; margin-left: 12px; }
#hudSub { font: 12px ui-monospace, Menlo, monospace; color: #dbe4ee; margin-top: 2px; white-space: pre-wrap; }
.togwrap { position: absolute; top: 96px; bottom: 64px; width: 46px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.togwrap.l { left: 8px; } .togwrap.r { right: 8px; }
.togwrap span { font-size: 10px; color: #dbe4ee; text-shadow: 0 1px 2px #000; white-space: nowrap; }
.togwrap input { flex: 1; width: 40px; writing-mode: vertical-lr; direction: ltr; appearance: slider-vertical; -webkit-appearance: slider-vertical;
  accent-color: #ffe066; touch-action: none; cursor: ns-resize; }
.togwrap .bar { display: none; }
.holdbar { position: absolute; left: 60px; right: 60px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.holdbar button { background: rgba(13,17,23,.65); backdrop-filter: blur(6px); padding: 8px 10px; font-size: 12px; touch-action: none; user-select: none; -webkit-user-select: none; }
.holdbar button.on { background: var(--accent); border-color: var(--accent); }
#ctlState { font: 11px ui-monospace, Menlo, monospace; color: #ffe066; text-shadow: 0 1px 2px #000; width: 100%; text-align: center; min-height: 14px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 10px; }
.fgrid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.fgrid small { color: var(--muted); font-size: 10.5px; }
.fgrid input, .fgrid select { background: #0d1117; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; width: 100%; }
button.sm { padding: 6px 12px; }
.keys { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.keys td { padding: 3px 0; vertical-align: top; } .keys td:first-child { white-space: nowrap; padding-right: 10px; width: 1%; }
kbd { background: #21262d; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 11px ui-monospace, Menlo, monospace; }
@media (max-width: 900px) { body.fly #view { height: 58vh; } #hudMain b { font-size: 20px; } }

.apnote { font-size: 13px; color: #4de3ff; min-height: 18px; margin-bottom: 8px; }
.grow { flex: 1; min-width: 0; background: #0d1117; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; font: inherit; color-scheme: dark; }
button.on { background: var(--accent); border-color: var(--accent); }

@media (min-width: 901px) { body.fly .stage { position: sticky; top: 14px; align-self: start; } }

.cambar { position: absolute; top: 100px; left: 62px; display: flex; gap: 6px; }
.cambar button { background: rgba(13,17,23,.65); backdrop-filter: blur(6px); padding: 6px 10px; font-size: 12px; }
.cambar button.on { background: var(--accent); border-color: var(--accent); }
/* landing report and flare chart sit under the 3D view, never over the pilot */
#landrep { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-start; padding: 10px 12px; max-height: 24vh; overflow: auto; }
#landrep[hidden] { display: none !important; }
#flareChart { width: min(330px, 100%); border-radius: 8px; border: 1px solid rgba(255,255,255,.18); display: none; flex: none; }
#landing { flex: 1 1 260px; font-size: 12.5px; line-height: 1.4; color: #ffe066; }
#landing:empty { display: none; }

.viewbar button.on { background: var(--accent); border-color: var(--accent); }

pre.forces { margin: 8px 0 0; font-size: 11.5px; white-space: pre-wrap; }


.hdr { gap: 8px; flex-wrap: nowrap; }
.hdr select { background: #21262d; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; font: inherit; }
h1 b { font-weight: 700; }
table.turns { width: 100%; border-collapse: collapse; font-size: 12px; color: var(--text); }
table.turns th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px 5px 0; border-bottom: 1px solid var(--line); }
table.turns td { padding: 4px 4px 4px 0; border-bottom: 1px solid #1f252d; font-variant-numeric: tabular-nums; }
@media (max-width: 900px) { header { flex-wrap: wrap; } }

.rulebook { font-size: 12px; line-height: 1.45; }
.rulebook .tier { margin-top: 8px; }
.rulebook .tier > b { display: block; font-weight: 600; margin-bottom: 2px; }
.rulebook .rule { opacity: .6; padding-left: 4px; }
.rulebook .rule small { opacity: .6; margin-left: 4px; }
.rulebook .rule.used { opacity: .9; }
.rulebook .rule.on { opacity: 1; color: #ffe066; }
