:root {
  --paper: #f7f0e4;
  --ink: #111816;
  --muted: #58625e;
  --header: #0b2824;
  --intro: #acd0c3;
  --problem: #d5c9df;
  --progress: #efd0ae;
  --resolved: #bfd8c4;
  --notes: #ded5e5;
  --notice: #f2e5b8;
  --tab-all: #e7a27f;
  --tab-random: #c9b9d7;
  --link: #164fa3;
  --border: #15211e;
  --content-width: 920px;
  --header-height: 70px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 22px);
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.skip-link {
  background: white;
  color: black;
  left: 12px;
  padding: 9px 13px;
  position: fixed;
  top: 8px;
  transform: translateY(-140%);
  z-index: 1000;
}

.skip-link:focus {
  transform: none;
}

:focus-visible {
  outline: 3px solid #f3bf46;
  outline-offset: 2px;
}

/* Header */

.site-header {
  align-items: stretch;
  background: var(--header);
  color: white;
  display: grid;
  grid-template-columns: minmax(275px, 1fr) auto auto;
  height: var(--header-height);
  left: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  align-items: center;
  display: flex;
  gap: 34px;
  padding-left: 18px;
}

.brand {
  align-items: center;
  display: inline-flex;
  gap: 10px;
  text-decoration: none;
}

.brand svg {
  height: 42px;
  overflow: visible;
  width: 50px;
}

.brand svg path {
  fill: none;
  stroke: white;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.brand svg circle {
  fill: var(--tab-all);
  stroke: var(--header);
  stroke-width: 1.5;
}

.brand > span {
  display: grid;
  gap: 3px;
  line-height: 1;
}

.brand strong {
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.brand small {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-link {
  font-size: 0.95rem;
  text-decoration: none;
}

.header-link:hover {
  text-decoration: underline;
}

.header-tools {
  align-items: center;
  display: flex;
  gap: 28px;
  min-width: 0;
  padding: 0 30px;
}

.jump-form,
.search-form {
  align-items: center;
  display: flex;
  gap: 6px;
  min-width: 0;
}

.jump-form input,
.search-form input {
  background: #fafafa;
  border: 2px inset #ddd;
  border-radius: 4px;
  color: #161616;
  font-size: 0.82rem;
  height: 34px;
  padding: 0 10px;
  width: 132px;
}

.search-form input {
  width: 150px;
}

.jump-form button,
.search-form button {
  background: #fafafa;
  border: 1px solid #aaa;
  border-radius: 4px;
  color: #111;
  font-size: 0.82rem;
  height: 34px;
  padding: 0 9px;
}

.jump-form button:hover,
.search-form button:hover {
  background: #e7e7e7;
}

.header-tabs {
  display: flex;
  min-width: 0;
}

.tab {
  align-items: center;
  background: #f4f1e8;
  border: 0;
  color: #111;
  display: flex;
  font-size: 0.92rem;
  justify-content: center;
  padding: 0 18px;
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover {
  filter: brightness(0.94);
}

.tab-all {
  background: var(--tab-all);
}

.tab-random {
  background: var(--tab-random);
}

/* Introduction */

main {
  margin: 20px auto 90px;
  max-width: var(--content-width);
  padding: 0 18px;
}

.about-card {
  background: var(--intro);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 22px 24px 18px;
  scroll-margin-top: calc(var(--header-height) + 18px);
}

.about-card h1 {
  font-size: 1.55rem;
  margin: 0 0 16px;
}

.about-card h2 {
  font-size: 1.05rem;
  margin: 18px 0 8px;
}

.about-card p {
  margin: 0 0 10px;
}

.about-card ul {
  margin: 8px 0 0;
  padding-left: 37px;
}

.about-card li {
  margin: 4px 0;
}

.editing-guide {
  align-items: center;
  background: rgba(247, 240, 228, 0.62);
  border: 1px solid rgba(21, 33, 30, 0.55);
  border-radius: 16px;
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin: 20px 0 16px;
  padding: 16px 18px;
  scroll-margin-top: calc(var(--header-height) + 18px);
}

.editing-guide h2 {
  margin-top: 0;
}

.editing-guide p {
  margin-bottom: 0;
}

.editing-guide code {
  font-size: 0.92em;
}

.editing-guide-link {
  background: var(--header);
  border: 1px solid var(--header);
  border-radius: 999px;
  color: white;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 10px 14px;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.editing-guide-link:hover {
  background: transparent;
  color: var(--ink);
}

.signature {
  font-style: italic;
  padding-top: 5px;
  text-align: right;
}

.database-note {
  margin: 28px 10px 0;
}

/* Archive controls */

.problems-section {
  scroll-margin-top: calc(var(--header-height) + 18px);
}

.archive-line {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  margin: 34px 0 16px;
  text-align: center;
}

.archive-line p {
  margin: 0;
}

.filter-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: center;
  width: 100%;
}

.filter-controls > label {
  font-size: 0.78rem;
  font-weight: bold;
}

.filter-controls select {
  background: #fffdf8;
  border: 1px solid rgba(21, 33, 30, 0.55);
  border-radius: 5px;
  font-size: 0.78rem;
  max-width: min(440px, 75vw);
  padding: 5px 28px 5px 8px;
}

.text-filters {
  align-items: baseline;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.text-filters::before {
  content: "(";
}

.text-filters::after {
  content: ")";
}

.text-filters button {
  background: none;
  border: 0;
  color: var(--link);
  padding: 0;
  text-decoration: underline;
}

.text-filters button.active {
  color: var(--ink);
  font-weight: bold;
  text-decoration: none;
}

.tag-filter {
  align-items: center;
  background: var(--notes);
  border: 1px solid rgba(21, 33, 30, 0.4);
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.75rem;
  gap: 4px;
  padding: 3px 5px 3px 9px;
}

.tag-filter[hidden] {
  display: none;
}

.tag-filter button {
  background: transparent;
  border: 0;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  padding: 0 3px;
}

.archive-actions {
  align-items: center;
  border-bottom: 1px solid rgba(21, 33, 30, 0.35);
  border-top: 1px solid rgba(21, 33, 30, 0.35);
  display: flex;
  font-size: 0.78rem;
  justify-content: space-between;
  margin-bottom: 42px;
  min-height: 42px;
  padding: 6px 4px;
}

.archive-actions > span {
  font-weight: bold;
}

.archive-actions button {
  background: none;
  border: 0;
  color: var(--link);
  padding: 3px;
  text-decoration: underline;
}

.archive-actions button:disabled {
  color: #777;
  cursor: default;
  text-decoration: none;
}

/* Problems */

.problem-entry {
  margin: 0 0 48px;
  scroll-margin-top: calc(var(--header-height) + 22px);
}

.problem-card {
  background: var(--problem);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 32px 22px 16px;
  position: relative;
}

.problem-entry.status-partial .problem-card {
  background: var(--progress);
}

.problem-entry.status-solved .problem-card {
  background: var(--resolved);
}

.status-stamp {
  background: #eee;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: "Courier New", monospace;
  font-size: 0.82rem;
  left: -9px;
  padding: 8px 11px;
  position: absolute;
  top: -14px;
}

.problem-card h2 {
  font-size: 1.25rem;
  line-height: 1.25;
  margin: 0 0 16px;
}

.problem-statement {
  font-size: 1rem;
  line-height: 1.38;
}

.problem-statement p {
  margin: 0 0 12px;
}

.problem-statement p:last-child {
  margin-bottom: 0;
}

.display-equation {
  background: rgba(255, 255, 255, 0.24);
  border-left: 2px solid rgba(21, 33, 30, 0.32);
  font-size: 1.02em;
  line-height: 1.5;
  margin: 12px 0;
  max-width: 100%;
  overflow-x: auto;
  padding: 8px 12px;
}

.display-equation-fallback {
  font-family: "STIX Two Math", "Cambria Math", Georgia, "Times New Roman", serif;
  white-space: pre-wrap;
}

.math-line {
  min-width: max-content;
  padding-left: var(--math-indent, 0);
}

.math-line + .math-line {
  margin-top: 4px;
}

.math-line mjx-container[display="true"] {
  margin: 0 !important;
  text-align: left !important;
}

.math-inline {
  white-space: nowrap;
}

.math-inline mjx-container {
  margin: 0 0.03em;
}

.inline-equation {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  white-space: nowrap;
}

.problem-meta {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  font-size: 0.68rem;
  gap: 12px;
  justify-content: space-between;
  margin-top: 18px;
}

.problem-meta-left,
.problem-tags {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.problem-number,
.problem-edit-link,
.problem-meta-left button,
.problem-tags button {
  background: none;
  border: 0;
  color: var(--link);
  padding: 0;
  text-decoration: none;
}

.problem-number:hover,
.problem-edit-link:hover,
.problem-meta-left button:hover,
.problem-tags button:hover {
  text-decoration: underline;
}

.problem-edit-link {
  font-weight: 700;
}

.problem-tags button + button::before {
  color: var(--ink);
  content: "|";
  margin-right: 5px;
}

.problem-notes {
  background: var(--notes);
  border-radius: 20px;
  margin: 9px 10px 0;
  overflow: hidden;
}

.problem-notes > summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: bold;
  list-style: none;
  padding: 14px 18px;
  user-select: none;
}

.problem-notes > summary::-webkit-details-marker {
  display: none;
}

.problem-notes > summary::after {
  content: "+";
  float: right;
  font-size: 1.1rem;
  font-weight: normal;
}

.problem-notes[open] > summary {
  border-bottom: 1px solid rgba(21, 33, 30, 0.25);
}

.problem-notes[open] > summary::after {
  content: "−";
}

.notes-inner {
  padding: 16px 20px 24px;
}

.editorial-notice {
  background: var(--notice);
  border-radius: 16px;
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 0 0 20px;
  padding: 13px 15px;
}

.notes-inner h3 {
  font-size: 0.95rem;
  margin: 20px 0 8px;
}

.notes-inner h3:first-of-type {
  margin-top: 0;
}

.notes-inner p {
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 10px;
}

.notes-inner ul,
.notes-inner ol {
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 8px 0 12px;
  padding-left: 28px;
}

.notes-inner li {
  margin: 6px 0;
}

.progress-test {
  border-left: 5px solid var(--header);
  margin: 20px 0;
  padding: 3px 0 3px 14px;
}

.progress-test h3 {
  margin-top: 0;
}

.cross-reference-list {
  display: flex;
  flex-wrap: wrap;
  font-size: 0.82rem;
  gap: 7px;
}

.cross-reference-list a {
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(21, 33, 30, 0.3);
  border-radius: 8px;
  color: var(--link);
  padding: 6px 8px;
  text-decoration: none;
}

.cross-reference-list a:hover {
  text-decoration: underline;
}

.resolution-note {
  background: #9fc4aa;
  border: 1px solid rgba(21, 33, 30, 0.45);
  border-radius: 14px;
  margin: 20px 0;
  padding: 14px 16px 4px;
}

.resolution-note h3 {
  margin-top: 0;
}

.problem-facts {
  border-collapse: collapse;
  font-size: 0.76rem;
  margin-top: 20px;
  width: 100%;
}

.problem-facts th,
.problem-facts td {
  border-top: 1px solid rgba(21, 33, 30, 0.25);
  padding: 8px 6px;
  text-align: left;
}

.problem-facts th {
  font-weight: normal;
  width: 22%;
}

.problem-facts td {
  font-weight: bold;
  overflow-wrap: anywhere;
}

.notes-inner .reading-list {
  list-style: none;
  padding-left: 0;
}

.reading-list li {
  align-items: baseline;
  display: grid;
  gap: 3px 7px;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.reading-list .reference-number {
  color: var(--ink);
  font-family: "Courier New", monospace;
}

.reading-list span:nth-child(2) {
  color: var(--muted);
}

.reading-list a {
  color: var(--link);
  font-size: 0.76rem;
  white-space: nowrap;
}

.entry-actions {
  border-top: 1px solid rgba(21, 33, 30, 0.25);
  display: flex;
  font-size: 0.75rem;
  gap: 14px;
  margin-top: 22px;
  padding-top: 12px;
}

.entry-actions button,
.entry-actions a {
  background: none;
  border: 0;
  color: var(--link);
  padding: 0;
  text-decoration: underline;
}

.entry-actions .primary-edit-action {
  font-weight: 700;
}

.empty-state {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 35px;
  text-align: center;
}

.empty-state h2 {
  font-size: 1.15rem;
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0 0 14px;
}

.empty-state button {
  background: none;
  border: 0;
  color: var(--link);
  text-decoration: underline;
}

/* Footer */

.site-footer {
  align-items: center;
  border-top: 1px solid rgba(21, 33, 30, 0.4);
  display: flex;
  font-size: 0.72rem;
  justify-content: space-between;
  margin: 0 auto;
  max-width: var(--content-width);
  min-height: 82px;
  padding: 18px;
}

.site-footer span:nth-child(2) {
  color: var(--muted);
}

.toast {
  background: var(--header);
  bottom: 18px;
  color: white;
  font-size: 0.8rem;
  left: 50%;
  opacity: 0;
  padding: 10px 15px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 10px);
  transition: opacity 120ms linear, transform 120ms linear;
  z-index: 200;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1100px) {
  .site-header {
    grid-template-columns: minmax(230px, 1fr) auto auto;
  }

  .header-link {
    display: none;
  }

  .header-tools {
    gap: 8px;
    padding: 0 14px;
  }

  .jump-form input,
  .search-form input {
    width: 112px;
  }

  .tab {
    padding: 0 12px;
  }
}

@media (max-width: 820px) {
  :root {
    --header-height: 148px;
  }

  .site-header {
    grid-template-columns: 1fr auto;
    grid-template-rows: 62px 42px 44px;
    height: var(--header-height);
  }

  .header-left {
    grid-column: 1;
    grid-row: 1;
  }

  .header-tabs {
    grid-column: 2;
    grid-row: 1;
  }

  .tab {
    font-size: 0.76rem;
    padding: 0 10px;
  }

  .header-tools {
    border-top: 1px solid rgba(255, 255, 255, 0.18);
    gap: 12px;
    grid-column: 1 / -1;
    grid-row: 2 / 4;
    justify-content: center;
    padding: 8px 14px;
  }

  .jump-form input,
  .search-form input {
    width: min(30vw, 180px);
  }
}

@media (max-width: 560px) {
  :root {
    --header-height: 176px;
  }

  .site-header {
    grid-template-columns: 1fr;
    grid-template-rows: 62px 48px 66px;
  }

  .header-left {
    grid-column: 1;
    justify-content: center;
    padding: 0;
  }

  .brand small {
    font-size: 0.56rem;
  }

  .header-tabs {
    display: grid;
    grid-column: 1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-row: 2;
    overflow: hidden;
    width: 100%;
  }

  .tab {
    flex: 1;
    font-size: 0.72rem;
    min-width: 0;
    overflow: hidden;
    padding-left: 4px;
    padding-right: 4px;
    text-overflow: ellipsis;
  }

  .header-tools {
    align-items: stretch;
    display: grid;
    gap: 6px;
    grid-column: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-row: 3;
    padding: 10px;
  }

  .jump-form,
  .search-form {
    display: grid;
    gap: 4px;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
    width: 100%;
  }

  .jump-form input,
  .search-form input {
    min-width: 0;
    width: 100%;
  }

  main {
    margin-top: 12px;
    padding: 0 10px;
  }

  .about-card {
    border-radius: 18px;
    padding: 18px;
  }

  .about-card h1 {
    font-size: 1.3rem;
  }

  .editing-guide {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .editing-guide-link {
    white-space: normal;
  }

  .database-note {
    margin-left: 5px;
    margin-right: 5px;
  }

  .archive-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
    padding: 8px 4px;
  }

  .problem-entry {
    margin-bottom: 38px;
  }

  .problem-card {
    border-radius: 18px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .problem-card h2 {
    font-size: 1.12rem;
  }

  .problem-statement {
    font-size: 0.93rem;
  }

  .problem-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .problem-notes {
    border-radius: 15px;
    margin-left: 5px;
    margin-right: 5px;
  }

  .notes-inner {
    padding: 14px;
  }

  .problem-facts,
  .problem-facts tbody,
  .problem-facts tr,
  .problem-facts th,
  .problem-facts td {
    display: block;
  }

  .problem-facts tr {
    border-top: 1px solid rgba(21, 33, 30, 0.25);
    padding: 7px 0;
  }

  .problem-facts th,
  .problem-facts td {
    border: 0;
    padding: 2px 0;
    width: auto;
  }

  .site-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}

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

  * {
    transition: none !important;
  }
}

@media print {
  .site-header,
  .about-card,
  .database-note,
  .archive-line,
  .archive-actions,
  .site-footer,
  .toast,
  .entry-actions {
    display: none !important;
  }

  body {
    background: white;
    font-size: 11pt;
  }

  main {
    margin: 0;
    max-width: none;
    padding: 0;
  }

  .problem-entry {
    break-inside: avoid;
    margin-bottom: 28px;
  }

  .problem-card,
  .problem-notes {
    background: white !important;
  }

  .problem-notes > summary {
    display: none;
  }

  .problem-notes > .notes-inner {
    display: block !important;
  }
}
