html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }
.stage { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px; }
.scene { position: relative; min-width: 0; }
.scene canvas { display: block; width: 100% !important; height: 100% !important; outline: none; }
.labels { position: absolute; inset: 0 340px 0 0; pointer-events: none; overflow: hidden; }
.labels span { position: absolute; transform: translate(-50%, -50%); font: 600 12px var(--sans); color: var(--muted); white-space: nowrap; text-shadow: 0 0 3px var(--ground); }
.labels span.desk { font-size: 13px; color: var(--ink); text-transform: uppercase; letter-spacing: .08em; }
.labels span.ks { color: var(--breach); background: var(--breach-bg); border: 1px solid var(--breach); border-radius: 4px; padding: 2px 8px; font-size: 12px; text-shadow: none;
  max-width: 280px; white-space: normal; text-align: center; }
.labels span.book { font-family: var(--mono); font-weight: 500; }
.labels span.book.sel { color: var(--accent); font-weight: 700; }
.tip { position: absolute; z-index: 4; pointer-events: none; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .18); max-width: 280px; }
.tip b { font-family: var(--mono); }
.panel { border-left: 1px solid var(--rule); background: var(--surface); overflow-y: auto; padding: 16px; font-size: 14px; }
.panel h1 { font-size: 18px; }
.panel p { margin: 0 0 10px; }
.legend { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; font-size: 13px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.k-ok { background: var(--accent); } .k-ov { background: var(--override); outline: 2px solid var(--override); outline-offset: 1px; }
.k-br { background: var(--breach); } .k-ks { background: var(--stopped); } .k-dr { background: var(--accent); opacity: .45; }
.status { font-size: 12px; color: var(--muted); }
#books { display: grid; gap: 4px; margin: 8px 0 12px; }
#books h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 2px; }
#books button { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; font: 13px var(--sans); color: var(--ink);
  background: var(--soft); border: 1px solid transparent; border-radius: 5px; padding: 6px 8px; cursor: pointer; }
#books button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); }
#books button code { font-weight: 600; }
#books button .x { color: var(--breach); font-weight: 600; }
#detail .tk { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; display: grid; gap: 4px; }
#detail .tk.br { border-color: var(--breach); } #detail .tk.ov { border-color: var(--override); }
#detail .tk .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#detail .tk button, #detail .tk a { font: 600 12px var(--sans); border: 1px solid var(--accent); color: var(--accent); background: var(--surface); border-radius: 4px; padding: 4px 8px; cursor: pointer; text-decoration: none; }
#detail .msg { font-family: var(--mono); font-size: 12px; padding: 6px 8px; border-radius: 4px; }
#detail .msg.refused { background: var(--breach-bg); color: var(--breach); } #detail .msg.ok { background: var(--done-bg); color: var(--done); }
@keyframes flash { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.flash { animation: flash .35s 3; }

/* the 2D fallback */
.flat { position: absolute; inset: 0 340px 0 0; overflow: auto; padding: 16px; background: var(--ground); }
.flat svg { width: 100%; height: auto; display: block; }
.flat svg text { font: 11px var(--sans); fill: var(--muted); }
.flat svg text.desk { font-weight: 700; fill: var(--ink); text-transform: uppercase; letter-spacing: .08em; }
.flat svg text.code { font-family: var(--mono); }
.flat svg text.ks { fill: var(--breach); font-weight: 600; }

/* hero: the scene alone, inside the home page */
body.hero .top, body.hero .panel { display: none; }
body.hero .stage { grid-template-columns: 1fr; }
body.hero .labels, body.hero .flat { inset: 0; }
body.hero .labels span.book { display: none; }
body.hero .labels span.ks { font-size: 10.5px; max-width: 200px; padding: 1px 6px; }
body.hero .labels span.desk { font-size: 11px; }

@media (max-width: 760px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: 58vh auto; overflow-y: auto; }
  body { overflow: auto; }
  .labels, .flat { inset: 0 0 auto 0; height: 58vh; }
  .panel { border-left: 0; border-top: 1px solid var(--rule); }
}

/* the hero sits in a small iframe: never take the narrow-screen layout there */
body.hero { overflow: hidden; }
body.hero .stage { position: fixed; inset: 0; display: block; overflow: hidden; }
body.hero .scene { position: absolute; inset: 0; }
body.hero .labels, body.hero .flat { inset: 0; height: auto; }
