/* city.css -- the frame around one generated picture.
 * Layout: a masthead, one row of controls, the scene with a rail, then the notes.
 * Nothing here draws the city; the city is geometry. This file is typography,
 * rhythm, the SVG's presentation defaults and the zoom dependent detail levels.
 */

:root {
  --bg: #0c0f12;
  --panel: #12171c;
  --panel-2: #171d23;
  --line: #252d35;
  --line-soft: #1c232a;
  --ink: #e9e5dd;
  --ink-dim: #98a2ab;
  --ink-faint: #67727b;
  --brass: #d9a95f;
  --brass-dim: #8a6f42;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --gap: 1.15rem;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  text-rendering: optimizeLegibility;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--brass); color: #14100a; padding: 0.5rem 0.9rem; z-index: 30;
}
.skip:focus { left: 0.4rem; top: 0.4rem; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.01em; }

/* ------------------------------------------------------------ masthead --- */

.masthead {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--gap);
  padding: 1.5rem 1.6rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.brand { min-width: 0; }
.masthead h1 {
  font-size: clamp(1.5rem, 1rem + 1.5vw, 2.15rem);
  line-height: 1.1;
  display: flex; flex-direction: column;
}
.masthead h1 span {
  font: 400 0.52em/1.4 var(--sans);
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--brass);
  margin-top: 0.45em;
}
.tagline { margin: 0.7rem 0 0; color: var(--ink-dim); max-width: 62ch; font-size: 0.95rem; }
.masthead-meta {
  margin: 0; font: 400 0.8rem/1 var(--mono); color: var(--ink-faint);
  letter-spacing: 0.08em; white-space: nowrap;
}

/* ------------------------------------------------------------- toolbar --- */

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap);
  padding: 0.85rem 1.6rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.ctl { display: flex; align-items: center; gap: 0.45rem; }
.ctl-label {
  font: 400 0.68rem/1 var(--sans); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint); margin-right: 0.15rem;
}
.ctl > label { font: 400 0.68rem/1 var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }

input[type=text] {
  font: 400 0.95rem/1 var(--mono);
  background: #0a0d10; color: var(--ink);
  border: 1px solid var(--line); border-radius: 2px;
  padding: 0.42rem 0.55rem; width: 12ch; min-width: 8ch;
}
button {
  font: 500 0.8rem/1 var(--sans); letter-spacing: 0.04em;
  background: #1b2229; color: var(--ink);
  border: 1px solid var(--line); border-radius: 2px;
  padding: 0.45rem 0.7rem; cursor: pointer;
  transition: background 120ms linear, border-color 120ms linear;
}
button:hover { background: #222b33; border-color: #35414c; }
.az { font-family: var(--mono); width: 2.1rem; padding: 0.45rem 0; text-align: center; }
.az.on { background: var(--brass); border-color: var(--brass); color: #14100a; }
button:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible, output:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}

input[type=range] { width: clamp(90px, 16vw, 210px); accent-color: var(--brass); }
output { font: 400 0.82rem/1 var(--mono); color: var(--ink-dim); min-width: 4.6ch; }
.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.86rem; color: var(--ink-dim); cursor: pointer; }
.check input { accent-color: var(--brass); }

/* --------------------------------------------------------------- stage --- */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  height: clamp(420px, 66vh, 880px);
}
.frame { position: relative; overflow: hidden; border-right: 1px solid var(--line); min-height: 0; }
.skybox { position: absolute; inset: 0; background: linear-gradient(180deg, #24405f, #96b4c9); }
.stars {
  position: absolute; left: 50%; top: 50%; width: 1px; height: 1px;
  opacity: 0; transition: opacity 400ms linear;
}
.sun {
  position: absolute; left: 50%; top: 44%; width: 74px; height: 74px;
  margin: -37px 0 0 -37px; border-radius: 50%;
  background: radial-gradient(circle at 42% 38%, #fffbf0, #ffe9b8 58%, rgba(255, 240, 210, 0) 62%);
  transition: transform 400ms cubic-bezier(0.3, 0.7, 0.3, 1);
}
.sun.below { opacity: 0.55; }

.canvas {
  position: absolute; inset: 0;
  touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none;
}
.canvas.grabbing { cursor: grabbing; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.nojs {
  position: absolute; left: 1rem; right: 1rem; bottom: 1rem;
  background: #12171c; border: 1px solid var(--line); padding: 0.8rem 1rem;
  color: var(--ink-dim); font-size: 0.9rem; margin: 0;
}

/* -------------------------------------------------------- the scene ------ */

#scene text { font-family: var(--sans); }
/* Every face is stroked with its own colour so adjacent faces overlap by half a
   pixel: the seams cannot open, at any scale, because the stroke is device space. */
#scene .f {
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
#scene .k-RU-up { stroke-width: 1.1; }
symbol, #defsTex * { vector-effect: non-scaling-stroke; }
#defsTex rect { stroke: none; }
#scene .ripple { stroke: none; }
#scene .wet { fill: rgba(6, 22, 32, 0.28); stroke: none; }
#scene .awn { fill: rgba(255, 245, 230, 0.30); stroke: none; }
#scene .sgn {
  font-size: 0.30px; font-weight: 700; letter-spacing: 0.01px;
  fill: #f6ead6; stroke: none; display: none;
}
#scene .glow { opacity: 0; }
#scene .beam { opacity: 0; transition: opacity 600ms linear; }
#scene .beam path { stroke: none; }
#lBeam > g { transform-box: view-box; transform-origin: 0 0; }
.beamspin { transform-origin: 0 0; transform: scale(1, 0.5); animation: sweep 26s linear infinite; }
@keyframes sweep {
  from { transform: scale(1, 0.5) rotate(0deg); }
  to { transform: scale(1, 0.5) rotate(360deg); }
}

/* detail levels: shapes that only exist once you are close enough to read them */
#scene .l2, #scene .l3 { display: none; }
#scene.lod2 .l2 { display: inline; }
#scene.lod2 .sgn { display: none; }
#scene.lod3 .l2, #scene.lod3 .l3, #scene.lod3 .sgn { display: inline; }
#scene.far [class*="f-GL"], #scene.far .lit, #scene.far .k-PA-py, #scene.far .k-PA-px { display: none; }
#scene.far .ripple { display: none; }

/* generator overlay */
#lGrid { display: none; }
#scene.showgrid #lGrid { display: inline; }
.gridline { fill: none; stroke: rgba(230, 240, 250, 0.42); stroke-width: 1; vector-effect: non-scaling-stroke; }
.zg-terrace { fill: rgba(126, 206, 154, 0.16); stroke: none; }
.zg-warehouse { fill: rgba(224, 168, 92, 0.17); stroke: none; }
.zg-market { fill: rgba(206, 122, 190, 0.18); stroke: none; }
.zg-crane { fill: rgba(120, 186, 228, 0.17); stroke: none; }
.zg-road { fill: rgba(240, 240, 240, 0.10); stroke: none; }
.zg-water { fill: rgba(60, 120, 190, 0.14); stroke: none; }

/* hover and selection */
.ov { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ovf { stroke-width: 1; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.ov.hov, .ovf.hov { stroke: #f4f1e8; }
.ovf.hov { fill: rgba(244, 241, 232, 0.10); }
.ov.sel, .ovf.sel { stroke: var(--brass); }
.ovf.sel { fill: rgba(217, 169, 95, 0.14); }
#scene .s { cursor: pointer; }

/* dossier */
.dossier {
  position: absolute; right: 0.9rem; bottom: 0.9rem; width: min(20rem, calc(100% - 1.8rem));
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  padding: 0.85rem 1rem 0.95rem;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}
.dossier h2 { font-size: 1.05rem; margin: 0 0 0.55rem; padding-right: 1.6rem; }
.dossier dl { margin: 0; display: grid; grid-template-columns: 6.4rem 1fr; gap: 0.24rem 0.7rem; }
.dossier dt { font: 400 0.66rem/1.5 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }
.dossier dd { margin: 0; font-size: 0.88rem; color: var(--ink); }
.d-close { position: absolute; right: 0.5rem; top: 0.5rem; padding: 0.15rem 0.45rem; line-height: 1.2; }

.hint {
  position: absolute; left: 0.9rem; bottom: 0.9rem; max-width: 30rem; margin: 0;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line); padding: 0.7rem 0.9rem; font-size: 0.84rem; color: var(--ink-dim);
}
.hint h2 { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.35rem; }
kbd {
  font: 400 0.78rem/1 var(--mono); background: #0a0d10; border: 1px solid var(--line);
  border-radius: 2px; padding: 0.1rem 0.3rem; color: var(--ink);
}

/* --------------------------------------------------------------- rail ---- */

.rail { padding: 1.1rem 1.15rem 1.4rem; background: var(--panel); overflow: auto; min-height: 0; }
.rail-title {
  font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint);
  margin: 0 0 0.6rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem;
}
.rail-title span { font: 400 0.62rem/1.4 var(--sans); letter-spacing: 0.06em; text-transform: none; color: var(--ink-faint); }
.rail-title:not(:first-child) { margin-top: 1.5rem; }
#mini {
  display: block; width: 100%; aspect-ratio: 1; background: #0a0d10;
  border: 1px solid var(--line); cursor: crosshair;
}
.m-water { fill: #143045; stroke: none; }
.mz-terrace { fill: #4f6e53; stroke: none; }
.mz-warehouse { fill: #7d5f3a; stroke: none; }
.mz-market { fill: #7a4f72; stroke: none; }
.mz-crane { fill: #3f6b80; stroke: none; }
.mz-road { fill: #2e363d; stroke: none; }
.mz-water { fill: #143045; stroke: none; }
.m-vp {
  fill: rgba(217, 169, 95, 0.10); stroke: var(--brass); stroke-width: 0.18;
  vector-effect: non-scaling-stroke; stroke-linejoin: round;
}
.readout { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0.3rem; }
.readout dt { font: 400 0.64rem/1.5 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); margin-top: 0.55rem; }
.readout dd { margin: 0; font: 400 0.86rem/1.45 var(--mono); color: var(--ink); overflow-wrap: anywhere; }
.rail-note { margin: 1.3rem 0 0; font-size: 0.8rem; color: var(--ink-faint); line-height: 1.5; }

/* ------------------------------------------------------------- notes ----- */

.notes {
  padding: 2.6rem 1.6rem 2.2rem;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  display: grid; grid-template-columns: minmax(0, 68ch); justify-content: center; gap: 0;
}
.notes > * { grid-column: 1; }
.notes h2 { font-size: 1.5rem; margin-bottom: 1.1rem; }
.notes h3 {
  font: 600 0.74rem/1 var(--sans); letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--brass); margin: 2rem 0 0.7rem;
}
.notes h3:first-of-type { margin-top: 0; }
.notes p { margin: 0 0 0.85rem; color: #cdd3d9; font-size: 0.98rem; }
.notes code { font: 400 0.86em/1 var(--mono); color: var(--ink); }
.formula {
  font: 400 1rem/1.6 var(--mono); color: var(--ink);
  background: #0c1013; border-left: 2px solid var(--brass-dim);
  padding: 0.5rem 0.8rem; margin: 0.9rem 0;
}
.formula.inline { display: inline; padding: 0; border: 0; background: none; }
.log { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.log li { margin: 0 0 0.75rem; font-size: 0.92rem; color: #c4cbd2; }
.log strong { color: var(--ink); font-weight: 500; }

.colophon { padding: 1.4rem 1.6rem 2rem; border-top: 1px solid var(--line); color: var(--ink-faint); font-size: 0.85rem; }

/* -------------------------------------------------------- responsive ----- */

@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(340px, 56vh) auto; height: auto; }
  .frame { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail { overflow: visible; display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 0 1.2rem; align-items: start; }
  .rail-title:nth-of-type(2), .rail-note, .share { grid-column: 1 / -1; }
  #mini { grid-row: 1 / 3; }
  .masthead { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
}
@media (max-width: 560px) {
  body { font-size: 15px; }
  .toolbar { gap: 0.75rem; padding: 0.7rem 0.9rem; }
  .masthead, .notes, .colophon { padding-left: 0.9rem; padding-right: 0.9rem; }
  .dossier { left: 0.6rem; right: 0.6rem; width: auto; }
  .hint { display: none; }
}

/* ---------------------------------------------------- reduced motion ----- */

@media (prefers-reduced-motion: reduce) {
  .beamspin { animation: none; transform: scale(1, 0.5) rotate(28deg); }
  .sun, #scene .beam, .stars, button { transition: none; }
}
#scene.reduced .beamspin { animation: none; }
