:root {
  --bg: #0c0c0e;
  --bg-panel: #121214;
  --bg-elevated: #1a1a1e;
  --border: #2a2a30;
  --text: #d4d4d8;
  --muted: #71717a;
  --gold: #f7c948;
  --gold-dim: #b8901f;
  --good: #4ade80;
  --bad: #f87171;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Fira Code", "Consolas", ui-monospace, monospace;
  --sidebar-w: min(440px, 42vw);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  height: 100%;
  min-height: 0;
}

/* ---------- Preview ---------- */
.preview {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: #08080a;
  border-right: 1px solid var(--border);
}

.preview-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.55rem 0.9rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.brand-line .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}
.brand-line .title {
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  font-size: 0.75rem;
}
.transport .speed {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
}
.transport .speed strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 2.8em;
}
.transport input[type="range"] {
  width: 90px;
  accent-color: var(--gold);
}
.transport button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.28rem 0.55rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.transport button:hover { border-color: var(--gold); color: var(--gold); }
.transport button.active {
  border-color: var(--gold);
  color: var(--gold);
  background: #2a2100;
}
.transport .fps {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 1rem;
  background:
    radial-gradient(ellipse at center, #121218 0%, #08080a 70%);
}

#c {
  width: min(100%, calc(100vh - 140px), 720px);
  height: auto;
  aspect-ratio: 1;
  max-height: calc(100vh - 140px);
  display: block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px #1c1c22, 0 12px 40px rgba(0,0,0,0.45);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: var(--gold);
  color: #111;
  font-size: 0.78rem;
  font-weight: 600;
}
.hud-credit {
  margin: 0;
  color: #111;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 0.72rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud-credit a {
  color: #111;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.hud-credit a:hover {
  color: #000;
  text-decoration-thickness: 2px;
}
.hud-meta {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  opacity: 0.85;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--bg-panel);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #0e0e10;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.7rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
  background: linear-gradient(180deg, transparent, rgba(247,201,72,0.04));
}

.tab-panels {
  min-height: 0;
  position: relative;
}
.panel {
  display: none;
  height: 100%;
  min-height: 0;
}
.panel.active {
  display: flex;
  flex-direction: column;
}

.panel-scroll {
  overflow-y: auto;
  padding: 1.1rem 1.15rem 2rem;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #b4b4bc;
}

.panel-scroll h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f4f4f5;
  letter-spacing: -0.02em;
  margin-bottom: 0.55rem;
}
.panel-scroll h2 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.55rem;
}
.lede {
  color: #a1a1aa;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
.lede strong { color: #e4e4e7; }

.block {
  margin-bottom: 1.35rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid #1f1f24;
}
.block:last-of-type { border-bottom: none; }
.block p + p { margin-top: 0.55rem; }

.credit {
  background: linear-gradient(135deg, #171204 0%, #121214 60%);
  border: 1px solid #3a2f10;
  border-radius: 8px;
  padding: 0.9rem 1rem 1rem;
  margin-bottom: 1.25rem;
}
.credit .tweet-ref {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.65rem;
}
.tweet-embed {
  margin-top: 0.85rem;
  max-width: 100%;
  overflow: hidden;
  border-radius: 8px;
}
.tweet-embed .twitter-tweet {
  margin: 0 auto !important;
}
/* fallback text before widgets.js hydrates */
.tweet-embed blockquote.twitter-tweet {
  padding: 0.75rem 0.9rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #2a2a30;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #c8c8d0;
}
.tweet-embed blockquote.twitter-tweet a {
  color: var(--gold);
}

/* Worklog TOC + entries */
.worklog-toc {
  margin: 0 0 1.5rem;
  padding: 0.85rem 0.9rem 1rem;
  background: #0e0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.worklog-toc h2 {
  margin-bottom: 0.65rem;
}
.worklog-toc ol {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
}
.worklog-toc li {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}
.worklog-toc a {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  flex: 1;
  min-width: 0;
  color: #b4b4bc;
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.35;
  padding: 0.35rem 0.4rem;
  border-radius: 4px;
}
.worklog-toc a:hover {
  background: rgba(247, 201, 72, 0.06);
  color: #e4e4e7;
  text-decoration: none;
}
.worklog-toc .toc-n {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-dim);
  border: 1px solid #4a3c12;
  border-radius: 3px;
  background: #171204;
}
.worklog-toc .toc-t { min-width: 0; }
.worklog-toc li.toc-current a {
  color: #f4f4f5;
  background: rgba(247, 201, 72, 0.08);
  border: 1px solid rgba(247, 201, 72, 0.2);
}
.worklog-toc li.toc-current .toc-n {
  color: #111;
  background: var(--gold);
  border-color: var(--gold);
}
.toc-badge {
  flex-shrink: 0;
  align-self: center;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #111;
  background: var(--gold);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
}

.worklog {
  margin-bottom: 1.35rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid #1f1f24;
  scroll-margin-top: 0.75rem;
}
.worklog:last-of-type { border-bottom: none; }
.worklog header {
  margin-bottom: 0.55rem;
}
.worklog .wl-turn {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 0.25rem;
}
.worklog h2 {
  font-size: 0.95rem !important;
  letter-spacing: -0.01em !important;
  text-transform: none !important;
  color: #f0f0f4 !important;
  font-weight: 650 !important;
  margin-bottom: 0 !important;
  line-height: 1.3;
}
.worklog p + p { margin-top: 0.5rem; }
.worklog.wl-latest {
  padding: 0.85rem 0.9rem 1rem;
  background: linear-gradient(135deg, #171204 0%, #121214 70%);
  border: 1px solid #3a2f10;
  border-radius: 8px;
  border-bottom: 1px solid #3a2f10;
}

.fineprint {
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: #52525b;
  line-height: 1.4;
}

kbd {
  font-family: var(--mono);
  font-size: 0.75em;
  background: #1c1c22;
  border: 1px solid #333;
  border-radius: 3px;
  padding: 0.05em 0.35em;
  color: #d4d4d8;
}
code {
  font-family: var(--mono);
  font-size: 0.88em;
  color: #fbe7a3;
}

/* ---------- Shader editor ---------- */
#panel-shader {
  background: #0d0d10;
}

.shader-toolbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: #101014;
  flex-shrink: 0;
}
.shader-toolbar button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.32rem 0.7rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.shader-toolbar button:hover { border-color: #555; }
.shader-toolbar button.primary {
  background: #2a2200;
  border-color: var(--gold-dim);
  color: var(--gold);
}
.shader-toolbar button.primary:hover {
  border-color: var(--gold);
  background: #383000;
}
.compile-status {
  margin-left: auto;
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.compile-status.ok { color: var(--good); }
.compile-status.err { color: var(--bad); }
.compile-status.busy { color: #fbbf24; }

#shaderEditor {
  flex: 1;
  min-height: 0;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: #0a0a0c;
  color: #d4d4d8;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 0.75rem 0.85rem;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
#shaderEditor:focus {
  box-shadow: inset 0 0 0 1px rgba(247, 201, 72, 0.15);
}

.compile-log {
  flex-shrink: 0;
  max-height: 28%;
  overflow: auto;
  margin: 0;
  padding: 0.55rem 0.75rem;
  background: #1a0808;
  border-top: 1px solid #4a1515;
  color: #fca5a5;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.compile-log[hidden] { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 48vh 1fr;
  }
  .preview { border-right: none; border-bottom: 1px solid var(--border); }
  :root { --sidebar-w: 100%; }
  #c {
    width: min(100%, calc(48vh - 100px));
    max-height: calc(48vh - 100px);
  }
}

/* ---------- Video embed (About tab) ---------- */
.video-embed {
  margin-top: 0.85rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2a2a30;
  background: #000;
}
.video-embed iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

#c { cursor: grab; }
#c:active { cursor: grabbing; }
