:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --accent: #3b82f6;
  --accent-soft: #93c5fd;
  --border: #d1d5db;
  --surface-soft: #fffdf9;
  --input-bg: #fffdf9;
  --shadow: rgba(0, 0, 0, 0.05);
  --danger: #b91c1c;
}

body[data-theme="paper"] {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --accent: #3b82f6;
  --accent-soft: #93c5fd;
  --border: #d1d5db;
  --surface-soft: #fffdf9;
  --input-bg: #fffdf9;
  --shadow: rgba(0, 0, 0, 0.05);
  --danger: #b91c1c;
}

body[data-theme="crt"] {
  --bg: #0b1120;
  --panel: #0f172a;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22d3ee;
  --accent-soft: rgba(34, 211, 238, 0.25);
  --border: rgba(148, 163, 184, 0.5);
  --surface-soft: rgba(15, 23, 42, 0.9);
  --input-bg: #01060f;
  --shadow: rgba(45, 212, 191, 0.2);
  --danger: #f87171;
}

body[data-theme="rescue"] {
  --bg: #020c1a;
  --panel: #041e34;
  --ink: #fef5e6;
  --muted: #ffcba4;
  --accent: #ff7a18;
  --accent-soft: rgba(255, 122, 24, 0.25);
  --border: rgba(255, 122, 24, 0.8);
  --surface-soft: #052a45;
  --input-bg: #031628;
  --shadow: rgba(255, 122, 24, 0.35);
  --danger: #ff9f68;
}

body[data-theme="rescue"] .panel,
body[data-theme="rescue"] .ad {
  box-shadow: 0 0 0 2px rgba(255, 122, 24, 0.35), 0 0 30px rgba(255, 122, 24, 0.25);
}

body[data-theme="rescue"] textarea,
body[data-theme="rescue"] .ad,
body[data-theme="rescue"] .panel {
  border-color: rgba(255, 122, 24, 0.85);
}

body[data-theme="rescue"] button {
  border-color: rgba(255, 122, 24, 0.9);
  box-shadow: 0 0 12px rgba(255, 122, 24, 0.35);
}

body[data-theme="midnight"] {
  --bg: #0d0b1a;
  --panel: #1c1633;
  --ink: #f3f4f6;
  --muted: #c4b5fd;
  --accent: #a855f7;
  --accent-soft: rgba(168, 85, 247, 0.25);
  --border: rgba(167, 139, 250, 0.4);
  --surface-soft: #2b2150;
  --input-bg: #120d24;
  --shadow: rgba(168, 85, 247, 0.18);
  --danger: #f472b6;
}

body[data-theme="sunset"] {
  --bg: #fff7ed;
  --panel: #fff1e6;
  --ink: #7c2d12;
  --muted: #9a3412;
  --accent: #fb923c;
  --accent-soft: rgba(251, 146, 60, 0.3);
  --border: #fed7aa;
  --surface-soft: #ffe4d0;
  --input-bg: #fff8ee;
  --shadow: rgba(249, 115, 22, 0.25);
  --danger: #c2410c;
}

body[data-theme="grove"] {
  --bg: #ecfdf5;
  --panel: #ffffff;
  --ink: #064e3b;
  --muted: #047857;
  --accent: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.2);
  --border: #a7f3d0;
  --surface-soft: #d1fae5;
  --input-bg: #ecfdf5;
  --shadow: rgba(16, 185, 129, 0.25);
  --danger: #dc2626;
}

body[data-theme="terminal"] {
  --bg: #050505;
  --panel: #0d0d0d;
  --ink: #d1fae5;
  --muted: #6ee7b7;
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.25);
  --border: rgba(110, 231, 183, 0.5);
  --surface-soft: #111827;
  --input-bg: #020617;
  --shadow: rgba(34, 197, 94, 0.2);
  --danger: #f87171;
}

body[data-theme="hyper"] {
  --bg: radial-gradient(circle at top, #1a1a2e 0%, #05050a 45%, #010103 100%);
  --panel: rgba(8, 10, 26, 0.75);
  --ink: #f8fafc;
  --muted: #cbd5f5;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.3);
  --border: rgba(76, 201, 240, 0.8);
  --surface-soft: rgba(10, 12, 30, 0.85);
  --input-bg: rgba(5, 7, 18, 0.9);
  --shadow: rgba(124, 58, 237, 0.25);
  --danger: #fb7185;
}

body[data-theme="hyper"] .panel,
body[data-theme="hyper"] .ad {
  border-color: transparent;
  backdrop-filter: blur(16px);
  border-image: linear-gradient(120deg, rgba(76, 201, 240, 0.9), rgba(124, 58, 237, 0.9)) 1;
  box-shadow: 0 0 20px rgba(76, 201, 240, 0.25), 0 0 50px rgba(124, 58, 237, 0.25);
}

body[data-theme="hyper"] textarea {
  border-color: transparent;
  border-image: linear-gradient(90deg, rgba(76, 201, 240, 0.85), rgba(232, 121, 249, 0.85)) 1;
  color: #e0f2ff;
}

body[data-theme="hyper"] button {
  border-image: linear-gradient(90deg, rgba(76, 201, 240, 0.9), rgba(236, 72, 153, 0.9)) 1;
  background: rgba(5, 8, 20, 0.8);
  color: #f8fafc;
  box-shadow: 0 0 15px rgba(236, 72, 153, 0.35);
}

body[data-theme="hyper"] button:hover {
  background: rgba(9, 20, 45, 0.9);
}

body[data-theme="aurora"] {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.9);
  --ink: #101828;
  --muted: #475467;
  --accent: #9333ea;
  --accent-soft: rgba(147, 51, 234, 0.15);
  --border: rgba(147, 51, 234, 0.25);
  --surface-soft: rgba(241, 245, 255, 0.9);
  --input-bg: rgba(255, 255, 255, 0.95);
  --shadow: rgba(79, 70, 229, 0.15);
  --danger: #e11d48;
  background: #ffffff;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.25), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(236, 72, 153, 0.2), transparent 40%),
    radial-gradient(circle at 50% 80%, rgba(16, 185, 129, 0.15), transparent 45%);
}

body[data-theme="aurora"] .panel,
body[data-theme="aurora"] .ad {
  border-color: transparent;
  border-image: linear-gradient(135deg, rgba(79, 70, 229, 0.7), rgba(249, 115, 22, 0.7)) 1;
  box-shadow: 0 0 20px rgba(147, 51, 234, 0.15), 0 0 35px rgba(79, 70, 229, 0.1);
  background-image:
    linear-gradient(125deg, rgba(236, 72, 153, 0.12), rgba(79, 70, 229, 0.12)),
    linear-gradient(320deg, rgba(8, 145, 178, 0.08), rgba(249, 115, 22, 0.05));
  background-blend-mode: screen;
}

body[data-theme="aurora"] textarea {
  border-color: transparent;
  border-image: linear-gradient(90deg, rgba(79, 70, 229, 0.6), rgba(8, 145, 178, 0.6)) 1;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.9));
}

body[data-theme="aurora"] button {
  border-color: transparent;
  border-image: linear-gradient(120deg, rgba(79, 70, 229, 0.8), rgba(8, 145, 178, 0.8)) 1;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.8), rgba(252, 252, 255, 0.95));
  color: #0f172a;
  box-shadow: 0 0 15px rgba(79, 70, 229, 0.2);
  position: relative;
  overflow: hidden;
}

body[data-theme="aurora"] .ad {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(249, 115, 22, 0.1));
  color: #0f172a;
}

body[data-theme="aurora"] .token-count strong[data-band="safe"] {
  color: #0f172a;
}

body[data-theme="aurora"] button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(236, 72, 153, 0.15), rgba(79, 70, 229, 0.15));
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

body[data-theme="aurora"] button:hover::after {
  opacity: 1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

body[data-theme="crt"] .panel {
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.35), 0 0 25px rgba(34, 211, 238, 0.2);
}

a.skip-link {
  position: absolute;
  left: -999px;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  z-index: 1000;
}

a.skip-link:focus {
  left: 12px;
  top: 12px;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 24px;
  margin: 16px 0;
  width: 100%; 
  box-shadow: 4px 4px 0 var(--shadow);
}

.panel h1,
.panel h2,
.panel h3 {
  font-family: "IBM Plex Mono", "JetBrains Mono", "Courier Prime", monospace;
  margin-top: 0;
  color: var(--ink);
}

.intro {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.lede {
  font-size: 1.05rem;
  max-width: 52ch;
}

.toggle-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.toggle-bar button {
  width: 160px;
}

.grid {
  display: grid;
  grid-template-columns: clamp(160px, 14vw, 220px) minmax(0, 1fr) clamp(160px, 14vw, 220px);
  column-gap: 16px;
  row-gap: 16px;
  max-width: 1280px;
  margin: 16px auto 24px;
  align-items: stretch;
  min-height: 60vh;
}

.panel--input,
.panel--context {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

textarea {
  width: 100%;
  flex: 1 1 auto;
  min-height: 200px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--border);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.95rem;
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--ink);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.controls--top {
  margin-top: 0;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.controls--top .token-count--inline {
  margin-left: auto;
}

button {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  border: 2px solid var(--ink);
  background: var(--panel);
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

button:hover {
  background: var(--accent-soft);
}

button:active {
  transform: translateY(1px);
}

.ghost {
  border-color: var(--muted);
  color: var(--muted);
}

.hint {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.utility-ads {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.ad-desktop-only {
  display: flex;
}

@media (min-width: 769px) {
  .utility-ads {
    display: none;
  }
}

.ad {
  background: var(--surface-soft);
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  min-height: 80px;
}

.ad img {
  display: block;
  max-width: 100%;
  height: auto;
}

.ad-banner img,
.ad-fold img,
.ad-sky img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-small img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

body.dev-mode .ad {
  border: 2px dashed rgba(30, 41, 59, 0.25);
}

body:not(.dev-mode) .ad {
  border: 2px solid transparent;
}

.ad-banner,
.ad-fold,
.ad-banner-bottom {
  max-width: 1280px;
  margin: 16px auto;
  width: 100%;
}

.ad-banner,
.ad-fold,
.ad-banner-bottom {
  max-width: 1280px;
  margin: 16px auto;
  width: 100%;
}

.ad-sky {
  min-height: 600px;
  width: clamp(160px, 14vw, 220px);
}

.ad-small {
  min-height: 100px;
}

body.ads-hidden .ad {
  display: none;
}

.grid .panel {
  width: 100%;
}

body:not(.ads-hidden) .grid .panel {
  margin: 16px;
  width: calc(100% - 32px);
}

body.ads-hidden .grid {
  grid-template-columns: minmax(0, 1fr);
  min-height: 50vh;
}

@media (min-width: 769px) {
  .ad-banner,
  .ad-fold,
  .ad-banner-bottom {
    min-height: 300px;
  }
}

.status {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.9rem;
}

#statusMessage[data-tone="success"] {
  color: #15803d;
}

#statusMessage[data-tone="warn"] {
  color: #b45309;
}

#statusMessage[data-tone="error"] {
  color: #b91c1c;
}

.token-count strong {
  font-family: "IBM Plex Mono", monospace;
}

.token-count--inline {
  font-size: 0.9rem;
}

.token-count strong[data-band="safe"] {
  color: var(--ink);
}

.token-count strong[data-band="warn"] {
  color: #d97706;
}

.token-count strong[data-band="danger"] {
  color: #dc2626;
}

.token-count strong[data-band="cap"] {
  color: #be123c;
}

.options ul {
  padding-left: 1.25rem;
}

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

@media (max-width: 768px) {
  .ad-desktop-only {
    display: none !important;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: min(960px, 100%);
    margin: 8px auto 16px;
    row-gap: 12px;
  }

  body:not(.ads-hidden) .grid .panel {
    margin: 8px 0;
    width: 100%;
  }

  .toggle-bar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .toggle-bar button {
    width: auto;
  }

  .panel {
    padding: 16px;
  }

  button {
    width: 100%;
  }

  .controls {
    flex-direction: column;
  }

  .status {
    flex-direction: column;
  }
}
