/* public/style.css */
:root {
  --bg: #111;
  --panel: #0b0b0b;
  --panel-2: #0a0a0a;
  --fg: #0f0;
  --fg-dim: #0a0;
  --accent: #0ff;
  --muted: #9aa09a;
  --border: #0f0;
  --shadow: 0 2px 10px rgba(0,255,0,0.06), inset 0 0 0 1px rgba(0,255,0,0.15);
  --shadow-strong: 0 6px 20px rgba(0,255,0,0.10), inset 0 0 0 1px rgba(0,255,0,0.18);
  --ring: 0 0 0 2px rgba(0,255,128,0.45);
  --composer-h: 78px; /* updated at runtime */
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(0,255,0,0.04), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* App shell */
.app {
  min-height: 100svh;
  max-width: 860px;
  margin: 0 auto;
  padding-inline: 16px;
  display: flex;
  flex-direction: column;
}

/* Header / ASCII */
.header { padding-top: 16px; }

.brand {
  border: 1px solid var(--border);
  padding: 8px 12px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  border-radius: 6px;
}

.brand > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  color: #fff;
  margin: -8px -12px 8px -12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.brand[open] > summary::after { content: " ▲"; color: var(--muted); }
.brand:not([open]) > summary::after { content: " ▼"; color: var(--muted); }

.ascii {
  margin: 0;
  color: var(--fg);
  font-size: clamp(12px, 1.8vw, 16px);
  white-space: pre;
  overflow: auto;
}

/* Top bar (session info + privacy link) */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.top-bar a.privacy-link {
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
.top-bar a.privacy-link:hover { opacity: 0.85; }

/* Session text */
.session {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

/* Chat stream */
.chat {
  flex: 1 1 auto;
  margin-top: 12px;
  padding-bottom: calc(var(--composer-h) + 16px);
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 6px;
}

/* Messages */
.message {
  padding: 10px 12px;
  border-bottom: 1px dashed rgba(0,255,0,0.25);
  animation: fadeIn 0.25s ease-in forwards;
  opacity: 0.0;
}
.message.hydrated { opacity: 1; } /* when restored from storage */
.message:last-child { border-bottom: none; }

.user { color: var(--accent); }
.ai { color: var(--fg); }
strong { color: #fff; }

/* Markdown polish inside messages */
.message p { margin: 0.5em 0; }
.message h1, .message h2, .message h3 {
  margin: 0.8em 0 0.4em;
  line-height: 1.2;
  color: #ccffcc;
  border-bottom: 1px dashed rgba(0,255,0,0.25);
  padding-bottom: 0.2em;
}
.message h1 { font-size: 1.25rem; }
.message h2 { font-size: 1.1rem; }
.message h3 { font-size: 1rem; }

.message ul, .message ol {
  margin: 0.4em 0 0.8em 1.4em;
  padding-left: 0.8em;
}
.message li { margin: 0.25em 0; }

.message blockquote {
  margin: 0.8em 0;
  padding: 0.6em 0.8em;
  background: #0f0f0f;
  border-left: 2px solid var(--fg);
  color: #c9f7c9;
  border-radius: 4px;
}

.message a {
  color: var(--accent);
  text-decoration: underline;
}
.message a:hover { opacity: 0.9; }

/* code & pre */
code {
  background: #1c1c1c;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--fg);
  border: 1px solid rgba(0,255,0,0.25);
  word-break: break-word; /* avoid overflow on inline code */
}
pre code {
  display: block;
  padding: 10px 12px;
  overflow: auto;
  box-shadow: inset 0 0 0 1px rgba(0,255,0,0.15);
  border-radius: 6px;
  white-space: pre; /* keep code blocks monospaced/scrollable */
}

/* Tables */
.message table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
}
.message th, .message td {
  border: 1px solid rgba(0,255,0,0.25);
  padding: 6px 8px;
}
.message th { background: #0f0f0f; }

/* Images in messages */
.message img {
  max-width: 100%;
  height: auto;
  border: 1px solid rgba(0,255,0,0.25);
  border-radius: 6px;
}

/* Composer pinned to bottom */
.composer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  width: min(860px, calc(100% - 32px));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-strong);
  padding: 10px;
  border-radius: 8px;
}

.composer input {
  font: inherit;
  padding: 12px 14px;
  color: var(--fg);
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.composer input:focus { box-shadow: var(--ring); }
.composer input[disabled] {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Actions */
.actions {
  display: grid;
  gap: 8px;
  grid-auto-flow: column;
}

button {
  font: inherit;
  padding: 12px 14px;
  background: #222;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.06s ease;
  touch-action: manipulation;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }

/* Disabled buttons */
button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
}
button[disabled]:hover { filter: none; }

/* Retro working state (replaces hourglass) */
.composer.sending,
.composer.sending * {
  cursor: progress !important;
}
.thinking {
  animation: blink-temp 1.2s steps(1, end) infinite;
  color: var(--muted);
}

/* Jump-to-latest */
.jump {
  position: fixed;
  right: 14px;
  bottom: calc(var(--composer-h) + 24px);
  padding: 8px 10px;
  background: #1a1a1a;
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  transition: opacity 0.2s ease;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.jump.hide { opacity: 0; pointer-events: none; }

/* ——— Privacy overlay: smooth fade/slide in & out ——— */
.privacy-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(17,17,17,0.7);
  backdrop-filter: blur(3px);
  z-index: 40;

  opacity: 0;
  visibility: hidden;
  transition:
    opacity 200ms ease,
    visibility 200ms ease;
}
.privacy-overlay.show { opacity: 1; visibility: visible; }

.privacy-panel {
  width: min(800px, calc(100% - 32px));
  max-height: 90vh;
  overflow: auto;

  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-strong);

  transform: translateY(8px);
  opacity: 0;
  transition:
    transform 200ms ease,
    opacity 200ms ease;
}
.privacy-overlay.show .privacy-panel {
  transform: translateY(0);
  opacity: 1;
}

.privacy-panel h2 {
  margin: 0 0 8px 0;
  color: #ccffcc;
  border-bottom: 1px dashed rgba(0,255,0,0.25);
  padding-bottom: 6px;
  font-size: 1.1rem;
}
.privacy-panel p { margin: 0.6em 0; color: #c9f7c9; }
.privacy-panel ul { margin: 0.6em 0 0.6em 1.2em; }
.privacy-panel li { margin: 0.3em 0; }
.privacy-panel a { color: var(--accent); }
.privacy-panel a:hover { opacity: 0.85; }
.privacy-close { margin-top: 10px; display: inline-block; }

/* Scrollbars (Chrome/Edge/Safari) */
.chat::-webkit-scrollbar,
body::-webkit-scrollbar { width: 10px; height: 10px; }
.chat::-webkit-scrollbar-track,
body::-webkit-scrollbar-track { background: #0a0a0a; }
.chat::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(0,255,0,0.4), rgba(0,255,128,0.4));
  border: 1px solid rgba(0,255,0,0.35);
  border-radius: 8px;
}
.chat::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover { filter: brightness(1.1); }

/* Firefox */
* {
  scrollbar-color: rgba(0,255,0,0.45) #0a0a0a;
  scrollbar-width: thin;
}

/* Animations */
@keyframes fadeIn { to { opacity: 1; } }
@keyframes blink-temp { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .message { animation: none !important; }
  .thinking { animation: none !important; }
  .jump { transition: none !important; }
  .privacy-overlay,
  .privacy-panel {
    transition: none !important;
  }
}

/* Mobile refinements */
@media (max-width: 520px) {
  .actions { grid-auto-flow: row; }
  .composer { gap: 6px; padding: 8px; }
  .composer input, button { padding: 12px; }
  .jump { right: 10px; }
  .brand { padding: 6px 10px; }
  .brand > summary { padding: 6px 10px; }
  .chat { margin-top: 10px; }
}

/* Helpful utilities */
.hide { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
