/* ============================================================
   MAYA Web UI — Session 16 UX
   Chic night palette · cloud bubbles · Nunito · kids-friendly
   ============================================================ */

/* ── Nunito — local font (RPi-safe, no CDN) ─────────────────── */
@font-face {
  font-family: 'Nunito';
  src: url('/static/nunito-400.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('/static/nunito-700.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('/static/nunito-800.ttf') format('truetype');
  font-weight: 800;
  font-display: swap;
}

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Core — warm deep night */
  --bg:           #0d0b1a;
  --bg-2:         #15122a;
  --bg-3:         #1e1a36;
  --bg-glass:     rgba(21, 18, 42, 0.88);
  --border:       #28234a;
  --border-soft:  rgba(167, 139, 250, 0.14);

  /* Accent — lavender/violet */
  --accent:       #a78bfa;
  --accent-dim:   #8b6ef5;
  --accent-deep:  #6d28d9;
  --accent-glow:  rgba(167, 139, 250, 0.2);
  --accent-light: #c4b5fd;

  /* Message bubbles */
  --user-from:    #4338ca;
  --user-to:      #7c3aed;
  --maya-bubble:  rgba(139, 110, 245, 0.14);

  /* Text */
  --text:         #eee9ff;
  --text-muted:   #a09ac4;
  --text-dim:     #5e5888;

  /* Status */
  --online:  #34d399;
  --offline: #f87171;
  --warn:    #fbbf24;

  /* Shape */
  --radius:      20px;
  --radius-sm:   14px;
  --radius-pill: 999px;
  --radius-msg:  26px;

  /* Layout */
  --sidebar-w: 280px;
  --header-h:  60px;

  /* Mastery level colours */
  --curious:   #fbbf24;
  --learning:  #60a5fa;
  --practiced: #34d399;
  --expert:    #c084fc;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', 'Trebuchet MS', 'Segoe UI Variable', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.7;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────────── */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header — frosted glass ────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border-soft);
  box-shadow: 0 1px 0 rgba(167, 139, 250, 0.07),
              0 4px 24px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(130deg, #e0c3fc 0%, var(--accent-light) 40%, var(--accent) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
  user-select: none;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.4s, box-shadow 0.4s;
}
.status-dot.online  { background: var(--online);  box-shadow: 0 0 7px var(--online); }
.status-dot.offline { background: var(--offline); }
.status-dot.warn    { background: var(--warn);    box-shadow: 0 0 7px var(--warn); }

.status-text {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.header-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.select-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.select-group label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
  white-space: nowrap;
  font-weight: 500;
}

.select-group select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  padding: 5px 28px 5px 13px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a78bfa'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.select-group select:hover,
.select-group select:focus {
  border-color: var(--accent);
  background-color: rgba(167, 139, 250, 0.08);
  color: var(--text);
}
.select-group select option {
  background: var(--bg-2);
  color: var(--text);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover {
  background: rgba(167, 139, 250, 0.1);
  color: var(--accent-light);
}

/* ── Body ──────────────────────────────────────────────────── */
#body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar — always slide-out overlay ────────────────────── */
.sidebar {
  position: fixed;
  left: -100%;
  top: var(--header-h);
  bottom: 0;
  z-index: 10;
  width: min(var(--sidebar-w), 88vw);
  background: var(--bg-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: left 0.25s ease;
  box-shadow: 6px 0 30px rgba(0, 0, 0, 0.5);
}
.sidebar.open { left: 0; }

.sidebar-section {
  padding: 20px 18px;
}
.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-dim);
  margin-bottom: 13px;
  font-weight: 600;
}

/* Recent topics — pill chips */
.topic-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.topic-list li {
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 8px 5px 13px;
  border-radius: var(--radius-pill);
  background: rgba(167, 139, 250, 0.07);
  border: 1px solid rgba(167, 139, 250, 0.1);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s, color 0.2s;
}
.topic-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topic-list li:hover:not(.empty) {
  background: rgba(167, 139, 250, 0.14);
  color: var(--accent-light);
}
.topic-list li.empty {
  background: none;
  border: none;
  font-style: italic;
  color: var(--text-dim);
  padding-left: 2px;
}

/* Mastery list */
.mastery-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.mastery-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.mastery-list li:last-child { border-bottom: none; padding-bottom: 0; }
.mastery-list li.empty      { color: var(--text-dim); font-style: italic; border: none; }

/* × delete buttons on history items */
.history-del-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.topic-list li:hover .history-del-btn,
.mastery-list li:hover .history-del-btn { opacity: 1; }
.history-del-btn:hover { color: var(--offline); }

/* Clear all history button */
.clear-history-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-family: inherit;
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  width: 100%;
}
.clear-history-btn:hover {
  border-color: var(--offline);
  color: var(--offline);
}

.mastery-topic {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.mastery-badge {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.level-curious   { background: rgba(251,191,36,0.15);  color: var(--curious); }
.level-learning  { background: rgba(96,165,250,0.15);  color: var(--learning); }
.level-practiced { background: rgba(52,211,153,0.15);  color: var(--practiced); }
.level-expert    { background: rgba(192,132,252,0.2);  color: var(--expert); }

/* ── Sidebar tab bar ───────────────────────────────────────── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  padding: 12px 8px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  letter-spacing: 0.2px;
}
.sidebar-tab:hover { color: var(--text-muted); background: rgba(167,139,250,0.05); }
.sidebar-tab.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent);
  background: rgba(167,139,250,0.06);
}

.sidebar-panel { display: flex; flex-direction: column; overflow-y: auto; flex: 1; }
.sidebar-panel[hidden] { display: none; }

/* ── Persona form ──────────────────────────────────────────── */
.pf-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.5;
}

.persona-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pf-label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-top: 4px;
}
.pf-label:first-child { margin-top: 0; }

.pf-field {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  line-height: 1.55;
  padding: 8px 10px;
  resize: vertical;
  min-height: 48px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  scrollbar-width: thin;
}
.pf-field:focus {
  border-color: var(--accent);
  background: rgba(167,139,250,0.06);
}

.save-persona-btn {
  margin-top: 6px;
  background: linear-gradient(135deg, var(--accent-deep), var(--accent-dim));
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(109,40,217,0.35);
  align-self: flex-start;
}
.save-persona-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(109,40,217,0.5);
}
.save-persona-btn:active { transform: translateY(0); }

/* Save toast */
.persona-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(52,211,153,0.15);
  border: 1px solid rgba(52,211,153,0.35);
  color: var(--practiced);
  padding: 8px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
.persona-toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 9;
}
.sidebar-overlay.visible { display: block; }

/* ── Chat main ─────────────────────────────────────────────── */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── MAYA Hero Eyes — DO NOT CHANGE THIS SECTION ─────────── */
#maya-hero {
  flex-shrink: 0;
  height: var(--hero-h, 50vh);
  background:
    radial-gradient(ellipse at 30% 25%, rgba(109, 40, 217, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 70%, rgba(139, 92, 246, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 60% 15%, rgba(59, 130, 246, 0.10) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 55%, #12082e 0%, #09061a 55%, #080810 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  overflow: hidden;
  position: relative;
}

/* CSS star field — 28 tiny stars at fixed positions */
#maya-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.2px 1.2px at  8%  12%, rgba(255,255,255,0.65) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 22%  38%, rgba(200,210,255,0.50) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 37%   7%, rgba(255,255,255,0.70) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 51%  25%, rgba(180,160,255,0.60) 0%, transparent 100%),
    radial-gradient(1.2px 1.2px at 63%  14%, rgba(255,255,255,0.55) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 78%   9%, rgba(200,220,255,0.70) 0%, transparent 100%),
    radial-gradient(1.3px 1.3px at 88%  32%, rgba(255,255,255,0.60) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 94%  18%, rgba(180,200,255,0.50) 0%, transparent 100%),
    radial-gradient(0.9px 0.9px at  5%  55%, rgba(255,255,255,0.45) 0%, transparent 100%),
    radial-gradient(1.4px 1.4px at 14%  72%, rgba(200,180,255,0.55) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 27%  61%, rgba(255,255,255,0.40) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 42%  85%, rgba(210,200,255,0.60) 0%, transparent 100%),
    radial-gradient(1.2px 1.2px at 57%  78%, rgba(255,255,255,0.50) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 69%  64%, rgba(180,210,255,0.65) 0%, transparent 100%),
    radial-gradient(0.9px 0.9px at 82%  52%, rgba(255,255,255,0.45) 0%, transparent 100%),
    radial-gradient(1.1px 1.1px at 91%  77%, rgba(200,180,255,0.55) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 16%  91%, rgba(255,255,255,0.40) 0%, transparent 100%),
    radial-gradient(1.3px 1.3px at 33%  46%, rgba(167,139,250,0.55) 0%, transparent 100%),
    radial-gradient(0.7px 0.7px at 48%  93%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1.1px 1.1px at 74%  88%, rgba(200,220,255,0.50) 0%, transparent 100%),
    radial-gradient(0.9px 0.9px at  3%  28%, rgba(255,255,255,0.60) 0%, transparent 100%),
    radial-gradient(1.4px 1.4px at 96%  45%, rgba(180,160,255,0.45) 0%, transparent 100%),
    radial-gradient(0.8px 0.8px at 44%  52%, rgba(255,255,255,0.30) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 59%  41%, rgba(200,190,255,0.45) 0%, transparent 100%),
    radial-gradient(1.2px 1.2px at 85%  66%, rgba(255,255,255,0.55) 0%, transparent 100%),
    radial-gradient(0.7px 0.7px at 72%  29%, rgba(210,200,255,0.40) 0%, transparent 100%),
    radial-gradient(1.0px 1.0px at 11%  80%, rgba(255,255,255,0.50) 0%, transparent 100%),
    radial-gradient(1.3px 1.3px at 98%  90%, rgba(180,200,255,0.60) 0%, transparent 100%);
  pointer-events: none;
  animation: star-twinkle 5s ease-in-out infinite alternate;
  z-index: 0;
}

/* Nebula soft glow ring behind the eyes */
#maya-hero::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(60vw, 420px);
  height: min(30vh, 180px);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(109, 40, 217, 0.14) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: nebula-pulse 6s ease-in-out infinite alternate;
}

/* Ensure canvas + content stays above star layer */
#maya-eyes-container { position: relative; z-index: 1; }
#maya-caption        { position: relative; z-index: 1; }

#maya-eyes-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

#maya-p5-canvas canvas {
  border-radius: 24px;
  display: block;
}

#maya-caption {
  max-width: min(92vw, 700px);
  text-align: center;
  font-size: clamp(13px, 1.8vw, 18px);
  color: #c8e6ff;
  line-height: 1.5;
  padding: 0 8px;
  min-height: 1.6em;
  opacity: 0;
  transition: opacity 0.35s ease;
  word-wrap: break-word;
}
#maya-caption.visible { opacity: 1; }

.emotion-label {
  font-size: 10px;
  color: #333;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 4px;
  display: none;
}
/* ── Hero resize handle ────────────────────────────────────── */
.hero-resize {
  flex-shrink: 0;
  height: 6px;
  background: var(--border);
  cursor: ns-resize;
  position: relative;
  transition: background 0.2s;
  user-select: none;
}
.hero-resize:hover,
.hero-resize.dragging {
  background: var(--accent-dim);
}
.hero-resize::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.45;
}

/* ── END Hero Eyes ─────────────────────────────────────────── */

/* ── Messages ──────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  background:
    radial-gradient(ellipse at 80% 5%,  rgba(109, 40, 217, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 15% 90%, rgba(139, 92, 246, 0.05) 0%, transparent 45%),
    var(--bg);
}

/* System message (session start, errors) */
.system-message {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
  padding: 6px 18px;
  background: rgba(167, 139, 250, 0.08);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: var(--radius-pill);
  align-self: center;
  max-width: 80%;
  letter-spacing: 0.3px;
}

.message {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 80%;
  animation: msg-in 0.22s ease-out;
}
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.maya { align-self: flex-start; }

.message-avatar {
  font-size: 24px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.message-content { display: flex; flex-direction: column; gap: 4px; }
.message.user .message-content { align-items: flex-end; }

/* Bubbles */
.bubble {
  padding: 13px 18px;
  border-radius: var(--radius-msg);
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
  font-size: 15px;
  font-weight: 500;
}

/* Markdown rendering inside MAYA bubbles */
.message.maya .bubble { white-space: normal; }
.bubble ul, .bubble ol { margin: 6px 0 6px 18px; padding: 0; }
.bubble li { margin: 2px 0; line-height: 1.6; }
.bubble strong { font-weight: 700; }
.bubble .md-heading { display: block; font-size: 1.05em; margin: 4px 0 2px; }

/* ── User bubble — vibrant indigo-violet cloud ──────────────── */
.message.user .bubble {
  background: linear-gradient(145deg, var(--user-from) 0%, var(--user-to) 60%, #a855f7 100%);
  color: #f0ebff;
  border-bottom-right-radius: 6px;
  border: none;
  box-shadow: 0 6px 24px rgba(99, 56, 237, 0.38),
              0 2px 6px rgba(0, 0, 0, 0.25),
              0 1px 0 rgba(255,255,255,0.08) inset;
}

/* ── MAYA bubble — cloud lavender ───────────────────────────── */
.message.maya .bubble {
  background: linear-gradient(145deg, #1e1650 0%, #231960 60%, #1a1448 100%);
  border: 1px solid rgba(167,139,250,0.35);
  border-bottom-left-radius: 6px;
  color: #ede9ff;
  box-shadow: 0 6px 28px rgba(109,64,209,0.22),
              0 2px 8px rgba(0,0,0,0.3),
              0 0 0 1px rgba(167,139,250,0.08) inset;
  position: relative;
}

/* Cloud speech tail on MAYA bubble */
.message.maya .bubble::before {
  content: '';
  position: absolute;
  bottom: 10px;
  left: -10px;
  border: 10px solid transparent;
  border-right-color: #1e1650;
  border-left: 0;
}

/* Provider / language badges */
.message-badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.provider-badge, .lang-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.provider-badge { background: var(--accent-glow); color: var(--accent-light); }
.lang-badge     { background: rgba(52,211,153,0.12); color: var(--practiced); }

/* ── Thinking indicator ────────────────────────────────────── */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 24px;
  font-size: 13px;
  color: var(--text-dim);
}
.thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}
.thinking-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  animation: dot-bounce 1.3s ease-in-out infinite;
  opacity: 0.85;
}
.thinking-dots span:nth-child(1) { background: #a78bfa; }
.thinking-dots span:nth-child(2) { background: #60a5fa; animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { background: #34d399; animation-delay: 0.4s; }
.thinking-text { font-size: 12px; color: var(--text-dim); }

/* ── Input area ────────────────────────────────────────────── */
.input-area {
  padding: 12px 16px 16px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  border-top: 1px solid rgba(167,139,250,0.1);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  padding: 12px 22px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  resize: none;
  max-height: 120px;
  outline: none;
  line-height: 1.55;
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
  scrollbar-width: thin;
}
#input:focus {
  border-color: var(--accent);
  background: rgba(139, 110, 245, 0.08);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.12);
}
#input::placeholder { color: var(--text-dim); font-style: italic; font-weight: 400; }

.send-btn {
  background: linear-gradient(135deg, #6d28d9, #8b5cf6, #a78bfa);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0 22px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  height: 44px;
  min-width: 52px;
  align-self: flex-end;
  flex-shrink: 0;
  transition: transform 0.12s, box-shadow 0.15s, background 0.2s;
  box-shadow: 0 4px 18px rgba(109, 40, 217, 0.45);
  letter-spacing: -0.5px;
}
.send-btn:hover:not(:disabled) {
  transform: scale(1.07) translateY(-1px);
  box-shadow: 0 8px 26px rgba(109, 40, 217, 0.6);
  background: linear-gradient(135deg, #7c3aed, #9d74f7, #c4b5fd);
}
.send-btn:active:not(:disabled) { transform: scale(0.97); }
.send-btn:disabled { opacity: 0.22; cursor: default; box-shadow: none; }

/* ── Mic button ────────────────────────────────────────────── */
.mic-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 10px;
  height: 40px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  align-self: flex-end;
  transition: background 0.2s, color 0.2s;
  line-height: 1;
}
.mic-btn:hover { background: rgba(167, 139, 250, 0.1); color: var(--accent-light); }
.mic-btn.listening {
  color: var(--offline);
  background: rgba(248, 113, 113, 0.1);
  animation: mic-pulse 1s ease-in-out infinite;
}
/* Push-to-talk active — holding button — green glow pulse */
.mic-btn.ptt-active {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.15);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.45);
  animation: mic-pulse 0.7s ease-in-out infinite;
}
/* MAYA is talking — tap to interrupt — cyan glow pulse */
.mic-btn.maya-talking {
  color: #00e5ff;
  background: rgba(0, 229, 255, 0.1);
  animation: mic-interrupt 1.4s ease-in-out infinite;
}
.mic-btn[hidden] { display: none; }

/* ── Keyframes ─────────────────────────────────────────────── */
@keyframes star-twinkle {
  0%   { opacity: 0.6; }
  30%  { opacity: 1.0; }
  60%  { opacity: 0.7; }
  100% { opacity: 0.9; }
}

@keyframes nebula-pulse {
  from { opacity: 0.6; transform: translate(-50%, -50%) scale(1.0); }
  to   { opacity: 1.0; transform: translate(-50%, -50%) scale(1.15); }
}

@keyframes mic-pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.5; transform: scale(1.12); }
}

@keyframes mic-interrupt {
  0%, 100% { box-shadow: 0 0 0px  rgba(0, 229, 255, 0);    }
  50%       { box-shadow: 0 0 16px rgba(0, 229, 255, 0.5);  }
}

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.4; }
  40%           { transform: scale(1.2);  opacity: 1;   }
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

/* ── Responsive: tablet / mobile (< 900px) ─────────────────── */
@media (max-width: 900px) {
  .header-controls { gap: 8px; }
  .select-group label { display: none; }
}

/* ── Responsive: RPi 800×480 touch screen ──────────────────── */
@media (max-width: 900px) and (pointer: coarse) {
  :root { --header-h: 62px; }

  .send-btn   { height: 48px; font-size: 18px; padding: 0 22px; }
  .mic-btn    { height: 48px; font-size: 22px; padding: 0 12px; }
  #input      { font-size: 15px; padding: 11px 16px; }
  .message    { max-width: 92%; }
  .messages   { padding: 16px 14px 10px; }
  .input-area { padding: 10px 14px 14px; }
  .icon-btn   { font-size: 22px; padding: 8px 10px; }
  .select-group select { padding: 6px 26px 6px 12px; font-size: 14px; }
}

/* ── Todos / Reminders ─────────────────────────────────────── */
.todo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 4px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
  flex-shrink: 0;
  box-sizing: border-box;
}

.todo-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
}

.todo-text {
  flex: 1;
  word-break: break-word;
}

.todo-due-label {
  font-size: 11px;
  opacity: 0.6;
}

.todo-done-btn {
  background: rgba(109,40,217,0.15);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.todo-done-btn:hover { background: var(--accent); color: #fff; }

.todo-del-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s;
}
.todo-del-btn:hover { color: #f87171; }

.todo-add-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  padding: 9px 14px;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}
.todo-input:focus { border-color: var(--accent); }

.todo-due {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  padding: 7px 12px;
  box-sizing: border-box;
  outline: none;
  width: 100%;
  color-scheme: dark;
  transition: border-color 0.2s;
}
.todo-due:focus { border-color: var(--accent); }

.todo-add-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: 12px;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 700;
  padding: 9px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.todo-add-btn:hover { opacity: 0.88; }

/* ── PIN lock overlay ──────────────────────────────────────── */
#pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}
#pin-overlay.pin-fade-out {
  opacity: 0;
  pointer-events: none;
}

#pin-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 32px 36px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: 28px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.5),
              0 0 0 1px rgba(167,139,250,0.08) inset;
  width: min(340px, 92vw);
}

.pin-logo {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(130deg, #e0c3fc 0%, var(--accent-light) 40%, var(--accent) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
  user-select: none;
}

.pin-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -14px;
  letter-spacing: 0.3px;
}

.pin-dots {
  display: flex;
  gap: 18px;
  padding: 6px 0;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--accent-dim);
  background: transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.15);
}
.pin-dot.error {
  background: #f87171;
  border-color: #f87171;
}

.pin-error {
  font-size: 13px;
  color: #f87171;
  font-weight: 600;
  letter-spacing: 0.2px;
  min-height: 18px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.pin-key {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 20px;
  font-weight: 700;
  height: 58px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:hover {
  background: var(--bg);
  border-color: var(--accent-dim);
}
.pin-key:active {
  transform: scale(0.93);
  background: var(--accent-glow);
  border-color: var(--accent);
}

.pin-key-del {
  font-size: 18px;
  color: var(--text-muted);
}
.pin-key-del:hover { color: var(--text); }

.pin-key-empty {
  /* placeholder for bottom-left cell */
}

@keyframes pin-shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX( 8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX( 5px); }
}
.pin-dots.shake { animation: pin-shake 0.45s ease; }

/* ── Scrollbars (Webkit) ───────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
