/* Pothead — light, paper-and-ink, serif. Restrained palette: ivory, warm ink, one terracotta accent.
   One control system: every button, input and select shares a height and a rounded-square corner (no pills). */
:root {
  --paper: #F4F1EA; --paper-2: #FBFAF6; --paper-3: #EDE8DD;
  --ink: #1F1E1B; --ink-2: #5C5955; --ink-3: #9A968F; --line: #E2DDD2; --line-2: #CFC8BA;
  --accent: #D97757; --accent-ink: #B65A37; --accent-soft: #F6E4DA;
  --slate: #6B7C93; --ochre: #C89B3C; --sage: #7E8B6D; --danger: #B4443C;
  --c-idle: var(--slate); --c-emo: var(--ochre); --c-vis: var(--sage); --c-fin: var(--ink);
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 14px;          /* cards: panels, navbar, plea */
  --r: 8px;                /* controls: buttons, inputs, selects, bubbles */
  --h: 32px;               /* control height */
  --shadow: 0 1px 2px rgba(31, 30, 27, 0.04), 0 14px 36px rgba(60, 45, 20, 0.07);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
body { background: #cfc8bb; }
canvas#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---- lens: a faint vignette and grain so the render reads like a photo ---- */
.lens { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse 78% 70% at 50% 46%, rgba(0,0,0,0) 55%, rgba(30, 22, 12, 0.22) 100%); }
.lens::after { content: ""; position: absolute; inset: 0; opacity: 0.045; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* ---- boot overlay ---- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); z-index: 50; transition: opacity 0.6s ease; }
.boot.hidden { opacity: 0; pointer-events: none; }
.boot-card { width: min(420px, 86vw); text-align: center; }
.boot-title { font-size: 40px; font-weight: 500; letter-spacing: -0.01em; color: var(--ink); font-style: italic; }
.boot-msg { margin: 10px 0 18px; color: var(--ink-2); min-height: 1.2em; font-size: 15px; }
.boot-bar { height: 2px; background: var(--line); overflow: hidden; }
.boot-bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }

/* ---- controls ---- */
.btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: var(--h); padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r); background: var(--paper-2); color: var(--ink);
  font: inherit; font-size: 13px; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s; }
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.btn.square { width: var(--h); padding: 0; }
.btn.accent { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.active { border-color: var(--accent-ink); background: var(--accent-soft); color: var(--accent-ink); }  /* recording / listening */

input[type="checkbox"] { accent-color: var(--ink); width: 14px; height: 14px; margin: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 18px; margin: 0; }
select, .keyrow input, #chat-input { height: var(--h); min-width: 0; background: var(--paper-2); color: var(--ink); border: 1px solid var(--line-2); border-radius: var(--r); font: inherit; font-size: 13px; }
select { appearance: none; padding: 0 28px 0 10px; cursor: pointer;
  background: var(--paper-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235C5955' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 14px; }
.keyrow input { flex: 1; padding: 0 10px; }
select:focus, .keyrow input:focus, #chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- HUD grid ---- */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; display: grid;
  grid-template-columns: 320px 1fr 320px; grid-template-rows: auto 1fr auto; gap: 14px; padding: 14px; }
.hud.hidden { display: none; }
.hud > * { pointer-events: auto; }
.hud.panels-hidden .panel { display: none; }

/* ---- navbar ---- */
.hud-top { grid-column: 1 / -1; position: relative; display: flex; align-items: center; gap: 12px; padding: 7px;
  background: rgba(251, 250, 246, 0.85); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.btn.back { padding: 0 12px 0 8px; gap: 4px; }
.btn.panels { padding: 0 12px 0 10px; }
.sep { width: 1px; height: 20px; background: var(--line); }
.brand { font-size: 19px; font-weight: 500; font-style: italic; display: flex; align-items: center; gap: 9px; color: var(--ink); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); transition: background 0.3s; }
.dot.live { background: var(--sage); }
.dot.speaking { background: var(--accent); animation: pulse 0.7s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217,119,87,0.45);} 70% { box-shadow: 0 0 0 7px rgba(217,119,87,0);} 100% { box-shadow: 0 0 0 0 rgba(217,119,87,0);} }
.spacer { flex: 1; }
.toolbar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: calc(var(--r) + 4px); background: var(--paper-2); }
.toolbar .tool { border-color: transparent; background: transparent; }
.toolbar .tool svg { width: 18px; height: 18px; }
.toolbar .tool:hover { background: var(--paper-3); border-color: transparent; }
.toolbar .tool.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
body.tool-active canvas#stage { cursor: default; } /* the pointer itself holds the tool */

/* ---- side panels ---- */
.panel { background: rgba(251, 250, 246, 0.9); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
  padding: 14px 16px; overflow: auto; align-self: start; max-height: 100%; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.panel.left { grid-column: 1; grid-row: 2 / 4; }   /* both panels run down beside the chat */
.panel.right { grid-column: 3; grid-row: 2 / 4; }
.panel section + section { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
h3 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; font-size: 15px; font-weight: 500; color: var(--ink); letter-spacing: -0.005em; white-space: nowrap; }
h3 .sub { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 10.5px; font-weight: 400; color: var(--ink-3); }

.grid { display: grid; gap: 6px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.emotions { grid-template-columns: repeat(3, 1fr); gap: 5px; }
.btn.emo { height: 30px; padding: 0 4px; text-transform: capitalize; }
.btn.emo.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.grid.toggles { grid-template-columns: 1fr 1fr; gap: 5px 6px; margin-top: 10px; }
.grid.toggles label { display: flex; gap: 7px; align-items: center; color: var(--ink-2); font-size: 13px; }

.row { display: grid; grid-template-columns: 92px 1fr 36px; align-items: center; gap: 10px; margin-top: 6px; color: var(--ink-2); font-size: 13px; }
.row output { font-family: var(--mono); font-size: 11px; text-align: right; color: var(--ink); }
.row.select { grid-template-columns: 92px 1fr; }
section > h3 + .row { margin-top: 0; }
.keyrow { display: flex; gap: 6px; margin-top: 8px; }

.meter { position: relative; height: 20px; margin-top: 10px; border-radius: var(--r); background: var(--paper-3); overflow: hidden; border: 1px solid var(--line); }
.meter > div { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, var(--sage), var(--ochre)); transition: width 0.05s linear; }
.meter > span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; color: var(--ink-2); }

.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; }
.c-idle { background: var(--c-idle); } .c-emo { background: var(--c-emo); } .c-vis { background: var(--c-vis); } .c-fin { background: var(--c-fin); }
canvas#monitor { width: 100%; height: auto; display: block; }

/* ---- chat: a short transcript (older bubbles fade out at the top) over the input ---- */
.chat { grid-column: 2; grid-row: 3; align-self: end; justify-self: center; width: min(640px, 100%); display: flex; flex-direction: column; gap: 8px; }
.transcript { display: flex; flex-direction: column; gap: 5px; max-height: 100px; overflow: auto; padding: 18px 2px 0; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px); mask-image: linear-gradient(to bottom, transparent 0, #000 18px); }
.transcript::-webkit-scrollbar { display: none; }
.transcript:empty { display: none; }
.transcript .msg { max-width: 85%; padding: 7px 12px; border-radius: 10px; line-height: 1.4; font-size: 14px; background: rgba(251, 250, 246, 0.94); border: 1px solid var(--line); box-shadow: var(--shadow); }
.transcript .msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.transcript .msg.ai { align-self: flex-start; }
.transcript .msg.sys { align-self: center; color: var(--ink-3); font-size: 12px; padding: 2px 8px; background: transparent; border: none; box-shadow: none; font-style: italic; }
.transcript .msg .tag { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--accent-ink); margin-bottom: 2px; }
#chat-form { display: flex; gap: 6px; padding: 6px; background: rgba(251, 250, 246, 0.9); border: 1px solid var(--line); border-radius: calc(var(--r) + 6px); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
#chat-input { flex: 1; padding: 0 12px; font-size: 15px; border-color: transparent; background: transparent; }
#chat-input:focus { border-color: transparent; box-shadow: none; }
#chat-form:focus-within { border-color: var(--line-2); }
#chat-input::placeholder { color: var(--ink-3); font-style: italic; }
#chat-form .btn { height: 36px; width: 36px; }
#chat-form #chat-input { height: 36px; }

.drop-overlay { position: fixed; inset: 0; display: none; place-items: center; z-index: 40; background: rgba(244, 241, 234, 0.8); border: 2px dashed var(--accent); color: var(--accent-ink); font-size: 24px; font-style: italic; pointer-events: none; }
.drop-overlay.show { display: grid; }

/* ---- the plea (tab-close guard) ---- */
.plea { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; background: rgba(244, 241, 234, 0.55); backdrop-filter: blur(6px); }
.plea.show { display: grid; }
.plea-card { width: min(520px, 90vw); background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 28px; text-align: center; }
.plea-card h2 { margin: 0 0 8px; font-size: 24px; font-weight: 500; font-style: italic; }
.plea-card p { margin: 0 0 18px; font-size: 16px; color: var(--ink-2); line-height: 1.5; }
.plea-card .actions { display: flex; gap: 8px; justify-content: center; }

@media (max-width: 1100px) {  /* no monitor: the AI card moves under the face controls */
  .hud { grid-template-columns: 290px 1fr; }
  .panel.left { grid-row: 2; }
  .panel.right { grid-column: 1; grid-row: 3; align-self: end; }
  .monitor-section { display: none; }
  .chat { grid-column: 2; }
}
@media (max-width: 860px) {
  .btn.back span { display: none; }
  .btn.back { width: var(--h); padding: 0; }
  .hud-top { flex-wrap: wrap; }
  .toolbar { position: static; transform: none; order: 5; flex-basis: 100%; justify-content: center; }
}
@media (max-width: 480px) {
  .btn.panels span { display: none; }
  .btn.panels { width: var(--h); padding: 0; }
}
@media (max-width: 720px) {
  .hud { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .panel.left { grid-column: 1; max-height: 44vh; }
  .panel.right { display: none; }
  .chat { grid-column: 1; }
}
