/* CSS RESET & BASE STYLES */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Core System Serif Typography Rule */
body,
button,
select,
textarea,
input {
  font-family: Georgia, Cambria, "Times New Roman", Times, serif !important;
}

/* Variables */
:root {
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --emerald-500: #10b981;
  --yellow-500: #eab308;
  --slate-900: #0f172a;
  --slate-950: #020617;
  --neutral-300: #d4d4d4;
  --neutral-500: #737373;
  --neutral-800: #262626;
}

/* Continuous novel styling variables governed by active themes */
[data-theme="parchment"] {
  --color-bg: #f9f6f0;
  --color-panel: #f3efe3;
  --color-text-primary: #1c1a17;
  --color-border: #e5dfd5;
  --color-dialogue: var(--amber-700);
  --color-action: #6b7280;
  --color-think-bg: #efece6;
  --color-selection-bg: #fde68a;
  --color-selection-text: #000;
}

[data-theme="midnight"] {
  --color-bg: #0f172a;
  --color-panel: #1e293b;
  --color-text-primary: #f1f5f9;
  --color-border: #334155;
  --color-dialogue: var(--amber-400);
  --color-action: #94a3b8;
  --color-think-bg: #1e293b;
  --color-selection-bg: var(--amber-700);
  --color-selection-text: #fff;
}

[data-theme="noir"] {
  --color-bg: #000000;
  --color-panel: #121212;
  --color-text-primary: #ffffff;
  --color-border: #262626;
  --color-dialogue: var(--amber-500);
  --color-action: #a3a3a3;
  --color-think-bg: #171717;
  --color-selection-bg: var(--amber-600);
  --color-selection-text: #fff;
}

::selection {
  background-color: var(--color-selection-bg);
  color: var(--color-selection-text);
}

body {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
  display: flex;
  flex-direction: column;
}

/* LAYOUT & UTILITIES (Used by JS as well) */
.flex {
  display: flex;
}
.flex-col {
  display: flex;
  flex-direction: column;
}
.flex-1 {
  flex: 1;
}
.flex-wrap {
  flex-wrap: wrap;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.justify-center {
  justify-content: center;
}
.justify-end {
  justify-content: flex-end;
}
.gap-1 {
  gap: 0.25rem;
}
.gap-2 {
  gap: 0.5rem;
}
.gap-3 {
  gap: 0.75rem;
}
.gap-4 {
  gap: 1rem;
}

.hidden {
  display: none !important;
}
.opacity-0 {
  opacity: 0;
}
.opacity-50 {
  opacity: 0.5;
}
.opacity-100 {
  opacity: 1;
}
.pointer-events-none {
  pointer-events: none;
}
.translate-x-full {
  transform: translateX(100%);
}
.relative {
  position: relative;
}
.absolute {
  position: absolute;
}
.fixed {
  position: fixed;
}
.inset-0 {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.font-mono {
  font-family: monospace !important;
}
.font-bold {
  font-weight: bold;
}
.italic {
  font-style: italic;
}
.uppercase {
  text-transform: uppercase;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* BUTTONS & INPUTS */
button {
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
}
input,
select,
textarea {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  border-radius: 4px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--amber-600);
  box-shadow: 0 0 0 1px var(--amber-600);
}
.btn {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
}
.btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
}
.btn-primary {
  background-color: var(--amber-600);
  color: white;
  border: none;
  font-weight: bold;
  padding: 0.5rem 1rem;
}
.btn-primary:hover {
  background-color: var(--amber-700);
}
.btn-danger {
  background-color: var(--red-600);
  color: white;
  border: none;
}
.btn-danger:hover {
  background-color: #b91c1c;
}

[data-theme="midnight"] .btn:hover,
[data-theme="noir"] .btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

/* STRUCTURAL COMPONENTS */
.app-header {
  background-color: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 1rem;
  z-index: 40;
  flex-shrink: 0;
}
.header-content {
  max-width: 80rem;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.viewport {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

.manuscript-container {
  width: 100%;
  max-width: 48rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-bottom: 1.5rem;
}

.story-seed-box {
  background-color: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 1rem;
  position: relative;
}
.story-seed-box textarea {
  width: 100%;
  background: transparent;
  border: none;
  resize: vertical;
  min-height: 4.5rem;
}
.story-seed-box textarea:focus {
  box-shadow: none;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 2px dashed var(--color-border);
  border-radius: 0.5rem;
}

.app-footer {
  background-color: var(--color-panel);
  border-top: 1px solid var(--color-border);
  padding: 1rem;
  flex-shrink: 0;
  z-index: 30;
}
.footer-inner {
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 0.75rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.input-area textarea {
  width: 100%;
  max-height: 12rem;
  background: transparent;
  border: none;
  resize: none;
  font-size: 1.125rem;
  padding: 0.5rem;
}
.input-area textarea:focus {
  box-shadow: none;
}

/* SIDEBAR */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 40;
  transition: opacity 0.3s;
}
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 100%;
  max-width: 28rem;
  background-color: var(--color-panel);
  border-left: 1px solid var(--color-border);
  z-index: 50;
  transition: transform 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 25px rgba(0, 0, 0, 0.1);
}
.sidebar-header,
.sidebar-footer {
  padding: 1rem;
  border-color: var(--color-border);
}
.sidebar-header {
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-footer {
  border-top: 1px solid var(--color-border);
}
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  transition: opacity 0.3s;
}
.modal-content {
  background-color: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  width: 100%;
  max-width: 44rem;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}
.modal-header {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.6;
}
.modal-footer {
  padding: 1rem;
  border-top: 1px solid var(--color-border);
  text-align: right;
  flex-shrink: 0;
}

.memory-ledger-editor,
.chronicle-summary-editor {
  width: 100%;
  min-height: 60vh;
  padding: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: vertical;
  font-family: monospace !important;
}

.memory-ledger-form-card,
.memory-ledger-entry-list,
.memory-ledger-raw-repair,
.memory-ledger-validation {
  border: 1px solid var(--color-border);
  border-radius: 0.65rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.025);
}

[data-theme="midnight"] .memory-ledger-form-card,
[data-theme="midnight"] .memory-ledger-entry-list,
[data-theme="midnight"] .memory-ledger-raw-repair,
[data-theme="midnight"] .memory-ledger-validation,
[data-theme="noir"] .memory-ledger-form-card,
[data-theme="noir"] .memory-ledger-entry-list,
[data-theme="noir"] .memory-ledger-raw-repair,
[data-theme="noir"] .memory-ledger-validation {
  background: rgba(255, 255, 255, 0.035);
}

.memory-ledger-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--amber-600);
  font-weight: bold;
  font-size: 0.92rem;
}

.memory-ledger-count {
  min-width: 1.6rem;
  height: 1.6rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(217, 119, 6, 0.16);
  color: var(--amber-600);
  font-family: monospace !important;
  font-size: 0.78rem;
  font-weight: bold;
}

.memory-entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.memory-entry-form label {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  font-size: 0.78rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.82;
  line-height: 1.25;
}

.memory-entry-form input,
.memory-entry-form textarea,
.memory-entry-form select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.memory-entry-form textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.memory-entry-card {
  border: 1px solid var(--color-border);
  border-radius: 0.65rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.025);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

[data-theme="midnight"] .memory-entry-card,
[data-theme="noir"] .memory-entry-card {
  background: rgba(255, 255, 255, 0.035);
}

.memory-entry-badge {
  align-self: flex-start;
  border: 1px solid rgba(217, 119, 6, 0.42);
  border-radius: 9999px;
  padding: 0.15rem 0.45rem;
  color: var(--amber-600);
  background: rgba(217, 119, 6, 0.1);
  font-family: monospace !important;
  font-size: 0.68rem;
  font-weight: bold;
  text-transform: uppercase;
}

.memory-entry-subject {
  font-size: 1rem;
  font-weight: bold;
  line-height: 1.3;
}

.memory-entry-scene {
  font-size: 0.78rem;
  opacity: 0.62;
  line-height: 1.3;
}

.memory-entry-description {
  font-size: 0.86rem;
  line-height: 1.45;
  opacity: 0.92;
}

.memory-entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.memory-entry-tag {
  border: 1px solid rgba(217, 119, 6, 0.28);
  border-radius: 9999px;
  padding: 0.12rem 0.42rem;
  color: var(--amber-600);
  background: rgba(217, 119, 6, 0.08);
  font-size: 0.68rem;
}

.memory-entry-edit-card {
  border-color: rgba(217, 119, 6, 0.42);
  background: rgba(217, 119, 6, 0.055);
}

.memory-entry-edit-title {
  color: var(--amber-600);
  font-weight: bold;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.memory-entry-inline-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.memory-entry-inline-form label {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  font-size: 0.78rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.82;
  line-height: 1.25;
}

.memory-entry-inline-form input,
.memory-entry-inline-form textarea {
  width: 100%;
  padding: 0.52rem 0.62rem;
  font-size: 0.88rem;
  line-height: 1.4;
}

.memory-entry-inline-form textarea {
  min-height: 6rem;
  resize: vertical;
}

.memory-entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.memory-entry-actions .btn,
.memory-entry-actions .btn-danger {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 0.45rem;
}

.memory-ledger-empty {
  border: 1px dashed var(--color-border);
  border-radius: 0.55rem;
  padding: 0.75rem;
  font-size: 0.8rem;
  opacity: 0.68;
  line-height: 1.45;
}

.memory-ledger-raw-repair summary {
  cursor: pointer;
  color: var(--amber-600);
  font-weight: bold;
}

.memory-ledger-raw-warning {
  margin: 0.65rem 0;
  color: var(--amber-700);
  background-color: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 0.45rem;
  padding: 0.55rem 0.65rem;
  font-size: 0.76rem;
  line-height: 1.4;
}

[data-theme="midnight"] .memory-ledger-raw-warning,
[data-theme="noir"] .memory-ledger-raw-warning {
  color: var(--amber-400);
}

.memory-ledger-validation {
  display: none;
  font-size: 0.76rem;
  line-height: 1.4;
}

.memory-ledger-validation.visible {
  display: block;
}

.memory-ledger-validation.error {
  color: var(--red-500);
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.08);
}

.memory-ledger-validation.warning {
  color: var(--amber-700);
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.08);
}

[data-theme="midnight"] .memory-ledger-validation.warning,
[data-theme="noir"] .memory-ledger-validation.warning {
  color: var(--amber-400);
}

.memory-ledger-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (max-width: 639px) {
  #memoryModal .modal-content {
    max-height: 96vh;
  }

  #memoryModal .modal-body {
    padding: 1rem;
  }

  #memoryModal .modal-footer {
    align-items: stretch;
    flex-direction: column-reverse;
    gap: 0.6rem;
  }

  .memory-ledger-footer-actions {
    flex-direction: column-reverse;
    width: 100%;
  }

  .memory-ledger-footer-actions button,
  #memoryModal .modal-footer > button {
    width: 100%;
    min-height: 2.45rem;
  }

  .memory-entry-actions {
    justify-content: stretch;
  }

  .memory-entry-actions button {
    flex: 1;
  }
}

.memory-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.5rem;
}
.memory-tab {
  border: 1px solid var(--color-border);
  border-bottom-color: var(--color-border);
  border-radius: 9999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.72;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    opacity 0.18s ease;
}
.memory-tab:hover {
  opacity: 1;
  background-color: rgba(217, 119, 6, 0.08);
}
.memory-tab.active {
  opacity: 1;
  color: var(--amber-600);
  border-color: rgba(217, 119, 6, 0.45);
  background-color: rgba(217, 119, 6, 0.12);
}
.memory-tab-panel {
  display: none;
}
.memory-tab-panel.active {
  display: flex;
}

.chronicle-summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-family: monospace !important;
  font-size: 0.72rem;
  opacity: 0.68;
}
.chronicle-summary-meta span {
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  padding: 0.15rem 0.45rem;
}
.context-budget-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  font-size: 0.7rem;
  line-height: 1.35;
}
.context-budget-card {
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: 0.45rem;
  padding: 0.45rem 0.55rem;
  background: rgba(0, 0, 0, 0.025);
  cursor: help;
}
.context-budget-card:focus {
  outline: none;
  border-color: rgba(217, 119, 6, 0.65);
  box-shadow: 0 0 0 1px rgba(217, 119, 6, 0.25);
}
.context-budget-card::after {
  content: attr(data-tooltip);
  display: none;
  position: absolute;
  left: 0;
  right: auto;
  top: calc(100% + 0.35rem);
  z-index: 80;
  min-width: min(18rem, 82vw);
  max-width: 22rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 0.45rem;
  background: var(--color-panel);
  color: var(--color-text-primary);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18);
  white-space: normal;
  font-size: 0.68rem;
  line-height: 1.35;
  font-family: Georgia, Cambria, "Times New Roman", Times, serif !important;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
}
.context-budget-card:hover::after,
.context-budget-card:focus::after,
.context-budget-card:focus-within::after {
  display: block;
}
[data-theme="midnight"] .context-budget-card,
[data-theme="noir"] .context-budget-card {
  background: rgba(255, 255, 255, 0.035);
}
.context-budget-label {
  display: block;
  font-family: monospace !important;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.58;
}
.context-budget-value {
  display: block;
  margin-top: 0.12rem;
  font-family: monospace !important;
  font-weight: bold;
}
.summary-warning {
  display: none;
  color: var(--amber-700);
  background-color: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 0.375rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.35;
}
[data-theme="midnight"] .summary-warning,
[data-theme="noir"] .summary-warning {
  color: var(--amber-400);
}
.parameter-warning {
  display: none;
  color: var(--amber-700);
  background-color: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 0.375rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.7rem;
  line-height: 1.35;
}
[data-theme="midnight"] .parameter-warning,
[data-theme="noir"] .parameter-warning {
  color: var(--amber-400);
}

/* GENERATION PIPELINE STATUS */
.pipeline-status {
  padding: 0.75rem 1rem;
  margin: 0.25rem 0 0.75rem 0;
  background-color: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.24);
  border-left: 3px solid var(--amber-600);
  border-radius: 0.5rem;
  color: var(--color-text-primary);
}
.pipeline-status-header {
  cursor: pointer;
  user-select: none;
}
.pipeline-status-title {
  color: var(--amber-600);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: bold;
  font-family: monospace !important;
}
.pipeline-status-caret {
  font-size: 0.7rem;
  opacity: 0.65;
  transition: transform 0.18s ease;
}
.pipeline-status-rich {
  display: none;
}
.pipeline-status.expanded .pipeline-status-rich {
  display: block;
}
.pipeline-status.expanded .pipeline-status-caret {
  transform: rotate(90deg);
}
.pipeline-status-detail {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  line-height: 1.4;
  opacity: 0.76;
}
.pipeline-status-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}
.pipeline-step {
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  padding: 0.15rem 0.45rem;
  font-size: 0.68rem;
  opacity: 0.55;
  font-family: monospace !important;
}
.pipeline-step.active {
  opacity: 1;
  color: var(--amber-600);
  border-color: rgba(217, 119, 6, 0.55);
  background-color: rgba(217, 119, 6, 0.11);
}
.pipeline-step.done {
  opacity: 0.82;
  color: var(--emerald-500);
  border-color: rgba(16, 185, 129, 0.45);
}
.pipeline-step.warning {
  opacity: 1;
  color: var(--amber-600);
  border-color: rgba(217, 119, 6, 0.62);
  background-color: rgba(217, 119, 6, 0.12);
}
.pipeline-warning-note {
  margin-top: 0.55rem;
  padding: 0.5rem 0.6rem;
  border-left: 3px solid var(--amber-600);
  border-radius: 0.4rem;
  background-color: rgba(217, 119, 6, 0.1);
  font-size: 0.74rem;
  line-height: 1.4;
}
.pipeline-warning-title {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--amber-600);
  font-family: monospace !important;
  font-weight: bold;
}

/* ERROR MODAL */
.error-context-box {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  max-height: 55vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: monospace !important;
  font-size: 0.8rem;
  line-height: 1.45;
}

.generation-diagnostic-note {
  margin-top: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid var(--yellow-500);
  background-color: rgba(234, 179, 8, 0.08);
  border-radius: 0.375rem;
  font-size: 0.76rem;
  line-height: 1.45;
  opacity: 0.82;
  font-family: monospace !important;
}

.inline-edit-send-tooltip {
  position: fixed;
  z-index: 120;
  max-width: min(18rem, calc(100vw - 1rem));
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(217, 119, 6, 0.38);
  border-radius: 0.45rem;
  background: var(--color-panel);
  color: var(--color-text-primary);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(0.25rem);
  transition:
    opacity 0.16s ease,
    transform 0.16s ease;
  pointer-events: none;
}

.inline-edit-send-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.inline-edit-send-tooltip::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  bottom: -0.35rem;
  width: 0.65rem;
  height: 0.65rem;
  background: var(--color-panel);
  border-right: 1px solid rgba(217, 119, 6, 0.38);
  border-bottom: 1px solid rgba(217, 119, 6, 0.38);
  transform: rotate(45deg);
}

/* TYPOGRAPHY & MANUSCRIPT STYLES */
.manuscript-paragraph {
  text-indent: 1.25rem;
  margin-bottom: 0.75rem;
  line-height: 1.6;
  text-align: left;
  font-size: 0.9rem;
}
@media (min-width: 640px) {
  .manuscript-paragraph {
    text-indent: 2rem;
    line-height: 1.8;
    text-align: justify;
    font-size: 1.15rem;
  }
  .hide-on-mobile {
    display: inline;
  }
}
@media (max-width: 639px) {
  .hide-on-mobile {
    display: none;
  }
  .input-area textarea {
    font-size: 0.8rem;
  }
}

.manuscript-block .manuscript-paragraph:first-of-type {
  text-indent: 0;
}
.dialogue {
  color: var(--color-dialogue);
  font-style: italic;
}
.action {
  color: var(--color-action);
  font-weight: normal;
}

.user-action-block {
  color: var(--color-action);
  font-style: normal;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}
@media (min-width: 640px) {
  .user-action-block {
    font-size: 1.05rem;
    letter-spacing: 0.02em;
  }
}

.manuscript-block {
  position: relative;
  padding: 0.5rem 0 0.5rem 1rem;
  margin-left: -1rem;
  border-left: 2px solid transparent;
  transition: border-color 0.2s;
}
.manuscript-block:hover {
  border-color: rgba(217, 119, 6, 0.3);
}
.block-controls {
  position: absolute;
  right: 0;
  top: -0.75rem;
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  gap: 0.25rem;
  z-index: 10;
}
.block-controls-bottom {
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0.6rem;
  padding-top: 0.4rem;
  border-top: 1px dashed transparent;
}
.manuscript-block:hover .block-controls,
.manuscript-block:hover .block-controls-bottom,
.manuscript-block.controls-visible .block-controls,
.manuscript-block.controls-visible .block-controls-bottom {
  opacity: 1;
}
.manuscript-block:hover .block-controls-bottom,
.manuscript-block.controls-visible .block-controls-bottom {
  border-top-color: rgba(217, 119, 6, 0.18);
}

.think-section {
  margin: 0.75rem 0;
  padding: 0.75rem;
  background-color: rgba(0, 0, 0, 0.05);
  border-left: 2px solid var(--amber-600);
  border-radius: 0.375rem;
  font-family: monospace;
  font-size: 0.75rem;
  opacity: 0.8;
  user-select: all;
}
[data-theme="midnight"] .think-section,
[data-theme="noir"] .think-section {
  background-color: rgba(255, 255, 255, 0.05);
}

/* TOGGLE SWITCH */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.toggle-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.toggle-bg {
  width: 2.75rem;
  height: 1.5rem;
  background-color: var(--neutral-300);
  border-radius: 9999px;
  transition: background-color 0.2s;
  position: relative;
}
[data-theme="midnight"] .toggle-bg,
[data-theme="noir"] .toggle-bg {
  background-color: var(--neutral-800);
}
.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.2s;
  border: 1px solid #d1d5db;
}
.toggle-switch input:checked + .toggle-bg {
  background-color: var(--amber-600);
}
.toggle-switch input:checked + .toggle-bg .toggle-knob {
  transform: translateX(1.25rem);
  border-color: white;
}

/* ANIMATIONS */
.writing-cursor {
  display: inline-block;
  width: 8px;
  height: 17px;
  background-color: var(--color-dialogue);
  margin-left: 4px;
  animation: blink 1s step-start infinite;
  vertical-align: middle;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-bounce {
  animation: bounce 1s infinite;
}
@keyframes bounce {
  0%,
  100% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: none;
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}
.bg-red {
  background-color: var(--red-500);
}
.bg-yellow {
  background-color: var(--yellow-500);
}
.bg-green {
  background-color: var(--emerald-500);
}

.setup-card {
  border: 1px solid var(--color-border);
  border-radius: 0.65rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.025);
}
[data-theme="midnight"] .setup-card,
[data-theme="noir"] .setup-card {
  background: rgba(255, 255, 255, 0.035);
}
.ui-label,
.setup-label {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  opacity: 0.8;
  line-height: 1.25;
}
.provider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.4rem;
}
.model-picker-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 0.45rem;
}
@media (max-width: 639px) {
  .provider-row,
  .model-picker-grid {
    grid-template-columns: 1fr;
  }
}
.ui-help,
.setup-help {
  display: block;
  font-size: 10.5pt;
  opacity: 0.68;
  line-height: 1.35;
}
/* Searchable model dropdown */
.model-dropdown-wrap {
  position: relative;
}
.model-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  font-size: 0.875rem;
  max-width: 180px;
  min-width: 110px;
  cursor: pointer;
  text-align: left;
}
.model-dropdown-btn:hover {
  border-color: var(--amber-600);
}
.model-dropdown-caret {
  margin-left: auto;
  font-size: 0.6rem;
  opacity: 0.5;
  flex-shrink: 0;
}
.model-dropdown-panel {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  z-index: 60;
  min-width: 260px;
  max-height: 320px;
  background-color: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.model-search-input {
  margin: 0.35rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  flex-shrink: 0;
}
.model-search-input:focus {
  outline: none;
  border-color: var(--amber-600);
  box-shadow: 0 0 0 1px var(--amber-600);
}
.model-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.15rem 0;
}
.model-list-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-list-item:hover,
.model-list-item.focused {
  background: rgba(217, 119, 6, 0.12);
}
.model-list-empty {
  padding: 0.5rem 0.6rem;
  font-size: 0.75rem;
  opacity: 0.5;
  text-align: center;
}
.secret-status {
  font-family: monospace !important;
  font-size: 0.68rem;
  opacity: 0.75;
}

/* SCROLLBAR */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-action);
}
