:root {
  /* Fallback before JS measures header; updated via ResizeObserver */
  --sidebar-offset: 120px;
  /* Single source of horizontal inset — avoids double gutters & calc(100% - n) drift */
  --layout-pad-inline: clamp(12px, 3.5vw, 24px);
  --layout-pad-bottom: 40px;
  --layout-max-nav: 1380px;
  --layout-max-main: 1240px;

  /* ===== Base palette ===== */
  --bg: #FFFFFF;
  --surface: #f7f7f7;
  --text: #111111;
  --text-muted: #666666;
  --border: #e5e5e5;
  --accent: #4F46E5;
  --accent-soft: #4F46E533;

  /* Section background tiers — dark, color-blocked sections */
  --bg-group1: #111111;
  --text-group1: #F2F2F2;
  --info-icon-color: #818CF8;
  --bg-legal: #FFFFFF;
  --text-legal: #111111;
  --bg-contact: #FFFFFF;
  --text-contact: #111111;

  /* Height of the soft gradient band that blends one section tier into the next.
     Static (never animated) so prefers-reduced-motion needs no special case. */
  --section-blend: clamp(80px, 12vw, 150px);
  --section-pad: 40px;
  --section-divider: #808080;

  /* Derived surfaces & text hierarchy */
  --panel: var(--surface);
  --panel-strong: var(--surface);
  --panel-alt: var(--bg);
  --heading: var(--text);
  --muted: var(--text-muted);

  /* Derived accent interactions (AA-safe accent text + button gradient) */
  --accent-text: #4F46E5;
  --accent-start: #4338ca;
  --accent-end: #4F46E5;
  --accent-gradient: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  --on-accent: #ffffff;

  /* Semantic states */
  --success: #15803d;
  --error: #b91c1c;
  --warning: #b45309;
  --error-soft: rgba(185, 28, 28, 0.28);

  /* Elevation & chrome */
  --shadow: 0 18px 40px rgba(17, 17, 17, 0.1);
  --shadow-sm: 0 6px 18px rgba(17, 17, 17, 0.08);
  --button-shadow: 0 14px 26px rgba(99, 102, 241, 0.28);
  --message-bg: var(--surface);
  --mark-bg: var(--accent-soft);
  --spinner-track: rgba(17, 17, 17, 0.14);
  --dropdown-bg: var(--bg);
  --overlay: rgba(15, 17, 17, 0.4);
  --modal-backdrop: rgba(255, 255, 255, 0.45);

  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* ===== Base palette ===== */
  --bg: #000000;
  --surface: #111111;
  --text: #F2F2F2;
  --text-muted: #9a9a9a;
  --border: #262626;
  --accent: #818CF8;
  --accent-soft: #818CF833;

  /* Section background tiers — dark, color-blocked sections */
  --bg-group1: #FFFFFF;
  --text-group1: #111111;
  --info-icon-color: #4F46E5;
  --bg-legal: #262626;
  --text-legal: #F2F2F2;
  --bg-contact: #262626;
  --text-contact: #F2F2F2;

  /* Derived surfaces & text hierarchy */
  --panel: var(--surface);
  --panel-strong: var(--surface);
  --panel-alt: #262626;
  --heading: var(--text);
  --muted: var(--text-muted);

  /* Derived accent interactions (AA-safe accent text + button gradient) */
  --accent-text: #a5b4fc;
  --accent-start: #818CF8;
  --accent-end: #a5b4fc;
  --accent-gradient: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  --on-accent: #111111;

  /* Semantic states */
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --error-soft: rgba(248, 113, 113, 0.28);

  /* Elevation & chrome */
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 8px 22px rgba(0, 0, 0, 0.5);
  --button-shadow: 0 14px 26px rgba(129, 140, 248, 0.22);
  --message-bg: var(--surface);
  --mark-bg: var(--accent-soft);
  --spinner-track: rgba(242, 242, 242, 0.22);
  --dropdown-bg: #262626;
  --overlay: rgba(0, 0, 0, 0.55);
  --modal-backdrop: rgba(0, 0, 0, 0.55);
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: clip;
  max-width: 100%;
  /* Continue the Contact background into the browser overscroll area
     (replaces the old clip-path bottom extension). */
  background-color: var(--bg-contact);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: var(--bg);
  transition: background 220ms ease, color 220ms ease;
  overflow-x: clip;
  overflow-y: auto;
  padding-inline: var(--layout-pad-inline);
  max-width: 100%;
  box-sizing: border-box;
}

.page-scroll {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: visible;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
.panel,
.history-sidebar,
.message-box,
.summary-card,
.profile-dropdown,
.auth-dialog {
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.nav-shell {
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
  padding-top: 0;
  position: sticky;
  top: 0;
  z-index: 900;
  overflow-x: clip;
  overflow-y: visible;
  min-width: 0;
  padding-bottom: 0;
  background: transparent;
  border-bottom: none;
  box-shadow: none;
}

.content-shell {
  width: 100%;
  max-width: var(--layout-max-main);
  margin-inline: auto;
  padding-block: 0 var(--layout-pad-bottom);
  padding-inline: 0;
  display: grid;
  gap: 0;
  min-width: 0;
}

.landing-container {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  display: grid;
  gap: 0;
  min-width: 0;
}

.topbar,
.hero,
.workspace-grid {
  display: grid;
}

.topbar {
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-radius: 0;
  backdrop-filter: none;
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
  min-width: 0;
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
}

@media (min-width: 768px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

.topbar-left,
.topbar-actions,
.brand-mark,
.summary-header,
.summary-header-actions,
.file-meta,
.auth-actions,
.profile-menu {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-left,
.brand-mark,
.topbar-actions,
.summary-header {
  gap: 12px;
}

.topbar-left {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
}

@media (min-width: 768px) {
  .topbar-left {
    width: auto;
    flex: 1 1 auto;
  }
}

.topbar-actions {
  position: relative;
  overflow: visible;
  z-index: 400;
  min-width: 0;
  width: auto;
  max-width: none;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
}

.topbar-actions > * {
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .topbar-actions {
    width: auto;
    max-width: none;
  }
}

.brand-mark {
  min-width: 0;
  flex: 1 1 auto;
  gap: 10px;
  flex-wrap: nowrap;
}

.eyebrow,
.section-tag,
.meta-label,
.summary-label,
.sidebar-label {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-text);
}

.brand-mark h1,
.hero-copy h2,
.panel-heading h3,
.sidebar-header h2 {
  margin: 0;
  color: var(--heading);
}

.brand-mark h1 {
  font-size: 1.02rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.1;
}

.brand-mark > div {
  min-width: 0;
}

.icon-button,
.ghost-button,
.secondary-button,
.avatar-button,
.profile-action {
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--heading);
  cursor: pointer;
}

.icon-button,
.avatar-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

.menu-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.theme-toggle-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guest-actions,
.summary-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.guest-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.ghost-button,
.secondary-button,
.profile-action {
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 600;
}

.secondary-button {
  background: var(--accent-gradient);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow: none;
}

.profile-menu {
  position: relative;
  z-index: 500;
  overflow: visible;
  flex: 0 0 auto;
}

.avatar-button {
  border-radius: 999px;
  font-weight: 800;
}

.avatar-button:hover,
.ghost-button:hover,
.secondary-button:hover,
.icon-button:hover,
.profile-action:hover,
.primary-button:hover:not(:disabled) {
  opacity: 0.9;
}

.profile-dropdown {
  --profile-dropdown-shift: 0px;
  --profile-dropdown-max-width: 320px;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  left: auto;
  width: min(var(--profile-dropdown-max-width), calc(100vw - 24px));
  min-width: min(18rem, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 20px;
  background: var(--dropdown-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate3d(var(--profile-dropdown-shift), -8px, 0) scale(0.98);
  transform-origin: top right;
  pointer-events: none;
  visibility: hidden;
  z-index: 9999;
  overflow: hidden;
  isolation: isolate;
}

.profile-dropdown.is-open {
  opacity: 1;
  transform: translate3d(var(--profile-dropdown-shift), 0, 0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

.profile-dropdown.is-compact {
  top: calc(100% + 8px);
}

.profile-identity {
  display: grid;
  gap: 4px;
  padding: 2px 4px 6px;
}

.profile-name {
  margin: 0;
  color: var(--heading);
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-email {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-divider {
  height: 1px;
  margin: 0;
  background: var(--border);
}

.profile-action {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  background: var(--panel-strong);
}

.profile-action + .profile-action {
  margin-top: 2px;
}

.profile-action:focus-visible,
.avatar-button:focus-visible,
.field input:focus-visible,
.custom-select-trigger:focus-visible,
.custom-select-option:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field input:hover,
.custom-select-trigger:hover,
.profile-action:hover {
  border-color: var(--accent);
}

.hero {
  gap: 16px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

/* .auth-dialog,
.history-sidebar {
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
} */

.auth-dialog {
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.history-sidebar {
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero-copy {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 72px 24px 64px;
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
  max-width: 100%;
  text-align: center;
  align-items: center;
  justify-items: center;
}

.panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 24px 0;
}

.hero-copy h2 {
  font-size: clamp(1.9rem, 3.8vw, 3rem);
  line-height: 1.08;
  max-width: min(36rem, 100%);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hero-text,
.panel-heading p,
.sidebar-copy,
.summary-meta,
.summary-content,
.status-text,
.file-name,
.selected-files-empty,
.auth-message,
.history-empty {
  color: var(--muted);
}

.hero-text {
  margin: 8px 0 24px;
  max-width: min(52ch, 100%);
  line-height: 1.7;
}

.hero-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.hero-pills span {
  padding: 6px 14px;
  border-radius: 999px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.hero {
  padding-bottom: 40px;
}

.upload-panel {
  padding: 32px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.result-panel {
  padding: 32px;
  background: transparent;
}

.panel {
  display: grid;
  align-content: start;
  align-items: start;
  gap: 18px;
  padding: 24px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  height: auto;
  overflow-x: hidden;
  overflow-y: visible;
}

@media (min-width: 768px) {
  .panel {
    max-width: 100%;
  }
}

.panel-header-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
  width: 100%;
}

.panel-header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.panel-header-text {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.panel-header-text h3 {
  margin: 0;
  color: var(--heading);
}

.panel-header-text p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.workspace-grid > * ,
.panel > * ,
.summary-header > * ,
.file-meta > * {
  min-width: 0;
}

.panel-heading {
  display: grid;
  gap: 8px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  margin-bottom: 8px;
}

.panel-heading p {
  margin: 0;
  line-height: 1.6;
}

.upload-form {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.upload-dropzone {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 180px;
  min-width: 0;
  max-width: 100%;
  padding: 36px 24px;
  border-radius: 14px;
  border: 2px dashed var(--border);
  background: var(--panel-alt);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 180ms ease, background 180ms ease;
}

.dropzone-title,
.dropzone-subtitle {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.upload-dropzone.has-files {
  border-color: var(--accent);
}

.upload-dropzone:not(.is-drag-active):not(:hover) {
  border-color: var(--border);
}

.upload-dropzone.is-drag-active {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.dropzone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: none;
  color: var(--accent);
  font-size: 1.6rem;
  font-weight: 800;
}

.dropzone-title {
  color: var(--heading);
  font-size: 1.08rem;
  font-weight: 700;
}

.dropzone-subtitle {
  color: var(--muted);
}

input[type="file"] {
  display: none;
}

.controls-grid{
  display: grid;
  gap: 16px;
}

@media (min-width: 768px) {
  .controls-grid {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

.auth-form{
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel-alt);
  color: var(--text);
  box-shadow: none;
}

.custom-select {
  position: relative;
  min-width: 0;
}

.custom-select-trigger,
.custom-select-option {
  width: 100%;
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--panel-alt);
  box-shadow: none;
  cursor: pointer;
  text-align: left;
}

.custom-select.is-open .custom-select-trigger {
  border-color: var(--accent);
  box-shadow: none;
}

.custom-select-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.custom-select-caption {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.custom-select-value {
  color: var(--heading);
  font-weight: 800;
}

.custom-select-chevron {
  width: 12px;
  height: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 180ms ease, color 180ms ease;
  flex-shrink: 0;
}

.custom-select.is-open .custom-select-chevron {
  color: var(--accent);
  transform: rotate(-135deg) translateY(-1px);
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--dropdown-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 700;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  max-height: min(340px, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.custom-select-menu.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

.custom-select-option {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: none;
  cursor: pointer;
  text-align: left;
}

.custom-select-option:hover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.custom-select-option.is-selected {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.custom-select-option-title {
  color: var(--heading);
  font-weight: 600;
}

.custom-select-option-copy {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.file-meta {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: 100%;
  min-width: 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.file-meta.is-visible {
  opacity: 1;
  transform: none;
}

@media (min-width: 768px) {
  .file-meta {
    flex-direction: row;
    align-items: stretch;
  }
}

.file-meta > div {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 16px 18px;
  border-radius: 12px;
  border: none;
  background: var(--panel-alt);
  overflow: hidden;
}

@media (min-width: 768px) {
  .file-meta > div {
    flex: 1 1 0;
    width: auto;
  }
}

.file-name,
.status-text {
  margin: 0;
  font-weight: 700;
}

.file-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-text {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status-text::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background-color 200ms ease, opacity 200ms ease, transform 200ms ease;
}

.status-text.is-ready,
.status-text.is-summarizing {
  color: var(--accent-text);
}

.status-text.is-ready::before,
.status-text.is-summarizing::before {
  background: var(--accent);
}

.status-text.is-summarizing::before {
  animation: status-pulse 1.1s ease-in-out infinite;
}

.status-text.is-done {
  color: var(--success);
}

.status-text.is-done::before {
  background: var(--success);
}

.status-text.is-error {
  color: var(--error);
}

.status-text.is-error::before {
  background: var(--error);
}

@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.72);
  }
}

.upload-empty-state {
  margin: 0;
  padding: 2px 4px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-muted);
  text-align: center;
}

.selected-files {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  min-width: 0;
  max-width: 100%;
}

.selected-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.selected-file-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.selected-file-name,
.selected-file-meta {
  margin: 0;
}

.selected-file-name {
  display: block;
  color: var(--heading);
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.selected-file-remove {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--panel-alt);
  color: var(--heading);
  font-weight: 700;
  cursor: pointer;
}

.selected-file-remove:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.button-spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid var(--spinner-track);
  border-top-color: var(--on-accent);
  animation: spin 0.85s linear infinite;
}

.message-box {
  margin-top: 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--message-bg);
  border: 1px solid var(--border);
  line-height: 1.6;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-box.is-loading {
  color: var(--accent-text);
}

.message-box.is-success {
  color: var(--success);
}

.message-box.is-error {
  color: var(--error);
}

.summary-card {
  margin-top: 0;
  padding: 24px;
  border-radius: 12px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  min-height: 320px;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: none;
}

.summary-results {
  display: grid;
  gap: 18px;
  width: 100%;
  min-width: 0;
}

.summary-card--error {
  border-color: var(--error-soft);
}

.loading-state {
  display: grid;
  gap: 16px;
  padding: 24px;
  border-radius: 12px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  min-height: 320px;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 3px solid var(--spinner-track);
  border-top-color: var(--accent);
  animation: spin 0.85s linear infinite;
  margin: 0 auto;
}

.loading-text {
  margin: 0;
  color: var(--accent-text);
  font-weight: 700;
  font-size: 1.1rem;
}

.loading-skeleton {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.skeleton-line {
  height: 16px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--panel-alt) 25%, var(--border) 50%, var(--panel-alt) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-line:nth-child(1) {
  width: 100%;
}

.skeleton-line:nth-child(2) {
  width: 90%;
}

.skeleton-line:nth-child(3) {
  width: 95%;
}

.skeleton-line:nth-child(4) {
  width: 85%;
}

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

.summary-card--empty .summary-content {
  min-height: 0;
}

.summary-header {
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.summary-header > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.summary-header h3 {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-header-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.summary-meta {
  margin-bottom: 16px;
  font-size: 0.92rem;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.summary-content {
  display: grid;
  gap: 12px;
  min-height: 220px;
  min-width: 0;
  line-height: 1.8;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
}

.summary-paragraph,
.summary-bullet {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.summary-bullet {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  box-sizing: border-box;
}

mark {
  background: var(--mark-bg);
  color: inherit;
  padding: 0 0.18em;
  border-radius: 0.4em;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  transition: opacity 220ms ease;
  /* Above header/topbar so the sheet + dim layer stack predictably */
  z-index: 1100;
}

.sidebar-overlay.is-visible {
  opacity: 1;
}

.history-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(360px, calc(100% - 24px));
  padding: 24px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 24px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  min-width: 0;
  box-sizing: border-box;
  transform: translateX(-108%);
  opacity: 0;
  pointer-events: none;
  border-radius: 0 28px 28px 0;
}

.history-sidebar.is-closed {
  transform: translateX(-108%);
  opacity: 0;
  pointer-events: none;
}

.history-sidebar.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.sidebar-header > div {
  min-width: 0;
}

.sidebar-header h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-copy {
  margin: 16px 0 18px;
  line-height: 1.7;
}

.history-list {
  display: grid;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.history-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel-strong);
  padding: 14px;
  text-align: left;
  cursor: pointer;
}

.history-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.history-item-title,
.history-item-type,
.history-item-time {
  margin: 0;
}

.history-item-title {
  color: var(--heading);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-type,
.history-item-time {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Must sit above .nav-shell / .topbar (200–400) and sidebar (1200) */
  z-index: 2500;
  opacity: 0;
  transition: opacity 180ms ease;
}

.auth-modal.is-closed {
  opacity: 0;
  pointer-events: none;
}

.auth-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(8px);
  background: var(--modal-backdrop);
}

.auth-dialog {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-width: 0;
  margin-block: auto;
  flex-shrink: 0;
  max-height: min(90vh, calc(100vh - 32px));
  max-height: min(90dvh, calc(100dvh - 32px));
  padding: 24px;
  z-index: 1;
  transform: translateY(10px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
}

.auth-modal.is-open .auth-dialog {
  transform: translateY(0);
}

.auth-close-button {
  position: absolute;
  top: 16px;
  right: 16px;
}

.auth-warning {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--warning);
}

.auth-message {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.auth-tab {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  background: var(--panel-strong);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.auth-tab.is-active {
  color: var(--on-accent);
  background: var(--accent-gradient);
  border-color: transparent;
}

.auth-actions {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.info-sections {
  display: grid;
  gap: 0;
  width: 100%;
  position: relative;
}

/* Full-bleed background layer for each color-blocked tier. Painted by a
   pseudo-element instead of the old box-shadow + clip-path trick, whose hard
   clip edges produced stray hairline "dividers" at the top of the Overview
   block and right after FAQ. Natural element edges don't alias, so the tiers
   now join seamlessly. */
.info-sections::before {
  content: "";
  position: absolute;
  inset: 0 -100vmax;
}

.info-sections.theme-sections::before {
  /* Page background dissolving into the Overview block, then solid */
  background: linear-gradient(
    to bottom,
    var(--bg),
    var(--bg-group1) var(--section-blend),
    var(--bg-group1)
  );
}

.info-sections.legal-sections::before {
  /* Previous block dissolving into Legal/Contact, then solid to the bottom */
  background: linear-gradient(
    to bottom,
    var(--bg-group1),
    var(--bg-legal) var(--section-blend),
    var(--bg-legal)
  );
}

.info-sections.theme-sections {
  color: var(--text-group1);
  margin-top: clamp(40px, 7vw, 60px);
  transition: color 220ms ease;
}

.info-sections.legal-sections {
  color: var(--text-legal);
  /* The page ends with Contact. Cover .content-shell's bottom padding with
     the section tier (pulled up via negative margin, net zero layout shift)
     so the grey runs to the true end of the document — otherwise that strip
     shows body's black background in dark mode. */
  padding-bottom: var(--layout-pad-bottom);
  margin-bottom: calc(-1 * var(--layout-pad-bottom));
}

/* Reserve room for the blend band so section content starts below it
   (keeps text out of mid-gradient contrast zones without layout shift). */
.info-sections.theme-sections .info-section:first-child,
.info-sections.legal-sections .info-section:first-child {
  padding-top: calc(var(--section-pad) + var(--section-blend));
}

/* One consistent divider between adjacent sections:
   Overview→Audience→Advantages→FAQ and Legal→Get-in-touch (sibling selector).
   Deliberately NOT between FAQ and Legal/Privacy: those blocks transition
   naturally through the blend band without a divider. */
.info-section + .info-section:not(#legal) {
  border-top: 1px solid var(--section-divider);
}

.info-section {
  position: relative; /* keeps content above the full-bleed ::before layer */
  padding: var(--section-pad) 0;
}

/* Section background tiers — dark color-blocked sections.
   The first four share .info-sections' background (one continuous dark block);
   only their text colors are set here. */
#whatIsIt,
#whoIsItFor,
#whyIsItBetter,
#faq {
  color: var(--text-group1);
}

#whatIsIt .section-tag,
#whoIsItFor .section-tag,
#whyIsItBetter .section-tag,
#faq .section-tag {
  color: var(--text-group1);
}

#whatIsIt h3,
#whoIsItFor h3,
#whyIsItBetter h3,
#faq h3 {
  color: var(--text-group1);
}

#whatIsIt .info-lead,
#whoIsItFor .info-lead,
#whyIsItBetter .info-lead,
#faq .faq-answer {
  color: var(--text-group1);
}

#whatIsIt .info-feature-item,
#whoIsItFor .info-card p,
#whyIsItBetter .info-feature-card p,
#faq .faq-answer {
  color: var(--text-group1);
}

/* Legal keeps the shared legal tier; Contact paints its own tier so it can
   diverge via --bg-contact/--text-contact without affecting Privacy. */
#privacy {
  color: var(--text-legal);
}

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

#privacy .section-tag,
#privacy h3,
#privacy .privacy-content p {
  color: var(--text-legal);
}

#contact .section-tag,
#contact h3,
#contact .info-lead {
  color: var(--text-contact);
}

.info-section-inner {
  display: grid;
  gap: 18px;
  max-width: 100%;
}

.info-section h3 {
  margin: 0;
  color: var(--heading);
}

.info-lead {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--text);
  max-width: 640px;
}

#whatIsIt .info-lead,
#whoIsItFor .info-lead,
#whyIsItBetter .info-lead {
  color: var(--text-group1);
}

[data-theme="dark"] #whatIsIt .info-lead,
[data-theme="dark"] #whoIsItFor .info-lead,
[data-theme="dark"] #whyIsItBetter .info-lead {
  color: var(--text-group1);
}

.info-feature-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 600px) {
  .info-feature-list {
    grid-template-columns: 1fr;
  }
}

.info-feature-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.92rem;
  color: var(--text);
}

#whatIsIt .info-feature-item {
  color: var(--text-group1);
}

[data-theme="dark"] #whatIsIt .info-feature-item {
  color: var(--text-group1);
}

.info-feature-item-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--info-icon-color);
  margin-top: 2px;
}

.info-feature-icon {
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  font-size: 1rem;
}

.info-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.info-card {
  padding: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: grid;
  gap: 8px;
  cursor: pointer;
}

.info-card-icon {
  width: 28px;
  height: 28px;
  color: var(--info-icon-color);
}

#whatIsIt .info-card,
#whoIsItFor .info-card,
#whyIsItBetter .info-feature-card,
#faq .faq-item {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] #whatIsIt .info-card,
[data-theme="dark"] #whoIsItFor .info-card,
[data-theme="dark"] #whyIsItBetter .info-feature-card,
[data-theme="dark"] #faq .faq-item {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.2);
}

.info-card h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--heading);
}

#whatIsIt .info-card h4,
#whoIsItFor .info-card h4,
#whyIsItBetter .info-feature-card h4 {
  color: var(--text-group1);
}

[data-theme="dark"] #whatIsIt .info-card h4,
[data-theme="dark"] #whoIsItFor .info-card h4,
[data-theme="dark"] #whyIsItBetter .info-feature-card h4 {
  color: var(--text-group1);
}

#faq .faq-question {
  color: var(--text-group1);
}

[data-theme="dark"] #faq .faq-question {
  color: var(--text-group1);
}

.info-card p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--muted);
}

#whoIsItFor .info-card p {
  color: var(--text-group1);
}

[data-theme="dark"] #whoIsItFor .info-card p {
  color: var(--text-group1);
}

.info-card-grid--features {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.info-feature-card {
  padding: 22px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: grid;
  gap: 10px;
  cursor: pointer;
}

#whyIsItBetter .info-feature-card {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] #whyIsItBetter .info-feature-card {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.2);
}

.info-feature-card-icon {
  width: 32px;
  height: 32px;
  color: var(--info-icon-color);
}

@property --border-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

.info-card,
.info-feature-card {
  position: relative;
}

.info-card::before,
.info-feature-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(
    from var(--border-angle),
    var(--accent),
    var(--accent-soft),
    var(--accent)
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.info-card:hover::before,
.info-feature-card:hover::before {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .info-card:hover::before,
  .info-feature-card:hover::before {
    animation: border-angle-spin 2s linear infinite;
  }
}

@keyframes border-angle-spin {
  to {
    --border-angle: 360deg;
  }
}

.info-feature-card h4 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--heading);
}

.info-feature-card p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--muted);
}

#whyIsItBetter .info-feature-card p {
  color: var(--text-group1);
}

[data-theme="dark"] #whyIsItBetter .info-feature-card p {
  color: var(--text-group1);
}

.faq-list {
  display: grid;
  gap: 8px;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-strong);
  overflow: hidden;
}

#faq .faq-item {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] #faq .faq-item {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.2);
}

.faq-question {
  padding: 16px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--heading);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "+";
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--info-icon-color);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.faq-item[open] .faq-question::after {
  content: "\2212";
}

.faq-answer {
  margin: 0;
  padding: 0 18px 16px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
}

.privacy-content {
  display: grid;
  gap: 12px;
}

.privacy-content p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
}

.privacy-updated {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-legal);
  opacity: 0.8;
}

[data-theme="dark"] .privacy-updated {
  color: var(--text-legal);
  opacity: 0.8;
}

.contact-email {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 10px;
  text-decoration: none;
  transition: opacity 0.2s ease;
  width: fit-content;
}

.contact-email:hover {
  opacity: 0.88;
}

.contact-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Contact form (Get in touch) — mirrors the app's input/button design system */
.contact-form {
  display: grid;
  gap: 14px;
  max-width: 520px;
}

.contact-field {
  display: grid;
  gap: 6px;
}

.contact-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-contact);
}

.contact-field input,
.contact-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
}

.contact-field input:focus,
.contact-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.contact-field textarea {
  resize: vertical;
  min-height: 120px;
}

.contact-honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.contact-status {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
}

.contact-status.is-success {
  color: var(--success);
}

.contact-status.is-error {
  color: var(--error);
}

.contact-submit {
  justify-self: start;
}

.contact-submit[disabled] {
  opacity: 0.7;
  cursor: progress;
}

@media (max-width: 1024px) {
  .info-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .info-card-grid--features {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  :root {
    --section-pad: 28px;
  }

  .info-section {
    padding: var(--section-pad) 0;
  }

  .info-card-grid,
  .info-card-grid--features {
    grid-template-columns: 1fr;
  }

  .info-lead {
    font-size: 0.95rem;
  }
}

.usage-widget {
  display: grid;
  gap: 12px;
  padding: 16px 20px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.usage-widget-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-text);
}

.usage-bars {
  display: grid;
  gap: 10px;
}

.usage-bar-item {
  display: grid;
  gap: 6px;
}

.usage-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.usage-bar-name {
  font-size: 0.82rem;
  color: var(--muted);
}

.usage-bar-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}

.usage-bar-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent-gradient);
  transition: width 0.3s ease;
}

.usage-bar-fill--alt {
  background: linear-gradient(135deg, var(--accent-soft), var(--accent));
}

.settings-page {
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
}

.settings-panel {
  display: grid;
  gap: 28px;
}

.settings-section {
  display: grid;
  gap: 14px;
}

.settings-section-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--heading);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.88rem;
  color: var(--text);
  min-width: 0;
}

.settings-value {
  font-weight: 600;
  color: var(--heading);
  overflow-wrap: anywhere;
  min-width: 0;
}

.settings-usage-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.settings-usage-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.settings-usage-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}

.settings-usage-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.settings-usage-reset {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.settings-back-button {
  justify-self: start;
}

.settings-ai-section {
  display: grid;
  gap: 16px;
}

.settings-ai-key-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

.settings-ai-key-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--heading);
  min-width: 0;
}

.settings-byok-status {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
  overflow-wrap: anywhere;
  min-width: 0;
}

.settings-byok-status.connected {
  color: var(--success);
}

.settings-byok-disconnected {
  display: grid;
  gap: 12px;
}

.settings-ai-key-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.settings-ai-key-input input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.settings-ai-key-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-ai-key-link {
  font-size: 0.85rem;
  color: var(--accent-text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow-wrap: anywhere;
  min-width: 0;
}

.settings-ai-key-link:hover {
  text-decoration: underline;
}

.settings-byok-connected {
  display: grid;
  gap: 12px;
  align-items: center;
}

.settings-byok-message {
  margin: 0;
  font-size: 0.9rem;
  color: var(--success);
  font-weight: 500;
}

/* Inline BYOK feedback inside the Settings page (errors/success). The global
   message box is hidden while Settings is open, so BYOK needs its own. */
.settings-byok-message-text {
  margin: 4px 0 0 0;
  font-size: 0.85rem;
  font-weight: 500;
}

.settings-byok-message-text.is-success {
  color: var(--success);
}

.settings-byok-message-text.is-error {
  color: var(--error);
}

.guest-api-key-section {
  display: grid;
  gap: 8px;
  padding: 16px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 16px;
}

.guest-api-key-section input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.guest-api-key-section input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 4px 0 0 0;
}

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

@media (max-width: 1024px) {
  :root {
    --sidebar-offset: 108px;
  }

  body.sidebar-open .page-scroll {
    overflow: visible;
    touch-action: none;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .history-sidebar {
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 380px);
    max-width: calc(100vw - 12px);
    padding: calc(env(safe-area-inset-top, 0px) + 20px) 20px
      calc(env(safe-area-inset-bottom, 0px) + 20px);
    border-radius: 0 24px 24px 0;
  }
}

@media (max-width: 767px) {
  :root {
    --sidebar-offset: 100px;
  }

  .landing-container {
    gap: 0;
  }

  .topbar {
    gap: 10px;
    padding: 12px 16px;
    border-radius: 0;
  }

  .hero {
    padding-bottom: 24px;
  }

  .hero-copy {
    padding: 40px 16px;
  }

  .upload-panel {
    padding: 24px 20px;
    border-radius: 16px;
  }

  .result-panel {
    padding: 24px 20px;
    overflow-y: auto;
    max-height: none;
  }

  .summary-header,
  .file-meta {
    flex-wrap: wrap;
  }

  .topbar-left {
    flex-wrap: nowrap;
    gap: 10px;
  }

  .topbar-actions {
    width: auto;
    margin-left: auto;
    align-self: center;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .file-meta,
  .summary-header {
    width: 100%;
  }

  .summary-header-actions,
  .auth-actions {
    width: 100%;
    justify-content: stretch;
  }

  .guest-actions {
    display: flex;
    width: auto;
    max-width: 100%;
    gap: 6px;
  }

  .guest-actions button,
  .summary-header-actions button,
  .auth-actions button {
    flex: 1;
    min-width: 0;
  }

  .guest-actions button {
    flex: 0 1 auto;
    padding: 8px 10px;
    font-size: 0.88rem;
    white-space: nowrap;
  }

  .icon-button,
  .avatar-button {
    width: 40px;
    height: 40px;
    border-radius: 8px;
  }

  .theme-toggle-icon {
    width: 18px;
    height: 18px;
  }

  .ghost-button,
  .secondary-button,
  .profile-action {
    padding: 8px 10px;
  }

  .brand-mark h1 {
    font-size: clamp(0.92rem, 3.9vw, 1rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .auth-dialog,
  .history-sidebar {
    padding: 18px;
    border-radius: 18px;
  }

  .hero-copy h2 {
    font-size: clamp(1.42rem, 5.4vw, 2.2rem);
    line-height: 1.14;
  }

  .upload-dropzone {
    min-height: 160px;
    padding: 24px 16px;
  }

  .summary-card {
    padding: 18px;
    min-height: 240px;
  }

  .summary-results {
    gap: 14px;
  }

  .summary-content {
    min-height: 180px;
  }

  .field input,
  .custom-select-trigger {
    font-size: 16px;
  }

  .selected-file-item {
    align-items: flex-start;
  }

  .panel-heading h3 {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .panel-header-row {
    gap: 12px;
  }

  .panel-header-icon {
    width: 40px;
    height: 40px;
  }

  .panel-header-icon svg {
    width: 18px;
    height: 18px;
  }

  .loading-state {
    padding: 18px;
    min-height: 240px;
  }

  .loading-spinner {
    width: 40px;
    height: 40px;
  }

  .loading-text {
    font-size: 1rem;
  }

  .loading-skeleton {
    max-width: 100%;
  }

  .settings-usage-grid {
    grid-template-columns: 1fr;
  }

  .settings-ai-key-input {
    grid-template-columns: 1fr;
  }

  .settings-ai-key-input .secondary-button {
    justify-self: stretch;
  }
}

@media (max-width: 480px) {
  :root {
    --layout-pad-bottom: 28px;
  }

  .nav-shell {
    padding-top: 0;
    padding-bottom: 0;
  }

  .content-shell {
    padding-block: 0 var(--layout-pad-bottom);
    gap: 16px;
  }

  .landing-container {
    gap: 0;
  }

  .topbar {
    padding: 12px 16px;
    gap: 8px;
    border-radius: 0;
  }

  .topbar-left {
    gap: 8px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .guest-actions {
    flex-wrap: nowrap;
  }

  .hero-copy {
    padding: 32px 16px;
  }

  .hero-pills span {
    padding: 5px 10px;
    font-size: 0.76rem;
  }

  .upload-panel {
    padding: 20px 16px;
    border-radius: 14px;
  }

  .result-panel {
    padding: 20px 16px;
    overflow-y: auto;
    max-height: none;
  }

  .guest-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 6px;
  }

  .guest-actions button {
    font-size: 0.84rem;
    padding: 7px 9px;
  }

  .summary-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-header-actions button {
    flex: none;
    width: 100%;
  }

  .auth-dialog {
    padding: 18px 16px 20px;
    border-radius: 20px;
  }

  .auth-close-button {
    top: 12px;
    right: 12px;
  }

  .history-sidebar {
    width: min(88vw, 340px);
    max-width: calc(100vw - 6px);
    padding-inline: 14px;
  }

  .panel-header-row {
    gap: 10px;
  }

  .panel-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .panel-header-icon svg {
    width: 16px;
    height: 16px;
  }

  .panel-header-text h3 {
    font-size: 0.98rem;
  }

  .panel-header-text p {
    font-size: 0.84rem;
  }

  .custom-select-trigger {
    padding: 12px 14px;
    border-radius: 8px;
  }

  .custom-select-menu {
    padding: 10px;
    border-radius: 12px;
  }

  .custom-select-option {
    padding: 12px;
    border-radius: 8px;
  }

  .selected-file-item {
    flex-direction: column;
  }

  .selected-file-remove {
    align-self: flex-start;
  }

  .loading-state {
    padding: 16px;
    min-height: 200px;
  }

  .loading-spinner {
    width: 36px;
    height: 36px;
  }

  .loading-text {
    font-size: 0.95rem;
  }
}

/* ===== Scroll reveal (fade-up, triggered via IntersectionObserver) ===== */
html.js-reveal [data-reveal-section] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.55s ease-out, transform 0.55s ease-out;
}

html.js-reveal [data-reveal-section].is-revealed {
  opacity: 1;
  transform: none;
}

html.js-reveal [data-reveal-section] [data-reveal-stagger] > * {
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
  transition-delay: calc(var(--reveal-order, 0) * 60ms);
}

html.js-reveal [data-reveal-section]:not(.is-revealed) [data-reveal-stagger] > * {
  opacity: 0;
  transform: translateY(16px);
}

html.js-reveal [data-reveal-section].is-revealed [data-reveal-stagger] > * {
  opacity: 1;
  transform: none;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  html.js-reveal [data-reveal-section],
  html.js-reveal [data-reveal-section] [data-reveal-stagger] > * {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .file-meta {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .info-card::before,
  .info-feature-card::before {
    animation: none !important;
  }

  .info-card:hover::before,
  .info-feature-card:hover::before {
    opacity: 1;
    background: var(--accent);
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
