/* =========================================================================
   THE FORGE -- phone app (PWA). Same brand family as forge-chat + BBT Train.
   Brand law: black + steel blue + grey. Cool tones only. NO orange / warm / gold.
   ========================================================================= */
:root {
  --bg:        #0c0c0e;
  --bg-elev:   #161618;
  --bg-elev-2: #1f1f23;
  --line:      #2a2a2f;
  --txt:       #f4f4f5;
  --txt-dim:   #9a9aa2;
  --txt-faint: #6a6a72;
  --accent:    #2d5aa0;   /* steel blue */
  --accent-hi: #4a90d9;
  --accent-dim:#13243f;
  --danger:    #d9534f;
  --ok:        #3fa45b;
  --radius:    16px;
  --radius-sm: 11px;
  --maxw:      820px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  height: 100dvh;
  overflow: hidden;
  /* steel-blue glow + faint starfield (matches the BBT app) */
  background:
    radial-gradient(1.4px 1.4px at 18% 12%, rgba(255,255,255,.18), transparent),
    radial-gradient(1px 1px at 72% 20%, rgba(255,255,255,.14), transparent),
    radial-gradient(1.3px 1.3px at 52% 64%, rgba(255,255,255,.12), transparent),
    radial-gradient(1px 1px at 33% 80%, rgba(255,255,255,.10), transparent),
    radial-gradient(130% 70% at 50% -10%, rgba(45,90,160,.22), transparent 60%),
    linear-gradient(180deg, #0a0e1a, #08080c);
}

/* ====================== LOCK SCREEN ====================== */
#lock {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: max(40px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
}
#lock.hide { animation: lockOut .32s ease forwards; }
@keyframes lockOut { to { opacity: 0; transform: scale(1.04); visibility: hidden; } }
.lock-inner { width: 100%; max-width: 360px; text-align: center; }
.lock-mark {
  height: 78px; width: 78px; border-radius: 20px; margin: 0 auto 18px;
  background: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 30px rgba(45,90,160,.45);
}
.lock-mark img { height: 56px; width: 56px; object-fit: contain; }
.lock-title { font-weight: 800; letter-spacing: 3px; font-size: 19px; }
.lock-sub { color: var(--txt-faint); font-size: 12.5px; margin-top: 5px; letter-spacing: .4px; }

.pin-dots { display: flex; gap: 20px; justify-content: center; margin: 34px 0 0; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--txt-dim); transition: .15s;
}
.pin-dots span.on { background: var(--accent-hi); border-color: var(--accent-hi); box-shadow: 0 0 10px rgba(74,144,217,.6); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-9px); }
  40%,80% { transform: translateX(9px); }
}
.pin-error { color: var(--danger); font-size: 12.5px; height: 16px; margin-top: 12px; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;
  margin: 22px auto 0; max-width: 290px;
}
.keypad button {
  height: 74px; width: 74px; margin: 0 auto; border-radius: 50%;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  color: var(--txt); font-size: 28px; font-weight: 500;
  cursor: pointer; transition: .1s; backdrop-filter: blur(4px);
  display: grid; place-items: center;
}
.keypad button:active { background: var(--accent); border-color: var(--accent); transform: scale(.94); }
.keypad button.ghost { background: none; border: none; font-size: 24px; color: var(--txt-dim); }
.keypad button.ghost:active { background: none; transform: scale(.9); color: var(--accent-hi); }

/* ====================== APP SHELL ====================== */
#app { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20,24,40,.92), rgba(10,12,20,.85));
  backdrop-filter: blur(8px); flex: none;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-badge {
  height: 32px; width: 32px; border-radius: 9px; flex: none; background: #fff;
  display: grid; place-items: center; box-shadow: 0 1px 8px rgba(45,90,160,.4);
}
.brand-badge img { height: 24px; width: 24px; object-fit: contain; }
.brand-name { font-weight: 800; letter-spacing: 1.4px; font-size: 14px; display: block; }
.brand-sub { color: var(--txt-faint); font-size: 10px; }
.spacer { flex: 1; }
.pill { font-size: 10.5px; color: var(--txt-dim); border: 1px solid var(--line);
  background: var(--bg-elev-2); border-radius: 999px; padding: 4px 9px; white-space: nowrap; }
.btn {
  background: var(--bg-elev-2); color: var(--txt); border: 1px solid var(--line);
  border-radius: 10px; height: 32px; padding: 0 10px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: .12s;
}
.btn:active { transform: scale(.96); }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* messages */
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.thread { max-width: var(--maxw); margin: 0 auto; padding: 18px 14px 8px; }
.msg { display: flex; gap: 11px; margin-bottom: 20px; animation: rise .18s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .avatar { height: 30px; width: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.msg.user .avatar { background: var(--accent-dim); color: var(--accent-hi); border: 1px solid var(--accent); }
.msg.assistant .avatar { background: #fff; padding: 4px; }
.msg.assistant .avatar img { width: 100%; height: 100%; object-fit: contain; }
.msg .body { min-width: 0; flex: 1; }
.msg .who { font-size: 10.5px; color: var(--txt-faint); font-weight: 700; letter-spacing: .6px; text-transform: uppercase; margin-bottom: 5px; }
.bubble { line-height: 1.6; font-size: 15px; word-wrap: break-word; }
.msg.user .bubble { color: var(--txt); white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.bubble h1,.bubble h2,.bubble h3 { line-height: 1.3; margin: 14px 0 8px; font-weight: 800; }
.bubble h1 { font-size: 19px; } .bubble h2 { font-size: 16px; } .bubble h3 { font-size: 15px; }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul,.bubble ol { margin: 4px 0 12px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble a { color: var(--accent-hi); text-decoration: none; border-bottom: 1px solid rgba(74,144,217,.35); }
.bubble strong { font-weight: 700; }
.bubble code { background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.bubble pre { background: #0a0a0c; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 6px 0 12px; }
.bubble pre code { background: none; border: none; padding: 0; }

/* media inside a message bubble */
.msg-media { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.msg-media img, .msg-media video { width: 132px; height: 132px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #000; }

.toolchip { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--txt-dim);
  background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; margin: 0 0 10px; }
.toolchip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-hi); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.caret { display: inline-block; width: 7px; height: 16px; vertical-align: -2px; margin-left: 2px; background: var(--accent-hi); animation: blink 1s steps(2) infinite; border-radius: 1px; }
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }

/* empty state */
.empty { max-width: var(--maxw); margin: 7vh auto 0; text-align: center; padding: 0 20px; }
.empty .mark { height: 60px; width: 60px; border-radius: 16px; background: #fff; margin: 0 auto 16px; display: grid; place-items: center; box-shadow: 0 4px 24px rgba(45,90,160,.4); }
.empty .mark img { height: 44px; width: 44px; object-fit: contain; }
.empty h1 { font-size: 22px; font-weight: 800; }
.empty p { color: var(--txt-dim); margin-top: 8px; font-size: 14px; }
.suggest { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.suggest button { background: var(--bg-elev); border: 1px solid var(--line); color: var(--txt-dim); border-radius: 12px; padding: 10px 14px; font-size: 13px; cursor: pointer; text-align: left; max-width: 240px; }

/* composer */
#composer { flex: none; border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10,12,20,.6), rgba(8,8,12,.96));
  padding-bottom: env(safe-area-inset-bottom); }
.composer-inner { max-width: var(--maxw); margin: 0 auto; padding: 10px 14px 12px; }

.tray { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 2px 10px; }
.tray .att { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.tray .att img, .tray .att video { width: 100%; height: 100%; object-fit: cover; }
.tray .att .vbadge { position: absolute; left: 4px; bottom: 4px; font-size: 11px; }
.tray .att .x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; border: none; font-size: 13px; cursor: pointer; display: grid; place-items: center; }

.inputwrap { display: flex; align-items: flex-end; gap: 7px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; padding: 7px 7px 7px 7px; }
.inputwrap:focus-within { border-color: var(--accent); }
#input { flex: 1; background: none; border: none; color: var(--txt); resize: none; outline: none; font: inherit; font-size: 16px; line-height: 1.5; max-height: 180px; padding: 7px 2px; }
#input::placeholder { color: var(--txt-faint); }
.iconbtn { height: 38px; width: 38px; flex: none; border-radius: 11px; border: 1px solid var(--line); background: var(--bg-elev-2); color: var(--txt); cursor: pointer; display: grid; place-items: center; font-size: 17px; transition: .12s; }
.iconbtn:active { transform: scale(.93); }
.iconbtn:disabled { opacity: .4; }
.iconbtn.plus { font-size: 23px; font-weight: 400; }
.iconbtn.plus.has { background: var(--accent); border-color: var(--accent); color: #fff; }
.iconbtn.send { background: var(--accent); border-color: var(--accent); color: #fff; }
.iconbtn.mic.rec { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1s infinite; }
.hint { color: var(--txt-faint); font-size: 11px; text-align: center; margin-top: 8px; }
.hint .live { color: var(--accent-hi); }
.hint .ok { color: var(--ok); }
.hint .err { color: var(--danger); }

/* + sheet */
#sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: grid; align-items: end; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-card { background: var(--bg-elev); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 10px 12px max(14px, env(safe-area-inset-bottom)); max-width: var(--maxw); margin: 0 auto; width: 100%; }
.sheet-card button { width: 100%; height: 54px; background: none; border: none; border-bottom: 1px solid var(--line); color: var(--txt); font-size: 16px; text-align: left; padding: 0 10px; cursor: pointer; }
.sheet-card button.cancel { color: var(--accent-hi); font-weight: 700; text-align: center; border: none; margin-top: 6px; }

/* settings overlay */
#settings { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; animation: fade .15s ease; }
.settings-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 18px; padding: 20px 18px; width: 100%; max-width: 380px; }
.settings-card h2 { font-size: 17px; font-weight: 800; }
.settings-card p { color: var(--txt-dim); font-size: 12.5px; margin: 6px 0 14px; line-height: 1.5; }
.settings-card label { display: block; font-size: 11px; color: var(--txt-faint); font-weight: 700; letter-spacing: .5px; text-transform: uppercase; margin: 10px 0 5px; }
.settings-card input { width: 100%; background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 10px; color: var(--txt); font-size: 15px; padding: 11px 12px; outline: none; }
.settings-card input:focus { border-color: var(--accent); }
.settings-row { font-size: 12.5px; min-height: 18px; margin-top: 10px; }
.settings-row .live { color: var(--accent-hi); }
.settings-row .ok { color: var(--ok); }
.settings-row .err { color: var(--danger); }
.settings-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.ghost-btn { background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--txt); border-radius: 10px; padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.primary-btn { background: var(--accent); border: 1px solid var(--accent); color: #fff; border-radius: 10px; padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer; }
.media-placeholder { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--txt-dim); background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; margin-bottom: 9px; }

#view::-webkit-scrollbar { width: 0; }
