/* Fonts: DINish (OFL libre DIN — the display face anime.js uses) + JetBrains Mono
   (OFL — a free stand-in for anime.js's commercial Berkeley Mono) for technical labels. */
@font-face {
  font-family: 'DINish';
  src: url('assets/fonts/dinish-var.woff2') format('woff2-variations');
  font-weight: 100 900; font-stretch: 75% 125%; font-style: normal; font-display: swap;
}
@font-face { font-family:'JetBrains Mono'; src:url('assets/fonts/jetbrains-mono-400.woff2') format('woff2'); font-weight:400; font-display:swap; }
@font-face { font-family:'JetBrains Mono'; src:url('assets/fonts/jetbrains-mono-500.woff2') format('woff2'); font-weight:500; font-display:swap; }
@font-face { font-family:'JetBrains Mono'; src:url('assets/fonts/jetbrains-mono-700.woff2') format('woff2'); font-weight:700; font-display:swap; }

:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #76b900;        /* NVIDIA green */
  --accent-dim: #5c8f00;
  --warn: #e3873c;
  --font-body: 'DINish', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-code: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font-body);
  background: var(--bg); color: var(--text);
}
body { display: flex; }

/* ---- Panel ---- */
#panel {
  width: 340px; min-width: 340px; height: 100vh;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
#panel header { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); }
#panel h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
#panel .sub { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.accent { color: var(--accent); font-weight: 600; }

/* ---- Engine selector ---- */
#engine-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
#engine-bar label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#engine-bar select {
  flex: 1; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.stats .eng { color: var(--accent); font-weight: 600; margin-bottom: 2px; }

#controls { flex: 1; overflow-y: auto; padding: 8px 14px 14px; }
.group { margin-top: 14px; }
.group > h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.field { margin-bottom: 11px; }
.field .row { display: flex; justify-content: space-between; align-items: baseline; }
.field label { font-size: 12.5px; color: var(--text); }
.field .val { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
.field input[type=range] {
  width: 100%; margin-top: 6px; accent-color: var(--accent); cursor: pointer;
}
.field select {
  width: 100%; margin-top: 4px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.loading { color: var(--muted); font-size: 13px; }

/* ---- Actions ---- */
#actions { padding: 12px 14px; border-top: 1px solid var(--line); display: grid;
  grid-template-columns: 1fr 1fr; gap: 8px; }
#actions button {
  padding: 9px 10px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
#actions button:hover { border-color: var(--accent-dim); }
#actions button.primary { grid-column: 1 / -1; background: var(--accent-dim);
  border-color: var(--accent); color: #0b0f06; font-weight: 700; }
#actions button.primary:hover { background: var(--accent); }
#actions button:disabled { opacity: .5; cursor: wait; }

/* ---- Viewport ---- */
#viewport { position: relative; flex: 1; min-width: 0; height: 100vh; }
#viewport canvas { display: block; }
.stats {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(14,17,22,.78); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 13px; font-size: 12px; color: var(--muted); line-height: 1.65;
  backdrop-filter: blur(6px); min-width: 190px;
}
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.stats .ok { color: var(--accent); }
.stats .bad { color: var(--warn); }
.status {
  position: absolute; bottom: 12px; left: 12px; z-index: 5;
  font-size: 12px; color: var(--muted);
  background: rgba(14,17,22,.78); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 11px; backdrop-filter: blur(6px);
}
.status.busy { color: var(--accent); }
.status.err { color: var(--warn); }

/* ---- Viewport annotation controls ---- */
.anno-dock {
  position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  width: max-content; max-width: calc(100% - 24px); padding: 8px;
  background: rgba(14,17,22,.94); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); backdrop-filter: blur(8px);
}
#btn-author {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 13px; cursor: pointer;
}
#btn-author:hover { border-color: var(--accent); }

.anno-canvas {
  position: absolute; inset: 0; z-index: 3;
  width: 100%; height: 100%;
}
.anno-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  max-width: 100%;
}
.anno-bar .grp { display: flex; align-items: center; gap: 5px; }
.anno-bar .grp + .grp { border-left: 1px solid var(--line); padding-left: 12px; }
.anno-bar .tbtn {
  padding: 6px 9px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 12.5px; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.anno-bar .tbtn:hover { border-color: var(--accent-dim); }
.anno-bar .anno-close { font-size: 22px; line-height: 1; padding: 4px 8px; }
.anno-bar .tbtn.on { background: var(--accent-dim); border-color: var(--accent); color: #0b0f06; font-weight: 700; }
.anno-bar .tbtn.primary { background: var(--accent-dim); border-color: var(--accent); color: #0b0f06; font-weight: 700; }
.anno-bar .tbtn.primary:hover { background: var(--accent); }
.anno-bar .swatch {
  width: 22px; height: 22px; padding: 0; border-radius: 6px; cursor: pointer;
  border: 2px solid rgba(255,255,255,.25);
}
.anno-bar .swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }

/* ---- Part selector (mirrors engine bar) ---- */
#part-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2);
}
#part-bar label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#part-bar select {
  flex: 1; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
#part-bar select:disabled { opacity: .6; }

/* ---- Design actions ---- */
#actions button.wide { grid-column: 1 / -1; }
#btn-save.dirty { box-shadow: inset 0 0 0 2px var(--warn); }

/* ---- Routing: editor vs gallery ---- */
#gallery-page { display: none; width: 100%; height: 100vh; overflow-y: auto; padding: 28px 32px; }
body[data-view="gallery"] #panel,
body[data-view="gallery"] #viewport { display: none; }
body[data-view="gallery"] #gallery-page { display: block; }

/* ---- Gallery ---- */
.gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.gallery-head h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.gallery-error { color: var(--warn); }
.gallery-head .count { color: var(--muted); font-size: 15px; font-weight: 400; margin-left: 6px; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 40px 4px; }
.swatch {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column; transition: border-color .12s;
}
.swatch:hover { border-color: var(--accent-dim); }
.swatch-thumb {
  aspect-ratio: 4 / 3; background: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.swatch-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.swatch-thumb .noimg { color: var(--muted); font-size: 12px; }
.swatch-meta { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.swatch-label { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch-sub { font-size: 11.5px; color: var(--muted); }
.swatch-ops { display: flex; gap: 6px; padding: 8px 12px 12px; }
.swatch-ops button {
  padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 12px; cursor: pointer;
}
.swatch-ops button[data-op="open"] { flex: 1; }
.swatch-ops button:hover { border-color: var(--accent-dim); }

/* ---- Modal (in-app prompt) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 0; border: 0; width: 100%; height: 100%; max-width: none; max-height: none; color: var(--text);
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
}
.modal-overlay:not([open]) { display: none; }
.modal-overlay::backdrop { background: transparent; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; width: 340px; max-width: calc(100% - 32px); box-shadow: 0 12px 44px rgba(0,0,0,.5);
}
.modal-title { margin: 0 0 12px; font-size: 16px; }
.modal-confirm { width: 460px; }
.modal-message { margin: 0; color: var(--muted); font-size: 14px; }
.modal-confirm .modal-actions { flex-wrap: wrap; }
.modal-input {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; font-size: 14px;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button {
  padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 13px; cursor: pointer;
}
.modal-actions button:hover { border-color: var(--accent-dim); }
.modal-actions button.primary { background: var(--accent-dim); border-color: var(--accent); color: #0b0f06; font-weight: 700; }
.modal-actions button.primary:hover { background: var(--accent); }

.gallery-section {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 26px 0 12px; font-weight: 600;
}
.gallery-section .count { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
.swatches.templates { margin-bottom: 4px; }
.swatch.template { border-style: dashed; }
.swatch.template .swatch-ops button { flex: 1; }
.swatch.template .swatch-thumb .noimg { color: var(--text); font-weight: 600; font-size: 14px; }

/* AI design workspace */
[hidden] { display: none !important; }
#ai-panel, #ai-topbar, #ai-empty, #ai-parameters { display: none; }
body[data-view="ai"] #panel, body[data-view="ai"] #gallery-page { display:none; }
body[data-view="ai"] #ai-panel { display:flex; }
body[data-view="ai"] #viewport { display:block; }
body[data-view="ai"] #ai-topbar { display:flex; }
body[data-view="ai"] #ai-empty:not([hidden]) { display:block; }
body[data-view="ai"] #ai-parameters { display:block; }
body[data-view="ai"] #stats { top:70px; }
#ai-panel {
  position:relative; width:390px; min-width:300px; max-width:60vw; height:100vh;
  flex:none; flex-direction:column; background:var(--panel); border-right:1px solid var(--line);
}
#ai-panel.collapsed { width:48px !important; min-width:48px; }
#ai-panel.collapsed > :not(.chat-header) { display:none; }
#ai-panel.collapsed .chat-header > div { display:none; }
#ai-panel.collapsed .chat-header { padding:12px 8px; }
.chat-header { display:flex; align-items:center; justify-content:space-between; padding:20px 18px; border-bottom:1px solid var(--line); }
.chat-model { display:block; color:var(--muted); font-size:12px; margin-top:6px; }
#ai-panel button, #ai-topbar button, #ai-parameters button, .gallery-new {
  background:var(--panel-2); color:var(--text); border:1px solid var(--line); border-radius:7px;
  padding:8px 12px; cursor:pointer; font:inherit; font-size:13px;
}
#ai-panel button:hover, #ai-topbar button:hover, .gallery-new:hover { border-color:var(--accent); }
#ai-panel button.primary, #ai-topbar button.primary, .gallery-new.primary { background:var(--accent-dim); border-color:var(--accent); color:#0b0f06; font-weight:600; }
#ai-panel button:disabled, #ai-topbar button:disabled, #ai-parameters button:disabled { opacity:.45; cursor:default; }
.chat-messages { flex:1; overflow:auto; padding:20px 18px; min-height:0; scroll-behavior:auto; }
.chat-welcome { padding:35px 3px; }
.welcome-icon { color:var(--accent); font-size:30px; }
.chat-welcome h2 { font-size:21px; margin:15px 0 8px; }
.chat-welcome p { color:var(--muted); font-size:14px; line-height:1.6; }
.chat-welcome .chat-example { margin-top:25px; padding:14px; border:1px solid var(--line); border-radius:10px; font-size:13px; }
.chat-message { margin-bottom:26px; overflow-wrap:anywhere; font-size:14px; line-height:1.55; }
.chat-message.user { padding:12px; background:var(--panel-2); border-radius:12px; }
.message-head { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:8px; font-size:12px; }
.message-head time, .chat-message small { color:var(--muted); font-size:11px; }
.chat-message.system { color:var(--muted); border-left:2px solid var(--line); padding-left:12px; }
.message-markdown p { margin:6px 0; white-space:pre-wrap; }
.message-markdown pre { overflow:auto; background:var(--bg); padding:12px; border-radius:7px; font-size:12px; }
.message-markdown code { font-family:ui-monospace,monospace; }
#ai-panel .message-copy { padding:2px 0; background:none; border:none; color:var(--muted); font-size:11px; }
.message-image { display:block; max-width:100%; max-height:220px; border-radius:8px; margin:8px 0; }
.chat-run { border-top:1px solid var(--line); padding:10px 16px; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px; font-size:12px; color:var(--muted); }
.chat-run:empty { display:none; }
.run-dismiss { background:none; border:1px solid var(--line); color:var(--muted); }   /* secondary action next to Continue/Retry */
.run-dismiss:hover { color:var(--text); border-color:var(--accent-dim); }
.run-active::before { content:'●'; color:var(--accent); margin-right:7px; }
.run-error, .chat-error { color:var(--warn); font-size:12px; line-height:1.5; overflow-wrap:anywhere; }
.run-error { width:100%; margin:0; }
.chat-error { padding:10px 16px; }
.chat-composer { margin:0 12px 14px; padding:10px; border:1px solid var(--line); border-radius:12px; background:var(--bg); }
.chat-composer:focus-within { border-color:var(--accent-dim); }
.chat-composer textarea { width:100%; resize:vertical; max-height:230px; min-height:70px; background:transparent; color:var(--text); border:0; outline:none; font:inherit; font-size:14px; line-height:1.5; }
.composer-actions { display:flex; align-items:center; gap:8px; }
.composer-actions span { color:var(--muted); font-size:11px; flex:1; }
.attachment { display:flex; align-items:center; gap:7px; font-size:11px; padding:6px; border:1px solid var(--line); border-radius:6px; margin-bottom:8px; }
.attachment img { width:44px; height:36px; object-fit:cover; border-radius:4px; }
.attachment span { flex:1; overflow-wrap:anywhere; }
.chat-resize { position:absolute; top:0; bottom:0; right:-3px; width:6px; cursor:col-resize; z-index:10; }
.chat-resize:hover, .chat-resize:focus { background:var(--accent-dim); }
#ai-topbar { position:absolute; inset:0 0 auto; z-index:7; padding:12px 16px; min-height:58px; gap:8px; align-items:center; border-bottom:1px solid var(--line); background:rgba(14,17,22,.95); }
.ai-title { font-size:14px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1; }
.ai-save-state { color:var(--muted); font-size:11px; white-space:nowrap; }
#ai-empty { position:absolute; top:42%; left:50%; transform:translate(-50%,-50%); width:80%; max-width:440px; text-align:center; z-index:2; pointer-events:none; }
#ai-empty h2 { font-size:24px; font-weight:500; }
#ai-empty p { color:var(--muted); line-height:1.6; font-size:14px; }
#ai-parameters { position:absolute; right:14px; top:70px; z-index:6; max-height:60vh; max-width:250px; overflow:auto; background:var(--panel); border:1px solid var(--line); border-radius:8px; }
#ai-parameters:empty { display:none !important; }
#ai-parameters summary { cursor:pointer; padding:10px 14px; font-size:13px; }
#ai-parameters form { padding:0 12px 12px; }
#ai-parameters label { display:flex; flex-direction:column; gap:4px; margin:8px 0; font-size:12px; }
#ai-parameters input { background:var(--bg); color:var(--text); border:1px solid var(--line); border-radius:5px; padding:7px; width:100%; }
@media(max-width:1050px) { #ai-panel { width:330px; } .ai-save-state { display:none; } #ai-topbar { flex-wrap:wrap; } .ai-title { min-width:70px; } }
.message-duration { display:block; margin-top:8px; }
.message-activity { margin-top:6px; font-size:11px; color:var(--muted); }
.message-activity summary { cursor:pointer; }
.message-activity div { padding:3px 0 3px 12px; }
.chat-message > small { display:block; margin-top:6px; }
#ai-panel .message-copy { display:block; margin-top:5px; }
