:root {
  color-scheme: dark;
  --bg-main: #111b2b;
  --bg-sidebar: #0c1422;
  --bg-composer: #1a2a3d;
  --bg-hover: #22344a;
  --bg-surface: #18263a;
  --bg-input: #101b2b;
  --border: #2d4058;
  --border-strong: #3a506b;
  --text-main: #edf4ff;
  --text-dim: #a4b4c9;
  --text-subtle: #8293aa;
  --accent: #9dc7ff;
  --edu-green: #34d399;
  --rude-red: #f87171;
  --device-gutter: 22px;
  --control-size: 36px;
}

body[data-theme="charcoal"] {
  --bg-main: #171717;
  --bg-sidebar: #111111;
  --bg-composer: #212121;
  --bg-hover: #2a2a2a;
  --bg-surface: #1f1f1f;
  --bg-input: #141414;
  --border: #2f2f2f;
  --border-strong: #444444;
  --text-main: #ececec;
  --text-dim: #9b9b9b;
  --text-subtle: #737373;
  --accent: #9dc7ff;
}

body[data-theme="forest"] {
  --bg-main: #111d1a;
  --bg-sidebar: #0b1512;
  --bg-composer: #192923;
  --bg-hover: #243a30;
  --bg-surface: #17251f;
  --bg-input: #101b16;
  --border: #30463a;
  --border-strong: #496552;
  --text-main: #edf5ef;
  --text-dim: #a8b9ad;
  --text-subtle: #82988a;
  --accent: #a7e0bd;
}

body[data-theme="lavender"] {
  --bg-main: #1c1828;
  --bg-sidebar: #14111e;
  --bg-composer: #292338;
  --bg-hover: #352d48;
  --bg-surface: #241f32;
  --bg-input: #191624;
  --border: #403653;
  --border-strong: #594b70;
  --text-main: #f4efff;
  --text-dim: #c0b3d8;
  --text-subtle: #998bad;
  --accent: #d1b3ff;
}

body[data-theme="rose"] {
  --bg-main: #28171d;
  --bg-sidebar: #1d1116;
  --bg-composer: #382129;
  --bg-hover: #492b36;
  --bg-surface: #301d25;
  --bg-input: #21141a;
  --border: #51313d;
  --border-strong: #704453;
  --text-main: #fff0f3;
  --text-dim: #d8b5c0;
  --text-subtle: #b18b98;
  --accent: #ffb6c8;
}

body[data-theme="sunset"] {
  --bg-main: #271b19;
  --bg-sidebar: #1d1413;
  --bg-composer: #38251f;
  --bg-hover: #4a3027;
  --bg-surface: #30211d;
  --bg-input: #211816;
  --border: #563a2e;
  --border-strong: #74503b;
  --text-main: #fff2e8;
  --text-dim: #d8b9a2;
  --text-subtle: #b59680;
  --accent: #ffc078;
}

body[data-theme="ocean"] {
  --bg-main: #101f27;
  --bg-sidebar: #0a171e;
  --bg-composer: #172d36;
  --bg-hover: #20404a;
  --bg-surface: #15262f;
  --bg-input: #0d1b22;
  --border: #29444d;
  --border-strong: #3b5f67;
  --text-main: #e9fbff;
  --text-dim: #a8c6ce;
  --text-subtle: #829fa8;
  --accent: #81e1e6;
}

body[data-theme="contrast"] {
  --bg-main: #000;
  --bg-sidebar: #000;
  --bg-composer: #111;
  --bg-hover: #252525;
  --bg-surface: #090909;
  --bg-input: #000;
  --border: #fff;
  --border-strong: #fff;
  --text-main: #fff;
  --text-dim: #fff;
  --text-subtle: #e6e6e6;
  --accent: #ffed00;
}

* { box-sizing: border-box; }

html[data-text-size="small"] { font-size: 14px; }
html[data-text-size="normal"] { font-size: 16px; }
html[data-text-size="large"] { font-size: 18px; }

body[data-device-profile="phone"] {
  --device-gutter: 12px;
  --control-size: 44px;
}

body[data-device-profile="tablet"] {
  --device-gutter: 18px;
  --control-size: 44px;
}

body[data-device-profile="desktop"] {
  --device-gutter: 22px;
  --control-size: 36px;
}

html {
  min-width: 0;
  min-height: 100%;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

/* SLIM SIDEBAR (ChatGPT / Claude / Grok style) */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  transition: width 0.2s ease;
}


.sidebar.collapsed {
  width: 0;
  padding: 0;
  overflow: hidden;
  border: none;
}

.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px 12px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--text-main);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-size);
  min-height: var(--control-size);
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 1rem;
}

.sidebar-open-btn,
.sidebar-backdrop {
  display: none;
}

body.sidebar-collapsed .sidebar-open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text-main); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--control-size);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.new-chat-btn:hover { background: var(--bg-hover); }

.changelog-nav-btn,
.docs-nav-btn,
.pug-studios-nav-btn,
.install-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--control-size);
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg-main);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.changelog-nav-btn:hover,
.docs-nav-btn:hover,
.pug-studios-nav-btn:hover,
.install-nav-btn:hover {
  filter: brightness(1.08);
  color: var(--bg-main);
}


.sidebar-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-subtle);
  padding: 18px 12px 6px 12px;
}

.sidebar-search-input {
  width: 100%;
  min-height: 32px;
  margin: 2px 0 8px 0;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
}

.sidebar-search-input::placeholder {
  color: var(--text-subtle);
}

.history-list {
  flex: 1 0 auto;
  min-height: 140px;
  max-height: 45vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 8px 7px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  color: var(--text-main);
  cursor: pointer;
}

.history-item-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.history-item:hover .history-item-actions,
.history-item:focus-within .history-item-actions,
body[data-device-profile="tablet"] .history-item-actions,
body[data-device-profile="phone"] .history-item-actions {
  opacity: 1;
}

.history-action-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 0.74rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.history-action-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text-main);
}

.history-action-btn.danger:hover {
  border-color: var(--rude-red);
  color: var(--rude-red);
}

.history-item:hover, .history-item.active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.history-item:hover, .history-item.active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.encryption-pill {
  font-size: 0.74rem;
  color: var(--edu-green);
  padding: 4px 10px;
  opacity: 0.85;
}

.wipe-btn {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  font-size: 0.78rem;
  text-align: left;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  min-height: var(--control-size);
}

.wipe-btn:hover { color: var(--rude-red); }
.settings-btn { color: var(--text-dim); }
.settings-btn:hover { color: var(--text-main); background: var(--bg-hover); }

.account-profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--control-size);
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
  font-family: inherit;
}

.account-profile-btn:hover { background: var(--bg-hover); }

.avatar-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.account-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.account-meta span { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-meta small { font-size: 0.73rem; color: var(--text-dim); }

/* MAIN AREA */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
  min-width: 0;
  min-height: 0;
}

.topbar {
  padding: 14px var(--device-gutter);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.version-pill {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.holiday-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.76rem;
  padding: 3px 10px;
  border-radius: 999px;
}

.engine-status {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* CENTER STAGE */
.chat-stage {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 24px var(--device-gutter);
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

.welcome-card {
  margin: auto 0;
  text-align: center;
  position: relative;
  padding: 20px;
}

.prompt-chips {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.prompt-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.prompt-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* Subtle ambient radial glow */
.hero-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  height: 140px;
  background: radial-gradient(circle, rgba(93, 151, 221, 0.2) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.welcome-card h1 {
  position: relative;
  z-index: 1;
  font-size: 1.85rem;
  font-weight: 500;
  letter-spacing: -0.4px;
  margin: 0 0 8px 0;
  color: var(--text-main);
}

.welcome-card p {
  position: relative;
  z-index: 1;
  font-size: 0.88rem;
  color: var(--text-dim);
  margin: 0;
}

/* CHAT BUBBLES (Clean ChatGPT / Claude style) */
.bubble {
  line-height: 1.65;
  white-space: pre-wrap;
  font-size: 0.96rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.bubble.user {
  background: var(--bg-hover);
  color: var(--text-main);
  padding: 11px 18px;
  border-radius: 20px;
  max-width: 75%;
  align-self: flex-end;
}

.bubble.ai {
  background: transparent;
  color: var(--text-main);
  padding: 4px 0;
  width: 100%;
  max-width: 100%;
  align-self: flex-start;
}

.bubble-text a.citation-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble-text a.citation-link:hover { color: var(--text-main); }

.widget-card {
  width: 100%;
  min-width: 0;
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #171717;
}

.widget-card.is-expanded {
  position: fixed;
  inset: 12px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  width: auto;
  max-width: none;
  margin: 0;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.72);
}

.widget-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.widget-card-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.widget-card-title {
  min-width: 0;
  margin: 0;
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.widget-reload-btn,
.widget-expand-btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-hover);
  color: var(--text-main);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.widget-reload-btn:hover,
.widget-expand-btn:hover { filter: brightness(1.15); }

.aerial-widget-frame {
  display: block;
  width: 100%;
  height: min(68vh, 720px);
  min-height: 500px;
  border: none;
  border-radius: 0 0 12px 12px;
  background: #171717;
}

.widget-card.is-expanded .aerial-widget-frame {
  flex: 1 1 auto;
  height: 0;
  min-height: 0;
}

.bubble.ai.edu { border-left: 2px solid var(--edu-green); padding-left: 14px; }
.bubble.ai.rude { border-left: 2px solid var(--rude-red); padding-left: 14px; }

.media-tag {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--text-main);
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
}

.disclaimer {
  display: block;
  margin-top: 10px;
  font-size: 0.76rem;
  color: var(--text-subtle);
}

.bubble-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.bubble-action-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}

.bubble-action-btn:hover,
.bubble-action-btn.is-speaking {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-main);
}

.code-block-card {
  margin: 10px 0;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-input);
  overflow: hidden;
  white-space: normal;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.code-copy-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 3px 9px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.code-copy-btn:hover {
  border-color: var(--accent);
}

.code-block-pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-main);
  white-space: pre;
}

/* FLOATING PILL COMPOSER (Exact ChatGPT / Grok / Claude box) */
.composer-wrapper {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 0 var(--device-gutter) 16px;
  min-width: 0;
}

.attachment-preview {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-main);
}

.pill-composer {
  background: var(--bg-composer);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 14px 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.pill-composer input[type="text"] {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.98rem;
  width: 100%;
  min-width: 0;
  padding: 2px 0;
}

.pill-composer input[type="text"]:focus { outline: none; }
.pill-composer input[type="text"]::placeholder { color: var(--text-subtle); }

.composer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pill-tool-btn {
  width: var(--control-size);
  height: var(--control-size);
  flex: 0 0 var(--control-size);
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pill-tool-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-main); }
.pill-tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pill-tool-btn.is-listening {
  border-color: var(--rude-red);
  color: var(--rude-red);
  background: rgba(248, 113, 113, 0.14);
}

.pill-select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.8rem;
  min-height: var(--control-size);
  cursor: pointer;
}

.pill-select.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.pill-select.subtle:hover { background: var(--bg-hover); color: var(--text-main); }
.pill-select:focus { outline: none; }

.send-circle-btn {
  width: var(--control-size);
  height: var(--control-size);
  flex: 0 0 var(--control-size);
  border-radius: 50%;
  background: #ffffff;
  color: #000000;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.send-circle-btn:disabled {
  background: var(--bg-hover);
  color: var(--text-subtle);
  cursor: not-allowed;
}

.bottom-caption {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-subtle);
  margin-top: 8px;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px;
}

.modal h2 {
  margin: 0 0 14px 0;
  font-size: 1.15rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 10px;
}

.tab-btn {
  flex: 1;
  min-height: var(--control-size);
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
}

.tab-btn.active { background: var(--bg-hover); color: var(--text-main); }

.form-group { margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.8rem; color: var(--text-dim); }
.settings-description { margin: 0; color: var(--text-dim); font-size: 0.82rem; }
.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  cursor: pointer;
}
.setting-toggle input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}
.setting-help { margin: 0; color: var(--text-subtle); font-size: 0.74rem; line-height: 1.4; }

.modal input, .modal select, .modal textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.class-create-row input { width: auto; }

.primary-btn {
  width: 100%;
  min-height: var(--control-size);
  background: #fff;
  color: #000;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.primary-btn:hover { background: #e5e5e5; }

.secondary-btn {
  flex: 1;
  min-height: var(--control-size);
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.secondary-btn:hover { background: var(--bg-hover); }

.consent-copy {
  color: #d4d4d4;
  font-size: 0.86rem;
  line-height: 1.55;
}

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 18px 0;
  color: var(--text-main);
  font-size: 0.86rem;
  line-height: 1.45;
}

.consent-check input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.consent-actions {
  display: flex;
  gap: 10px;
}

.consent-actions .primary-btn {
  flex: 1;
  width: auto;
}

.danger-btn {
  width: 100%;
  margin-top: 16px;
  background: transparent;
  border: 1px solid #451a1a;
  color: var(--rude-red);
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}

.readonly-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  color: #9ca3af;
  line-height: 1.5;
}

.status-msg { font-size: 0.82rem; margin-top: 10px; color: #d4d4d4; }

.bunny-scene {
  display: none;
  position: fixed;
  z-index: 20;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(116px + env(safe-area-inset-bottom));
  align-items: flex-end;
  justify-content: space-between;
  width: 136px;
  height: 48px;
  pointer-events: none;
  font-family: sans-serif;
}

body[data-bunny-enabled="true"] .bunny-scene[data-playing="true"] { display: flex; }

.bunny-character {
  display: inline-block;
  font-size: 2rem;
  line-height: 1;
  transform-origin: center bottom;
  animation: bunny-hop var(--bunny-duration, 2.8s) ease-in-out infinite;
}

.bunny-carrot {
  display: inline-block;
  font-size: 1.5rem;
  line-height: 1;
  transform-origin: center;
  animation: carrot-eaten var(--bunny-duration, 2.8s) ease-in-out infinite;
}

body[data-bunny-mode="once"] .bunny-character,
body[data-bunny-mode="once"] .bunny-carrot {
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
}

body[data-animation-speed="slow"] { --bunny-duration: 4.4s; }
body[data-animation-speed="normal"] { --bunny-duration: 2.8s; }
body[data-animation-speed="fast"] { --bunny-duration: 1.6s; }

@keyframes bunny-hop {
  0%, 8% { transform: translate(0, 0) rotate(0); }
  22% { transform: translate(24px, -24px) rotate(-8deg); }
  36% { transform: translate(46px, 0) rotate(0); }
  50% { transform: translate(70px, -22px) rotate(7deg); }
  64%, 75% { transform: translate(88px, 0) scale(0.94); }
  84% { transform: translate(88px, 0) scale(0.86) rotate(8deg); }
  100% { transform: translate(88px, 0) scale(1); }
}

@keyframes carrot-eaten {
  0%, 64% { opacity: 1; transform: scale(1) rotate(0); }
  78% { opacity: 0.7; transform: scale(0.65) rotate(-14deg); }
  90%, 100% { opacity: 0; transform: scale(0.1) rotate(20deg); }
}

html[dir="rtl"] .sidebar { border-right: 0; border-left: 1px solid var(--border); }
html[dir="rtl"] .sidebar.collapsed { border-left: 0; }

@media (max-width: 900px) {
  .bunny-scene { bottom: calc(184px + env(safe-area-inset-bottom)); }

  html[dir="rtl"] .sidebar {
    inset: 0 0 0 auto;
    border-left: 1px solid var(--border);
  }

  html[dir="rtl"] .sidebar.collapsed {
    transform: translateX(105%);
    border-left: 1px solid #222;
  }
}

html[data-reduced-motion="true"] *,
html[data-reduced-motion="true"] *::before,
html[data-reduced-motion="true"] *::after {
  scroll-behavior: auto !important;
  transition-duration: 0.01ms !important;
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
}

html[data-reduced-motion="true"] .bunny-character,
html[data-reduced-motion="true"] .bunny-carrot {
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  html:not([data-reduced-motion="false"]) *,
  html:not([data-reduced-motion="false"]) *::before,
  html:not([data-reduced-motion="false"]) *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  html:not([data-reduced-motion="false"]) .bunny-character,
  html:not([data-reduced-motion="false"]) .bunny-carrot {
    animation: none !important;
  }
}
body[data-device-profile="tablet"] .chat-stage,
body[data-device-profile="tablet"] .composer-wrapper {
  max-width: 860px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 1024px) {
  .sidebar { width: 230px; }
  .sidebar.collapsed { width: 0; }
  .topbar { padding-right: 16px; padding-left: 16px; }
}

@media (max-width: 600px) {
  .widget-card.is-expanded { inset: 6px; }
  .aerial-widget-frame {
    height: min(62vh, 600px);
    min-height: 360px;
  }
}

@media (max-height: 520px) {
  .aerial-widget-frame {
    height: min(60vh, 480px);
    min-height: 280px;
  }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(84vw, 300px);
    height: 100vh;
    height: 100dvh;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateX(0);
    transition: transform 0.22s ease;
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.4);
  }

  .sidebar.collapsed {
    width: min(84vw, 300px);
    padding: 12px;
    overflow: hidden;
    border-right: 1px solid #222;
    transform: translateX(-105%);
    box-shadow: none;
  }

  .sidebar-open-btn {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-width: var(--control-size);
    min-height: var(--control-size);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 39;
    padding: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
  }

  body.sidebar-open .sidebar-backdrop { display: block; }
  body.sidebar-open { overflow: hidden; }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }

  .topbar-left {
    flex: 1 1 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .topbar-right { width: 100%; min-width: 0; }
  .engine-status { line-height: 1.4; overflow-wrap: anywhere; }
  .version-pill { font-size: 0.82rem; }

  .chat-stage {
    padding: 16px 12px;
    gap: 16px;
  }

  .welcome-card { padding: 16px 4px; }
  .welcome-card h1 { font-size: clamp(1.35rem, 6vw, 1.85rem); }
  .bubble.user { max-width: 90%; padding: 10px 14px; }

  .composer-wrapper {
    padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  }

  .pill-composer { padding: 10px 12px; border-radius: 18px; }
  .pill-composer input[type="text"] { font-size: 16px; }
  .composer-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar-left .pill-select { flex: 1; min-width: 0; }
  .toolbar-right .pill-select { flex: 1; width: 0; min-width: 0; }
  .pill-select { min-height: var(--control-size); font-size: 0.76rem; }
  .pill-tool-btn, .send-circle-btn {
    width: var(--control-size);
    height: var(--control-size);
    flex-basis: var(--control-size);
  }
  .bottom-caption { font-size: 0.66rem; line-height: 1.4; padding: 0 4px; }

  .modal-backdrop {
    align-items: flex-start;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  }

  .modal {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    padding: 18px;
    border-radius: 14px;
  }

  .modal input, .modal select, .modal textarea { font-size: 16px; }
  .tabs { flex-wrap: wrap; }
  .tab-btn { min-width: calc((100% - 12px) / 3); }
  .class-create-row { flex-wrap: wrap; }
  .class-create-row input { flex: 1 1 160px; }
  .readonly-box { overflow-wrap: anywhere; }
}

@media (max-width: 380px) {
  .topbar {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }
  .chat-stage { padding-right: 10px; padding-left: 10px; }
  .composer-wrapper { padding-right: 7px; padding-left: 7px; }
  .pill-composer { padding-right: 9px; padding-left: 9px; }
  .consent-actions { flex-direction: column-reverse; }
  .consent-actions .primary-btn { min-height: 42px; }
}

@media (max-height: 520px) and (max-width: 900px) {
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .chat-stage { padding-top: 10px; padding-bottom: 10px; }
  .welcome-card { padding-top: 8px; padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

@media (max-width: 900px) {
  html[dir="rtl"] .sidebar.collapsed { transform: translateX(105%); }
}

/* BATCH 1: LIVE SIDEBAR CLOCK, TOPBAR UTILITIES & ZEN MODE */
.sidebar-live-clock {
  margin: 0 0 10px 0;
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
}

.topbar-utilities {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}

.topbar-util-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.topbar-util-btn:hover,
.topbar-util-btn.is-active {
  background: var(--bg-hover);
  border-color: var(--accent);
}

body.zen-mode .sidebar,
body.zen-mode .sidebar-backdrop {
  display: none !important;
}

body.zen-mode .chat-area {
  max-width: 960px;
  margin: 0 auto;
}

/* BATCH 2: PINNED CHATS & PUG PARTY EMOJI RAIN */
.history-item.is-pinned {
  border: 1px solid var(--accent);
}

.pug-rain-drop {
  position: fixed;
  top: -40px;
  font-size: 1.8rem;
  z-index: 9999;
  pointer-events: none;
  animation: pugFall 2.8s linear forwards;
}

@keyframes pugFall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0.15;
  }
}

/* BATCH 3: SPEED/WORD BADGE, SYSTEM DIAGNOSTICS & ACHIEVEMENTS */
.bubble-metrics-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--text-subtle);
  font-weight: 500;
}

.diagnostics-grid,
.achievements-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diag-row,
.achievement-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 0.84rem;
}

.achievement-card.is-unlocked {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.achievement-card.is-locked {
  opacity: 0.55;
}

.achievement-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  transform: translateY(140%);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

.achievement-toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}
