:root {
  --bg: #1c1b19;
  --bg-2: #242220;
  --panel: #262421;
  --panel-2: #2d2b28;
  --line: #38352f;
  --line-2: #46423b;
  --ink: #ece9e3;
  --muted: #a49f95;
  --faint: #746f66;
  --clay: #d97757;      /* Claude coral accent */
  --clay-bri: #e58f72;
  --clay-dim: #7a4433;
  --green: #83b46a;
  --amber: #d9a441;
  --red: #d97070;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over class display rules
   (e.g. .login/.studio/.admin set display:flex). Without this, a hidden
   screen stays visible. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
b { font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 15px;
  font-size: 14px;
  font-weight: 600;
  transition: background .14s, border-color .14s, transform .08s, opacity .14s;
}
.btn:hover { border-color: var(--clay); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--clay); border-color: var(--clay); color: #241009; }
.btn.primary:hover { background: var(--clay-bri); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--clay); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ===================== LOGIN ===================== */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
}
.term {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 60px -24px rgba(0,0,0,.7);
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.r { background: #e0655b; } .dot.y { background: #e0b23c; } .dot.g { background: #7fb069; }
.term-title { margin-left: 8px; font-family: var(--mono); font-size: 12px; color: var(--faint); }
.term-body { padding: 20px 22px 24px; font-family: var(--mono); font-size: 13.5px; line-height: 1.7; }
.ln { margin: 0 0 4px; }
.prompt { color: var(--clay); font-weight: 700; margin-right: 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.login-form { margin: 16px 0 6px; }
.login-form label { display: block; margin-bottom: 8px; color: var(--ink); }
.login-row { display: flex; gap: 9px; }
.code-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line-2);
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 13px;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .06em;
  text-transform: uppercase;
  outline: none;
}
.code-input:focus { border-color: var(--clay); box-shadow: 0 0 0 3px rgba(217,119,87,.18); }
.err { color: var(--red); min-height: 18px; margin: 10px 0 0; font-size: 12.5px; }
.login-foot { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }

/* ===================== STUDIO ===================== */
.studio { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 16px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand .diamond { color: var(--clay); margin-right: 4px; }
.brand .slash { color: var(--faint); }
.hud { display: flex; align-items: center; gap: 14px; }
.hud-bal { display: flex; flex-direction: column; gap: 3px; min-width: 128px; }
.hud-k { font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); }
.hud-v { font-family: var(--mono); font-size: 17px; font-weight: 700; color: var(--green); line-height: 1; }
.hud-v.low { color: var(--amber); } .hud-v.out { color: var(--red); }
.bal-track { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bal-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--clay)); transition: width .5s ease; }
.hud-sep { width: 1px; height: 30px; background: var(--line); }
.hud-meta { display: flex; gap: 7px; }
.hud-chip { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 4px 9px; border-radius: 6px; }

.grid { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.panel { min-height: 0; overflow-y: auto; }
.controls { border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.sec-title { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--clay); font-weight: 700; margin-top: 4px; }

/* model picker */
.models { display: grid; gap: 8px; }
.model {
  text-align: left; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; transition: border-color .14s, background .14s;
}
.model:hover { border-color: var(--line-2); }
.model.sel { border-color: var(--clay); background: #2c2521; }
.model-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.model-name { font-weight: 700; font-size: 14px; }
.model-name .maker { color: var(--faint); font-weight: 400; font-size: 11.5px; margin-left: 5px; }
.tier { font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); }
.tier.Budget { color: var(--green); border-color: #3c5230; }
.tier.Standard { color: #78b6c9; border-color: #2f4d55; }
.tier.Premium { color: var(--amber); border-color: #5a4620; }
.tier.Flagship { color: var(--clay-bri); border-color: var(--clay-dim); }
.model-blurb { color: var(--muted); font-size: 12px; margin: 5px 0 7px; line-height: 1.35; }
.model-stats { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 11px; color: var(--faint); }
.model-cost { color: var(--ink); }
.model-cost b { color: var(--clay-bri); }
.bars { display: inline-flex; gap: 6px; }
.bar-g { display: inline-flex; align-items: center; gap: 3px; }
.pips { display: inline-flex; gap: 2px; }
.pip { width: 5px; height: 5px; border-radius: 1px; background: var(--line-2); }
.pip.on { background: var(--clay); }
.badge-exp { font-family: var(--mono); font-size: 10px; color: var(--amber); border: 1px solid #5a4620; border-radius: 5px; padding: 1px 5px; }

/* warning box */
.warn-box {
  background: #2f2413; border: 1px solid #6a5122; border-radius: 9px;
  padding: 11px 13px; font-size: 12.5px; line-height: 1.45; color: #e8cf9e;
}
.warn-box b { color: var(--amber); }

/* modes + starters */
.modes { display: inline-flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; width: max-content; }
.mode-tab { border: none; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 5px 12px; border-radius: 6px; }
.mode-tab.active { background: var(--panel-2); color: var(--ink); }
.starters { display: flex; flex-wrap: wrap; gap: 6px; }
.starter {
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  font-size: 12px; padding: 6px 10px; border-radius: 999px; transition: border-color .14s;
}
.starter:hover { border-color: var(--clay); }

.prompt-box {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 9px; padding: 11px 13px; font-family: var(--sans); font-size: 14px; line-height: 1.5;
  resize: vertical; min-height: 84px; outline: none;
}
.prompt-box:focus { border-color: var(--clay); box-shadow: 0 0 0 3px rgba(217,119,87,.15); }
.refine { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.refine input { accent-color: var(--clay); }

.btn.build {
  background: var(--clay); border-color: var(--clay); color: #241009; font-size: 15px; padding: 12px;
  border-radius: 9px; font-weight: 700;
}
.btn.build:hover { background: var(--clay-bri); }
.build-hint { font-size: 11.5px; color: var(--faint); font-family: var(--mono); margin: 0; min-height: 15px; text-align: center; }

/* preview */
.preview { display: flex; flex-direction: column; overflow: hidden; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); flex: none; }
.tabs { display: inline-flex; gap: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 3px; }
.tab { border: none; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 5px 13px; border-radius: 5px; font-family: var(--mono); }
.tab.active { background: var(--panel-2); color: var(--ink); }
.preview-actions { display: flex; align-items: center; gap: 10px; }
.last-cost { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.last-cost b { color: var(--clay-bri); }

.stage { flex: 1; position: relative; background: #141311; min-height: 0; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); text-align: center; padding: 20px; }
.empty p { margin: 0; }
.empty-diamond { font-size: 40px; color: var(--clay); opacity: .5; margin-bottom: 8px; }
.frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.codeview { position: absolute; inset: 0; margin: 0; overflow: auto; padding: 16px; font-family: var(--mono); font-size: 12px; line-height: 1.5; color: #cfc8bd; background: #141311; white-space: pre-wrap; word-break: break-word; }

/* agent log */
.agentlog { position: absolute; inset: 0; padding: 22px; font-family: var(--mono); font-size: 13px; line-height: 1.9; color: var(--muted); overflow: auto; }
.agentlog .l { opacity: 0; animation: fadein .25s forwards; }
.agentlog .l .b { color: var(--clay); }
.agentlog .l .ok { color: var(--green); }
.agentlog .cursor { display: inline-block; width: 8px; height: 15px; background: var(--clay); animation: blink 1s steps(2) infinite; vertical-align: text-bottom; }
@keyframes fadein { to { opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(10px);
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--ink);
  padding: 11px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 12px 30px -10px rgba(0,0,0,.6);
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 40; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { border-color: #3c5230; } .toast.bad { border-color: #5a2f2f; }
.toast b { color: var(--clay-bri); }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .controls { border-right: none; border-bottom: 1px solid var(--line); }
  .stage { min-height: 60vh; }
  .hud-bal { min-width: 104px; }
  .brand { font-size: 13px; }
}
