/* ===== theme tokens ============================================== */
/* Each theme sets --fg (text/borders/glow colour) and --bg (near-black
   backdrop, tinted very slightly per theme so it doesn't feel like a
   plain dark-mode app). Everything else derives from these two. */
:root {
  --fg: #33ff66;
  --bg: #060a06;
  --panel: #0c140c;
  --font: 'Cascadia Code', 'Consolas', 'JetBrains Mono', monospace;
}
[data-theme="green"]  { --fg: #33ff66; --bg: #060a06; --panel: #0c140c; }
[data-theme="amber"]  { --fg: #ffb000; --bg: #0a0704; --panel: #14100a; }
[data-theme="blue"]   { --fg: #4fc3ff; --bg: #06090c; --panel: #0a1218; }
[data-theme="white"]  { --fg: #e8e8f0; --bg: #08080a; --panel: #101014; }
[data-theme="red"]    { --fg: #ff4d4d; --bg: #0a0505; --panel: #150a0a; }
[data-theme="purple"] { --fg: #c86dff; --bg: #090610; --panel: #120a1c; }

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
}
body { overflow: hidden; }
button, input, textarea, select {
  font-family: inherit;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 2px;
}
button {
  cursor: pointer;
  padding: 6px 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}
button:hover { background: color-mix(in srgb, var(--fg) 15%, transparent); }
button:disabled { opacity: 0.4; cursor: default; }
input, textarea { padding: 6px 8px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--fg) 50%, transparent); }
a { color: var(--fg); }
[hidden] { display: none !important; }

.glow { text-shadow: 0 0 6px color-mix(in srgb, var(--fg) 70%, transparent); }
.dim { opacity: 0.6; }
.blink { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* ===== CRT effect ================================================== */
/* Toggleable overlay: scanlines + a soft vignette glow. Deliberately
   subtle and static -- the brief explicitly asks to avoid distracting
   animation, this is texture, not motion. */
#crt-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0,0,0,0) 0px,
      rgba(0,0,0,0.12) 1px,
      rgba(0,0,0,0) 2px
    );
  box-shadow: inset 0 0 120px 20px rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity 0.3s;
}
body.crt-on #crt-overlay { opacity: 1; }
body.crt-on { text-shadow: 0 0 2px color-mix(in srgb, var(--fg) 40%, transparent); }

/* ===== boot screen ================================================== */
#boot-screen {
  position: fixed; inset: 0; background: var(--bg); color: var(--fg);
  display: flex; align-items: center; justify-content: center; z-index: 10000;
  padding: 20px;
}
#boot-lines { white-space: pre-wrap; line-height: 1.7; max-width: 560px; }
#boot-lines .cursor { display: inline-block; width: 0.6em; }

/* ===== auth screen ================================================== */
#auth-screen {
  height: 100%; display: flex; align-items: center; justify-content: center;
}
/* .modal-card is the shared "bordered terminal panel" frame, used by the
   login form AND the avatar-editor/settings modals. Form-specific sizing
   (inputs/buttons stretched to 100% width) stays scoped to .auth-card only
   -- it leaked into the modals once before when they shared one class,
   turning small circular theme swatches into full-width pills. */
.modal-card {
  border: 1px solid var(--fg); background: var(--panel);
  padding: 28px; width: 320px;
}
.modal-card h1 { font-size: 1rem; margin: 0 0 4px; letter-spacing: 0.08em; }
.auth-card .subtitle { font-size: 0.75rem; opacity: 0.7; margin-bottom: 20px; }
.auth-card label { display: block; font-size: 0.75rem; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.05em; }
.auth-card input { width: 100%; margin-top: 6px; }
.auth-card button { width: 100%; margin-top: 6px; }
.auth-toggle { margin-top: 16px; font-size: 0.75rem; text-align: center; cursor: pointer; text-decoration: underline; opacity: 0.8; }
.auth-error { color: #ff5c5c; font-size: 0.75rem; margin-top: 12px; min-height: 1em; }

/* ===== main shell =================================================== */
#app-shell { height: 100%; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  border-bottom: 1px solid var(--fg); padding: 8px 14px; flex: 0 0 auto; row-gap: 6px;
}
#topbar .brand { font-size: 0.85rem; letter-spacing: 0.1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
#topbar nav button { background: transparent; }
#topbar nav button.active { background: color-mix(in srgb, var(--fg) 20%, transparent); }
#status-line { font-size: 0.7rem; opacity: 0.7; padding: 2px 14px; border-bottom: 1px solid color-mix(in srgb, var(--fg) 30%, transparent); flex: 0 0 auto; min-height: 1.4em; }

#main-panels { flex: 1 1 auto; display: flex; min-height: 0; }

#contacts-panel, #profile-panel {
  width: 260px; flex: 0 0 auto; border-right: 1px solid color-mix(in srgb, var(--fg) 40%, transparent);
  display: flex; flex-direction: column; min-height: 0;
}
#profile-panel { border-right: none; border-left: 1px solid color-mix(in srgb, var(--fg) 40%, transparent); }
.panel-header { padding: 10px 12px; font-size: 0.7rem; letter-spacing: 0.1em; opacity: 0.7; border-bottom: 1px solid color-mix(in srgb, var(--fg) 25%, transparent); }

#contacts-list { flex: 1 1 auto; overflow-y: auto; }
.contact-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 12%, transparent);
}
.contact-row:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.contact-row.active { background: color-mix(in srgb, var(--fg) 18%, transparent); }
.contact-row .avatar-wrap { position: relative; flex: 0 0 auto; }
.contact-row .online-dot {
  position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border-radius: 50%;
  background: #555; border: 1px solid var(--bg);
}
.contact-row .online-dot.online { background: #4dff4d; }
.contact-row .meta { flex: 1 1 auto; min-width: 0; }
.contact-row .name-row { display: flex; justify-content: space-between; font-size: 0.8rem; }
.contact-row .preview { font-size: 0.72rem; opacity: 0.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge {
  background: var(--fg); color: var(--bg); border-radius: 8px; font-size: 0.65rem;
  padding: 1px 6px; min-width: 1.2em; text-align: center;
}

#chat-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
#chat-header { padding: 10px 14px; border-bottom: 1px solid color-mix(in srgb, var(--fg) 25%, transparent); font-size: 0.85rem; display: flex; align-items: center; gap: 10px; }
#chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; opacity: 0.5; font-size: 0.8rem; }
#message-list { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }

.message-row { display: flex; gap: 8px; max-width: 78%; }
.message-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.message-bubble {
  border: 1px solid color-mix(in srgb, var(--fg) 55%, transparent);
  padding: 7px 10px; font-size: 0.82rem; word-break: break-word;
}
.message-row.mine .message-bubble { background: color-mix(in srgb, var(--fg) 12%, transparent); }
.message-meta { font-size: 0.62rem; opacity: 0.55; margin-top: 4px; }

.voice-player { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.voice-player button { padding: 4px 8px; }
.voice-player .voice-bar { flex: 1; height: 4px; background: color-mix(in srgb, var(--fg) 25%, transparent); position: relative; }
.voice-player .voice-progress { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--fg); }
.voice-player .voice-duration { font-size: 0.68rem; opacity: 0.7; }

#composer { border-top: 1px solid color-mix(in srgb, var(--fg) 25%, transparent); padding: 10px; display: flex; gap: 8px; flex: 0 0 auto; }
#composer textarea { flex: 1 1 auto; resize: none; height: 40px; }
#rec-btn.recording { background: #ff3333; color: #200; border-color: #ff3333; }
#rec-indicator { font-size: 0.7rem; color: #ff5c5c; align-self: center; }

/* ===== profile panel ================================================ */
#profile-panel { padding: 0; }
.profile-body { padding: 14px; overflow-y: auto; }
.profile-username { font-size: 0.95rem; margin-bottom: 2px; }
.profile-id { font-size: 0.65rem; opacity: 0.5; margin-bottom: 16px; }
.avatar-preview { image-rendering: pixelated; border: 1px solid var(--fg); }

/* ===== avatar editor ================================================ */
#avatar-editor { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#avatar-grid-canvas { image-rendering: pixelated; border: 1px solid var(--fg); touch-action: none; cursor: crosshair; }
.avatar-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.avatar-tools input[type="color"] { width: 34px; height: 28px; padding: 0; }
.avatar-tools label { font-size: 0.7rem; display: flex; align-items: center; gap: 4px; }

/* ===== settings ====================================================== */
.settings-section { padding: 14px; border-top: 1px solid color-mix(in srgb, var(--fg) 20%, transparent); }
.settings-section h3 { font-size: 0.7rem; letter-spacing: 0.1em; opacity: 0.7; margin: 0 0 10px; }
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.theme-swatch.active { border-color: var(--fg); }
.crt-toggle-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 0.75rem; }

/* ===== mobile ======================================================== */
.mobile-only { display: none; }
@media (max-width: 820px) {
  /* Positioned relative to #main-panels (not the viewport) so it always
     starts exactly where the panel area begins, regardless of how tall
     the topbar ends up -- it wraps to two rows once the nav buttons don't
     fit next to the brand text, so a fixed pixel offset here would drift. */
  #contacts-panel, #profile-panel { display: none; position: absolute; inset: 0; width: auto; z-index: 500; background: var(--bg); }
  #contacts-panel.mobile-visible, #profile-panel.mobile-visible { display: flex; }
  #main-panels { position: relative; }
  #chat-panel { width: 100%; }
  .mobile-only { display: inline-flex; }
  .message-row { max-width: 90%; }
  #topbar { padding: 6px 10px; }
  #topbar .brand { font-size: 0.72rem; max-width: 45%; }
  #topbar nav button { padding: 5px 8px; font-size: 0.68rem; }
}
