:root {
  --ink: #101c2c;
  --ink-soft: #405063;
  --paper: #f3f6fa;
  --paper-bright: #ffffff;
  --line: #d4dde8;
  --signal: #007fff;
  --signal-dark: #005fbf;
  --signal-soft: #d9ecff;
  --coral: #e95f4c;
  --blue: #8fc7ff;
  --serif: "Newsreader", Georgia, serif;
  --sans: "DM Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input { font: inherit; }
button { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  transform: translateY(-180%);
  padding: 0.7rem 1rem;
  color: #fff;
  background: var(--signal);
  border-radius: 999px;
}
.skip-link:focus { transform: translateY(0); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.honeypot {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
}

.masthead {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: clamp(170px, 18vw, 220px);
  padding: 1rem clamp(1rem, 4vw, 4.5rem) 0.9rem;
  color: #fff;
  background:
    radial-gradient(circle at 72% -35%, rgba(0, 127, 255, 0.5), transparent 34%),
    linear-gradient(125deg, #101c2c 0%, #152943 64%, #20354a 100%);
  border-bottom: 4px solid var(--signal);
}

.header-top,
.header-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
}

.header-top { flex: 1 1 auto; }

.masthead-copy {
  position: absolute;
  top: 50%;
  left: clamp(1rem, 4vw, 4.5rem);
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  transform: translateY(-50%);
}

h1 {
  margin: 0;
  font: 500 clamp(2.35rem, 4.8vw, 4.5rem)/0.94 var(--serif);
  letter-spacing: -0.05em;
}
.title-primary,
.title-secondary { display: inline; }

.week-label {
  margin: 0;
  color: var(--blue);
  font: 500 clamp(1rem, 1.7vw, 1.35rem)/1.15 var(--serif);
  white-space: nowrap;
}

.top-actions,
.edition-summary,
.edition-actions,
.controls,
.filter-group {
  display: flex;
  align-items: center;
}

.top-actions {
  position: absolute;
  top: 1rem;
  right: clamp(1rem, 4vw, 4.5rem);
  flex: 0 0 auto;
  gap: 0.55rem;
}
.header-tools { flex: 0 0 auto; justify-content: flex-end; margin-top: 0.75rem; }
.edition-summary { gap: 0.65rem; color: #cad5e1; font-size: 0.75rem; white-space: nowrap; }
.edition-actions { gap: 0.3rem; }
.controls { gap: 0.8rem; }
.filter-group { gap: 0.25rem; }

.text-button,
.primary-button,
.edition-button,
.quiet-button,
.filter-button,
.close-button,
.vote-button,
.archive-entry {
  border: 0;
  cursor: pointer;
}

.text-button {
  min-height: 36px;
  padding: 0.45rem 0.7rem;
  color: #fff;
  background: transparent;
}
.text-button:hover { color: var(--blue); }

.primary-button {
  min-height: 44px;
  padding: 0.7rem 1rem;
  color: #fff;
  background: var(--signal);
  border: 1px solid var(--signal);
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}
.primary-button:hover { transform: translateY(-1px); background: var(--signal-dark); }
.primary-button.compact { min-height: 36px; padding: 0.45rem 0.75rem; font-size: 0.78rem; }

.edition-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
}
.edition-button:hover:not(:disabled) { background: var(--signal); border-color: var(--signal); }
.edition-button:disabled { opacity: 0.28; cursor: default; }

.filter-button {
  padding: 0.42rem 0.65rem;
  color: #d4dee8;
  background: transparent;
  border-radius: 999px;
  font-size: 0.72rem;
}
.filter-button:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.filter-button.active { color: #fff; background: var(--signal); font-weight: 700; }

.search-wrap { width: min(28vw, 280px); }
.search-wrap input,
.modal-form input {
  width: 100%;
  min-height: 42px;
  padding: 0.65rem 0.8rem;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: none;
}
.search-wrap input { min-height: 36px; background: rgba(255, 255, 255, 0.96); font-size: 0.78rem; }
input:focus { border-color: var(--signal); box-shadow: 0 0 0 3px rgba(0, 127, 255, 0.18); }

.catalog {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3rem) clamp(3rem, 7vw, 7rem);
}

.paper-list { border-top: 1px solid var(--line); }
.paper-card {
  padding: 1.65rem 0 1.8rem;
  border-bottom: 1px solid var(--line);
  animation: paper-in 380ms both;
  animation-delay: calc(var(--entry-index) * 18ms);
}
@keyframes paper-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.paper-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-bottom: 0.65rem;
}

.paper-meta,
.paper-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.paper-meta { gap: 0.5rem; }
.paper-actions { flex: 0 0 auto; gap: 0.45rem; }

.category-tag,
.source-tag,
.date-tag {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.category-tag { padding: 0.27rem 0.46rem; background: #e5ebf2; border-radius: 2px; }
.category-featured .category-tag { color: #fff; background: var(--signal); }
.category-some .category-tag { background: var(--blue); }
.source-tag,
.date-tag { color: var(--ink-soft); }
.source-tag::after { content: "·"; margin-left: 0.5rem; color: #8b98a8; }

.paper-title {
  max-width: 950px;
  margin: 0;
  font: 500 clamp(1.45rem, 2.5vw, 2rem)/1.1 var(--serif);
  letter-spacing: -0.018em;
}
.paper-title a {
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: text-decoration-color 160ms ease;
}
.paper-title a:hover { text-decoration-color: var(--ink); }
.paper-authors { margin: 0.55rem 0 0; color: var(--ink-soft); font-size: 0.78rem; line-height: 1.5; }
.authors-compact { display: none; }
.paper-summary { max-width: 900px; margin: 0.7rem 0 0; color: #27384c; font: 400 1rem/1.55 var(--serif); }

.vote-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 32px;
  padding: 0.32rem 0.6rem;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid #aab6c4;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  transition: transform 150ms ease, color 150ms ease, background 150ms ease;
}
.vote-button:hover { transform: translateY(-1px); color: var(--ink); background: var(--paper-bright); }
.vote-icon { font-size: 1.05rem; font-weight: 700; line-height: 1; }
.vote-up.active { color: #fff; background: var(--signal); border-color: var(--signal-dark); }
.vote-down.active { color: #fff; background: var(--coral); border-color: #b33e2c; }

.quiet-button {
  padding: 0.65rem 0.85rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.quiet-button:hover { background: var(--paper-bright); }
.empty-state { padding: 5rem 1rem; text-align: center; }

.modal {
  width: min(calc(100% - 2rem), 680px);
  max-height: min(760px, calc(100vh - 2rem));
  padding: 0;
  color: var(--ink);
  background: var(--paper-bright);
  border: 0;
  box-shadow: 0 28px 90px rgba(5, 13, 24, 0.36);
}
.modal::backdrop { background: rgba(8, 17, 30, 0.72); backdrop-filter: blur(5px); }
.modal-actions { display: flex; justify-content: flex-end; padding: 1rem 1rem 0; }
.close-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 1.4rem;
}
.archive-list { max-height: 620px; overflow: auto; padding: 0 2rem 2rem; }
.archive-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 1.1rem 0.2rem;
  background: transparent;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.archive-entry:hover .archive-date,
.archive-entry.current .archive-date { text-decoration: underline; text-underline-offset: 4px; }
.archive-entry.current::before {
  content: "Current";
  margin-right: 0.7rem;
  padding: 0.25rem 0.45rem;
  color: #fff;
  background: var(--signal);
  border-radius: 2px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
}
.archive-date { margin-right: auto; font: 500 1.25rem/1 var(--serif); }
.archive-count { color: var(--ink-soft); font-size: 0.75rem; }
.subscribe-modal { padding-bottom: 2rem; }
.modal-form { display: grid; gap: 0.5rem; padding: 0 2rem; }
.modal-form label { font-size: 0.78rem; font-weight: 700; }
.modal-form .primary-button { margin-top: 0.4rem; }

.toast {
  position: fixed;
  z-index: 60;
  right: 1rem;
  bottom: 1rem;
  max-width: calc(100% - 2rem);
  padding: 0.9rem 1.15rem;
  color: #fff;
  background: var(--ink);
  border-left: 5px solid var(--signal);
  box-shadow: 0 12px 36px rgba(5, 13, 24, 0.25);
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

button:focus-visible,
a:focus-visible,
input:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }

@media (max-width: 980px) {
  .masthead { min-height: 170px; }
  .header-top { align-items: center; }
  .masthead-copy { display: block; }
  .week-label { margin-top: 0.25rem; }
  .header-tools { display: none; }
  .paper-topline { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 650px) {
  .masthead { min-height: 132px; padding: 0.65rem 0.75rem; }
  .header-top { position: relative; align-items: center; justify-content: center; }
  .masthead-copy { top: 50%; right: 8.7rem; left: 0.85rem; width: auto; padding-top: 0; }
  .masthead h1 { font-size: clamp(1.8rem, 8.5vw, 2.15rem); line-height: 0.9; }
  .title-primary,
  .title-secondary { display: block; }
  .title-secondary {
    margin-top: 0.25rem;
    font-family: var(--sans);
    font-size: 0.5em;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.025em;
  }
  .week-label { margin-top: 0.5rem; font-size: clamp(0.72rem, 3.2vw, 0.86rem); }
  .top-actions {
    top: 50%;
    right: 0.75rem;
    width: 7.55rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    transform: translateY(-50%);
  }
  .top-actions .text-button,
  .top-actions .primary-button.compact {
    width: 100%;
    min-height: 29px;
    padding: 0.3rem 0.42rem;
    font-size: 0.62rem;
    line-height: 1.1;
    white-space: nowrap;
  }
  .top-actions .text-button {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 4px;
  }
  .catalog { padding-inline: 1rem; }
  .paper-actions { align-items: center; width: auto; }
  .authors-full { display: none; }
  .authors-compact { display: inline; }
  .modal-actions,
  .archive-list,
  .modal-form { padding-inline: 1.2rem; }
}

@media (max-width: 430px) {
  .masthead h1 { font-size: clamp(1.65rem, 8vw, 1.9rem); }
  .paper-actions { flex-direction: row; }
}

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