/* Light, warm off-white theme with a charcoal-navy header band, a crimson
   accent, serif display headings, and a golden-rectangle tiling motif —
   deliberately distinct from the other icarm sites: elliptic-rank (light
   teal, serif body), ruzsa-genus-one (dark indigo, amber), additive-squares
   (lavender, violet/magenta, slab, graph paper), littlewood-ultraflat (dark
   spruce, phosphor mint/coral, mono), eq677 (blue-cast light, cobalt), and
   matroid-correlation-constants (warm paper, teal + rust). */
:root {
  --bg: #f9f7f3;           /* warm off-white */
  --fg: #1f2328;           /* charcoal ink */
  --muted: #6b6f76;
  --accent: #b3123f;       /* crimson */
  --accent-dark: #8e0f33;
  --accent-soft: #f8e6ec;
  --tile-2: #e0a100;       /* ochre — second tile */
  --tile-3: #1f6f8b;       /* petrol — third tile */
  --border: #e3ded6;
  --panel: #fffefc;        /* cards, inputs */
  --panel-soft: #f1ede6;
  --code-bg: #efebe4;
  --header-bg: #1e2a36;    /* charcoal-navy header band */
  --header-fg: #f3f1ec;
  --header-muted: #a9b3bd;
  --ok: #1f6e3d;
  --ok-bg: #e2f0e6;
  --bad: #a4142f;
  --bad-bg: #f8e3e6;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--fg);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent-dark);
}
a:hover {
  color: var(--accent);
}

code {
  font-family: var(--mono);
  background: var(--code-bg);
  padding: 0.05em 0.3em;
  border-radius: 3px;
  font-size: 0.92em;
}

.muted {
  color: var(--muted);
}
.nowrap {
  white-space: nowrap;
}
.math {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.04em;
}
.rules {
  font-family: var(--mono);
  font-size: 0.95em;
  font-weight: 600;
}

/* ---------------- header ---------------- */

header {
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 3px solid var(--accent);
}

header .inner {
  max-width: 940px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

header h1 a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}
header h1 a:hover {
  color: #fff;
}

.logo-mark {
  height: 0.85em;
  width: auto;
  display: inline-block;
  border-radius: 1px;
}

header nav {
  font-size: 0.92rem;
  display: inline-flex;
  align-items: baseline;
  gap: 1.1rem;
}
header nav a {
  color: var(--header-muted);
  text-decoration: none;
}
header nav a:hover {
  color: var(--header-fg);
}
.auth-nav {
  display: inline-flex;
  align-items: baseline;
  gap: 0.7rem;
  padding-left: 0.9rem;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}
.auth-user {
  font-weight: 600;
}
.auth-logout {
  display: inline;
  margin: 0;
}
.auth-logout button {
  background: none;
  border: none;
  color: var(--header-muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}
.auth-logout button:hover {
  color: var(--header-fg);
}

/* ---------------- layout ---------------- */

main {
  max-width: 940px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 3rem;
}

section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1.3rem 1.7rem;
  margin: 1.2rem 0;
}

h2 {
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  margin: 0.1rem 0 0.8rem;
  line-height: 1.3;
}
h3 {
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 1.4rem 0 0.5rem;
}
h4 {
  font-family: var(--serif);
  font-size: 1rem;
  margin: 1.2rem 0 0.4rem;
}

footer {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.footer-links {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
footer a {
  color: var(--muted);
}
footer a:hover {
  color: var(--accent-dark);
}

/* ---------------- hero ---------------- */

.hero p {
  max-width: 64rem;
}
.hero-challenge {
  padding: 0.7rem 1rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 2px;
}
.ex {
  white-space: nowrap;
}

/* ---------------- plots ---------------- */

.size-filter {
  margin: 0.2rem 0 0.6rem;
  font-size: 0.92rem;
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
}
.size-filter .current {
  font-weight: 700;
  color: var(--accent-dark);
  border-bottom: 2px solid var(--accent);
}

.score-plot,
.ratio-plot,
.pq-plot {
  width: 100%;
  height: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: block;
}
.pq-plot {
  margin-top: 0.6rem;
}
svg .grid {
  stroke: #ece8e1;
  stroke-width: 1;
}
svg .grid.one {
  stroke: var(--accent);
  stroke-dasharray: 4 3;
  stroke-opacity: 0.6;
}
svg .axis {
  stroke: var(--fg);
  stroke-width: 1.3;
}
svg .tick {
  font-size: 12px;
  fill: var(--muted);
}
svg .axis-title {
  font-size: 13px;
  fill: var(--fg);
}
.score-plot .dot {
  fill: var(--panel);
  stroke-width: 1.6;
  opacity: 0.95;
}
.score-plot .dot.record {
  stroke-width: 1.2;
}
.score-plot a:hover .dot {
  stroke-width: 3;
}
/* one hue per alphabet size */
.score-plot .dot.s3 { stroke: #b3123f; }
.score-plot .dot.s4 { stroke: #e0a100; }
.score-plot .dot.s5 { stroke: #1f6f8b; }
.score-plot .dot.s6 { stroke: #3f8a3a; }
.score-plot .dot.s7 { stroke: #7a3fa0; }
.score-plot .dot.s8 { stroke: #d96a1a; }
.score-plot .dot.s9 { stroke: #4a4f57; }
.score-plot .dot.record.s3 { fill: #b3123f; }
.score-plot .dot.record.s4 { fill: #e0a100; }
.score-plot .dot.record.s5 { fill: #1f6f8b; }
.score-plot .dot.record.s6 { fill: #3f8a3a; }
.score-plot .dot.record.s7 { fill: #7a3fa0; }
.score-plot .dot.record.s8 { fill: #d96a1a; }
.score-plot .dot.record.s9 { fill: #4a4f57; }

.ratio-plot .window {
  fill: var(--accent-soft);
}
.ratio-plot .ratio {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
}
.ratio-plot .mark {
  fill: var(--panel);
  stroke: var(--fg);
  stroke-width: 1.6;
}
.pq-plot .p {
  fill: none;
  stroke: var(--tile-3);
  stroke-width: 1.6;
}
.pq-plot .q {
  fill: none;
  stroke: var(--tile-2);
  stroke-width: 1.6;
}
.pq-plot .legend {
  font-size: 12px;
  font-weight: 600;
}
.pq-plot .legend.p {
  fill: var(--tile-3);
}
.pq-plot .legend.q {
  fill: var(--tile-2);
}
.plot-caption {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 0.6rem;
}
.plot-empty {
  padding: 1.5rem 0;
}

/* ---------------- tables ---------------- */

.table-scroll {
  overflow-x: auto;
}

table.records {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8rem 0;
  font-size: 0.94rem;
}
table.records th,
table.records td {
  text-align: left;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--border);
}
table.records thead th {
  font-family: var(--serif);
  font-size: 0.92rem;
  font-weight: 600;
  border-bottom: 2px solid var(--fg);
}
table.records th a.sort {
  color: var(--muted);
  text-decoration: none;
}
table.records th a.sort:hover {
  color: var(--accent-dark);
}
table.records th a.sort.asc,
table.records th a.sort.desc {
  color: var(--accent-dark);
}
table.records th a.sort.asc::after {
  content: " \2191";
}
table.records th a.sort.desc::after {
  content: " \2193";
}
table.records td.num,
table.records th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.records tr:hover td {
  background: var(--panel-soft);
}
table.records tr.record-row td {
  background: #fdf6f8;
}
table.records tr.revoked td {
  opacity: 0.55;
}

.rules-link {
  font-family: var(--mono);
  font-size: 0.9em;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-dark);
}

.status {
  font-size: 0.78rem;
  padding: 0.1rem 0.5rem;
  border-radius: 2px;
  white-space: nowrap;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status.record {
  background: var(--accent);
  color: #fff;
}
.status.former {
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ---------------- submit form ---------------- */

.submit-help {
  font-size: 0.94rem;
}
.submit label {
  display: block;
  font-family: var(--serif);
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}
.submit textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.92rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
  resize: vertical;
}
.submit textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
.submit textarea:disabled {
  background: var(--panel-soft);
  color: var(--muted);
  cursor: not-allowed;
}
.submit-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.7rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

button,
.login-cta {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover,
.login-cta:hover {
  background: var(--accent-dark);
  color: #fff;
}
.login-page {
  max-width: 26rem;
}
.login-page .login-cta {
  display: block;
  text-align: center;
}
button.danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--bad);
  padding: 0.15rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 500;
}
button.danger:hover {
  background: var(--bad-bg);
  color: var(--bad);
}

/* ---------------- submission result ---------------- */

.result.accepted {
  border-left: 5px solid var(--ok);
}
.result.rejected {
  border-left: 5px solid var(--bad);
}
.errors {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 3px;
  padding: 0.7rem 1rem 0.7rem 2rem;
  font-family: var(--mono);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}
.record-banner {
  padding: 0.6rem 0.9rem;
  border-radius: 3px;
  background: var(--panel-soft);
}
.record-banner.new {
  background: var(--ok-bg);
}
.record-banner.improved {
  background: var(--accent-soft);
}

/* ---------------- substitution detail ---------------- */

.entry-meta {
  color: var(--muted);
}
.status-line {
  padding: 0.5rem 0.8rem;
  background: var(--panel-soft);
  border-radius: 3px;
  font-size: 0.94rem;
}
.status-line.record {
  background: var(--accent-soft);
}
.detail-grid {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) 2fr;
  gap: 1.5rem;
}
.rule-table {
  font-family: var(--mono);
  font-size: 1.05rem;
  border-collapse: collapse;
}
.rule-table td {
  padding: 0.15rem 0.4rem;
}
.rule-table .letter {
  font-weight: 700;
  color: var(--accent-dark);
}
.rule-table .arrow {
  color: var(--muted);
}
.rule-table .image {
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}
.invariants {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
  font-size: 0.94rem;
}
.invariants dt {
  color: var(--muted);
}
.invariants dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------------- comments ---------------- */

.comment-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.7rem 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.comment-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.4rem 0;
}
.comment-list {
  list-style: none;
  padding: 0;
}
.comment-list li {
  margin: 0.9rem 0;
}
.comment-delete {
  display: inline;
}
.comment-delete button {
  font: inherit;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.comment-form {
  margin-top: 0.8rem;
}
.comment-form textarea {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
  resize: vertical;
}
.comment-form button {
  margin-top: 0.6rem;
}

/* ---------------- activity ---------------- */

.activity {
  list-style: none;
  padding: 0;
}
.activity li {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.activity .comment-body {
  margin-top: 0.4rem;
  font-size: 0.92rem;
}
.pager {
  margin-top: 1rem;
}

/* ---------------- api docs ---------------- */

.code-block {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--header-bg);
  color: var(--header-fg);
  border-radius: 3px;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
}

/* ---------------- profile ---------------- */

.name-form,
.token-form {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0.6rem 0 1rem;
}
.name-form label {
  font-family: var(--serif);
  font-size: 0.95rem;
}
.name-form input,
.token-form input {
  font: inherit;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
}
.token-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 0.7rem 1rem;
  margin: 0.6rem 0;
  overflow-wrap: anywhere;
}

/* ---------------- responsive ---------------- */

@media (max-width: 640px) {
  header .inner {
    flex-direction: column;
    gap: 0.3rem;
  }
  header nav {
    flex-wrap: wrap;
    gap: 0.8rem;
  }
  main {
    padding: 1rem 0.8rem 2rem;
  }
  section {
    padding: 1rem;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
