@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=VT323&display=swap');

/* ── Variables ─────────────────────────────────────────────────── */
:root {
  --bg:             #09090a;
  --bg-warm:        #0e0c09;
  --surface:        #111210;
  --surface-2:      #191714;
  --border:         #252320;
  --border-bright:  #3a3530;
  --orange:         #ff6a00;
  --orange-bright:  #ff8c2a;
  --orange-dim:     #7a3200;
  --orange-faint:   rgba(255, 106, 0, 0.07);
  --orange-glow:    rgba(255, 106, 0, 0.18);
  --orange-glow-sm: rgba(255, 106, 0, 0.10);
  --text:           #e5d6b8;
  --text-dim:       #8a7b63;
  --text-muted:     #4a4337;
  --font-mono:      'Share Tech Mono', 'Courier New', monospace;
  --font-display:   'VT323', monospace;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

/* ── Body & Background ──────────────────────────────────────────── */
body {
  font-family: var(--font-mono);
  background-color: var(--bg-warm);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 106, 0, 0.05) 1px, transparent 0);
  background-size: 28px 28px;
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: stretch;
  cursor: default;
}

/* ── Scanlines overlay ──────────────────────────────────────────── */
.scanlines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  pointer-events: none;
  z-index: 900;
}

/* ── Vignette ───────────────────────────────────────────────────── */
.vignette {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
  z-index: 901;
}

/* ── Layout ─────────────────────────────────────────────────────── */
.layout {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow:
    0 0 0 1px var(--orange-faint),
    0 0 60px rgba(255, 106, 0, 0.04),
    inset 0 0 120px rgba(0,0,0,0.3);
}

/* ── Header ─────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-warm);
  flex-shrink: 0;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--orange-dim), transparent);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Window manager dots */
.wm-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}
.wm-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-bright);
  border: 1px solid var(--border);
}
.wm-dot--active {
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange-glow);
  animation: dotPulse 3s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 6px var(--orange-glow); }
  50%       { box-shadow: 0 0 14px var(--orange-glow), 0 0 28px rgba(255,106,0,0.1); }
}

/* Title */
.header-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  color: var(--orange-bright);
  text-shadow: 0 0 20px var(--orange-glow);
  line-height: 1;
}
.title-ext {
  color: var(--text-dim);
  text-shadow: none;
}

/* Connection badge */
.conn-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
.conn-light {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}
.conn-light.on {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}
.conn-light.err {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

/* CLR button */
.clr-btn {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border-bright);
  padding: 3px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.clr-btn:hover {
  color: var(--orange-bright);
  border-color: var(--orange-dim);
  box-shadow: 0 0 10px var(--orange-glow-sm);
}
.clr-btn:active {
  transform: scale(0.95);
}

/* ── Sysbar ──────────────────────────────────────────────────────── */
.sysbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-warm);
  flex-shrink: 0;
  overflow: hidden;
}
.sysbar-item { white-space: nowrap; }
.sysbar-val { color: var(--orange-dim); margin-left: 2px; }
.sysbar-sep { color: var(--border-bright); }

.sysbar-blink {
  color: var(--orange-dim);
  animation: blinkText 2s step-end infinite;
}
@keyframes blinkText {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ── Messages ────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* custom scrollbar */
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--orange-dim);
  border-radius: 2px;
}
.messages::-webkit-scrollbar-thumb:hover { background: var(--orange); }

/* Message rows */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: msgIn 0.18s ease-out both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.user      { align-self: flex-end;   align-items: flex-end;   flex-direction: column; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

/* Bubbles */
.bubble {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.65;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}

.message.user .bubble {
  background: var(--orange);
  color: #0a0700;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%);
  text-shadow: none;
}
.message.user .bubble::before {
  content: '> ';
  opacity: 0.5;
}

.message.assistant .bubble {
  background: var(--surface-2);
  color: var(--text);
  border-left: 2px solid var(--orange);
  box-shadow:
    -4px 0 16px rgba(255, 106, 0, 0.08),
    inset 0 0 0 1px rgba(255,106,0,0.04);
}
.message.assistant .bubble.error {
  border-left-color: #ef4444;
  color: var(--text-dim);
  font-style: italic;
}

/* Timestamps */
.msg-meta {
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 2px;
}

/* ── Typing indicator ────────────────────────────────────────────── */
.typing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 2px solid var(--orange-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  animation: msgIn 0.18s ease-out both;
}
.typing-cursor {
  display: inline-block;
  width: 9px;
  height: 14px;
  background: var(--orange);
  animation: cursorBlink 0.9s step-end infinite;
  vertical-align: middle;
  box-shadow: 0 0 8px var(--orange-glow);
}
@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Composer ────────────────────────────────────────────────────── */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-warm);
  flex-shrink: 0;
  position: relative;
}
.composer::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--orange-dim), transparent);
}

.prompt {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--orange);
  text-shadow: 0 0 10px var(--orange-glow);
  flex-shrink: 0;
  padding-bottom: 11px;
  user-select: none;
}

.composer-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-bright);
  border-bottom: 2px solid var(--orange-dim);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  padding: 8px 12px;
  outline: none;
  max-height: 130px;
  overflow-y: auto;
  caret-color: var(--orange);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-input::placeholder { color: var(--text-muted); }
.composer-input:focus {
  border-color: var(--border-bright);
  border-bottom-color: var(--orange);
  box-shadow: 0 4px 16px rgba(255,106,0,0.1), 0 0 0 1px rgba(255,106,0,0.06);
}

.send-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--orange);
  background: transparent;
  border: 1px solid var(--orange-dim);
  padding: 8px 14px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
  text-shadow: 0 0 10px var(--orange-glow);
}
.send-btn:hover {
  background: var(--orange-faint);
  border-color: var(--orange);
  box-shadow: 0 0 14px var(--orange-glow-sm);
}
.send-btn:active { transform: scale(0.96); }
.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Mascot ──────────────────────────────────────────────────────── */

/* Shared pixelation + orange filter */
.mascot-header,
.mascot-avatar {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* Orange amber tint: sepia base → saturate → hue toward orange → slight darken */
  filter:
    sepia(100%)
    saturate(500%)
    hue-rotate(10deg)
    brightness(0.82)
    contrast(1.15);
}

/* Header mascot — small, glowing */
.mascot-header {
  width: 32px;
  height: 32px;
  object-fit: cover;
  /* Force extra pixelation: render at 8px internally, CSS scales up jaggedly */
  object-position: center top;
  border: 1px solid var(--orange-dim);
  box-shadow: 0 0 10px var(--orange-glow), 0 0 20px rgba(255,106,0,0.08);
  flex-shrink: 0;
}

/* Per-message avatar */
.mascot-avatar {
  width: 28px;
  height: 28px;
  object-fit: cover;
  object-position: center top;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 18px; /* align with bubble bottom, above timestamp */
  border: 1px solid var(--orange-dim);
  opacity: 0.85;
}

/* Message layout when avatar is present */
.message.assistant {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

.message-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* ── Clear animation ─────────────────────────────────────────────── */
.layout.clearing {
  animation: glitchClear 0.35s steps(1, end);
}
@keyframes glitchClear {
  0%   { filter: brightness(1)    saturate(1)    ; clip-path: inset(0 0 0 0); }
  15%  { filter: brightness(4)    saturate(0)    ; clip-path: inset(2% 0 2% 0); }
  30%  { filter: brightness(0.2)  saturate(0)    ; clip-path: inset(0 4% 0 4%); }
  50%  { filter: brightness(3)    hue-rotate(20deg); clip-path: inset(0 0 0 0); }
  70%  { filter: brightness(0.4)  saturate(3)    ; }
  85%  { filter: brightness(1.5)  saturate(0)    ; }
  100% { filter: brightness(1)    saturate(1)    ; clip-path: inset(0 0 0 0); }
}

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  align-self: center;
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  line-height: 2;
  animation: msgIn 0.3s ease-out;
}
.empty-state-ascii {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--border-bright);
  display: block;
  margin-bottom: 8px;
  line-height: 1.2;
}
