*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d1117;
  --green: rgba(34, 197, 94, 1);
  --green-dim: rgba(34, 197, 94, 0.55);
  --green-faint: rgba(0, 255, 65, 0.04);
  --panel-bg: rgba(13, 17, 23, 0.42);
  --border: rgba(34, 197, 94, 0.18);
  --text: #e2e8f0;
  --text-dim: #6b7280;
  --syntax-key: #86efac;
  --syntax-val: #fbbf24;
  --font: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Background layers ── */
#bg-canvas {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
}
.grid-overlay {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background-image:
    linear-gradient(var(--green-faint) 1px, transparent 1px),
    linear-gradient(90deg, var(--green-faint) 1px, transparent 1px);
  background-size: 32px 32px;
}
.top-glow {
  position: fixed; top: -80px; left: 50%; transform: translateX(-50%);
  width: 600px; height: 300px; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse, rgba(34,197,94,0.08) 0%, transparent 70%);
}
.bottom-glow {
  position: fixed; bottom: 0; left: 0; right: 0; height: 50%; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 100%, rgba(34,197,94,0.05) 0%, transparent 70%);
}

/* ── Shell / panel ── */
.shell {
  position: relative; z-index: 10;
  max-width: 780px; margin: 0 auto; padding: 40px 24px;
  height: 100vh; display: flex; flex-direction: column;
}

.window {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 0 40px rgba(34,197,94,0.06), 0 20px 60px rgba(0,0,0,0.4);
  overflow: hidden;
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}

.titlebar {
  background: rgba(22, 27, 34, 0.5);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid rgba(34,197,94,0.1);
  position: relative;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-r { background: #ff5f57; }
.dot-y { background: #febc2e; }
.dot-g { background: #28c840; }
.titlebar-text { color: var(--text-dim); font-size: 11px; margin-left: 8px; flex: 1; }

/* version i-button */
.version-btn {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid rgba(34,197,94,0.3);
  background: transparent;
  color: var(--text-dim); font-size: 10px; font-family: var(--font);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.version-btn:hover { color: var(--green); border-color: var(--green-dim); }

/* version popup */
.version-popup {
  display: none; position: absolute; top: 38px; right: 12px; z-index: 100;
  background: rgba(13,17,23,0.95); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 14px; min-width: 200px;
  backdrop-filter: blur(8px);
  font-size: 11px; line-height: 1.8;
}
.version-popup.open { display: block; }
.version-popup .vp-cmd { color: rgba(74,222,128,0.8); margin-bottom: 6px; }
.version-popup .vp-row { display: flex; gap: 16px; }
.version-popup .vp-ver { color: var(--syntax-key); min-width: 52px; }
.version-popup .vp-date { color: var(--text-dim); }

/* ── Terminal body ── */
.terminal-body {
  padding: 24px; font-size: 13px; line-height: 1.8;
  flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.terminal-static { flex-shrink: 0; }
.terminal-footer  { flex-shrink: 0; }

.prompt-line { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.ps1-user { color: #22c55e; }
.ps1-at   { color: var(--text-dim); }
.ps1-host { color: #4ade80; }
.ps1-sym  { color: var(--text); }
.ps1-path { color: #60a5fa; }
.cmd      { color: var(--text); }

.output { padding: 8px 0 16px; }
.kv { display: flex; gap: 16px; margin: 2px 0; flex-wrap: wrap; }
.k  { color: var(--syntax-key); min-width: 72px; }
.v  { color: var(--syntax-val); }
.cm { color: var(--text-dim); font-size: 12px; }

.divider { border-top: 1px solid rgba(34,197,94,0.08); margin: 8px 0 20px; }
.hint    { color: var(--text-dim); font-size: 12px; margin-bottom: 10px; }

/* ── Chat input ── */
.chat-area {
  border: 1px solid rgba(34,197,94,0.22);
  border-radius: 6px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,255,65,0.03); cursor: text;
}
.chat-arrow { color: #22c55e; font-size: 14px; flex-shrink: 0; }

.chat-input-wrap {
  flex: 1; position: relative; display: flex; align-items: center;
  min-width: 0; overflow: hidden;
}
.chat-mirror {
  font-family: var(--font); font-size: 13px; color: var(--text);
  white-space: pre; pointer-events: none; flex-shrink: 0;
  max-width: calc(100% - 10px); overflow: hidden;
}
.chat-placeholder {
  position: absolute; left: 0;
  color: var(--text-dim); font-family: var(--font); font-size: 13px;
  pointer-events: none; white-space: nowrap;
}
.chat-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: transparent; border: none; outline: none;
  caret-color: transparent; color: transparent;
  font-family: var(--font); font-size: 13px;
}

/* block cursor — always visible when not loading */
.cursor-blink {
  display: inline-block; width: 8px; height: 14px;
  background: #22c55e; vertical-align: middle; flex-shrink: 0;
  animation: blink 1.1s step-end infinite;
  box-shadow: 0 0 6px rgba(34,197,94,0.6);
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Chat messages ── */
.messages {
  flex: 1; overflow-y: auto; min-height: 0;
  margin-top: 16px; padding-right: 4px;
}
.messages::-webkit-scrollbar { width: 3px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(34,197,94,0.2); border-radius: 2px; }
.msg { margin-bottom: 14px; font-size: 13px; line-height: 1.8; }
.msg-user { color: rgba(34,197,94,0.8); }
.msg-user::before { content: '→ '; }
.msg-ai   { color: #d1d5db; padding-left: 16px; border-left: 2px solid rgba(34,197,94,0.2); }
.msg-ai .k { color: var(--syntax-key); }
.msg-ai .v { color: var(--syntax-val); }
.msg-error { color: #f87171; font-size: 12px; padding-left: 16px; }
.msg-soft  { color: var(--text-dim); font-size: 12px; padding-left: 16px; }

/* loading indicator — fixed content, no layout shift */
.msg-loading { min-height: 1.8em; color: var(--text-dim) !important; }
.msg-loading { animation: blink 1s step-end infinite; }

/* ── Links ── */
.links { margin-top: 16px; display: flex; gap: 12px; flex-wrap: wrap; }
.lnk {
  color: var(--text-dim); font-size: 11px; text-decoration: none;
  border: 1px solid rgba(34,197,94,0.15); border-radius: 4px;
  padding: 4px 10px; background: rgba(13,17,23,0.25);
  transition: color 0.2s, border-color 0.2s;
}
.lnk:hover { color: #22c55e; border-color: var(--green-dim); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .shell { padding: 16px 12px; }
  .terminal-body { padding: 16px; font-size: 11px; }
  .window { border-radius: 8px; }
  .links { gap: 8px; }
  .lnk { font-size: 10px; padding: 3px 8px; }
  .cm { display: none; }
}

@media (min-width: 641px) and (max-width: 1024px) {
  .shell { max-width: 90%; }
}

@media (min-width: 1441px) {
  .shell { max-width: 780px; }
}