:root {
  color-scheme: light;
  --bg: #f0f5fa;
  --surface: #ffffff;
  --surface-strong: #fbfdff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #d9e2ec;
  --primary: #002f7d;
  --primary-dark: #001f54;
  --primary-soft: #f2e8f7;
  --blue: #0f76b7;
  --blue-soft: #e8f4fb;
  --teal: #078b8f;
  --teal-soft: #e2f7f6;
  --amber: #c98312;
  --amber-soft: #fff5dd;
  --danger: #c2414b;
  --danger-soft: #feecef;
  --success: #17835d;
  --success-soft: #e9f8f2;
  --shadow: 0 22px 70px rgba(30, 41, 59, 0.12);
  --shadow-soft: 0 14px 34px rgba(30, 41, 59, 0.08);
  --radius: 8px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #111827;
  --surface: #182033;
  --surface-strong: #202a41;
  --text: #edf2f7;
  --muted: #a5b4c7;
  --line: #334155;
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --primary-soft: rgba(181, 107, 208, 0.16);
  --blue: #61b6ec;
  --blue-soft: rgba(97, 182, 236, 0.14);
  --teal: #59c5c8;
  --teal-soft: rgba(89, 197, 200, 0.13);
  --amber: #f1b342;
  --amber-soft: rgba(241, 179, 66, 0.15);
  --danger: #f17480;
  --danger-soft: rgba(241, 116, 128, 0.15);
  --success: #5dd39e;
  --success-soft: rgba(93, 211, 158, 0.14);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 14px 34px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(142, 68, 173, 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.app-shell {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 42px;
}

.topbar,
.tabs,
.panel,
.welcome-card {
  border: 1px solid color-mix(in srgb, var(--line), transparent 16%);
  background: color-mix(in srgb, var(--surface), transparent 4%);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 22px;
  border-radius: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-logo {
  width: 74px;
  height: 74px;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
  padding: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand-kicker {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2 {
  font-family: Raleway, Inter, sans-serif;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
}

.brand-subtitle {
  margin-top: 8px;
  color: var(--muted);
  max-width: 780px;
}

.topbar-actions,
.toolbar,
.modal-footer,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.counter {
  min-width: 138px;
  padding: 12px 16px;
  text-align: right;
  border-radius: var(--radius);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.counter span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.counter strong {
  display: block;
  color: var(--primary);
  font-size: 30px;
  line-height: 1;
}

.icon-button,
.primary-button,
.secondary-button,
.upload-action {
  min-height: 42px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
  cursor: pointer;
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.icon-button.ghost {
  background: transparent;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
  padding: 0 16px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(142, 68, 173, 0.22);
}

.secondary-button {
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  padding: 0 14px;
  font-weight: 700;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.upload-action:hover {
  transform: translateY(-1px);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.primary-button:disabled,
.secondary-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  padding: 8px;
  border-radius: 12px;
  overflow-x: auto;
}

.tab {
  flex: 1 0 150px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  border-radius: var(--radius);
  background: transparent;
  font-weight: 800;
  white-space: nowrap;
}

.tab.is-active {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(142, 68, 173, 0.2);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.workspace-grid,
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 18px;
}

.panel {
  padding: 22px;
  border-radius: 12px;
}

.panel + .panel,
.articles-panel {
  margin-top: 18px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-heading h2 {
  font-size: 24px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 800;
  font-size: 13px;
}

.issue-parts {
  display: grid;
  gap: 12px;
}

.issue-part {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.issue-part.is-ready {
  border-color: color-mix(in srgb, var(--success), transparent 46%);
  background: color-mix(in srgb, var(--success-soft), var(--surface) 42%);
}

.part-number {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
  font-size: 20px;
}

/* .part-number.infinity {
  background: var(--teal);
} */

.part-body {
  min-width: 0;
}

.part-body h3 {
  font-size: 17px;
}

.part-body p,
.file-state,
.dropzone span,
.empty-state p,
.info-content p {
  color: var(--muted);
}

.file-state {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-action {
  min-width: 118px;
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary), transparent 54%);
  background: var(--primary-soft);
  padding: 0 14px;
  font-weight: 800;
}

.upload-action input,
.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone {
  min-height: 242px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  border: 2px dashed color-mix(in srgb, var(--primary), transparent 48%);
  border-radius: 12px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--primary-soft), transparent 24%), transparent),
    var(--surface-strong);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.dropzone svg {
  width: 46px;
  height: 46px;
  color: var(--primary);
}

.dropzone strong {
  font-size: 22px;
}

.dropzone.is-over {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.issue-rules {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--blue-soft), var(--surface) 35%);
  border: 1px solid color-mix(in srgb, var(--blue), transparent 74%);
}

.issue-rules h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.issue-rules ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.issue-rules li {
  display: flex;
  gap: 8px;
  align-items: center;
}

.issue-rules svg {
  color: var(--success);
  flex: 0 0 auto;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 190px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 24px;
}

.empty-state svg {
  width: 42px;
  height: 42px;
  color: var(--primary);
}

.article-list {
  display: grid;
  gap: 12px;
}

.article-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.article-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.article-title-row input,
.article-meta input {
  width: 100%;
  min-height: 38px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.article-title-row input {
  font-weight: 800;
  font-size: 18px;
}

.article-meta {
  display: grid;
  grid-template-columns: 1fr 170px 120px;
  gap: 10px;
  margin-top: 10px;
}

.article-chip,
.toast,
.finding-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.article-chip {
  padding: 4px 9px;
  color: var(--teal);
  background: var(--teal-soft);
}

.article-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.article-actions .icon-button {
  width: 38px;
  min-height: 38px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.summary-strip div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  color: var(--primary);
}

.select-control {
  min-height: 42px;
  min-width: 210px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
}

.select-control.wide {
  width: 100%;
  margin-bottom: 16px;
}

.spell-results {
  display: grid;
  gap: 10px;
}

.spell-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.spell-card h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

.finding {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.finding:first-of-type {
  border-top: 0;
}

.finding p {
  color: var(--muted);
  font-size: 14px;
}

.finding-tag {
  align-self: start;
  padding: 4px 8px;
  color: var(--amber);
  background: var(--amber-soft);
}

.text-preview {
  max-height: 560px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.75;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
}

.spell-mark {
  border-radius: 4px;
  background: color-mix(in srgb, var(--amber), transparent 68%);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--amber);
  padding: 1px 2px;
}

.review-grid {
  display: grid;
  gap: 12px;
}

.score-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.score-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.score-head strong {
  font-size: 17px;
}

.score {
  color: var(--primary);
  font-weight: 900;
}

.score-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line), transparent 20%);
  overflow: hidden;
  margin: 10px 0;
}

.score-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--primary));
}

.score-card p,
.review-note,
.archive-card p {
  color: var(--muted);
}

.review-note {
  min-height: 310px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  line-height: 1.75;
}

.archive-list {
  display: grid;
  gap: 12px;
}

.archive-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.info-content {
  display: grid;
  gap: 18px;
}

.info-content > p {
  font-size: 17px;
  line-height: 1.75;
  max-width: 980px;
}

.info-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.info-cards article {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.info-cards svg {
  width: 28px;
  height: 28px;
  color: var(--primary);
  margin-bottom: 12px;
}

.info-cards h3 {
  margin-bottom: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  z-index: 50;
  background: rgba(15, 23, 42, 0.56);
}

.modal-backdrop.is-visible {
  display: grid;
}

.welcome-card {
  width: min(560px, 100%);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: 20px;
}

.welcome-body {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 34px 32px 26px;
  text-align: center;
}

.welcome-icon {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 14px 28px rgba(142, 68, 173, 0.22);
}

.welcome-icon svg {
  width: 42px;
  height: 42px;
}

.welcome-body h3 {
  font-size: 26px;
}

.welcome-body p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.65;
}

.dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-bottom: 16px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
}

.dot.is-active {
  width: 34px;
  background: var(--primary);
}

.modal-footer {
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-strong);
}

.step-counter {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100% - 36px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.toast.success {
  border-color: color-mix(in srgb, var(--success), transparent 48%);
  background: color-mix(in srgb, var(--success-soft), var(--surface) 24%);
}

.toast.warning {
  border-color: color-mix(in srgb, var(--amber), transparent 48%);
  background: color-mix(in srgb, var(--amber-soft), var(--surface) 24%);
}

.toast.error {
  border-color: color-mix(in srgb, var(--danger), transparent 48%);
  background: color-mix(in srgb, var(--danger-soft), var(--surface) 24%);
}

@media (max-width: 980px) {
  .topbar,
  .brand,
  .topbar-actions,
  .panel-heading,
  .modal-footer {
    align-items: stretch;
  }

  .topbar,
  .workspace-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .brand,
  .topbar-actions,
  .panel-heading {
    flex-direction: column;
  }

  .counter {
    text-align: left;
  }

  .article-meta,
  .info-cards {
    grid-template-columns: 1fr;
  }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1380px);
    padding-top: 10px;
  }

  .topbar,
  .panel {
    padding: 16px;
  }

  .brand-logo {
    width: 64px;
    height: 64px;
  }

  .issue-part {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .upload-action {
    grid-column: 1 / -1;
    width: 100%;
  }

  .article-card,
  .archive-card,
  .finding {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .modal-footer {
    gap: 10px;
  }
}
