:root {
  --bg: #0e0f12; --panel: #15171c; --grid: #23262e; --ink: #ece6da; --muted: #8b8778; --accent: #e0a458;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--grid); padding: 8px 14px; border-radius: 6px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.top { display: flex; align-items: baseline; gap: 18px; padding: 14px 24px; border-bottom: 1px solid var(--grid); }
.brand { font: 28px var(--serif); letter-spacing: 0.02em; color: var(--accent); }
.tag { color: var(--muted); }
.crumbs { margin-left: auto; color: var(--muted); }

/* gallery */
.gallery { padding: 24px; max-width: 1400px; margin: 0 auto; }
.gallery h2 { font: 22px var(--serif); color: var(--muted); margin: 28px 0 12px; font-weight: normal; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.gcard { display: block; background: var(--panel); border: 1px solid var(--grid); border-radius: 10px; overflow: hidden; }
.gcard:hover { border-color: var(--accent); }
.gcard canvas { display: block; width: 100%; aspect-ratio: 1; background: var(--bg); }
.gcard .meta { padding: 12px 14px 14px; }
.gcard h3 { margin: 0 0 2px; font: 20px var(--serif); }
.gcard .origin { color: var(--muted); font-size: 16px; margin: 0 0 6px; }
.gcard .lesson { margin: 0; }

/* model page */
.model { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; padding: 16px 24px; height: calc(100vh - 62px); }
.stage-col { display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.stage canvas { background: var(--bg); border: 1px solid var(--grid); border-radius: 6px; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls .speed { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.controls .tick, .controls .seed { font-family: var(--mono); color: var(--muted); }
.controls #present { margin-left: auto; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.presets button { font-size: 16px; }

.panel { overflow-y: auto; min-height: 0; padding-right: 4px; }
.panel h1 { font: 32px var(--serif); margin: 0 0 4px; font-weight: normal; }
.panel .origin { color: var(--muted); margin: 0 0 14px; }
.params { display: grid; gap: 8px; margin-bottom: 14px; }
.param { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.param label { font-size: 16px; color: var(--muted); }
.param .val { font-family: var(--mono); font-size: 16px; }
.param input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.chart { width: 100%; height: 150px; display: block; border-radius: 6px; margin-bottom: 14px; }
.card { font-size: 20px; line-height: 1.5; }
.card p { margin: 0 0 12px; }
.card b { color: var(--accent); font-weight: 600; font-family: var(--serif); }
.keys { color: var(--muted); font-size: 16px; }

/* presentation mode */
body.present .top, body.present .panel, body.present .keys { display: none; }
body.present .model { grid-template-columns: 1fr; height: 100vh; padding: 8px; gap: 6px; }
/* Controls and presets overlay the stage (position: absolute) instead of sharing
   the row with it, so the invisible-but-present flex items don't permanently
   steal width/height from the stage once the chart also joins this row. */
body.present .controls, body.present .presets { position: absolute; left: 0; z-index: 2; opacity: 0; transition: opacity .3s; }
body.present .controls { bottom: 0; }
body.present .presets { bottom: 54px; }
body.present.mouse .controls, body.present.mouse .presets { opacity: 1; }
body.present .stage-col { flex-direction: row; position: relative; }
body.present .stage { flex: 1; }
body.present .stage-col > .chart { width: 320px; height: 150px; align-self: flex-end; }

@media (max-width: 1000px) {
  .model { grid-template-columns: 1fr; height: auto; }
  .stage canvas { width: 100% !important; height: auto !important; }
}
