/* ==========================================================================
   Google AI Studio x Material Design 3 Glassmorphism (Monet Palette)
   ========================================================================== */

:root {
  /* Default: Deep Monet Cosmic Indigo (Dark Mode) */
  --bg: #090b14;
  --bg-gradient: radial-gradient(circle at 15% 20%, #1a153a 0%, #090b14 60%);
  
  /* Glass & Surfaces */
  --surface-glass: rgba(23, 26, 45, 0.65);
  --surface-glass-hover: rgba(33, 38, 65, 0.75);
  --surface-glass-active: rgba(45, 52, 88, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-highlight: rgba(184, 169, 232, 0.35);
  --glass-shadow: 0 12px 36px -8px rgba(0, 0, 0, 0.45);
  --backdrop-blur: blur(24px) saturate(180%);

  /* Typography */
  --text: #eef0f8;
  --text-muted: #9196b0;
  --text-dim: #60657e;

  /* Monet Water Lilies Palette & Google Accents */
  --primary: #8ab4f8;          /* Google AI Radiant Blue */
  --primary-glow: rgba(138, 180, 248, 0.25);
  --monet-violet: #c084fc;     /* Monet Water Lilies Purple */
  --secondary: #fdd663;        /* Warm Amber/Coral */
  --tertiary: #a2d4e8;         /* Water Blue-Green */
  --ok: #81c995;               /* Google Green / Finalized */
  --warn: #fdd663;             /* Amber / Working */
  --error: #f88282;            /* Coral Red / Error */
  
  /* Radii */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  /* Warm Pearl & Lavender (Light Mode) */
  --bg: #f3f5fc;
  --bg-gradient: radial-gradient(circle at 15% 20%, #e6e3f8 0%, #f3f5fc 60%);
  
  --surface-glass: rgba(255, 255, 255, 0.75);
  --surface-glass-hover: rgba(255, 255, 255, 0.9);
  --surface-glass-active: rgba(240, 243, 255, 0.95);
  --glass-border: rgba(100, 110, 160, 0.15);
  --glass-border-highlight: rgba(107, 92, 168, 0.4);
  --glass-shadow: 0 12px 32px -8px rgba(90, 100, 140, 0.15);

  --text: #161824;
  --text-muted: #5e647e;
  --text-dim: #9aa0ba;

  --primary: #4e5ba6;
  --primary-glow: rgba(78, 91, 166, 0.15);
  --monet-violet: #7c4dff;
  --secondary: #d97706;
  --tertiary: #0284c7;
  --ok: #16a34a;
  --warn: #d97706;
  --error: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Outfit', 'Inter', system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Ambient Glass Glow Background Orbs */
.ambient-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.22;
  animation: floatOrb 25s ease-in-out infinite alternate;
}

[data-theme="light"] .orb { opacity: 0.35; }

.orb-primary {
  width: 500px;
  height: 500px;
  background: var(--primary);
  top: -150px;
  left: -100px;
}

.orb-secondary {
  width: 450px;
  height: 450px;
  background: var(--monet-violet);
  bottom: -150px;
  right: -100px;
  animation-delay: -7s;
}

.orb-tertiary {
  width: 400px;
  height: 400px;
  background: var(--tertiary);
  top: 40%;
  left: 55%;
  animation-delay: -14s;
}

@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-40px, 40px) scale(1.1); }
  100% { transform: translate(30px, -20px) scale(0.95); }
}

/* Glass Core Utilities */
.glass-panel {
  background: var(--surface-glass);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--glass-border);
}

.glass-card {
  background: var(--surface-glass);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
  transition: all var(--transition-normal);
}

.glass-card:hover {
  border-color: var(--glass-border-highlight);
  box-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] .glass-card:hover {
  box-shadow: 0 16px 40px -8px rgba(90, 100, 140, 0.22);
}

/* Top Navigation Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 2rem;
  position: sticky;
  top: 0;
  z-index: 50;
  height: 68px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 6px;
}

.brand-logo svg {
  width: 100%;
  height: 100%;
}

.brand-text {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 30%, var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-weight: 400;
  font-size: 0.95rem;
  opacity: 0.7;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.15);
  padding: 5px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--glass-border);
}

[data-theme="light"] .tabs {
  background: rgba(230, 235, 250, 0.6);
}

.tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-icon {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.tab.active {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--monet-violet));
  box-shadow: 0 4px 12px var(--primary-glow);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.05);
}

/* Main Container */
.main-container {
  position: relative;
  z-index: 1;
  max-width: 1360px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.view {
  display: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.view.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   1. Dashboard View
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-wrap svg { width: 24px; height: 24px; }

.icon-status { background: rgba(129, 201, 149, 0.15); color: var(--ok); }
.icon-chapter { background: rgba(138, 180, 248, 0.15); color: var(--primary); }
.icon-agent { background: rgba(192, 132, 252, 0.15); color: var(--monet-violet); }
.icon-tokens { background: rgba(253, 214, 99, 0.15); color: var(--secondary); }
.icon-final { background: rgba(162, 212, 232, 0.15); color: var(--tertiary); }

.stat-content {
  flex: 1;
  min-width: 0;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight-num {
  font-family: 'Outfit', sans-serif;
  color: var(--primary);
}

.font-mono {
  font-family: 'Consolas', 'Cascadia Code', monospace;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: capitalize;
  font-size: 1.1rem;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background-color: var(--ok);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px var(--ok);
  animation: pulseGreen 1.5s infinite;
}

@keyframes pulseGreen {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 14px var(--ok); }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Controls Bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.75rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, rgba(138, 180, 248, 0.08), rgba(192, 132, 252, 0.08));
}

.controls-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.controls-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.controls-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.controls-buttons {
  display: flex;
  gap: 0.75rem;
}

/* MD3 Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn svg { width: 18px; height: 18px; }

.md-filled-btn {
  background: linear-gradient(135deg, var(--primary), var(--monet-violet));
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.md-filled-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(192, 132, 252, 0.4);
}

.md-tonal-btn {
  background: rgba(253, 214, 99, 0.15);
  color: var(--warn);
  border: 1px solid rgba(253, 214, 99, 0.3);
}

.md-tonal-btn:hover:not(:disabled) {
  background: rgba(253, 214, 99, 0.25);
  transform: translateY(-2px);
}

.md-gradient-btn {
  background: linear-gradient(135deg, #fdd663, #f88282);
  color: #11131f;
  font-weight: 700;
}

.md-gradient-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(253, 214, 99, 0.4);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

.panel-box {
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.panel-icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
}

.panel-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--error);
  background: rgba(248, 130, 130, 0.15);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
}

.live-indicator .dot {
  width: 6px;
  height: 6px;
  background: var(--error);
  border-radius: 50%;
  animation: pulseRed 1s infinite;
}

@keyframes pulseRed {
  0% { opacity: 0.3; }
  50% { opacity: 1; }
  100% { opacity: 0.3; }
}

.chart-container {
  width: 100%;
  height: 210px;
  position: relative;
}

#token-chart {
  width: 100%;
  height: 100%;
}

.terminal-box {
  height: 210px;
  overflow-y: auto;
  font-family: 'Consolas', 'Cascadia Code', monospace;
  font-size: 0.84rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

[data-theme="light"] .terminal-box {
  background: rgba(235, 240, 250, 0.8);
}

.ev {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.ev:hover {
  background: rgba(255, 255, 255, 0.04);
}

.ev .ev-time {
  color: var(--text-dim);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.ev .ev-src {
  color: var(--primary);
  font-weight: 600;
  flex-shrink: 0;
}

.ev.warn .ev-src { color: var(--warn); }
.ev.error .ev-src { color: var(--error); }

/* Preview Section */
.preview-section {
  min-height: 240px;
}

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

.novel-paper {
  height: 220px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.75rem;
  font-size: 1.05rem;
  line-height: 1.9;
  letter-spacing: 0.03em;
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", serif;
  white-space: pre-wrap;
}

[data-theme="light"] .novel-paper {
  background: rgba(245, 242, 235, 0.7);
  color: #2b2820;
}

.tok-header {
  color: var(--monet-violet);
  font-weight: 700;
  display: inline-block;
  margin: 0.6rem 0 0.2rem;
  font-size: 0.85rem;
  background: rgba(192, 132, 252, 0.15);
  padding: 0.1rem 0.6rem;
  border-radius: var(--radius-pill);
}

/* --------------------------------------------------------------------------
   2. Reader View
   -------------------------------------------------------------------------- */
.reader-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.5rem;
  align-items: start;
}

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

.chapter-sidebar {
  padding: 1.25rem;
  position: sticky;
  top: 84px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.8rem;
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar-tip {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-box {
  position: relative;
  margin-bottom: 1rem;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem 0.5rem 2.2rem;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition-fast);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.chapter-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.chapter-tree li {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  font-size: 0.92rem;
}

.chapter-tree li:hover {
  background: rgba(255, 255, 255, 0.05);
}

.chapter-tree li.active {
  background: rgba(138, 180, 248, 0.12);
  border-left-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

[data-theme="light"] .chapter-tree li.active {
  color: var(--primary);
}

.badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  font-weight: 600;
}

.badge.final { background: rgba(129, 201, 149, 0.2); color: var(--ok); }
.badge.working { background: rgba(253, 214, 99, 0.2); color: var(--warn); }
.badge.pending { background: rgba(255, 255, 255, 0.08); color: var(--text-muted); }

.export-box {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--glass-border);
}

.export-title {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.export-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.export-btn {
  padding: 0.45rem;
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
}

.export-btn:hover {
  background: var(--primary);
  color: #fff;
}

.novel-reader {
  padding: 3rem 4rem;
  min-height: 680px;
  max-width: 820px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .novel-reader { padding: 1.5rem 1.25rem; }
}

.reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  color: var(--text-muted);
  text-align: center;
}

.reader-empty svg {
  width: 56px;
  height: 56px;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.reader-content h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.reader-content p {
  margin: 0 0 1.25rem;
  text-indent: 2em;
  font-size: 1.15rem;
  line-height: 2.1;
  color: var(--text);
  letter-spacing: 0.02em;
}

.reader-meta {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.3rem 0.8rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-pill);
  margin-bottom: 2rem;
}

/* --------------------------------------------------------------------------
   3. God Mode View
   -------------------------------------------------------------------------- */
.god-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .god-layout { grid-template-columns: 1fr; }
}

.god-col {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.section-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: -0.5rem 0 1rem;
}

.editor-wrapper {
  flex: 1;
  margin-bottom: 1rem;
}

.code-editor, .intervention-input {
  width: 100%;
  min-height: 380px;
  background: rgba(0, 0, 0, 0.3);
  color: #a8c7fa;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: 'Consolas', 'Cascadia Code', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: all var(--transition-fast);
}

[data-theme="light"] .code-editor {
  background: #1e1e28;
  color: #e0e8ff;
}

.code-editor:focus, .intervention-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.intervention-input {
  min-height: 140px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.col-footer {
  display: flex;
  justify-content: flex-end;
}

.intervention-history {
  margin-top: 1.8rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--glass-border);
}

.history-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.intervention-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.intervention-list li {
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.intervention-list li.consumed {
  color: var(--text-dim);
  text-decoration: line-through;
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   4. Settings View
   -------------------------------------------------------------------------- */
.settings-container {
  max-width: 820px;
  margin: 0 auto;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.settings-group {
  padding: 1.5rem 1.8rem;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.group-icon {
  width: 28px;
  height: 28px;
  color: var(--monet-violet);
}

.group-title-text h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.group-title-text p {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.form-item.full-width {
  grid-column: 1 / -1;
}

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

.form-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-item label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-item input, .select-input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: all var(--transition-fast);
}

[data-theme="light"] .form-item input, [data-theme="light"] .select-input {
  background: rgba(255, 255, 255, 0.8);
}

.form-item input:focus, .select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon input {
  width: 100%;
  padding-right: 2.8rem;
}

.pwd-toggle-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1.1rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.save-settings-btn {
  padding: 0.85rem 2.2rem;
  font-size: 1.05rem;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  background: rgba(23, 26, 45, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border-highlight);
  color: var(--text);
  padding: 0.85rem 1.4rem;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.92rem;
  font-weight: 500;
  animation: slideInToast 0.3s ease-out forwards;
}

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

.toast.success { border-left: 4px solid var(--ok); }
.toast.error { border-left: 4px solid var(--error); }

/* ==========================================================================
   Mobile UI Optimizations (Native App Experience for Phones & Tablets)
   ========================================================================== */

@media (max-width: 768px) {
  /* Topbar optimization */
  .topbar {
    padding: 0.6rem 1rem;
    height: 56px;
  }
  .brand-text {
    font-size: 1.08rem;
  }
  .brand-sub {
    display: none; /* Save horizontal space on mobile header */
  }

  /* Convert Top Navigation Tabs into a Native Bottom App Bar (Dock) */
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    z-index: 100;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--glass-border);
    background: rgba(15, 18, 32, 0.88);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 4px 8px env(safe-area-inset-bottom, 4px);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
  }

  [data-theme="light"] .tabs {
    background: rgba(240, 244, 255, 0.92);
    box-shadow: 0 -8px 24px rgba(90, 100, 140, 0.15);
  }

  .tab {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px;
    font-size: 0.72rem;
    border-radius: 12px;
  }

  .tab-icon {
    width: 20px;
    height: 20px;
  }

  .tab.active {
    background: rgba(138, 180, 248, 0.15);
    color: var(--primary);
    box-shadow: none;
  }

  [data-theme="light"] .tab.active {
    background: rgba(78, 91, 166, 0.15);
    color: #4e5ba6;
  }

  /* Adjust Main Container for Bottom Bar */
  .main-container {
    padding: 1rem 0.85rem 88px;
  }

  .dashboard-grid, .god-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .panel-box {
    padding: 1.1rem;
  }

  .terminal-box, .chart-container {
    height: 180px;
  }

  .novel-paper {
    height: 260px;
    padding: 1rem;
    font-size: 1rem;
    line-height: 1.75;
  }

  /* Reader Layout Optimization */
  .reader-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .chapter-sidebar {
    position: relative;
    top: 0;
    padding: 1rem;
  }

  .chapter-tree {
    max-height: 160px;
  }

  .novel-reader {
    padding: 1.25rem 1rem;
    min-height: auto;
  }

  .reader-content h2 {
    font-size: 1.4rem;
  }

  .reader-content p {
    font-size: 1.05rem;
    line-height: 1.85;
  }
}

@media (max-width: 640px) {
  /* Stats KPI Grid */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .stats-grid .stat-card:first-child {
    grid-column: 1 / -1; /* First card full width */
  }

  .stat-card {
    padding: 0.85rem;
    gap: 0.65rem;
  }

  .stat-icon-wrap {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  /* Controls Action Bar */
  .controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: 1rem;
  }

  .controls-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .controls-buttons .btn:first-child {
    grid-column: 1 / -1; /* Primary Start button full width */
    padding: 0.85rem;
    font-size: 1.05rem;
  }

  /* God Mode & Settings Forms */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .code-editor {
    min-height: 220px;
    font-size: 0.82rem;
  }

  .intervention-input {
    min-height: 110px;
  }

  .export-btns {
    grid-template-columns: 1fr;
  }

  /* Toast Notification positioning above Bottom App Bar */
  .toast-container {
    bottom: 76px;
    right: 1rem;
    left: 1rem;
  }

  .toast {
    width: 100%;
    justify-content: center;
  }
}
