/* ── Theme variables ───────────────────────────────────────────── */

:root {
  --bg:         #1a1a1e;
  --surface:    #24242a;
  --border:     #3a3a44;
  --text:       #d4d4d8;
  --text-dim:   #71717a;
  --human-bg:   #2d2d3a;
  --human-text: #d4d4d8;
  --ai-bg:      #1e2430;
  --ai-text:    #d4d4d8;
  --accent:     #e6a817;
  --input-bg:   #24242a;
  --btn-bg:     #e6a817;
  --btn-text:   #1a1a1e;
  --btn-hover:  #f0bc3a;
  --font:       'Courier New', Courier, monospace;
}

body.theme-light {
  --bg:         #f5f5f0;
  --surface:    #ffffff;
  --border:     #dddddd;
  --text:       #222222;
  --text-dim:   #666666;
  --human-bg:   #dce8f7;
  --human-text: #222222;
  --ai-bg:      #f0f0eb;
  --ai-text:    #222222;
  --accent:     #4a6fa5;
  --input-bg:   #ffffff;
  --btn-bg:     #4a6fa5;
  --btn-text:   #ffffff;
  --btn-hover:  #3a5f95;
  --font:       system-ui, sans-serif;
}

body.theme-mono {
  --bg:         #050505;
  --surface:    #0d0d0d;
  --border:     #00401a;
  --text:       #00ff41;
  --text-dim:   #008020;
  --human-bg:   #001a00;
  --human-text: #00ff41;
  --ai-bg:      #0d0d0d;
  --ai-text:    #00ff41;
  --accent:     #00ff41;
  --input-bg:   #080808;
  --btn-bg:     #001a00;
  --btn-text:   #00ff41;
  --btn-hover:  #003300;
}

/* ── Reset & base ──────────────────────────────────────────────── */

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

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font, system-ui, sans-serif);
  font-size: 15px;
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

/* ── Controls bar ──────────────────────────────────────────────── */

#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.spacer { flex: 1; }

#chat-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 780px;
}

#time-remaining {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

#time-remaining::before {
  content: '⏱ ';
  font-size: 0.8em;
}

#progress-wrap {
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}

#controls label {
  font-size: 0.78rem;
  color: var(--text-dim);
  user-select: none;
}

button {
  padding: 7px 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover:not(:disabled) { background: var(--btn-hover); }

#btn-home {
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.15s;
}

#btn-home:hover {
  color: var(--accent);
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

button.muted {
  opacity: 0.45;
}

#btn-mute {
  display: none;
}

select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* ── Chat area ─────────────────────────────────────────────────── */

#chat-wrapper {
  flex: 1;
  position: relative;
  min-height: 0;
}

#chat-container {
  height: 100%;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

#chat-container.is-playing {
  cursor: pointer;
}

/* ── Center play overlay ────────────────────────────────────────── */

#play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

#play-overlay[hidden] {
  display: none;
}

#play-center-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 26px;
  line-height: 1;
  padding: 0 0 0 4px; /* nudge triangle visually centred */
  cursor: pointer;
  pointer-events: all;
  opacity: 0.88;
  transition: transform 0.15s, opacity 0.4s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
}

#play-center-btn:hover {
  transform: scale(1.1);
  opacity: 1;
}

#play-overlay.scrolling #play-center-btn {
  opacity: 0.15;
  transition: opacity 0.1s;
}

.message-row {
  display: flex;
}

.message-row.human { justify-content: flex-end; }
.message-row.ai    { justify-content: flex-start; }

.message {
  max-width: 72%;
  display: flex;
  flex-direction: column;
}

.message-row.human .message { align-items: flex-end; }
.message-row.ai    .message { align-items: flex-start; }

.label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  word-break: break-word;
  white-space: pre-wrap;
  min-width: 2ch;
}

.message-row.human .bubble {
  background: var(--human-bg);
  color: var(--human-text);
  border-bottom-right-radius: 4px;
}

.message-row.ai .bubble {
  background: var(--ai-bg);
  color: var(--ai-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ── Load error ────────────────────────────────────────────────── */

.load-error {
  color: var(--text-dim);
  text-align: center;
  margin-top: 40px;
  font-size: 0.95rem;
}

/* ── Home page ──────────────────────────────────────────────────── */

.home {
  padding: 8px 0;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.home-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ── Tag cards ──────────────────────────────────────────────────── */

.tag-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-card {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.tag-card:hover,
.tag-card.active {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-card.active {
  background: var(--surface);
}

.tag-card-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface);
  border-radius: 10px;
  padding: 1px 6px;
}

.tag-card.active .tag-card-count,
.tag-card:hover .tag-card-count {
  color: var(--accent);
}

/* ── Pinned chat list ───────────────────────────────────────────── */

.pinned-list-items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pinned-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.pinned-link:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.pinned-link-title {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.pinned-link-meta {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.pinned-link-desc {
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.4;
  opacity: 0.7;
  margin-top: 2px;
}

/* ── Typing cursor on active bubble ────────────────────────────── */

.bubble.active::after {
  content: '▌';
  display: inline-block;
  color: var(--accent);
  animation: blink 0.8s step-end infinite;
  margin-left: 1px;
}

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

/* ── Input area ────────────────────────────────────────────────── */

#input-area {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#human-input {
  width: 100%;
  height: auto;
  resize: none;
  overflow: hidden;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  caret-color: var(--accent);
  box-sizing: border-box;
}

#human-input:focus {
  border-color: var(--accent);
}
