:root {
  --bg: #030812;
  --cyan: #22d3ee;
  --cyan-bright: #67e8f9;
  --cyan-dim: #0e7490;
  --gold: #f5c542;
  --text: #cfeffb;
  --muted: #5b7a8a;
  --danger: #ff5d5d;
  --panel: rgba(8, 22, 34, 0.72);
  --line: rgba(34, 211, 238, 0.22);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 700px at 50% 8%, #062033 0%, var(--bg) 60%),
    var(--bg);
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

/* HUD background grid + scanline */
.hud-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(34, 211, 238, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 80%);
}
.scanline {
  position: fixed; left: 0; right: 0; height: 140px; z-index: 0; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(34,211,238,0.06), transparent);
  animation: scan 7s linear infinite;
}
@keyframes scan { 0%{ top:-140px } 100%{ top:100% } }

/* Top bar */
.hud-top {
  position: relative; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 26px; border-bottom: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.brand { font-family: 'Orbitron', sans-serif; font-weight: 700; letter-spacing: 3px; font-size: 18px; }
.brand em { color: var(--cyan); font-style: normal; }
.diamond { color: var(--cyan-bright); text-shadow: 0 0 12px var(--cyan); }
.hud-status { display: flex; gap: 10px; }
.chip {
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); background: var(--panel);
}
.chip.live { color: var(--cyan-bright); border-color: var(--cyan); box-shadow: 0 0 12px rgba(34,211,238,0.25); }

/* Stage */
.stage {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  padding: 26px 18px 40px; gap: 22px; max-width: 760px; margin: 0 auto;
}

/* ---------- ARC REACTOR ---------- */
.reactor-wrap {
  position: relative; width: 260px; height: 260px; margin-top: 12px;
  display: grid; place-items: center; cursor: pointer;
  filter: drop-shadow(0 0 30px rgba(34,211,238,0.35));
}
.ring {
  position: absolute; border-radius: 50%; border: 2px solid var(--cyan-dim);
}
.ring-outer { width: 250px; height: 250px; border-style: dashed; border-color: rgba(34,211,238,0.35);
  animation: spin 18s linear infinite; }
.ring-mid   { width: 195px; height: 195px; border-color: rgba(34,211,238,0.5);
  border-top-color: var(--cyan-bright); animation: spin 9s linear infinite reverse; }
.ring-inner { width: 140px; height: 140px; border-color: rgba(34,211,238,0.3);
  border-bottom-color: var(--cyan); animation: spin 6s linear infinite; }
.core {
  position: relative; width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #eafcff 0%, var(--cyan-bright) 30%, var(--cyan) 55%, var(--cyan-dim) 100%);
  box-shadow: 0 0 40px var(--cyan), inset 0 0 22px rgba(255,255,255,0.6);
  animation: breathe 3.4s ease-in-out infinite;
}
.core-glow { position: absolute; inset: -8px; border-radius: 50%;
  background: radial-gradient(circle, rgba(103,232,249,0.55), transparent 70%); }
.reactor-label {
  position: absolute; bottom: -6px; font-family: 'Orbitron', sans-serif;
  font-size: 11px; letter-spacing: 2px; color: var(--cyan-bright);
  text-shadow: 0 0 8px var(--cyan);
}

/* States */
.reactor-wrap.listening { filter: drop-shadow(0 0 45px rgba(34,211,238,0.8)); }
.reactor-wrap.listening .core { animation: pulse 0.7s ease-in-out infinite; background:
  radial-gradient(circle at 50% 45%, #fff 0%, var(--cyan-bright) 40%, var(--cyan) 70%); }
.reactor-wrap.listening .ring-outer { animation-duration: 4s; border-color: var(--cyan-bright); }
.reactor-wrap.speaking .core { animation: pulse 0.4s ease-in-out infinite; background:
  radial-gradient(circle at 50% 45%, #fff 0%, #ffe89a 35%, var(--gold) 75%);
  box-shadow: 0 0 46px var(--gold), inset 0 0 22px rgba(255,255,255,0.7); }
.reactor-wrap.thinking .ring-mid { border-top-color: var(--gold); animation-duration: 1.2s; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%,100%{ transform: scale(1); } 50%{ transform: scale(1.06); } }
@keyframes pulse { 0%,100%{ transform: scale(1); } 50%{ transform: scale(1.16); } }

/* Conversation */
.convo {
  width: 100%; min-height: 90px; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; line-height: 1.6; font-size: 15px;
  backdrop-filter: blur(6px);
}
.convo .hint { color: var(--muted); text-align: center; margin: 6px 0; }
.msg { margin: 10px 0; padding: 10px 14px; border-radius: 10px; white-space: pre-wrap; }
.msg.user { background: rgba(34,211,238,0.08); border-left: 3px solid var(--cyan); }
.msg.jarvis { background: rgba(245,197,66,0.06); border-left: 3px solid var(--gold); }
.msg .who { font-family: 'Orbitron', sans-serif; font-size: 10px; letter-spacing: 1.5px;
  color: var(--muted); text-transform: uppercase; display: block; margin-bottom: 4px; }
.msg .src { display: block; margin-top: 6px; font-size: 11px; color: var(--cyan-dim); }
.msg pre { background: #05141f; padding: 10px; border-radius: 8px; overflow-x: auto; }

/* Controls */
.controls, .text-row { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; justify-content: center; }
.ctl {
  font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 500;
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  transition: .15s; display: inline-flex; align-items: center; gap: 6px;
}
.ctl:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(34,211,238,0.25); }
.ctl.primary { background: linear-gradient(180deg, var(--cyan), var(--cyan-dim)); color: #02121a; border: none; font-weight: 600; }
.ctl.small { font-size: 12px; padding: 7px 12px; }
.ctl.active { border-color: var(--cyan-bright); color: var(--cyan-bright); box-shadow: 0 0 16px rgba(34,211,238,0.4); }
.premium-ctl { gap: 8px; }
.file-ctl { cursor: pointer; }
button:disabled, input:disabled { opacity: .5; cursor: not-allowed; }

.text-row #textInput {
  flex: 1; min-width: 200px; padding: 11px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.text-row #textInput:focus { outline: none; border-color: var(--cyan); }

/* Drawer */
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 320px; z-index: 5;
  background: rgba(4, 16, 26, 0.96); border-left: 1px solid var(--line);
  padding: 20px; transform: translateX(100%); transition: transform .25s ease;
  backdrop-filter: blur(8px); display: flex; flex-direction: column; gap: 12px;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center;
  font-family: 'Orbitron', sans-serif; letter-spacing: 2px; font-size: 14px; color: var(--cyan-bright); }
.x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.file-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.file-list li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; font-size: 13px; }
.file-list li .fn { color: var(--cyan-bright); word-break: break-all; }
.file-list li .meta { color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); }

.hud-foot { position: relative; z-index: 2; text-align: center; color: var(--muted);
  font-size: 11px; letter-spacing: 1px; padding: 18px; border-top: 1px solid var(--line); }

@media (max-width: 520px) {
  .reactor-wrap { width: 220px; height: 220px; }
  .drawer { width: 100%; }
}

/* System messages */
.msg.sys { background: rgba(91,122,138,0.12); border-left: 3px solid var(--muted); font-size: 13.5px; }
.msg.sys .who { color: var(--muted); }

/* ---------- Login overlay ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(800px 500px at 50% 40%, rgba(6,32,51,0.9), rgba(3,8,18,0.98));
  backdrop-filter: blur(8px);
}
.login-box {
  width: min(360px, 90vw); text-align: center; padding: 34px 28px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel);
  box-shadow: 0 0 60px rgba(34,211,238,0.25);
}
.login-core {
  width: 70px; height: 70px; margin: 0 auto 18px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #eafcff, var(--cyan-bright) 40%, var(--cyan) 70%, var(--cyan-dim));
  box-shadow: 0 0 34px var(--cyan), inset 0 0 16px rgba(255,255,255,0.6);
  animation: breathe 3s ease-in-out infinite;
}
.login-box h2 { font-family: 'Orbitron', sans-serif; letter-spacing: 3px; font-size: 18px; margin: 0 0 8px; color: var(--cyan-bright); }
.login-box p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-box input {
  width: 100%; padding: 12px 14px; border-radius: 10px; margin-bottom: 12px;
  background: #05141f; border: 1px solid var(--line); color: var(--text); font-size: 15px; text-align: center; letter-spacing: 2px;
}
.login-box input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 14px rgba(34,211,238,0.3); }
.login-box button {
  width: 100%; padding: 12px; border-radius: 10px; border: none; cursor: pointer;
  font-family: 'Orbitron', sans-serif; letter-spacing: 2px; font-weight: 700; font-size: 14px;
  background: linear-gradient(180deg, var(--cyan), var(--cyan-dim)); color: #02121a;
}
.login-box button:hover { filter: brightness(1.1); }
.login-err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ============ v5: richer answers, polish, mobile, admin ============ */

/* Message body typography */
.msg .body { font-size: 14.5px; }
.msg .body p { margin: 8px 0; }
.msg .body h2 { font-size: 17px; margin: 12px 0 6px; color: var(--cyan-bright); font-family: 'Orbitron', sans-serif; letter-spacing: .5px; }
.msg .body h3 { font-size: 15px; margin: 12px 0 6px; color: var(--cyan-bright); }
.msg .body h4 { font-size: 13.5px; margin: 10px 0 4px; color: var(--text); letter-spacing: .5px; text-transform: uppercase; opacity: .85; }
.msg .body ul, .msg .body ol { margin: 8px 0; padding-left: 22px; }
.msg .body li { margin: 4px 0; }
.msg .body strong { color: #fff; }
.msg .body code { background: #05141f; padding: 2px 6px; border-radius: 5px; font-family: ui-monospace, monospace; font-size: 13px; color: var(--cyan-bright); }
.msg .body pre { background: #05141f; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }

/* Tables — the star of the "visualization" upgrade */
.tbl-wrap { overflow-x: auto; margin: 12px 0; border-radius: 10px; border: 1px solid var(--line); }
.msg .body table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 280px; }
.msg .body thead th {
  background: linear-gradient(180deg, rgba(34,211,238,0.18), rgba(34,211,238,0.06));
  color: var(--cyan-bright); text-align: left; padding: 10px 12px; font-weight: 600;
  border-bottom: 1px solid var(--cyan-dim); white-space: nowrap;
}
.msg .body tbody td { padding: 9px 12px; border-bottom: 1px solid rgba(34,211,238,0.1); }
.msg .body tbody tr:nth-child(even) { background: rgba(34,211,238,0.035); }
.msg .body tbody tr:hover { background: rgba(34,211,238,0.08); }
.msg .body tbody tr:last-child td { border-bottom: none; }

/* Gear button */
.gear {
  background: var(--panel); border: 1px solid var(--line); color: var(--cyan-bright);
  width: 34px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; transition: .15s;
}
.gear:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(34,211,238,0.3); transform: rotate(45deg); }

/* Admin overlay */
.admin-overlay {
  position: fixed; inset: 0; z-index: 60; display: none; place-items: center;
  background: radial-gradient(700px 500px at 50% 30%, rgba(6,32,51,0.92), rgba(3,8,18,0.98));
  backdrop-filter: blur(8px); padding: 20px; overflow-y: auto;
}
.admin-box {
  position: relative; width: min(420px, 94vw); padding: 30px 26px; text-align: center;
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel);
  box-shadow: 0 0 60px rgba(34,211,238,0.25); max-height: 90vh; overflow-y: auto;
}
.admin-x { position: absolute; top: 14px; right: 16px; }
.admin-core {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #eafcff, var(--cyan-bright) 40%, var(--cyan) 70%, var(--cyan-dim));
  box-shadow: 0 0 28px var(--cyan), inset 0 0 14px rgba(255,255,255,0.6); animation: breathe 3s ease-in-out infinite;
}
.admin-box h2 { font-family: 'Orbitron', sans-serif; letter-spacing: 3px; font-size: 17px; margin: 0 0 6px; color: var(--cyan-bright); }
.admin-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.admin-box input {
  width: 100%; padding: 11px 14px; border-radius: 10px; margin-bottom: 10px;
  background: #05141f; border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.admin-box input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 12px rgba(34,211,238,0.25); }
.admin-btn {
  width: 100%; padding: 11px; border-radius: 10px; border: none; cursor: pointer; margin-top: 4px;
  font-family: 'Orbitron', sans-serif; letter-spacing: 1.5px; font-weight: 700; font-size: 13px;
  background: linear-gradient(180deg, var(--cyan), var(--cyan-dim)); color: #02121a;
}
.admin-btn.small { font-size: 12px; padding: 9px; letter-spacing: 1px; }
.admin-btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); margin-top: 18px; }
.admin-btn:hover { filter: brightness(1.1); }
.admin-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }
.admin-section { text-align: left; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 18px; }
.admin-section h3 { font-size: 14px; color: var(--cyan-bright); margin: 0 0 4px; }
.admin-hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.admin-msg { font-size: 12.5px; margin-top: 8px; min-height: 15px; }
.admin-msg.ok { color: var(--cyan-bright); }
.admin-msg.err { color: var(--danger); }
.hidden { display: none; }

/* Polish: nicer scrollbars */
.convo::-webkit-scrollbar, .drawer::-webkit-scrollbar, .admin-box::-webkit-scrollbar { width: 8px; }
.convo::-webkit-scrollbar-thumb, .drawer::-webkit-scrollbar-thumb, .admin-box::-webkit-scrollbar-thumb {
  background: rgba(34,211,238,0.3); border-radius: 4px;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
  .hud-top { padding: 14px 14px; flex-wrap: wrap; gap: 8px; }
  .brand { font-size: 15px; letter-spacing: 2px; }
  .chip { font-size: 10px; padding: 4px 8px; }
  .stage { padding: 18px 12px 34px; gap: 18px; }
  .reactor-wrap { width: 190px; height: 190px; }
  .ring-outer { width: 184px; height: 184px; } .ring-mid { width: 144px; height: 144px; } .ring-inner { width: 104px; height: 104px; }
  .core { width: 72px; height: 72px; }
  .controls .ctl, .text-row .ctl { font-size: 12.5px; padding: 9px 12px; }
  .convo { font-size: 14px; max-height: 45vh; }
  .msg .body { font-size: 14px; }
  .hud-foot { font-size: 10px; }
}
@media (max-width: 380px) {
  .controls { gap: 7px; } .controls .ctl { padding: 8px 10px; font-size: 12px; }
}

/* Memory category grouping in drawer */
.file-list .cat-head {
  border: none; background: none; padding: 12px 4px 6px; margin: 4px 0 2px;
  font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 1px;
  color: var(--cyan-bright); text-transform: uppercase; display: flex; align-items: center; gap: 6px;
}
.file-list .cat-count { margin-left: auto; background: rgba(34,211,238,0.15); color: var(--cyan-bright);
  border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.file-list .file-item { background: rgba(34,211,238,0.04); }
#memCategory { padding: 9px 10px; font-size: 12.5px; }
