:root {
  --ink: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --canvas: #f7f8fb;
  --surface: #ffffff;
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --brand-soft: #eef2ff;
  --success: #067647;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --error: #b42318;
  --error-soft: #fef3f2;
  --radius-sm: 0.65rem;
  --radius: 0.9rem;
  --radius-lg: 1.25rem;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
}

a,
button,
input,
select,
textarea,
summary {
  transition:
    color 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease,
    opacity 140ms ease;
}

a {
  text-underline-offset: 0.18em;
}

button,
summary,
input[type="file"] {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid rgba(99, 102, 241, 0.3);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 0.9rem;
  color: white;
  background: var(--brand-dark);
  border-radius: var(--radius-sm);
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-page {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.055), transparent 29rem),
    var(--canvas);
}

.app-header {
  position: sticky;
  z-index: 40;
  top: 0;
  border-bottom: 1px solid rgba(228, 231, 236, 0.9);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
}

.nav-shell {
  display: flex;
  align-items: center;
  width: min(1180px, calc(100% - 2.5rem));
  min-height: 4.25rem;
  margin: 0 auto;
  gap: 2rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.brand-symbol {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: white;
  background: var(--brand);
  border-radius: 0.65rem;
  box-shadow: 0 5px 12px rgba(79, 70, 229, 0.2);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

.desktop-nav {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  gap: 0.25rem;
}

.desktop-nav a {
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 0.68rem;
  color: #475467;
  font-size: 0.875rem;
  font-weight: 560;
  text-decoration: none;
}

.desktop-nav a:hover,
.desktop-nav a[aria-current="page"] {
  color: var(--brand-dark);
}

.desktop-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  right: 0.7rem;
  bottom: -1px;
  left: 0.7rem;
  height: 2px;
  background: var(--brand);
  border-radius: 999px 999px 0 0;
}

.nav-account {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 0.85rem;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.5rem;
  color: #98a2b3;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  font-size: 0.7rem;
  font-weight: 650;
}

.language-switcher a {
  color: var(--muted);
  text-decoration: none;
}

.language-switcher a[aria-current="true"] {
  color: var(--brand-dark);
  font-weight: 800;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  list-style: none;
  color: #344054;
  font-size: 0.82rem;
  font-weight: 600;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.avatar {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border: 1px solid #d9ddff;
  border-radius: 999px;
}

.account-popover {
  position: absolute;
  right: 0;
  width: 12rem;
  margin-top: 0.65rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow);
}

.account-popover p,
.account-popover a {
  display: block;
  margin: 0;
  padding: 0.6rem 0.7rem;
  border-radius: 0.55rem;
  font-size: 0.82rem;
}

.account-popover p {
  color: var(--muted);
}

.account-popover a {
  color: var(--ink);
  text-decoration: none;
}

.account-popover a:hover {
  background: #f2f4f7;
}

.mobile-menu {
  display: none;
  position: relative;
  margin-left: auto;
}

.mobile-menu > summary {
  list-style: none;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 650;
}

.mobile-menu > summary::-webkit-details-marker {
  display: none;
}

.mobile-menu nav {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  width: min(19rem, calc(100vw - 2rem));
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow);
}

.mobile-menu a {
  display: block;
  padding: 0.72rem 0.8rem;
  border-radius: 0.55rem;
  color: var(--ink);
  font-size: 0.88rem;
  text-decoration: none;
}

.mobile-menu a:hover {
  background: #f2f4f7;
}

.mobile-language-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.35rem;
}

.mobile-language-switcher a {
  text-align: center;
}

.page-shell {
  width: min(1120px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: 2.5rem 0 4rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.page-header h1,
.compact-header h1 {
  margin: 0.18rem 0 0;
  color: var(--ink);
  font-size: clamp(1.9rem, 4vw, 2.55rem);
  line-height: 1.15;
  letter-spacing: -0.04em;
}

.page-header p:not(.eyebrow),
.compact-header p:not(.eyebrow) {
  max-width: 43rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
}

.compact-header {
  margin-bottom: 1.75rem;
}

.eyebrow {
  margin: 0;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow-light {
  color: #c7d2fe;
}

.surface,
.card {
  padding: 1.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.surface h2,
.card h2 {
  letter-spacing: -0.02em;
}

.card:hover {
  border-color: #d7dbe2;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.68rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.78rem;
  font-size: 0.875rem;
  font-weight: 680;
  line-height: 1.2;
  text-decoration: none;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-primary {
  color: white;
  background: var(--brand);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.18);
}

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

.button-secondary {
  color: #344054;
  border-color: var(--line-strong);
  background: white;
}

.button-secondary:hover:not(:disabled) {
  background: #f9fafb;
}

.button-block {
  width: 100%;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-label {
  display: block;
  color: #344054;
  font-size: 0.84rem;
  font-weight: 650;
}

.form-label span {
  color: var(--muted);
  font-weight: 450;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.15rem;
}

.field {
  display: block;
  width: 100%;
  min-height: 2.8rem;
  margin-top: 0.4rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 0.75rem;
  background: white;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 430;
}

textarea.field {
  min-height: auto;
  resize: vertical;
  line-height: 1.55;
}

.field:hover {
  border-color: #98a2b3;
}

.field:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.13);
}

.field-help {
  margin: -0.28rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.password-field {
  position: relative;
}

.password-field .field {
  margin: 0;
  padding-right: 4rem;
}

.password-field button {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  padding: 0.35rem 0.5rem;
  color: var(--brand-dark);
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 700;
}

.quiet-link {
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
}

.form-message {
  padding: 0.78rem 0.9rem;
  border: 1px solid;
  border-radius: 0.75rem;
  font-size: 0.83rem;
}

.form-message-error {
  color: var(--error);
  border-color: #fecdca;
  background: var(--error-soft);
}

.form-message-success {
  color: var(--success);
  border-color: #abefc6;
  background: var(--success-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.71rem;
  font-weight: 650;
  line-height: 1.3;
}

.badge-pending,
.badge-review {
  color: var(--warning);
  background: var(--warning-soft);
}

.badge-grading,
.badge-processing {
  color: #3538cd;
  background: #eef4ff;
}

.badge-final,
.badge-published,
.badge-completed {
  color: var(--success);
  background: var(--success-soft);
}

.badge-draft,
.badge-queued {
  color: #475467;
  background: #f2f4f7;
}

.badge-failed {
  color: var(--error);
  background: var(--error-soft);
}

.confidence-low {
  color: var(--warning);
}

.confidence-mid {
  color: #3538cd;
}

.confidence-high {
  color: var(--success);
}

.math-copy {
  line-height: 1.65;
}

.upload-tile {
  display: flex;
  min-height: 11rem;
  flex-direction: column;
  padding: 1.15rem;
  border: 1px dashed #b9c0ce;
  border-radius: var(--radius);
  background: #fbfcfe;
}

.upload-tile:hover,
.upload-tile:focus-within {
  border-color: var(--brand);
  background: #f7f7ff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}

.upload-number {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  margin-bottom: 1rem;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
}

.upload-tile input[type="file"] {
  width: 100%;
  margin-top: auto;
  padding-top: 1rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.upload-tile input[type="file"]::file-selector-button {
  margin-right: 0.65rem;
  padding: 0.48rem 0.68rem;
  color: #344054;
  border: 1px solid var(--line-strong);
  border-radius: 0.55rem;
  background: white;
  font-weight: 650;
}

.metric-card {
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow-sm);
}

.metric-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.metric-card strong {
  display: block;
  margin-top: 0.25rem;
  color: var(--ink);
  font-size: 1.7rem;
  letter-spacing: -0.035em;
}

.metric-primary {
  border-color: #d9ddff;
  background: #f7f7ff;
}

.metric-primary strong {
  color: var(--brand-dark);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.account-summary {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0 0;
}

.account-summary div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.account-summary dt {
  color: var(--muted);
}

.account-summary dd {
  margin: 0;
  font-weight: 600;
}

table {
  border-collapse: collapse;
}

th {
  color: #475467;
  font-size: 0.75rem;
  font-weight: 650;
}

td,
th {
  vertical-align: top;
}

details > summary {
  border-radius: 0.5rem;
}

details[open] > summary {
  margin-bottom: 0.2rem;
}

.research-mode {
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.03), transparent 23rem),
    var(--canvas);
}

.research-mode .brand-symbol {
  background: #111827;
  box-shadow: none;
}

.research-shell {
  padding: 1.6rem;
  color: #e4e7ec;
  border: 1px solid #27334a;
  border-radius: var(--radius-lg);
  background: #111827;
  box-shadow: 0 15px 35px rgba(15, 23, 42, 0.12);
}

.research-card {
  padding: 0.9rem;
  border: 1px solid #2d3a52;
  border-radius: 0.8rem;
  background: #172033;
}

.auth-page {
  min-height: 100vh;
  color: var(--ink);
  background: #f8f9fc;
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(22rem, 0.95fr) minmax(28rem, 1.05fr);
  min-height: 100vh;
}

.auth-brand {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  padding: clamp(2rem, 5vw, 4.5rem);
  color: white;
  background:
    radial-gradient(circle at 20% 10%, rgba(129, 140, 248, 0.33), transparent 18rem),
    linear-gradient(145deg, #20205c, #312e81 58%, #3730a3);
}

.auth-brand .brand-mark {
  color: white;
}

.auth-brand .brand-symbol {
  color: #312e81;
  background: white;
}

.auth-brand-copy {
  max-width: 34rem;
  margin: auto 0;
}

.auth-brand-copy h1 {
  margin: 0.7rem 0 1rem;
  font-size: clamp(2.45rem, 5vw, 4.3rem);
  line-height: 1.03;
  letter-spacing: -0.055em;
}

.auth-brand-copy > p:last-child {
  max-width: 30rem;
  margin: 0;
  color: #e0e7ff;
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.7;
}

.auth-footnote {
  margin: auto 0 0;
  color: #c7d2fe;
  font-size: 0.76rem;
}

.auth-panel {
  display: grid;
  position: relative;
  place-items: center;
  padding: 4.5rem 2rem;
}

.auth-language {
  position: absolute;
  top: 1.5rem;
  right: 1.75rem;
}

.auth-card {
  width: min(100%, 25rem);
}

.auth-title {
  margin: 0.35rem 0 0;
  font-size: 2rem;
  line-height: 1.16;
  letter-spacing: -0.04em;
}

.auth-subtitle {
  margin: 0.65rem 0 1.65rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.auth-switch {
  margin: 1.5rem 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.84rem;
}

.auth-switch a {
  color: var(--brand);
  font-weight: 650;
  text-decoration: none;
}

.success-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  color: var(--success);
  border: 1px solid #abefc6;
  border-radius: 999px;
  background: var(--success-soft);
  font-size: 1.35rem;
  font-weight: 800;
}

.recovery-code {
  margin: 1.3rem 0 0.7rem;
  padding: 1rem;
  color: #312e81;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  background: #f5f5ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  overflow-wrap: anywhere;
}

.recovery-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.auth-card .button-block + .button-block {
  margin-top: 0.7rem;
}

@media (max-width: 1020px) {
  .desktop-nav {
    display: none;
  }

  .nav-account {
    margin-left: auto;
  }

  .mobile-menu {
    display: block;
    margin-left: 0;
  }

  .auth-layout {
    grid-template-columns: minmax(18rem, 0.75fr) minmax(25rem, 1.25fr);
  }

  .auth-brand-copy h1 {
    font-size: clamp(2.2rem, 5vw, 3.3rem);
  }
}

@media (max-width: 760px) {
  .nav-shell,
  .page-shell {
    width: min(100% - 1.25rem, 1120px);
  }

  .nav-shell {
    min-height: 3.8rem;
    gap: 0.75rem;
  }

  .nav-account {
    display: none;
  }

  .mobile-menu {
    margin-left: auto;
  }

  .page-shell {
    padding: 1.55rem 0 3rem;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
    margin-bottom: 1.35rem;
  }

  .page-header .button {
    width: 100%;
  }

  .surface,
  .card {
    padding: 1.05rem;
    border-radius: var(--radius);
  }

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

  .auth-layout {
    display: block;
  }

  .auth-brand {
    min-height: auto;
    padding: 1.15rem;
    background: #312e81;
  }

  .auth-brand-copy,
  .auth-footnote {
    display: none;
  }

  .auth-panel {
    display: block;
    min-height: calc(100vh - 4.3rem);
    padding: 4.6rem 1.25rem 2.5rem;
  }

  .auth-card {
    margin: 0 auto;
  }

  .auth-language {
    top: 1.2rem;
    right: 1.25rem;
  }

  .upload-tile {
    min-height: 9.5rem;
  }

  .overflow-x-auto {
    margin-right: -1.05rem;
    margin-left: -1.05rem;
    padding-right: 1.05rem;
    padding-left: 1.05rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
