/* ── Reset & Variables ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:    #00cc66;
  --gold:     #ebb22d;
  --blue:     #4da6ff;
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #7d8590;
  --mono:     'Space Mono', monospace;
  --sans:     'Inter', system-ui, sans-serif;
  --nav-h:    56px;
  --r:        8px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  letter-spacing: 0.01em;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--green) 1px, transparent 1px),
    linear-gradient(90deg, var(--green) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.03;
  pointer-events: none;
  z-index: 0;
}

/* ── Nav ─────────────────────────────────────────────────────────────────────── */
nav {
  position: fixed;
  inset: 0 0 auto;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(13,17,23,0.88);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  z-index: 50;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.nav-brand img   { height: 32px; width: auto; }
.nav-brand-name  { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--green); letter-spacing: 0; }

.nav-links       { display: flex; gap: 4px; }
.nav-links a {
  padding: 6px 12px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  border-radius: var(--r);
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface2); }

/* ── Page ────────────────────────────────────────────────────────────────────── */
#page {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: calc(var(--nav-h) + 24px) 16px 16px;
  min-height: 100vh;
}

/* ── App shell ───────────────────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 860px;
  height: calc(100vh - var(--nav-h) - 48px);
  min-height: 400px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0;
}

.header-title::before {
  content: '';
  width: 10px; height: 10px;
  background: var(--gold);
  border-radius: 2px;
  flex-shrink: 0;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
  flex-shrink: 0;
}
#status-dot.connected  { background: var(--green); box-shadow: 0 0 8px var(--green); }
#status-dot.connecting { background: var(--gold); animation: blink 0.5s infinite; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ── Messages ────────────────────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 20px;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Welcome state ───────────────────────────────────────────────────────────── */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  text-align: center;
  padding: 24px;
}

#welcome img     { width: 100%; max-width: 260px; height: auto; opacity: 0.9; }
#welcome-tagline { font-family: var(--mono); font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: 3px; }
#welcome-hint    { font-size: 15px; color: var(--muted); max-width: 340px; }

.welcome-examples { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 440px; }

.welcome-example {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, color 0.15s;
}
.welcome-example:hover   { border-color: var(--green); color: var(--text); }
.welcome-example::before { content: '>'; color: var(--green); font-weight: 700; flex-shrink: 0; }

#system-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 15px;
  color: var(--muted);
  margin: 0 auto;
}

/* ── Message bubbles ─────────────────────────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 82%;
  animation: fadeIn 0.18s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.user      { align-self: flex-end;   align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 4px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--gold);
  color: #0d1117;
  border-bottom-right-radius: 4px;
  letter-spacing: 0;
}

.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ── Markdown ────────────────────────────────────────────────────────────────── */
.bubble p              { margin: 0 0 0.8em; }
.bubble p:last-child   { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin: 1.2em 0 0.5em;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.bubble :is(h1,h2,h3):first-child { margin-top: 0; }

.bubble ul, .bubble ol { padding-left: 1.4em; margin: 0.6em 0; }
.bubble li             { margin: 0.3em 0; }

.bubble strong { font-weight: 600; }
.bubble em     { font-style: italic; color: #b0bac4; }

.bubble a       { color: var(--blue); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

/* Inline code */
.bubble code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--text);
  letter-spacing: 0;
}

/* Code blocks */
.bubble pre {
  margin: 0.8em 0;
  padding: 14px 16px;
  background: #0a0e13;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.bubble pre code {
  padding: 0;
  background: transparent;
  border: none;
  font-size: 13px;
  line-height: 1.65;
  color: #c9d1d9;
}

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.bubble .table-wrap {
  overflow-x: auto;
  margin: 0.8em 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

.bubble thead { background: var(--surface2); }

.bubble th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.bubble td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.bubble tr:last-child td { border-bottom: none; }

.bubble tbody tr:hover { background: rgba(255,255,255,0.02); }

/* ── Blockquote ──────────────────────────────────────────────────────────────── */
.bubble blockquote {
  margin: 0.8em 0;
  padding: 10px 16px;
  border-left: 3px solid var(--green);
  background: rgba(0,204,102,0.04);
  border-radius: 0 var(--r) var(--r) 0;
  color: #b0bac4;
  font-style: italic;
}

/* ── Softgate ────────────────────────────────────────────────────────────────── */
.upgrade-btn {
  display: inline-block;
  margin: 10px 0 6px;
  padding: 9px 18px;
  background: var(--gold);
  color: #0d1117;
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0;
  transition: opacity 0.15s;
}
.upgrade-btn:hover { opacity: 0.85; }

.redeem-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}
.redeem-row input {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 7px 10px;
  width: 200px;
  outline: none;
  letter-spacing: 0.04em;
}
.redeem-row input:focus { border-color: var(--green); }
.redeem-row button {
  padding: 7px 13px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.redeem-row button:hover { border-color: var(--green); color: var(--green); }

/* ── Copy button ─────────────────────────────────────────────────────────────── */
.copy-btn {
  display: none;
  margin-top: 4px;
  padding: 3px 9px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0;
  transition: color 0.15s, border-color 0.15s;
}
.msg.assistant:hover .copy-btn    { display: inline-block; }
.copy-btn:hover, .copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ── Thinking dots ───────────────────────────────────────────────────────────── */
.thinking      { display: flex; gap: 5px; padding: 14px 16px; }
.thinking span {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.thinking span:nth-child(1) { animation-delay: -0.32s; }
.thinking span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ── Footer / input ──────────────────────────────────────────────────────────── */
footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 11px 16px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#input:focus        { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,204,102,0.1); }
#input::placeholder { color: var(--muted); }
#input:disabled     { opacity: 0.4; cursor: not-allowed; }

#send-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 11px 20px;
  background: var(--green);
  border: none;
  border-radius: var(--r);
  color: #0d1117;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: 0;
  transition: opacity 0.15s, transform 0.1s;
}
#send-btn:hover:not(:disabled)  { opacity: 0.88; }
#send-btn:active:not(:disabled) { transform: scale(0.97); }
#send-btn:disabled              { opacity: 0.35; cursor: not-allowed; }
#send-btn svg                   { width: 16px; height: 16px; }

/* ── Auth modal ──────────────────────────────────────────────────────────────── */
#auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13,17,23,0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#auth-modal.visible { display: flex; }

.auth-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.auth-close:hover { color: var(--text); background: var(--surface2); }

.auth-card-title {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

#pending-hint {
  display: none;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
  word-break: break-word;
  line-height: 1.5;
  letter-spacing: 0;
}
#pending-hint.visible { display: flex; }
#pending-hint::before { content: '>'; color: var(--green); font-weight: 700; flex-shrink: 0; margin-top: 1px; }

#google-btn-slot { display: flex; justify-content: center; margin-bottom: 16px; }

.auth-footer-note {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.auth-footer-note a       { color: var(--blue); text-decoration: none; }
.auth-footer-note a:hover { text-decoration: underline; }

/* ── ToS ─────────────────────────────────────────────────────────────────────── */
#tos       { margin-top: 10px; text-align: center; }
#tos a     { color: var(--muted); font-size: 12px; text-decoration: none; }
#tos a:hover { color: var(--gold); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  nav              { padding: 0 14px; }
  .nav-links a     { padding: 6px 8px; font-size: 12px; }
  .nav-brand-name  { display: none; }
  #page            { padding-top: calc(var(--nav-h) + 12px); padding-bottom: 12px; }
  #app             { height: calc(100vh - var(--nav-h) - 24px); border-radius: 8px; }
  .msg             { max-width: 90%; }
  .bubble          { font-size: 15px; padding: 10px 14px; }
  footer           { padding: 12px 14px; }
  #send-btn span   { display: none; }
  #send-btn        { padding: 11px 14px; }
  .auth-card       { padding: 24px; }
  #welcome img     { max-width: 180px; }
}
