:root {
  --bg: #0c0d10;
  --panel: #141519;
  --panel-2: #1a1c21;
  --line: #26282e;
  --text: #e9e9ec;
  --muted: #8d919b;
  --accent: #e6b455;
  --accent-dim: #6b552a;
  --bad: #f0736a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* .field and .row set display, which beats the browser's own [hidden] rule. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "SF Pro Text", Inter, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.block { width: 100%; }
.pad { padding: 16px; }

/* ---- header ---- */
#top {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
.brand { font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.brand .dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 3px solid var(--accent);
}

#bar {
  height: 2px; flex: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: slide 1.1s linear infinite;
}
@keyframes slide { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* ---- layout ---- */
#app {
  flex: 1;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 340px;
  min-height: 0;
}
#rail, #side { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
#rail { border-right: 1px solid var(--line); }
#side { border-left: 1px solid var(--line); }
#center { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ---- controls ---- */
button, select, input, textarea {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #3a3d45; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: #17140c; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #f0c169; }
button.ghost { background: transparent; }
button.ghost.on { border-color: var(--accent); color: var(--accent); }
button.danger:hover { border-color: var(--bad); color: var(--bad); }
button.tiny, .ghost.tiny { padding: 4px 8px; font-size: 11.5px; border-radius: 7px; }
.file { display: inline-flex; align-items: center; cursor: pointer; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; font-size: 11.5px; }

.field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--muted); }
.field > span { padding-left: 2px; }
.field > select, .field > input { color: var(--text); font-size: 13px; }
.field.block { width: 100%; margin: 10px 0; }
.field.block input { width: 100%; }
.field.small > input[type=range] { width: 120px; padding: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); align-self: end; padding-bottom: 6px; }
.check input { width: 15px; height: 15px; }

/* ---- rail ---- */
.rail-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.rail-head select { width: 100%; }
.tiny-row { justify-content: space-between; }
#newChat { margin: 12px; width: calc(100% - 24px); }
#chatList { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-row {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: transparent; border: 1px solid transparent; text-align: left;
  padding: 7px 8px; margin-bottom: 2px; color: var(--muted);
}
.chat-row.on { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.chat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-count { font-size: 11px; color: var(--muted); }
.chat-del { opacity: 0; font-size: 15px; line-height: 1; padding: 0 2px; }
.chat-row:hover .chat-del { opacity: 0.6; }
.chat-del:hover { opacity: 1; color: var(--bad); }
.rail-foot { padding: 12px; border-top: 1px solid var(--line); }

/* ---- centre ---- */
.chat-name {
  background: transparent; border: none; border-bottom: 1px solid var(--line);
  border-radius: 0; padding: 12px 18px; font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em; flex: none;
}
.chat-name:focus { outline: none; border-bottom-color: var(--accent); }

/* ---- brief + recommendations ---- */
/* the start screen: one address, nothing else */
#start { flex: none; padding: 8vh 18px 0; max-width: 560px; margin: 0 auto; width: 100%; }
#start h1 { font-size: 25px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }
#start .lede { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.site-form { display: flex; gap: 8px; }
#siteUrl { flex: 1; font-size: 16px; padding: 11px 13px; background: var(--panel-2); }
.site-form button { padding: 11px 18px; font-size: 14px; }
.hint-in { width: 100%; margin-top: 8px; background: transparent; border-color: transparent; font-size: 12.5px; padding-left: 2px; }
.hint-in:focus { border-color: var(--line); background: var(--panel-2); padding-left: 11px; }

/* what it decided the company is, editable */
#who { flex: none; padding: 10px 18px 8px; border-bottom: 1px solid var(--line); }
.who-line { display: flex; gap: 8px; align-items: center; }
.who-name { background: transparent; border-color: transparent; font-weight: 600; font-size: 13.5px; width: 15ch; flex: none; }
.who-does { background: transparent; border-color: transparent; flex: 1; font-size: 13px; color: var(--muted); }
.who-line input:focus { background: var(--panel-2); border-color: var(--line); }
#who p { margin: 5px 2px 0; }

/* the five concepts */
#flow { flex: 1; overflow-y: auto; min-height: 0; }
#concepts { padding: 12px 18px 14px; border-bottom: 1px solid var(--line); }
.con-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.con-head span:first-child { font-weight: 600; }
.con-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 8px; }
.con { position: relative; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 11px 12px 9px; display: flex; flex-direction: column; gap: 6px; }
.con-n { position: absolute; top: 9px; right: 11px; font-size: 11px; color: var(--line); font-weight: 600; }
.con h4 { margin: 0; font-size: 13px; color: var(--accent); padding-right: 14px; line-height: 1.3; }
.con-idea { margin: 0; font-size: 12px; line-height: 1.5; flex: 1; }
.con-foot { display: flex; align-items: center; gap: 5px; }
.con-foot .chip { margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cliche { margin: 7px 2px 0; font-size: 11.5px; line-height: 1.45; color: #e6b455; }
.chip.dir { color: #9db8e8; border-color: #2f3d55; }

/* the knobs, folded away */
#advanced { margin-top: 9px; }
#advanced summary { cursor: pointer; font-size: 11.5px; color: var(--muted); list-style: none; user-select: none; }
#advanced summary::-webkit-details-marker { display: none; }
#advanced summary::before { content: "▸ "; }
#advanced[open] summary::before { content: "▾ "; }
#advanced summary:hover { color: var(--fg); }

#thread { padding: 18px; }
.empty { max-width: 460px; margin: 12vh auto; text-align: center; }
.empty h2 { font-size: 19px; margin: 0 0 6px; font-weight: 600; }

.msg { max-width: 640px; margin: 0 0 14px; }
.msg.user p { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; }
.msg.user .why { margin-top: 5px; background: transparent; border: none; padding: 0 2px; color: var(--accent); font-size: 11.5px; }
.msg.error p { margin: 0; border: 1px solid #4a2b28; background: #2a1a19; color: #f3a49d; border-radius: var(--radius); padding: 9px 12px; font-size: 12.5px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.frame { background: #fff; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; }
.frame.checker {
  background-image: linear-gradient(45deg, #22242a 25%, transparent 25%), linear-gradient(-45deg, #22242a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #22242a 75%), linear-gradient(-45deg, transparent 75%, #22242a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #1b1d22;
}
.frame img { max-width: 100%; max-height: 100%; display: block; }
.cap { padding: 9px 10px 10px; border-top: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { font-size: 10.5px; padding: 2px 6px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.chip.strong { color: var(--accent); border-color: var(--accent-dim); }
.chip.svg { color: #7fd1b9; border-color: #2c4d45; }
.cap-text { margin: 0 0 4px; font-size: 11.5px; line-height: 1.45; word-break: break-word; }
.cap-text b { color: var(--muted); font-weight: 600; }
.card-acts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.card-acts a { text-decoration: none; display: inline-block; }

/* ---- composer ---- */
#composer { flex: none; border-top: 1px solid var(--line); padding: 12px 18px 14px; background: var(--panel); }
#prompt { width: 100%; resize: vertical; min-height: 62px; }
.preview { margin: 6px 2px 0; font-size: 11.5px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.45; }
.preview:empty { display: none; }
.controls { margin-top: 10px; align-items: flex-end; }
.send-row { margin-top: 10px; }
.ref-tray { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ref { position: relative; width: 44px; height: 44px; border-radius: 7px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.ref img { width: 100%; height: 100%; object-fit: contain; }
.ref-x { position: absolute; top: -1px; right: -1px; padding: 0 4px; line-height: 1.2; border-radius: 0 6px 0 6px; background: #000a; border: none; font-size: 12px; }

/* ---- side ---- */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px; color: var(--muted); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
#library, #editHost { flex: 1; overflow-y: auto; min-height: 0; }
.lib-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 10px; }
.cell { padding: 0; aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.cell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cell.picked { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

/* ---- editor ---- */
.editor { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; }
.editor-head h3 { margin: 0; font-size: 14px; }
.editor-stage { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; aspect-ratio: 1; }
.editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.editor-mask { cursor: crosshair; touch-action: none; }
.editor-prompt { width: 100%; resize: vertical; }
.editor-acts { gap: 6px; }
.editor-acts button { font-size: 12px; padding: 5px 8px; }
.editor-status:empty { display: none; }

/* ---- dialog + toast ---- */
dialog {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 20px; max-width: 460px; width: calc(100% - 32px);
}
dialog::backdrop { background: #000b; }
dialog h2 { margin: 0 0 8px; font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-size: 12.5px; max-width: min(680px, 92vw);
  opacity: 0; pointer-events: none; transition: 0.18s; margin: 0; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { border-color: #4a2b28; color: #f3a49d; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 200px minmax(0, 1fr) 280px; }
}
@media (max-width: 880px) {
  body { overflow: auto; }
  #app { grid-template-columns: 1fr; }
  #rail, #side { border: none; border-top: 1px solid var(--line); }
  #flow { max-height: 60vh; }
}
