:root {
  color-scheme: dark;
  --bg:        #141f1a;
  --bg-2:      #1a2a24;
  --panel:     #1e2f28;
  --bar:       #203c35;
  --line:      rgba(222, 230, 202, 0.12);
  --line-2:    rgba(222, 230, 202, 0.22);
  --cream:     #f2ebd9;
  --dim:       #a9b7a9;
  --gold:      #e4bc78;
  --gold-dim:  #ad9870;
  --radius:    12px;
  --bar-h:     56px;
  --gap:       12px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over our display:flex/grid/block rules. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--cream);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button, select, a { font: inherit; }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Top bar ---- */
.topbar {
  flex: 0 0 var(--bar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: linear-gradient(180deg, var(--bar), #1b332d);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 20, 12, 0.35);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 0 1 auto; }
.brand-mark { width: 30px; height: 30px; fill: var(--gold); flex: 0 0 auto; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-title { font-weight: 600; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); white-space: nowrap; }

.mode-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 3px;
  gap: 3px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.mode-btn {
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.mode-btn:hover { color: var(--cream); }
.mode-btn.is-active { background: var(--gold); color: #243a30; font-weight: 600; }

.topbar-actions {
  flex: 0 0 auto;
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.ghost-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  transition: background .18s, border-color .18s;
}
.ghost-btn:hover { background: rgba(228, 188, 120, 0.14); border-color: var(--gold-dim); }

/* ---- Stage ---- */
.stage {
  flex: 1 1 auto;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
}
.stage.single  { grid-template-columns: 1fr; }
.stage.compare { grid-template-columns: 1fr 1fr; }

/* ---- Panel ---- */
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 16, 10, 0.3);
}

.panel-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--line);
}

.panel-select {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--cream);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a9b7a9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.panel-select:hover { border-color: var(--gold-dim); }

.panel-actions { display: inline-flex; gap: 6px; flex: 0 0 auto; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: background .18s, color .18s, border-color .18s;
}
.icon-btn:hover { color: var(--cream); background: rgba(228, 188, 120, 0.14); border-color: var(--gold-dim); }

.panel-view { position: relative; flex: 1 1 auto; min-height: 0; background: #0f1713; }
.panel-frame { width: 100%; height: 100%; border: 0; display: block; }
.panel-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 14px;
}

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---- Per-panel provenance popover ---- */
.panel-info {
  flex: 0 0 auto;
  margin: 0 var(--gap);
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 13px;
  line-height: 1.5;
}
.info-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 14px;
  row-gap: 3px;
  margin: 0;
}
.info-grid dt { color: var(--dim); font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; padding-top: 2px; }
.info-grid dd { margin: 0; color: var(--cream); overflow-wrap: anywhere; }
.info-note { margin: 10px 0 0; color: var(--dim); }
.info-note:empty { display: none; }
.icon-btn[aria-expanded="true"] { background: rgba(228, 188, 120, 0.16); border-color: var(--gold-dim); color: var(--gold); }

/* ---- Prompt slide-over ---- */
.overlay { position: fixed; inset: 0; z-index: 20; }
.overlay-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); animation: fade .2s ease; }
.prompt-panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(560px, 92vw);
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border-left: 1px solid var(--line-2);
  box-shadow: -14px 0 40px rgba(0, 0, 0, 0.45);
  animation: slide .24s cubic-bezier(.2,.7,.3,1);
}
.prompt-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  font-size: 15px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.prompt-body {
  flex: 1 1 auto;
  margin: 0;
  padding: 18px 20px;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--dim);
}

.prompt-panel--wide { width: min(720px, 94vw); }

/* ---- About document (rendered Markdown) ---- */
.doc-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 6px 28px 40px;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--cream);
  scroll-behavior: smooth;
}
.doc-body > :first-child { margin-top: 18px; }
.doc-body h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 18px 0 10px; }
.doc-body h2 { font-size: 16px; font-weight: 650; color: var(--gold); margin: 30px 0 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.doc-body h3 { font-size: 15px; font-weight: 600; margin: 20px 0 6px; }
.doc-body p { margin: 0 0 12px; }
.doc-body p, .doc-body li { color: var(--cream); }
.doc-body .doc-muted { color: var(--dim); }
.doc-body ul, .doc-body ol { margin: 0 0 12px; padding-left: 22px; }
.doc-body li { margin: 0 0 6px; }
.doc-body li::marker { color: var(--gold-dim); }
.doc-body strong { color: #fff; font-weight: 600; }
.doc-body a { color: var(--gold); text-decoration: underline; text-decoration-color: rgba(228,188,120,.4); text-underline-offset: 2px; }
.doc-body a:hover { text-decoration-color: var(--gold); }
.doc-body code { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--gold); background: rgba(228,188,120,.1); padding: 1px 6px; border-radius: 5px; overflow-wrap: anywhere; }
.doc-body pre { margin: 0 0 14px; padding: 12px 14px; overflow: auto; background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 9px; }
.doc-body pre code { background: none; padding: 0; color: var(--cream); font-size: 12.5px; }
.doc-table { overflow-x: auto; margin: 4px 0 16px; }
.doc-body table { width: 100%; border-collapse: collapse; margin: 0; font-size: 13.5px; }
.doc-body th, .doc-body td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.doc-body th { color: var(--dim); font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.doc-body tr:last-child td { border-bottom: 0; }
.doc-body td:first-child { white-space: nowrap; font-weight: 600; }

/* ---- Empty state ---- */
.empty-state {
  position: fixed; inset: var(--bar-h) 0 0 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 20px;
  background: var(--bg);
}
.empty-state svg { width: 64px; height: 64px; fill: var(--gold-dim); opacity: .7; margin-bottom: 8px; }
.empty-state h2 { margin: 0; font-weight: 600; }
.empty-state p { margin: 0; color: var(--dim); max-width: 34ch; }
.empty-state code { color: var(--gold); background: rgba(228,188,120,.1); padding: 1px 6px; border-radius: 5px; }

@keyframes fade  { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(100%); } }

/* ---- Responsive: stack compare panels ---- */
@media (max-width: 820px) {
  .stage.compare { grid-template-columns: 1fr; grid-auto-rows: 1fr; overflow-y: auto; }
  .stage.compare .panel { min-height: 60vh; }
  .brand-sub { display: none; }
}

/* ---- Responsive: tighten the top bar on phones ---- */
@media (max-width: 560px) {
  :root { --bar-h: 52px; --gap: 9px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand { gap: 9px; }
  .brand-mark { width: 26px; height: 26px; }
  .mode-btn { padding: 7px 12px; }
  .topbar-actions { gap: 6px; }
  .ghost-btn { padding: 9px; }        /* square icon button */
  .ghost-btn .btn-label { display: none; }
  .doc-body { padding: 6px 16px 32px; font-size: 14px; }
  .doc-body table { min-width: 560px; }   /* scroll sideways inside .doc-table rather than squeeze */
}
