:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #0f1025;
  --bg-card: #141530;
  --bg-card-hover: #1a1b40;
  --text-cream: #f5e6c8;
  --text-dim: #9e8e72;
  --text-muted: #6b5d4a;
  --accent-gold: #c4a35a;
  --accent-gold-bright: #e8c96d;
  --accent-burgundy: #8b3a4a;
  --accent-burgundy-light: #a84e60;
  --border-subtle: #252645;
  --border-gold: rgba(196, 163, 90, 0.3);
}

[data-theme="light"] {
  --bg-primary: #f0e6d2;
  --bg-secondary: #e8dcc4;
  --bg-card: #f5ecd8;
  --bg-card-hover: #efe3cb;
  --text-cream: #2a1f0e;
  --text-dim: #5a4a32;
  --text-muted: #7a6a52;
  --accent-gold: #8b6914;
  --accent-gold-bright: #a67c1a;
  --accent-burgundy: #7a2838;
  --accent-burgundy-light: #9a3848;
  --border-subtle: #d4c8a8;
  --border-gold: rgba(139, 105, 20, 0.3);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-primary);
  color: var(--text-cream);
  min-height: 100vh;
  transition: background 0.4s ease, color 0.4s ease;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 15% 20%, rgba(196, 163, 90, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 80%, rgba(139, 58, 74, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Vignette */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 0;
}

[data-theme="light"] body::after {
  background: radial-gradient(ellipse at center, transparent 60%, rgba(100,80,40,0.1) 100%);
}

.app-root {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.babel-header {
  text-align: center;
  padding: 48px 24px 36px;
  margin-bottom: 24px;
  position: relative;
}

.babel-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2.2rem, 6vw, 4.2rem);
  font-weight: 900;
  letter-spacing: 3px;
  background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-gold-bright) 40%, var(--accent-gold) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  line-height: 1.1;
}

.babel-tagline {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-size: clamp(0.85rem, 2vw, 1.15rem);
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.babel-stats {
  font-size: 0.78rem;
  color: var(--accent-gold);
  font-weight: 300;
  opacity: 0.8;
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  margin-bottom: 32px;
}

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

/* Sidebar */
.sidebar {
  background: var(--bg-card);
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  height: fit-content;
  position: sticky;
  top: 16px;
  transition: background 0.3s;
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
  }
}

.sidebar-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--accent-gold);
}

.filter-group {
  margin-bottom: 18px;
}

.filter-label {
  display: block;
  font-size: 0.72rem;
  margin-bottom: 6px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
}

.filter-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-cream);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s;
  appearance: none;
}

.filter-select:focus {
  outline: none;
  border-color: var(--accent-gold);
}

/* Coherence slider */
.coherence-track {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-burgundy), var(--accent-gold));
  outline: none;
  cursor: pointer;
}

.coherence-track::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gold-bright);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(196, 163, 90, 0.5);
}

.coherence-track::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gold-bright);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
}

.coherence-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Buttons */
.btn-gold {
  padding: 11px 24px;
  background: linear-gradient(135deg, var(--accent-gold) 0%, #b8941f 100%);
  border: none;
  border-radius: 10px;
  color: var(--bg-primary);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.25s;
  box-shadow: 0 3px 12px rgba(196, 163, 90, 0.3);
}

.btn-gold:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(196, 163, 90, 0.5);
}

.btn-gold:active {
  transform: translateY(0);
}

.btn-outline {
  padding: 9px 18px;
  background: transparent;
  border: 1px solid var(--accent-gold);
  border-radius: 8px;
  color: var(--accent-gold);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.btn-outline:hover {
  background: rgba(196, 163, 90, 0.1);
  transform: translateY(-1px);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.75rem;
}

/* Content area */
.content-area {
  background: var(--bg-card);
  padding: 24px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  min-height: 500px;
  transition: background 0.3s;
}

@media (max-width: 600px) {
  .content-area {
    padding: 16px;
  }
}

/* Search */
.search-modes {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-tab {
  flex: 1;
  padding: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.25s;
  text-align: center;
}

.mode-tab.active {
  background: rgba(196, 163, 90, 0.12);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  box-shadow: 0 0 12px rgba(196, 163, 90, 0.2);
}

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

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

@media (max-width: 600px) {
  .search-row {
    flex-direction: column;
  }
}

.search-input {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-primary);
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-cream);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 24px rgba(196, 163, 90, 0.2);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/* Email cards */
.email-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.2s;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
}

.email-card::before {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(196,163,90,0.06), transparent);
  transition: left 0.6s ease;
}

.email-card:hover::before {
  left: 100%;
}

.email-card:hover {
  border-color: var(--border-gold);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transform: translateY(-1px);
}

.email-card.expanded {
  border-color: var(--accent-gold);
  box-shadow: 0 8px 32px rgba(196,163,90,0.15);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.card-from {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 0.85rem;
  word-break: break-all;
}

.card-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'Playfair Display', serif;
  white-space: nowrap;
}

.card-subject {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-cream);
  line-height: 1.3;
}

.card-preview {
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.55;
  margin-bottom: 8px;
}

.card-coordinate {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  font-family: 'JetBrains Mono', monospace;
}

/* Expanded email */
.email-expanded {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 2px solid var(--accent-gold);
  animation: slideDown 0.3s ease;
}

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

.detail-field {
  font-size: 0.85rem;
  margin-bottom: 4px;
  line-height: 1.6;
}

.detail-field strong {
  color: var(--accent-gold);
}

.email-body-text {
  margin-top: 16px;
  line-height: 1.85;
  font-size: 0.9rem;
}

.email-body-text p {
  margin-bottom: 14px;
  color: var(--text-cream);
}

.email-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* Loading shimmer */
.shimmer {
  background: linear-gradient(90deg, var(--bg-primary) 25%, var(--bg-card) 50%, var(--bg-primary) 75%);
  background-size: 200% 100%;
  animation: shimmerAnim 1.5s infinite;
  border-radius: 6px;
  height: 16px;
  margin-bottom: 8px;
}

@keyframes shimmerAnim {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Scroll trigger */
.scroll-sentinel {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-style: italic;
  font-family: 'Playfair Display', serif;
  font-size: 0.88rem;
}

/* Footer */
.babel-footer {
  text-align: center;
  padding: 28px 20px;
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  font-family: 'Playfair Display', serif;
  color: var(--text-dim);
  line-height: 1.8;
  font-size: 0.88rem;
}

.babel-footer a {
  color: var(--accent-gold);
  text-decoration: none;
  font-weight: 700;
  transition: text-shadow 0.2s;
}

.babel-footer a:hover {
  text-shadow: 0 0 8px rgba(196,163,90,0.5);
}

.footer-disclaimer {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.2s, box-shadow 0.2s;
  color: var(--accent-gold);
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(196,163,90,0.3);
}

/* Bookmarks modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 28px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 18px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-gold);
  color: var(--bg-primary);
  padding: 10px 24px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  z-index: 300;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.2s forwards;
  box-shadow: 0 4px 20px rgba(196,163,90,0.4);
}

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

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Tone badge */
.tone-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
  vertical-align: middle;
}

.tone-business { background: rgba(52,120,180,0.2); color: #5ba3d9; }
.tone-personal { background: rgba(100,180,80,0.2); color: #7cc06a; }
.tone-mysterious { background: rgba(140,80,180,0.2); color: #b07ad0; }
.tone-spam { background: rgba(220,80,60,0.2); color: #e06050; }
.tone-romantic { background: rgba(220,100,140,0.2); color: #e88aaa; }
.tone-technical { background: rgba(80,180,200,0.2); color: #60c0d0; }
.tone-absurdist { background: rgba(220,180,40,0.2); color: #d0b840; }

/* Domain filter pills */
.domain-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.domain-pill {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'JetBrains Mono', monospace;
}

.domain-pill.active {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  background: rgba(196,163,90,0.1);
}

.domain-pill:hover {
  border-color: var(--accent-gold);
}