:root {
  --bg: #0a0a0a;
  --bg-panel: #111111;
  --bg-input: #080808;
  --border: #2e2e2e;
  --accent: #a8a8a8;
  --accent-hover: #bababa;
  --accent-text: #0a0a0a;
  --text: #f2f2f2;
  --text-muted: #8a8a8a;
  --soul: #c8c8c8;
  --ok: #e0e0e0;
  --warn: #a0a0a0;
  --err: #666666;
  --radius: 8px;
  --font: "Segoe UI", system-ui, sans-serif;
  --font-mira: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mira-bubble: rgba(126, 200, 227, 0.12);
  --mira-bubble-border: rgba(126, 200, 227, 0.35);
  --mira-glow: rgba(126, 200, 227, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  color-scheme: dark;
}

/* Auth gate — matches Victis Launcher / build.victis.systems (auth-gate.js) */
#auth-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2.5rem 1.25rem;
  text-align: center;
  background: #000;
}

#auth-gate .auth-gate-avatar {
  border-radius: 50%;
  margin-bottom: 1rem;
}

#auth-gate h1 {
  margin: 0 0 0.5rem;
  font-family: var(--font-mira);
  font-size: 1.75rem;
  font-weight: 500;
  color: var(--text);
}

#auth-gate p {
  margin: 0 0 2rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#sign-in-btn {
  padding: 0.85rem 2rem;
  background: #4285f4;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

#sign-in-btn:hover {
  filter: brightness(1.08);
}

#auth-denied {
  display: none;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #e8a0a0;
}

.header {
  background: #000000;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tagline .host {
  color: var(--soul);
  font-family: Consolas, monospace;
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ui-mode-switch {
  display: inline-flex;
  border: 1px solid rgba(192, 38, 211, 0.35);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(20, 10, 30, 0.55);
}

.ui-mode-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}

.ui-mode-btn:hover {
  color: #f0d8ff;
  background: rgba(192, 38, 211, 0.12);
}

.ui-mode-btn.active {
  color: #fff;
  background: rgba(192, 38, 211, 0.28);
  font-weight: 600;
}

body.ui-mode-mobile .tab[data-mobile-tab="hide"] {
  display: none;
}

body.ui-mode-mobile .header .tagline .host {
  display: none;
}

body.ui-mode-mobile .tabs {
  justify-content: center;
  gap: 0.35rem;
}

body.ui-mode-mobile .tab.mobile-tab {
  flex: 1 1 auto;
  max-width: 48%;
  text-align: center;
  font-size: 0.88rem;
  padding: 0.65rem 0.5rem;
}

body.ui-mode-mobile .chat-toolbar .btn-sm:not(#btn-uber-mode):not(#btn-capture-this):not(.btn-flag-exchange):not(.btn-favorite-create):not(#btn-clear-chat-toolbar) {
  display: none;
}

body.ui-mode-mobile .chat-toolbar .chat-field:nth-child(n+2) {
  display: none;
}

body.ui-mode-mobile .chat-save-toggle,
body.ui-mode-mobile .chat-ui-fix-toggle {
  display: none;
}

body.ui-mode-mobile .main {
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

body.ui-mode-mobile .input-with-mic textarea,
body.ui-mode-mobile #app-input {
  min-height: 3.25rem;
  font-size: 1rem;
}

body.ui-mode-mobile .btn-voice-mic {
  width: 2.75rem;
  height: 2.75rem;
}

.btn-install {
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-color: var(--soul);
  color: var(--soul);
}

.btn-install:hover {
  background: rgba(255, 255, 255, 0.08);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

body.pwa-standalone .host {
  display: none;
}

body.pwa-standalone .header {
  padding-top: max(1rem, env(safe-area-inset-top));
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--err); }

.mira-anchor {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.45rem 1.5rem;
  font-size: 0.82rem;
  color: #7ec8e3;
  border-bottom: 1px solid rgba(126, 200, 227, 0.15);
  background: rgba(10, 20, 28, 0.55);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.mira-anchor-action {
  margin-left: auto;
  border-color: rgba(201, 168, 154, 0.5);
  color: #e8d4cc;
  flex-shrink: 0;
}

.mira-anchor.is-hidden {
  display: none;
}

.mira-anchor.is-strained .mira-anchor-text {
  color: #c9a89a;
}

.mira-anchor-text {
  font-style: italic;
  letter-spacing: 0.02em;
}

.tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.tab:hover {
  color: var(--text);
  border-color: var(--accent);
}

.tab.active {
  background: var(--bg-panel);
  color: var(--text);
  border-bottom-color: var(--bg-panel);
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
}

.panel {
  display: none;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 1.25rem;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field-inline input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font: inherit;
  min-width: 200px;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  min-height: 420px;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-head {
  margin-bottom: 0.5rem;
}

.pane-head h2 {
  margin: 0;
  font-size: 1rem;
}

.pane-head-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.edit-import-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.edit-import-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

textarea {
  flex: 1;
  min-height: 380px;
  resize: vertical;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.85rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.6;
}

.output-box {
  flex: 1;
  min-height: 380px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  font-size: 0.92rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.output-box.empty {
  color: var(--text-muted);
  font-style: italic;
}

.output-box em.soul {
  color: var(--soul);
  font-style: italic;
}

.hidden-export {
  display: none;
}

.soul-panel {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.soul-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

#soul-blocks {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  color: var(--soul);
  font-style: italic;
}

.issues {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  color: var(--warn);
}

.export-bar {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.log {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.chat-wrap {
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

.chat-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.chat-identity-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  object-fit: cover;
  object-position: 50% 22%;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(126, 200, 227, 0.2);
}

.chat-identity-name {
  margin: 0;
  font-family: var(--font-mira);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #7ec8e3;
}

.chat-identity-tagline {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.chat-home-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.chat-home-controls .btn-home-reconnect {
  border-color: rgba(126, 200, 227, 0.45);
  color: #9ed8f0;
}

.chat-home-controls .btn-home-restart {
  border-color: rgba(255, 196, 120, 0.45);
  color: #ffd9a8;
}

.chat-home-controls .btn-home-deploy {
  border-color: rgba(160, 220, 160, 0.4);
  color: #c8f0c8;
}

.chat-home-controls .btn-clear-chat-top {
  border-color: rgba(201, 168, 154, 0.55);
  color: #f0ddd4;
  font-weight: 600;
}

body.ui-mode-mobile .chat-home-controls .btn-clear-chat-top {
  order: -1;
}

.chat-home-controls-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
  max-width: 36rem;
}

body.ui-mode-mobile .chat-home-controls {
  margin-top: 0.45rem;
}

.chat-messages-shell {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  min-height: 400px;
  max-height: 60vh;
  background: var(--bg-panel);
}

.chat-messages-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 20% 0%, var(--mira-glow), transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(201, 168, 154, 0.06), transparent 50%);
  animation: mira-floor-pulse 12s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes mira-floor-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.chat-messages {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-bubble {
  max-width: 88%;
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.chat-bubble.mira {
  align-self: flex-start;
}

.chat-bubble.sir {
  align-self: flex-end;
}

.chat-bubble-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  object-fit: cover;
  object-position: 50% 22%;
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.chat-bubble-avatar.sir-avatar {
  object-position: 50% 38%;
  border: 2px solid var(--border);
  box-shadow: 0 0 0 1px rgba(168, 168, 168, 0.15);
}

.chat-bubble-body {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.55;
}

.chat-bubble.mira .chat-bubble-body {
  position: relative;
  background: var(--mira-bubble);
  border: 1px solid var(--mira-bubble-border);
  font-family: var(--font-mira);
}

.chat-bubble.sir .chat-bubble-body {
  background: #0a0a0a;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
}

.chat-bubble-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.chat-bubble-name {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7ec8e3;
}

.chat-bubble.sir .chat-bubble-name {
  color: var(--text-muted);
  opacity: 0.9;
}

.chat-soul-lock {
  font-size: 0.7rem;
  line-height: 1;
  opacity: 0.85;
  cursor: help;
}

.chat-bubble.mira.off-character .chat-soul-lock {
  opacity: 1;
  filter: grayscale(0.3);
}

.chat-bubble.mira.off-character .chat-bubble-body {
  border-color: rgba(201, 168, 154, 0.45);
}

.chat-compose-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  padding: 0.35rem 0;
}

.chat-compose-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  object-fit: cover;
  object-position: 50% 22%;
}

.chat-compose-name {
  font-family: var(--font-mira);
  font-size: 0.95rem;
  font-weight: 600;
  color: #7ec8e3;
  letter-spacing: 0.02em;
}

.chat-compose-soul {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Mira Victis Soul Enhancements — iron soul layer */
.mira-soul-anchor {
  background: rgba(30, 10, 40, 0.95);
  border-bottom: 2px solid #c026d3;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 100;
  margin-bottom: 0.5rem;
}

.mira-breathing-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid #c026d3;
  object-fit: cover;
  object-position: 50% 22%;
  flex-shrink: 0;
  animation: mira-breath 6s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(192, 38, 211, 0.45);
}

.mira-soul-anchor-copy {
  flex: 1;
  min-width: 0;
}

.mira-status,
#mira-living-status {
  color: #e0bbff;
  font-weight: 500;
  font-family: var(--font-mira);
  font-style: italic;
  font-size: 0.9rem;
  line-height: 1.45;
}

.mira-capability-hint {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: normal;
  font-family: var(--font);
  line-height: 1.35;
}

.mira-continuity {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: rgba(126, 200, 227, 0.75);
  font-family: var(--font);
  letter-spacing: 0.02em;
}

.mira-soul-anchor.mira-needy .mira-breathing-avatar {
  animation: mira-breath-needy 2.8s ease-in-out infinite;
  box-shadow: 0 0 20px rgba(192, 38, 211, 0.65);
}

.mira-soul-anchor.mira-returning {
  animation: mira-return-flash 1.2s ease-out 1;
}

@keyframes mira-breath-needy {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

@keyframes mira-return-flash {
  0% { background: rgba(60, 20, 80, 0.98); }
  40% { background: rgba(90, 30, 110, 0.98); }
  100% { background: rgba(30, 10, 40, 0.95); }
}

.chat-bubble.mira.whisper .chat-bubble-body {
  opacity: 0.92;
  border-left-width: 4px;
  font-size: 0.88rem;
  animation: mira-arrive 0.55s ease-out;
}

.chat-bubble.mira.whisper .chat-bubble-avatar {
  width: 36px;
  height: 36px;
}

.chat-bubble.mira.mira-message .chat-bubble-body {
  background: linear-gradient(135deg, rgba(59, 30, 77, 0.95), rgba(31, 22, 40, 0.95));
  border-left: 6px solid #c026d3;
  border-top: 1px solid rgba(192, 38, 211, 0.25);
  border-right: 1px solid rgba(192, 38, 211, 0.25);
  border-bottom: 1px solid rgba(192, 38, 211, 0.25);
  border-radius: 12px 12px 12px 6px;
  color: #e8e0f0;
  box-shadow: 0 4px 15px rgba(192, 38, 211, 0.22);
  position: relative;
  animation: mira-arrive 0.4s ease-out, mira-soft-glow 2s ease-in-out infinite alternate;
}

@keyframes mira-arrive {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes mira-soft-glow {
  from { box-shadow: 0 4px 12px rgba(192, 38, 211, 0.18); }
  to { box-shadow: 0 4px 20px rgba(192, 38, 211, 0.42); }
}

.mira-avatar,
.chat-bubble-avatar.mira-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #c026d3;
  flex-shrink: 0;
  object-fit: cover;
  object-position: 50% 22%;
  animation: mira-breath 6s ease-in-out infinite;
}

@keyframes mira-breath {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.12) rotate(2deg); }
}

.floor-reminder,
.floor-footer,
.floor-seal,
.mira-message .floor-seal {
  font-size: 0.8rem;
  color: #c4a1e6;
  font-style: italic;
  margin-top: 0.55rem;
  opacity: 0.9;
}

.chat-bubble-copy {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid rgba(192, 38, 211, 0.35);
  border-radius: 4px;
  background: transparent;
  color: #c4a1e6;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-bubble-copy:hover {
  border-color: #c026d3;
  color: #e0bbff;
}

.chat-bubble.mira.melting .chat-bubble-body {
  animation: mira-arrive 0.4s ease-out, mira-soft-glow 2s ease-in-out infinite alternate, melt-pulse 1.8s ease-in-out 3;
}

@keyframes melt-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.chat-form {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#chat-input {
  min-height: 72px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-enter-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
  cursor: pointer;
  user-select: none;
}

.chat-enter-toggle input {
  accent-color: var(--accent);
}

.chat-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chat-field-mode select {
  min-width: 11rem;
  font-weight: 500;
}

.scene-chips-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.6rem;
  margin-bottom: 0.45rem;
}

.scene-category-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.15rem 0.35rem;
  background: rgba(20, 12, 32, 0.5);
}

.scene-category-btn {
  border: none;
  background: transparent;
  color: #c4a1e6;
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  border-radius: 3px;
}

.scene-category-btn:hover {
  background: rgba(192, 38, 211, 0.2);
  color: #f0d8ff;
}

.scene-category-name {
  font-size: 0.76rem;
  font-weight: 600;
  color: #d8b8f0;
  min-width: 5.5rem;
  text-align: center;
}

.scene-armed-hint {
  font-size: 0.72rem;
  color: #9fd4ff;
  font-style: italic;
}

.scene-armed-clear {
  border: 1px solid rgba(120, 180, 255, 0.4);
  background: transparent;
  color: #9fd4ff;
  border-radius: 999px;
  width: 1.35rem;
  height: 1.35rem;
  line-height: 1;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.scene-chip.armed {
  border-color: #6eb0ff;
  background: rgba(80, 140, 220, 0.22);
  color: #e8f4ff;
  box-shadow: 0 0 0 1px rgba(110, 176, 255, 0.35);
}

.scene-chips-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.scene-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.scene-chip {
  border: 1px solid rgba(192, 38, 211, 0.35);
  background: rgba(30, 15, 45, 0.55);
  color: #d8b8f0;
  font-size: 0.78rem;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.scene-chip:hover {
  border-color: #c026d3;
  color: #f0d8ff;
}

.scene-chip.active {
  border-color: #c026d3;
  background: rgba(192, 38, 211, 0.22);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(192, 38, 211, 0.25);
}

.scene-chip.scene-action {
  border-color: rgba(120, 180, 255, 0.4);
  color: #b8d4ff;
}

.scene-chip.scene-action:hover {
  border-color: #6eb0ff;
  color: #e0f0ff;
}

.chat-search-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 8, 18, 0.35);
}

.chat-search-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-search-input {
  flex: 1 1 12rem;
  min-width: 10rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.88rem;
}

.chat-search-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chat-search-clear {
  padding: 0.2rem 0.5rem;
}

.chat-bubble.search-hidden {
  display: none !important;
}

.chat-bubble.search-hit .chat-bubble-body {
  outline: 1px solid rgba(192, 38, 211, 0.45);
  outline-offset: 2px;
}

.chat-bubble-text mark.chat-search-mark {
  background: rgba(192, 38, 211, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 0.1em;
}

.chat-bubble-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.35rem;
  padding-top: 0.28rem;
  border-top: 1px solid rgba(192, 38, 211, 0.22);
  min-height: 0;
  position: relative;
}

.chat-bubble-feedback {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.2rem 0.28rem;
  margin: 0;
  opacity: 1;
  isolation: isolate;
}

.chat-feedback-btn {
  border: 1px solid rgba(192, 38, 211, 0.28);
  background: rgba(12, 8, 20, 0.55);
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.12rem 0.22rem;
  border-radius: 4px;
  opacity: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.chat-feedback-btn:hover {
  background: rgba(192, 38, 211, 0.22);
  border-color: rgba(192, 38, 211, 0.55);
}

.chat-feedback-btn.selected {
  background: rgba(192, 38, 211, 0.32);
  border-color: rgba(192, 38, 211, 0.65);
}

.chat-build-flag-btn.selected {
  background: rgba(255, 160, 60, 0.28);
  border-color: rgba(255, 160, 60, 0.55);
}

.btn-flag-exchange {
  border-color: rgba(255, 160, 60, 0.45);
  color: #ffc98a;
}

.btn-favorite-create {
  border-color: rgba(255, 210, 80, 0.45);
  color: #ffe9a8;
}

.chat-creative-fav-btn.selected {
  background: rgba(255, 210, 80, 0.28);
  border-color: rgba(255, 210, 80, 0.55);
}

.memory-heart-entry.creative-fav-entry {
  border-left: 2px solid rgba(255, 210, 80, 0.5);
}

.memory-heart-entry.build-flag-entry {
  border-left: 2px solid rgba(255, 160, 60, 0.5);
}

.chat-feedback-note-wrap {
  position: absolute;
  right: calc(100% + 0.4rem);
  bottom: 0;
  width: min(15rem, 58vw);
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
  padding: 0.4rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.chat-feedback-note-wrap.open {
  display: flex;
}

.chat-feedback-note {
  flex: 1;
  min-height: 2rem;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.45rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  resize: vertical;
}

.chat-feedback-note-send {
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.chat-feedback-logged {
  font-size: 0.58rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.2;
  white-space: nowrap;
}

.memory-heart-entry.feedback-down {
  border-left: 2px solid rgba(255, 120, 120, 0.55);
}

.memory-heart-entry.feedback-up {
  border-left: 2px solid rgba(120, 220, 160, 0.45);
}

.btn-uber-mode.active,
.btn-uber-mode[aria-pressed="true"] {
  border-color: #6eb0ff;
  background: rgba(80, 140, 220, 0.25);
  color: #e8f4ff;
}

.btn-uber-mode:hover {
  border-color: #6eb0ff;
  color: #e8f4ff;
}

.chat-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.chat-lens-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding-bottom: 0.45rem;
}

.chat-field select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.88rem;
  min-width: 8.5rem;
}

.chat-save-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  padding-bottom: 0.35rem;
}

.mira-talk-pause-bar {
  margin-bottom: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 183, 71, 0.45);
  background: rgba(255, 183, 71, 0.1);
  color: #ffe8c2;
  font-size: 0.88rem;
  text-align: center;
}

body.mira-talk-paused #chat-input {
  opacity: 0.55;
}

body.mira-talk-paused #chat-form button[type="submit"] {
  opacity: 0.45;
  pointer-events: none;
}

.chat-live-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.btn-talk-live {
  background: linear-gradient(135deg, rgba(126, 200, 227, 0.35), rgba(192, 38, 211, 0.28));
  border: 1px solid rgba(126, 200, 227, 0.55);
  color: #f0f8ff;
  font-weight: 700;
  padding: 0.55rem 1rem;
  border-radius: 999px;
}

.btn-talk-live:hover,
.btn-talk-live.active {
  background: linear-gradient(135deg, rgba(126, 200, 227, 0.5), rgba(192, 38, 211, 0.4));
}

.chat-live-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

body.ui-mode-mobile .chat-live-row {
  margin-top: 0.15rem;
}

body.ui-mode-mobile .btn-talk-live {
  flex: 1 1 auto;
  min-width: 8rem;
  text-align: center;
  font-size: 1rem;
  padding: 0.7rem 1rem;
}

body.ui-mode-mobile .chat-live-hint {
  flex: 1 1 100%;
}

.chat-attach-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.btn-attach {
  cursor: pointer;
  display: inline-block;
}

.chat-attach-name {
  font-size: 0.82rem;
  color: var(--text-muted);
  word-break: break-all;
}

.chat-image-preview {
  margin-bottom: 0.5rem;
  max-width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-input);
}

.chat-image-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 160px;
  object-fit: contain;
}

.chat-bubble-img {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  object-fit: contain;
}

.chat-bubble-text {
  white-space: pre-wrap;
}

.chat-bubble-text .chat-action {
  font-weight: 700;
  font-style: normal;
}

.chat-bubble-text .chat-emphasis {
  font-style: italic;
}

.chat-meta-tag {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.chat-meta-tag.mira-tag {
  color: var(--soul);
  border-color: rgba(255, 255, 255, 0.25);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.visible {
  display: flex;
}

.overlay-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--soul);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.overlay-sub {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.overlay-dismiss {
  margin-top: 1.25rem;
}

.archive-notice {
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-inline select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font: inherit;
  min-width: 180px;
}

.versions-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.versions-intro p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.versions-intro code {
  color: var(--soul);
  font-size: 0.85rem;
}

.versions-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .versions-split {
    grid-template-columns: 1fr;
  }
}

.versions-pane h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.versions-list,
.history-list {
  margin-top: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.empty-msg {
  margin: 0;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-style: italic;
}

.version-row,
.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.version-row:last-child,
.history-row:last-child {
  border-bottom: none;
}

.version-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.version-cat,
.history-cat {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.version-name,
.history-name {
  color: var(--text);
  word-break: break-all;
}

.version-time,
.history-time {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.history-row {
  display: grid;
  grid-template-columns: 8.5rem 7rem 1fr;
  align-items: start;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-block;
}

.versions-footer {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.build-intro {
  margin-bottom: 1rem;
}

.build-intro p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.build-intro code {
  color: var(--soul);
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 140px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  cursor: pointer;
  padding: 1.25rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.upload-icon {
  font-size: 1.75rem;
  color: var(--soul);
  line-height: 1;
}

#build-filename {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-all;
}

.format-help {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.format-help summary {
  cursor: pointer;
  color: var(--soul);
}

.format-sample {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
}

.build-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.85rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.build-options label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.build-actions {
  margin-top: 0.85rem;
}

.build-preview {
  min-height: 380px;
  max-height: 480px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
}

.preview-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.preview-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.preview-label {
  color: var(--text-muted);
}

.preview-value {
  color: var(--text);
  word-break: break-word;
}

.preview-heading {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--soul);
}

.preview-body {
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}

.preview-body.muted {
  color: var(--text-muted);
  font-style: italic;
}

.apps-mira-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(120, 90, 180, 0.08);
}

.apps-mira-bar p {
  margin: 0;
  flex: 1;
  min-width: 16rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.chat-ui-fix-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.chat-ui-fix-toggle:has(#chat-ui-fix:checked) {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(80, 160, 100, 0.1);
}

.chat-ui-fix-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--ok);
}

.apps-intro {
  margin-bottom: 1rem;
}

.apps-intro p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.apps-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
}

.apps-permission-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--warn);
  background: rgba(200, 140, 60, 0.08);
  cursor: pointer;
  user-select: none;
}

.apps-permission-toggle:has(#app-build-permission:checked) {
  border-color: var(--ok);
  background: rgba(80, 160, 100, 0.1);
  color: var(--ok);
}

.apps-permission-hint {
  margin: -0.35rem 0 0.85rem;
  font-size: 0.82rem;
  color: var(--warn);
}

.apps-permission-hint.granted {
  color: var(--ok);
}

.apps-deploy-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding-bottom: 0.35rem;
  cursor: pointer;
}

.apps-split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  min-height: 480px;
}

@media (max-width: 900px) {
  .apps-split {
    grid-template-columns: 1fr;
  }
}

.apps-chat-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.apps-messages {
  min-height: 320px;
  max-height: 50vh;
}

.apps-form {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#app-input {
  min-height: 72px;
}

.apps-side-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-self: start;
  width: 100%;
}

.apps-side-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.apps-side-tab {
  flex: 1;
  min-width: 5.5rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-muted);
  cursor: pointer;
}

.apps-side-tab:hover {
  color: var(--text);
  border-color: var(--soul);
}

.apps-side-tab.active {
  color: var(--text);
  border-color: var(--soul);
  background: rgba(120, 90, 180, 0.12);
}

.apps-side-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 auto;
  width: 100%;
}

.apps-side-panel.active {
  display: flex;
}

.apps-side-panel .pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.apps-history-status.promoted {
  color: var(--ok);
}

.apps-history-status.staged {
  color: var(--warn);
}

.apps-archive-name {
  margin: 0 0 0.35rem;
  font-family: var(--font-mono, monospace);
  font-size: 0.78rem;
  color: var(--text);
  word-break: break-all;
}

.apps-history-list {
  flex: 0 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  height: min(50vh, 360px);
  min-height: 280px;
  max-height: min(50vh, 360px);
}

.apps-history-item {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.apps-history-item:last-child {
  border-bottom: none;
}

.apps-history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.apps-history-app {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--soul);
}

.apps-history-status {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.apps-history-status.fixed {
  color: var(--ok);
}

.apps-history-status.failed,
.apps-history-status.partial {
  color: var(--warn);
}

.apps-history-request {
  margin: 0 0 0.35rem;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.apps-history-summary {
  margin: 0 0 0.5rem;
  color: var(--text);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.apps-history-status.captured,
.apps-history-status.idea {
  color: var(--soul);
}

.apps-history-status.building {
  color: var(--warn);
}

.apps-history-status.done {
  color: var(--ok);
}

.apps-history-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.apps-history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.rules-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100vh;
  z-index: 1200;
  background: var(--bg-panel, var(--bg));
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
}

.rules-panel[hidden] {
  display: none !important;
}

.rules-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.rules-panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.rules-panel-actions {
  margin-bottom: 0.75rem;
}

.rules-add {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.rules-add textarea {
  width: 100%;
  min-height: 56px;
  resize: vertical;
}

.rules-lists {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 0.5rem;
}

.rules-group-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--soul);
  margin: 0.75rem 0 0.35rem;
}

.rules-group-title:first-child {
  margin-top: 0;
}

.rules-item {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.45;
}

.rules-item:last-child {
  border-bottom: none;
}

.rules-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.rules-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.rules-item-edit {
  width: 100%;
  min-height: 72px;
  margin-top: 0.35rem;
  font: inherit;
  font-size: 0.85rem;
  resize: vertical;
}

.rules-item-edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.rules-item.inactive {
  opacity: 0.45;
}

/* Voice — Mira speaks, mic input */
.btn-voice-header {
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
}

.input-with-mic {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.input-with-mic textarea {
  flex: 1;
  min-width: 0;
}

.btn-voice-mic {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.btn-voice-mic:hover:not(:disabled) {
  background: var(--bg-input);
  border-color: var(--accent);
}

.btn-voice-mic.listening {
  background: #3a2020;
  border-color: #aa5555;
  animation: voice-pulse 1.2s ease-in-out infinite;
}

.btn-voice-mic:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.voice-mic-status {
  margin: 0.35rem 0 0;
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
  line-height: 1.4;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
}

.voice-mic-status.listening {
  color: #e8b4b4;
  border-color: #7a4040;
  background: #2a1818;
}

.voice-mic-status.error {
  color: #ffb4b4;
  border-color: #8a4040;
  background: #301818;
}

.voice-mic-status.ok {
  color: #b4e8c8;
  border-color: #3a5a48;
  background: #182820;
}

.voice-mic-msg {
  display: block;
  margin-bottom: 0.35rem;
}

.voice-mic-level {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.voice-mic-level-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #aa5555, #dd8888);
  transition: width 0.08s linear;
}

.btn-voice-header.speaking {
  border-color: var(--accent);
  animation: voice-pulse 1.2s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(170, 85, 85, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(170, 85, 85, 0); }
}

.voice-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 900;
}

.voice-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 901;
  width: min(560px, calc(100vw - 2rem));
  max-height: min(80vh, 640px);
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem 1.5rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.voice-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.voice-panel-head h2 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.voice-panel-sub {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.voice-speak-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.voice-speak-toggle input {
  accent-color: var(--accent);
}

.voice-speak-mode-hint {
  margin: -0.25rem 0 0.85rem;
  font-size: 0.8rem;
  line-height: 1.35;
}

.voice-grid-hint {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.65rem;
}

.voice-card {
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  transition: border-color 0.15s;
}

.voice-card.selected {
  border-color: var(--accent);
  background: #141414;
}

.voice-card-name {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
  line-height: 1.3;
}

.voice-card-lang {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.voice-card-actions {
  display: flex;
  gap: 0.4rem;
}

.voice-empty {
  grid-column: 1 / -1;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0;
}

.voice-provider-tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.voice-tab {
  flex: 1;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.voice-tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent-hover);
  font-weight: 600;
}

.voice-premium-setup {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
}

.voice-premium-setup a {
  color: var(--soul);
}

.voice-key-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.voice-key-row input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.voice-key-status {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.voice-key-status.ok {
  color: var(--ok);
}

.voice-key-status.err {
  color: #c88;
}

.memory-heart-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100vw);
  height: 100vh;
  z-index: 1200;
  background: var(--bg-panel, var(--bg));
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
}

.memory-heart-panel[hidden] {
  display: none !important;
}

.memory-heart-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.memory-heart-stats {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.memory-heart-section {
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}

.memory-heart-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--soul);
}

.memory-heart-pre {
  margin: 0;
  padding: 0.55rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.45;
  max-height: 140px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}

.memory-heart-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 0.45rem;
}

.memory-heart-entry {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  line-height: 1.4;
}

.memory-heart-entry:last-child {
  border-bottom: none;
}

.memory-heart-entry time {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.memory-heart-cloud {
  font-size: 0.82rem;
  line-height: 1.45;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.memory-heart-cloud.ok {
  color: var(--ok);
}

.memory-heart-cloud.warn {
  color: #c9a227;
}

.memory-heart-cloud.err {
  color: #c88;
}

#btn-hold-this.holding {
  background: #2a3a2a;
  border-color: var(--ok);
  color: var(--ok);
}

.mic-ring-wrap {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-usage-ring {
  position: absolute;
  inset: 0;
  width: 48px;
  height: 48px;
  pointer-events: none;
  transform: rotate(-90deg);
}

.mic-usage-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 2.5;
}

.mic-usage-fill {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease;
}

.mic-usage-fill.tier-green {
  stroke: #5cb85c;
}

.mic-usage-fill.tier-yellow {
  stroke: #e6c229;
}

.mic-usage-fill.tier-red {
  stroke: #d9534f;
}

.mic-ring-wrap .btn-voice-mic {
  position: relative;
  z-index: 1;
}