@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@300;400;500;600&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #111;
  --ink2: #555;
  --ink3: #999;
  --ink4: #ccc;
  --paper: #fafaf8;
  --line: #e8e8e4;
  --alive: #2a6ef5;
  --alive2: #e8501a;
  --alive3: #1a9e4a;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Geist Mono', monospace;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ══════════════════════════════
   HEADER
══════════════════════════════ */
header {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 44px;
  gap: 12px;
  flex-shrink: 0;
  background: var(--paper);
}

.wordmark {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}

.state-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--alive3);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
.state-dot.thinking { background: var(--alive); animation: blink 0.5s infinite; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.1} }

.hstats {
  display: flex;
  gap: 10px;
  font-size: 10px;
  color: var(--ink3);
}
.hstats b { color: var(--ink2); font-weight: 500; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.arousal-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--ink3);
  flex-shrink: 0;
}
.arousal-bar { width: 48px; height: 3px; background: var(--line); overflow: hidden; }
.arousal-fill { height: 100%; background: var(--alive); transition: width 0.6s ease; }

.explore-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink3);
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  touch-action: manipulation;
}
.explore-btn:hover { border-color: var(--ink); color: var(--ink); }

/* ── LEARN TOGGLE ── */
.learn-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink3);
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}
.learn-toggle-track {
  width: 28px;
  height: 14px;
  border-radius: 7px;
  background: var(--line);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.learn-toggle-track.on { background: var(--alive3); border-color: var(--alive3); }
.learn-toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.learn-toggle-track.on .learn-toggle-thumb { transform: translateX(14px); }
.learn-toggle-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink3);
  transition: color 0.2s;
}
.learn-toggle-track.on + .learn-toggle-label { color: var(--alive3); }

/* ══════════════════════════════
   BODY LAYOUT
══════════════════════════════ */
#body { flex: 1; display: flex; overflow: hidden; min-height: 0; }

/* ══════════════════════════════
   MAIN FEED
══════════════════════════════ */
#main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

#feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}
#feed::-webkit-scrollbar { width: 0; }

.entry {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  animation: slip 0.22s ease;
}
@keyframes slip { from { opacity:0; transform:translateY(5px); } }

.entry-you { font-size: 14px; color: var(--ink); line-height: 1.65; margin-bottom: 7px; word-break: break-word; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

.tag { font-size: 9px; color: var(--ink3); background: var(--line); padding: 2px 7px; border-radius: 2px; }
.tag.new   { background: #eef3ff; color: var(--alive); }
.tag.hot   { background: #fff0ec; color: var(--alive2); }
.tag.known { background: #edfaef; color: var(--alive3); }
.tag.learn-mode { background: #fff8e1; color: #b8860b; }
.tag.num   { background: #f3eeff; color: #7c4dff; }
.tag.sym   { background: #fce4ec; color: #c62828; }

.entry-ts { font-size: 9px; color: var(--ink4); margin-left: auto; flex-shrink: 0; }

/* ══════════════════════════════
   REPLY BLOCK
══════════════════════════════ */
.reply-block {
  margin-top: 10px;
  border-left: 2px solid var(--ink);
  padding: 0;
  position: relative;
  animation: slip 0.3s ease;
}
.reply-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 6px;
  border-bottom: 1px solid var(--line);
}
.reply-badge { font-size: 9px; letter-spacing: 0.12em; color: var(--ink3); text-transform: uppercase; }
.reply-mode-badge {
  font-size: 8px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  color: var(--ink3);
  border-radius: 2px;
  letter-spacing: 0.08em;
}
.reply-mode-badge.qa-hit  { border-color: var(--alive3); color: var(--alive3); }
.reply-mode-badge.qa-improved { border-color: var(--alive); color: var(--alive); }
.reply-mode-badge.generated { border-color: var(--ink4); color: var(--ink4); }

.coherence-badge {
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 2px;
  letter-spacing: 0.06em;
}
.coherence-badge.high { background: #edfaef; color: var(--alive3); }
.coherence-badge.mid  { background: #eef3ff; color: var(--alive); }
.coherence-badge.low  { background: var(--line); color: var(--ink3); }

.reply-words {
  padding: 12px 14px 10px;
  font-size: 14px;
  line-height: 1.85;
  color: var(--ink);
  position: relative;
  word-break: break-word;
  min-height: 44px;
}

/* word-by-word reveal */
.reply-word {
  display: inline;
  opacity: 0;
  animation: wordIn 0.18s ease forwards;
}
@keyframes wordIn { from{opacity:0;transform:translateY(3px)} to{opacity:1;transform:none} }

/* number / symbol coloring inside replies */
.token-num { color: #7c4dff; }
.token-sym { color: #c62828; }

/* thinking dots */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}
.thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ink3);
  animation: dotBounce 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-5px)} }

/* ══════════════════════════════
   FEEDBACK BUTTONS
══════════════════════════════ */
.reply-feedback {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 10px;
  border-top: 1px solid var(--line);
}
.fb-btn {
  background: transparent;
  border: 1px solid var(--line);
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--ink3);
  padding: 3px 10px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all 0.15s;
  border-radius: 2px;
  touch-action: manipulation;
}
.fb-btn:hover { border-color: var(--ink); color: var(--ink); }
.fb-btn.liked    { background: #edfaef; border-color: var(--alive3); color: var(--alive3); }
.fb-btn.disliked { background: #fff0ec; border-color: var(--alive2); color: var(--alive2); }

.fb-note {
  font-size: 9px;
  color: var(--ink4);
  letter-spacing: 0.04em;
  margin-left: 4px;
  transition: color 0.3s;
}
.fb-note.active { color: var(--ink3); }

.retry-hint {
  font-size: 9px;
  color: var(--alive2);
  letter-spacing: 0.04em;
  margin-left: auto;
  animation: slip 0.2s ease;
}

/* editable answer */
.fb-edit-area {
  flex: 1 1 100%;
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.fb-edit-input {
  flex: 1;
  min-width: 120px;
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--alive2);
  outline: none;
  padding: 3px 0;
  line-height: 1.5;
  resize: none;
}
.fb-save-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 4px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.fb-save-btn:hover { opacity: 0.8; }
.fb-discard-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  background: transparent;
  color: var(--ink3);
  border: 1px solid var(--line);
  padding: 4px 8px;
  cursor: pointer;
  touch-action: manipulation;
}

/* ══════════════════════════════
   INPUT BAR
══════════════════════════════ */
#input-area {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
#txt {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--line);
  outline: none;
  font-family: 'Geist Mono', monospace;
  font-size: 15px;
  color: var(--ink);
  padding: 5px 0;
  resize: none;
  line-height: 1.55;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
#txt:focus { border-color: var(--ink); }
#txt::placeholder { color: var(--ink4); }

#send {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 9px 16px;
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-appearance: none;
  border-radius: 0;
  touch-action: manipulation;
}
#send:active { opacity: 0.6; }
#send:disabled { opacity: 0.35; cursor: not-allowed; }

/* ══════════════════════════════
   THINK SIDEBAR
══════════════════════════════ */
#think {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.think-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.think-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--ink3);
  text-transform: uppercase;
  margin-bottom: 9px;
}

#monologue { font-size: 11px; color: var(--ink2); line-height: 1.8; min-height: 44px; }
.mono-line  { animation: slip 0.2s ease; padding: 1px 0; }
.mono-dim   { color: var(--ink4); }
.mono-hi    { color: var(--alive); }
.mono-fire  { color: var(--alive2); }
.mono-grow  { color: var(--alive3); }

#reasoning { font-size: 11px; color: var(--ink2); line-height: 1.75; min-height: 32px; }
.reason-step { padding: 2px 0; animation: slip 0.15s ease; }
.reason-word { color: var(--alive); font-weight: 500; }
.reason-why  { color: var(--ink3); }

#chain-trace { display: flex; flex-wrap: wrap; gap: 4px; min-height: 22px; align-items: center; }
.chain-word { font-size: 10px; padding: 2px 7px; border-radius: 2px; background: var(--line); color: var(--ink2); animation: slip 0.2s ease; }
.chain-word.chosen { background: var(--ink); color: var(--paper); }
.chain-word.maybe  { background: #eef3ff; color: var(--alive); }
.chain-arrow { color: var(--ink4); font-size: 10px; }

#sentence-struct { font-size: 10px; line-height: 1.8; color: var(--ink2); min-height: 22px; }
.struct-token { display: inline-block; margin: 2px 3px; }
.struct-token .s-label { font-size: 8px; color: var(--ink4); display: block; text-align: center; letter-spacing: 0.08em; }
.struct-token .s-word  { padding: 1px 5px; border: 1px solid var(--line); border-radius: 2px; }
.struct-token.subj .s-word { border-color: var(--alive);  color: var(--alive); }
.struct-token.verb .s-word { border-color: var(--alive2); color: var(--alive2); }
.struct-token.obj  .s-word { border-color: var(--alive3); color: var(--alive3); }
.struct-token.mod  .s-word { border-color: var(--ink4);   color: var(--ink3); }
.struct-token.num  .s-word { border-color: #7c4dff; color: #7c4dff; }
.struct-token.sym  .s-word { border-color: #c62828; color: #c62828; }

/* tabs */
.think-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--paper);
}
.think-tab {
  flex: 1;
  padding: 8px 0;
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: none;
  background: transparent;
  color: var(--ink3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  touch-action: manipulation;
}
.think-tab.active { color: var(--ink); border-bottom-color: var(--ink); background: #fff; }

.think-pane { display: none; flex: 1; overflow-y: auto; flex-direction: column; -webkit-overflow-scrolling: touch; }
.think-pane.active { display: flex; }
.think-pane::-webkit-scrollbar { width: 0; }

/* ══════════════════════════════
   MOBILE BRAIN TOGGLE
══════════════════════════════ */
#brain-toggle {
  display: none;
  position: fixed;
  bottom: 72px;
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  border: none;
  font-family: 'Geist Mono', monospace;
  font-size: 16px;
  cursor: pointer;
  z-index: 100;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  touch-action: manipulation;
}
#brain-sheet { display: none; position: fixed; inset: 0; z-index: 200; flex-direction: column; }
#brain-backdrop { flex: 1; background: rgba(0,0,0,0.25); }
#brain-panel {
  background: #fff;
  border-top: 1px solid var(--line);
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.brain-handle { text-align: center; padding: 10px 0 4px; cursor: pointer; touch-action: manipulation; }
.brain-handle-bar { display: inline-block; width: 32px; height: 3px; background: var(--line); border-radius: 2px; }

/* ══════════════════════════════
   ANALYTICS OVERLAY
══════════════════════════════ */
#analytics-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--paper);
  flex-direction: column;
  overflow: hidden;
}
#analytics-overlay.open { display: flex; }

#ao-header {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 44px;
  flex-shrink: 0;
  background: var(--paper);
}
#ao-header h2 { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; flex: 1; }
#ao-close {
  background: transparent;
  border: none;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink3);
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 0.06em;
}
#ao-close:hover { color: var(--ink); }

#ao-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
  align-content: start;
}

.ao-panel {
  border: 1px solid var(--line);
  background: #fff;
  padding: 14px 16px;
}
.ao-panel.full { grid-column: 1 / -1; }
.ao-panel-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink3);
  margin-bottom: 12px;
}

.ao-word-list { max-height: 260px; overflow-y: auto; }
.ao-word-list::-webkit-scrollbar { width: 0; }
.ao-word-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.ao-word-row:last-child { border-bottom: none; }
.ao-wr-word { font-size: 11px; color: var(--ink); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ao-wr-bar-wrap { width: 60px; height: 3px; background: var(--line); flex-shrink: 0; }
.ao-wr-bar { height: 100%; background: var(--alive); }
.ao-wr-count { font-size: 9px; color: var(--ink4); min-width: 24px; text-align: right; flex-shrink: 0; }
.ao-wr-sent { font-size: 9px; flex-shrink: 0; }

.ao-search {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  outline: none;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink);
  padding: 4px 0;
  margin-bottom: 10px;
}
.ao-search::placeholder { color: var(--ink4); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { padding: 10px 12px; background: var(--paper); border: 1px solid var(--line); }
.stat-num { font-size: 22px; font-weight: 300; color: var(--ink); line-height: 1; margin-bottom: 3px; }
.stat-desc { font-size: 9px; color: var(--ink3); letter-spacing: 0.06em; }

.sentiment-bar-wrap { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.sentiment-track { flex: 1; height: 4px; background: var(--line); position: relative; }
.sentiment-neg { position: absolute; top: 0; left: 0; bottom: 0; background: var(--alive2); }
.sentiment-pos { position: absolute; top: 0; right: 0; bottom: 0; background: var(--alive3); }
.sentiment-tick { position: absolute; top: -4px; bottom: -4px; width: 1px; background: var(--ink); left: 50%; }
.sentiment-needle {
  position: absolute; top: -5px; width: 2px; height: 14px;
  background: var(--ink); transform: translateX(-50%);
  transition: left 0.6s ease;
}
.sent-label { font-size: 9px; color: var(--ink3); }

#word-graph-canvas { width: 100%; height: 280px; background: #fafaf8; border: none; cursor: crosshair; display: block; }
.graph-tooltip {
  position: absolute; background: var(--ink); color: var(--paper);
  font-family: 'Geist Mono', monospace; font-size: 10px; padding: 4px 8px;
  pointer-events: none; display: none; z-index: 10;
}
.graph-wrap { position: relative; }

/* ══════════════════════════════
   Q&A OVERLAY
══════════════════════════════ */
#qa-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 600;
  background: var(--paper);
  flex-direction: column;
  overflow: hidden;
}
#qa-overlay.open { display: flex; }

#qa-header {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 44px;
  flex-shrink: 0;
  background: var(--paper);
}
#qa-header h2 { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; flex: 1; }
#qa-header-stats { font-size: 9px; color: var(--ink3); }
#qa-close {
  background: transparent;
  border: none;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink3);
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 0.06em;
}
#qa-close:hover { color: var(--ink); }

#qa-body { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; -webkit-overflow-scrolling: touch; }
#qa-body::-webkit-scrollbar { width: 0; }

.qa-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.qa-search {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  outline: none;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink);
  padding: 3px 0;
}
.qa-search::placeholder { color: var(--ink4); }

.qa-filter-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink3);
  padding: 3px 8px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.12s;
}
.qa-filter-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

#qa-list { flex: 1; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }

.qa-empty { color: var(--ink4); font-size: 12px; text-align: center; padding: 40px 0; letter-spacing: 0.05em; }

.qa-card {
  border: 1px solid var(--line);
  background: #fff;
  animation: slip 0.2s ease;
  position: relative;
}
.qa-card.flagged { border-color: #ffccbc; }
.qa-card.confirmed { border-color: #c8e6c9; }

.qa-card-q {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.qa-q-mark { font-size: 9px; font-weight: 600; color: var(--alive); letter-spacing: 0.1em; flex-shrink: 0; padding-top: 2px; }
.qa-q-text { font-size: 12px; color: var(--ink); line-height: 1.55; flex: 1; word-break: break-word; }

.qa-card-a {
  padding: 8px 14px 10px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.qa-a-mark { font-size: 9px; font-weight: 600; color: var(--alive3); letter-spacing: 0.1em; flex-shrink: 0; padding-top: 2px; }
.qa-a-text { font-size: 12px; color: var(--ink2); line-height: 1.55; flex: 1; word-break: break-word; font-style: italic; }
.qa-a-pending { font-size: 11px; color: var(--ink4); font-style: italic; }

.qa-card-meta {
  padding: 0 14px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.qa-ts { font-size: 9px; color: var(--ink4); }

.qa-conf-badge {
  font-size: 8px;
  padding: 1px 5px;
  border-radius: 2px;
  letter-spacing: 0.06em;
}
.qa-conf-badge.high    { background: #edfaef; color: var(--alive3); }
.qa-conf-badge.mid     { background: #eef3ff; color: var(--alive); }
.qa-conf-badge.low     { background: var(--line); color: var(--ink3); }
.qa-conf-badge.flagged { background: #fff0ec; color: var(--alive2); }

.qa-version-count { font-size: 8px; color: var(--ink4); }

.qa-card-edit {
  padding: 6px 14px 10px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 6px;
  align-items: center;
}
.qa-edit-input {
  flex: 1;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  outline: none;
  padding: 2px 0;
}
.qa-save-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 3px 9px;
  cursor: pointer;
}
.qa-del-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  background: transparent;
  color: var(--alive2);
  border: 1px solid #ffccbc;
  padding: 3px 7px;
  cursor: pointer;
  border-radius: 2px;
}

/* ══════════════════════════════
   RESPONSIVE
══════════════════════════════ */
@media (max-width: 640px) {
  #think { display: none; }
  #brain-toggle { display: flex; }
  #brain-sheet.open { display: flex; }
  #main { border-right: none; }
  .hstats .words-stat { display: none; }
  header { padding: 0 12px; gap: 8px; }
  .explore-btn span { display: none; }
  #ao-body { grid-template-columns: 1fr; padding: 14px; }
}
/* ══════════════════════════════
   MOBILE FIX — hide sidebar, show brain toggle
══════════════════════════════ */
@media (max-width: 640px) {
  #think { display: none !important; }
  #brain-toggle { display: flex !important; }
  #main { border-right: none; }
  .words-stat { display: none; }
  header { padding: 0 10px; gap: 6px; }
  .hstats { gap: 6px; }
  .header-right { gap: 6px; }
  .explore-btn span { display: none; }
  .explore-btn { padding: 4px 7px; }
  #ao-body { grid-template-columns: 1fr; padding: 12px; gap: 10px; }
  .ao-panel.full { grid-column: 1; }
}

/* Prevent horizontal overflow on all screen sizes */
#body { max-width: 100vw; overflow-x: hidden; }
html, body { max-width: 100vw; overflow-x: hidden; }

/* ══════════════════════════════
   WORDS OVERLAY
══════════════════════════════ */
#words-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 550;
  background: var(--paper);
  flex-direction: column;
  overflow: hidden;
}
#words-overlay.open { display: flex; }

#wo-header {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 44px;
  flex-shrink: 0;
  background: var(--paper);
}
#wo-header h2 { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; }
#wo-stats { font-size: 9px; color: var(--ink3); }
.wo-header-actions { display: flex; gap: 8px; margin-left: auto; }
#wo-close {
  background: transparent;
  border: none;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--ink3);
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 0.06em;
}
#wo-close:hover { color: var(--ink); }

#wo-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.wo-sort-btn {
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink3);
  padding: 3px 8px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.12s;
}
.wo-sort-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
#wo-search { flex: 1; min-width: 120px; }

#wo-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#wo-body::-webkit-scrollbar { width: 0; }

#wo-list { padding: 0 20px 20px; display: flex; flex-direction: column; }

.wo-row {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  animation: slip 0.18s ease;
  cursor: pointer;
  transition: background 0.1s;
}
.wo-row:hover { background: rgba(0,0,0,0.015); margin: 0 -20px; padding-left: 20px; padding-right: 20px; }

.wo-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
}
.wo-word {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
  min-width: 100px;
}
.wo-bar-wrap { flex: 1; height: 2px; background: var(--line); max-width: 120px; }
.wo-bar { height: 100%; background: var(--alive); transition: width 0.4s ease; }
.wo-count { font-size: 10px; color: var(--ink3); min-width: 28px; text-align: right; }
.wo-sent-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--ink4);
}
.wo-sent-dot.pos { background: var(--alive3); }
.wo-sent-dot.neg { background: var(--alive2); }

.wo-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 10px;
  color: var(--ink3);
  line-height: 1.6;
}
.wo-meta-group { display: flex; gap: 4px; align-items: center; }
.wo-meta-label { color: var(--ink4); font-size: 9px; letter-spacing: 0.06em; }
.wo-meta-words { display: flex; flex-wrap: wrap; gap: 3px; }
.wo-neighbor {
  font-size: 9px;
  padding: 1px 6px;
  background: var(--line);
  border-radius: 2px;
  color: var(--ink2);
}
.wo-meaning {
  font-size: 10px;
  color: var(--ink3);
  font-style: italic;
  margin-top: 4px;
  padding-left: 2px;
}

/* import label as button */
#import-label {
  cursor: pointer;
  display: flex;
  align-items: center;
  user-select: none;
}

/* qa card confirmed style (was cut off in original css) */
.qa-card.confirmed { border-color: #c8e6c9; }

/* reply feedback — no correction prompt shown automatically */
.fb-correct-area { display: none; }
/* ══════════════════════════════
   FIXED WORD MAP + WORDS UI
══════════════════════════════ */

/* Better analytics spacing */
.graph-wrap {
  position: relative;
  width: 100%;
  height: 70vh;
  min-height: 500px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at center, rgba(0,0,0,0.02) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}

/* Bigger actual graph */
#word-graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(to bottom, rgba(255,255,255,0.98), rgba(250,250,248,0.98));
  border: none;
  cursor: grab;
}

#word-graph-canvas:active {
  cursor: grabbing;
}

/* Tooltip improvement */
.graph-tooltip {
  position: absolute;
  background: rgba(17,17,17,0.96);
  color: white;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.6;
  pointer-events: none;
  z-index: 10;
  max-width: 220px;
  border: 1px solid rgba(255,255,255,0.06);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 30px rgba(0,0,0,0.15);
}

/* Learned words section fix */
#wo-body {
  background: #fff;
}

#wo-list {
  gap: 10px;
  padding-top: 16px;
}

/* Card style instead of flat rows */
.wo-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.wo-row:hover {
  margin: 0;
  padding: 14px;
  transform: translateY(-1px);
  border-color: #d8d8d8;
  box-shadow: 0 10px 24px rgba(0,0,0,0.04);
}

/* Word title */
.wo-word {
  font-size: 16px;
  letter-spacing: 0.03em;
}

/* Connection chips */
.wo-neighbor {
  padding: 4px 8px;
  border-radius: 999px;
  background: #f3f5f7;
  border: 1px solid #e5e7ea;
  font-size: 9px;
}

/* Better word frequency bars */
.wo-bar-wrap {
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: #ececec;
}

.wo-bar {
  border-radius: 999px;
}

/* Analytics panels look unified */
.ao-panel {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e8e8e4;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
}

/* Mobile improvements */
@media (max-width: 640px) {

  .graph-wrap {
    height: 60vh;
    min-height: 420px;
  }

  #wo-list {
    padding: 12px;
  }

  .wo-row {
    padding: 12px;
  }

  .wo-word {
    font-size: 15px;
  }

  .graph-tooltip {
    max-width: 160px;
    font-size: 9px;
  }
}
/* ══════════════════════════════
   MOBILE HEADER FIX
══════════════════════════════ */
@media (max-width: 640px) {

  header {
    height: auto;
    min-height: 44px;
    padding: 8px 10px;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .wordmark {
    font-size: 12px;
  }

  .hstats {
    width: 100%;
    order: 3;
    justify-content: flex-start;
    gap: 10px;
    padding-top: 2px;
    font-size: 9px;
  }

  .header-right {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
    max-width: 100%;
  }

  .explore-btn {
    font-size: 8px;
    padding: 4px 6px;
  }

  .explore-btn span {
    display: none;
  }

  .learn-toggle-wrap {
    transform: scale(0.92);
    transform-origin: right center;
  }

  .arousal-wrap {
    display: none;
  }

  /* Make analytics overlays fit mobile */
  #ao-header,
  #qa-header,
  #wo-header {
    padding: 0 12px;
    gap: 8px;
    flex-wrap: wrap;
    height: auto;
    min-height: 44px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  #ao-header h2,
  #qa-header h2,
  #wo-header h2 {
    font-size: 11px;
  }

  #wo-toolbar,
  .qa-toolbar {
    padding: 10px 12px;
  }

  /* Prevent horizontal overflow globally */
  * {
    max-width: 100%;
  }

  body {
    overflow-x: hidden;
  }
}
