:root {
  --bg: #dff3ef;
  --bg-deep: #083c4a;
  --bg-wash: #f6fff6;
  --panel: rgba(240, 252, 249, 0.68);
  --panel-strong: rgba(251, 255, 252, 0.88);
  --text: #0f2e35;
  --muted: #537179;
  --accent: #f36d4d;
  --accent-strong: #d4483a;
  --accent-soft: rgba(243, 109, 77, 0.14);
  --border: rgba(8, 60, 74, 0.12);
  --shadow: 0 28px 80px rgba(6, 45, 58, 0.16);
  --highlight-yellow: #ffd56b;
  --highlight-pink: #ffb6c8;
  --highlight-blue: #7ccae7;
  --highlight-green: #8ed8ad;
  --reader-font: "Iowan Old Style", "Palatino Linotype", serif;
  --reader-size: 18px;
}

body[data-theme="light"] {
  --bg: #eef7fb;
  --bg-deep: #1b5570;
  --bg-wash: #ffffff;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --text: #17303b;
  --muted: #5d7682;
  --accent: #ff6a53;
  --accent-strong: #d54d3f;
  --accent-soft: rgba(255, 106, 83, 0.12);
  --border: rgba(18, 62, 83, 0.12);
  --shadow: 0 24px 70px rgba(34, 73, 98, 0.14);
}

body[data-theme="dark"] {
  --bg: #081722;
  --bg-deep: #041019;
  --bg-wash: #123242;
  --panel: rgba(10, 32, 45, 0.84);
  --panel-strong: rgba(13, 42, 57, 0.92);
  --text: #e8f6f1;
  --muted: #91b5ba;
  --accent: #ff8a5b;
  --accent-strong: #eb5f49;
  --accent-soft: rgba(255, 138, 91, 0.14);
  --border: rgba(201, 235, 229, 0.1);
  --shadow: 0 26px 90px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.62), transparent 24%),
    radial-gradient(circle at 88% 14%, rgba(58, 175, 169, 0.34), transparent 24%),
    radial-gradient(circle at 78% 82%, rgba(243, 109, 77, 0.18), transparent 28%),
    linear-gradient(140deg, var(--bg) 0%, var(--bg-wash) 48%, color-mix(in srgb, var(--bg-deep) 16%, white) 100%),
    var(--bg);
  color: var(--text);
  position: relative;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 36rem;
  height: 36rem;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(80px);
  opacity: 0.48;
  z-index: -1;
}

body::before {
  top: -10rem;
  right: -8rem;
  background: radial-gradient(circle, rgba(6, 137, 149, 0.28), transparent 60%);
}

body::after {
  bottom: -16rem;
  left: -10rem;
  background: radial-gradient(circle, rgba(243, 109, 77, 0.2), transparent 58%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 64%, white) 100%);
  color: white;
  padding: 0.8rem 1.05rem;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 18px 36px color-mix(in srgb, var(--accent-strong) 28%, transparent);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

button.secondary {
  background: color-mix(in srgb, var(--panel-strong) 84%, white);
  color: var(--accent);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.small {
  padding: 0.45rem 0.75rem;
  border-radius: 12px;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button:hover {
  transform: translateY(-1px);
  filter: saturate(1.02);
}

.page-shell {
  width: min(1480px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.2rem 0 2rem;
}

.hero {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 1.35rem;
  align-items: end;
  margin-bottom: 1.5rem;
}

.hero-primary {
  display: grid;
  gap: 1rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(3rem, 7vw, 6rem);
  line-height: 0.88;
  letter-spacing: -0.075em;
  max-width: 9ch;
  text-wrap: balance;
}

.hero-copy {
  max-width: 40rem;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.65;
}

.hero-note,
.section-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.hero-stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.hero-stat {
  padding: 0.95rem 1rem;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.12));
  backdrop-filter: blur(16px);
}

.hero-stat strong,
.hero-stat span {
  display: block;
}

.hero-stat strong {
  margin-bottom: 0.3rem;
  letter-spacing: -0.02em;
}

.hero-stat span {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

.hero-card,
.panel {
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(1.25);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 1.35rem;
  position: relative;
  overflow: hidden;
}

.hero-card::before,
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.34), transparent 44%);
  pointer-events: none;
}

.panel {
  padding: 1.05rem;
  position: relative;
  overflow: hidden;
}

.auth-panel {
  padding: 1.35rem;
}

.auth-grid,
.app-grid {
  display: grid;
  gap: 1.25rem;
}

.auth-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-grid {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  align-items: start;
}

.stack {
  display: grid;
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field.compact {
  gap: 0.35rem;
}

.field span,
.eyebrow,
.hint,
.reader-meta,
.token-card span {
  color: var(--muted);
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel-strong) 86%, white);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
}

.control-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.grow {
  flex: 1;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.75rem;
}

.section-heading h2,
.section-heading h3 {
  margin: 0;
  letter-spacing: -0.03em;
}

.sidebar {
  position: sticky;
  top: 1rem;
}

.user-chip,
.token-card {
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--panel-strong) 92%, white), color-mix(in srgb, var(--panel) 84%, white));
}

.user-chip {
  display: grid;
  gap: 0.75rem;
}

.user-chip strong,
.chip-meta code,
.token-card code {
  display: block;
  overflow-wrap: anywhere;
}

.chip-meta {
  display: grid;
  gap: 0.25rem;
}

#user-plan {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.save-form-card {
  padding: 0.95rem;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel-strong) 76%, white);
}

.view-switcher-wrap {
  display: grid;
  gap: 0.5rem;
}

.view-switcher {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.35rem;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--bg-deep) 10%, white);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel-strong) 92%, white), color-mix(in srgb, var(--panel) 88%, white));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.view-chip {
  border: 0;
  border-radius: 16px;
  padding: 0.72rem 0.85rem;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.view-chip:hover {
  transform: none;
  filter: none;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
  background: rgba(255, 255, 255, 0.46);
}

.view-chip:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 58%, white);
  outline-offset: 2px;
}

.view-chip.active {
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 74%, white) 100%);
  color: white;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 12px 24px color-mix(in srgb, var(--accent-strong) 22%, transparent);
}

.save-list,
.feed-list,
.highlight-list,
.tag-list {
  display: grid;
  gap: 0.75rem;
}

.save-card,
.feed-card,
.highlight-card {
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid var(--border);
  background:
    linear-gradient(155deg, color-mix(in srgb, var(--panel-strong) 94%, white), color-mix(in srgb, var(--panel) 86%, white));
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.save-card {
  cursor: pointer;
}

.save-card.active {
  border-color: color-mix(in srgb, var(--accent) 55%, white);
  box-shadow: 0 20px 40px color-mix(in srgb, var(--accent) 14%, transparent);
}

.save-card:hover,
.feed-card:hover {
  transform: translateY(-2px);
}

.save-card:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 58%, white);
  outline-offset: 2px;
}

.save-card-header,
.save-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.9rem;
  align-items: start;
}

.save-card h3,
.feed-card h3 {
  margin: 0 0 0.35rem;
  line-height: 1.25;
}

.save-meta,
.feed-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.save-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.save-excerpt {
  margin: 0.75rem 0 0.95rem;
  color: color-mix(in srgb, var(--text) 84%, var(--muted));
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status-pill,
.flag-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill {
  background: rgba(58, 175, 169, 0.16);
  color: #0f6b67;
  border: 1px solid rgba(58, 175, 169, 0.18);
}

.status-pill.processing {
  background: rgba(255, 213, 107, 0.18);
  color: #7d5b11;
  border-color: rgba(255, 213, 107, 0.22);
}

.status-pill.failed {
  background: rgba(212, 72, 58, 0.14);
  color: #9f3d31;
  border-color: rgba(212, 72, 58, 0.18);
}

.flag-pill {
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  border: 1px solid var(--border);
}

.flag-pill.muted {
  color: var(--muted);
}

.save-flag-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag-pill {
  display: inline-flex;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(58, 175, 169, 0.12));
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 14%, var(--border));
  margin-right: 0.35rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
  font-weight: 700;
}

.content {
  min-width: 0;
}

.library-panel {
  max-height: 34vh;
  overflow: auto;
}

.reader-panel {
  min-height: 58vh;
}

.reader-actions {
  display: flex;
  gap: 0.6rem;
}

.reader-subtitle {
  margin-top: 0.35rem;
  max-width: 48rem;
}

.reader-content {
  min-height: 24rem;
  max-height: 60vh;
  overflow: auto;
  padding: 1.4rem 1.5rem;
  border-radius: 28px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel-strong) 92%, white), color-mix(in srgb, var(--panel) 80%, white));
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: 1.8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

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

.reader-content p,
.reader-content li,
.reader-content blockquote {
  max-width: 72ch;
}

.selection-composer {
  padding: 1rem;
  border-radius: 22px;
  border: 1px dashed color-mix(in srgb, var(--accent) 35%, white);
  background: linear-gradient(145deg, rgba(255, 250, 240, 0.54), rgba(255, 232, 216, 0.72));
}

.highlights-panel {
  margin-top: 1rem;
}

.highlight-card {
  border-left: 8px solid var(--highlight-yellow);
}

.highlight-quote {
  display: block;
  line-height: 1.55;
}

.highlight-card[data-color="pink"] {
  border-left-color: var(--highlight-pink);
}

.highlight-card[data-color="blue"] {
  border-left-color: var(--highlight-blue);
}

.highlight-card[data-color="green"] {
  border-left-color: var(--highlight-green);
}

.count-badge {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(58, 175, 169, 0.12));
  color: var(--accent);
  font-size: 0.9rem;
  border: 1px solid color-mix(in srgb, var(--accent) 10%, var(--border));
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: rgba(9, 33, 42, 0.92);
  color: white;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.24);
  max-width: 24rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.empty-state {
  padding: 1.2rem;
  border-radius: 22px;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--panel-strong) 72%, white);
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.empty-state.compact {
  padding: 0.95rem 1rem;
}

.empty-state.large {
  width: 100%;
  max-width: 38rem;
  text-align: center;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

@media (max-width: 1040px) {
  .hero,
  .app-grid,
  .auth-grid {
    grid-template-columns: 1fr;
  }

  .hero-stat-row {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .reader-content {
    max-height: none;
  }

  .library-panel {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .view-switcher {
    grid-template-columns: 1fr;
  }
}
