/*
 * Constraint Quest — visual system (W1)
 *
 * Direction: a printed-puzzle feel, not a SaaS dashboard. Serif display type,
 * sans body, one accent colour, hairline rules instead of cards-on-shadows.
 * No gradients, no glow, no decorative animation.
 *
 * Contrast: every text/background pair below is >= 4.5:1 except --ink-faint,
 * which is used only for non-essential metadata at >= 3:1.
 */

:root {
  /* Surfaces */
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-sunken: #efede7;
  --border: #d9d6ce;
  --border-strong: #b9b5aa;

  /* Text */
  --ink: #16181d;
  --ink-muted: #55585f;
  --ink-faint: #6f7278;
  --ink-inverse: #ffffff;

  /* Accent — verified 7.58:1 with white text, 7.27:1 as text on white */
  --accent: #115e59;
  --accent-hover: #0b4843;
  --accent-soft: #e6efed;

  /* Semantic */
  --success: #1b6b4b;
  --success-soft: #e5f0ea;
  --danger: #a32b2b;
  --danger-soft: #f7e7e7;
  --warning: #7a4e00;
  --warning-soft: #f6eedd;
  --info: #28527a;
  --info-soft: #e7eef5;

  /* Type */
  --font-display: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Space */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* Shape */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;

  /* Focus */
  --focus-ring: 0 0 0 3px rgba(17, 94, 89, 0.35);
  --focus-outline: 2px solid var(--accent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  /* Prevents long unbroken strings from forcing horizontal scroll at 320px. */
  min-width: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  /* No horizontal overflow anywhere; the shell handles its own padding. */
  overflow-x: hidden;
}

/* ---------- Layout ---------- */

.shell {
  width: 100%;
  max-width: 940px;
  margin-inline: auto;
  padding-inline: clamp(16px, 5vw, 32px);
}

.main {
  max-width: 780px;
  min-height: 60vh;
  padding-block: var(--sp-6) var(--sp-8);
}

.main:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent);
  color: var(--ink-inverse);
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  left: 0;
}

/* ---------- Focus ---------- */

/*
 * One focus treatment for every interactive element.
 *
 * Before this existed, only .btn, .answer-input and .skip-link had a styled
 * focus state; nav links, the wordmark and footer links fell back to the
 * browser default (`outline-style: auto`), which is not consistent across
 * platforms and is hard to see against this background.
 */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: 64px;
  flex-wrap: wrap;
  padding-block: var(--sp-3);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
}

.wordmark__mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  flex: none;
}

.wordmark__text {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a.wordmark:hover .wordmark__text {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.site-nav {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}

.site-nav__link:hover {
  color: var(--ink);
  background: var(--surface-sunken);
}

.site-nav__link[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Typography ---------- */

.eyebrow {
  margin: 0 0 var(--sp-2);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

h1,
.h1 {
  margin: 0 0 var(--sp-4);
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.015em;
  font-weight: 600;
}

h2,
.h2 {
  margin: 0 0 var(--sp-3);
  font-family: var(--font-display);
  font-size: clamp(21px, 3vw, 26px);
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 600;
}

h3,
.h3 {
  margin: 0 0 var(--sp-2);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

p {
  margin: 0 0 var(--sp-4);
}

p:last-child {
  margin-bottom: 0;
}

.prose {
  max-width: 68ch;
  color: var(--ink-muted);
  font-size: 16px;
  line-height: 1.65;
}

.lede {
  max-width: 60ch;
  font-size: clamp(17px, 2.2vw, 19px);
  line-height: 1.6;
  color: var(--ink-muted);
}

.lede strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 32px);
}

.card + .card {
  margin-top: var(--sp-5);
}

.card--notice {
  border-left: 3px solid var(--border-strong);
}

.card--empty {
  border-style: dashed;
  border-color: var(--border-strong);
  background: var(--surface);
}

.card--error {
  border-left: 3px solid var(--danger);
}

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: normal;
  text-align: center;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.btn--primary {
  background: var(--accent);
  color: var(--ink-inverse);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--surface-sunken);
}

.btn--quiet {
  background: transparent;
  color: var(--accent);
  padding-inline: var(--sp-3);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn--quiet:hover:not(:disabled) {
  color: var(--accent-hover);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn--block {
  width: 100%;
}

/* ---------- Answer form ---------- */

.answer-field {
  display: block;
  margin-bottom: var(--sp-2);
}

.answer-label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.answer-input {
  width: 100%;
  min-height: 54px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 17px;
  line-height: 1.3;
}

.answer-input::placeholder {
  color: var(--ink-faint);
  font-family: var(--font-body);
  font-size: 15px;
}

.answer-input:focus {
  outline: var(--focus-outline);
  outline-offset: 1px;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.answer-input:disabled {
  background: var(--surface-sunken);
  color: var(--ink-faint);
  cursor: not-allowed;
}

.answer-input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-hint {
  margin: var(--sp-2) 0 0;
  font-size: 13px;
  color: var(--ink-faint);
}

.field-error {
  margin: var(--sp-2) 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
}

/* Prefixes a text marker so the error is not signalled by colour alone. */
.field-error::before {
  content: "Error: ";
}

.form-row {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.form-row .btn {
  flex: 1 1 180px;
}

/* ---------- Score panel ---------- */

.score-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.score-cell {
  padding: var(--sp-4);
  border-right: 1px solid var(--border);
  min-width: 0;
}

.score-cell:last-child {
  border-right: none;
}

.score-cell__label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.score-cell__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.score-cell--score .score-cell__value {
  color: var(--accent);
}

/* ---------- Status badge ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 100px;
  border: 1px solid currentColor;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.status--active {
  color: var(--accent);
  background: var(--accent-soft);
}

.status--won {
  color: var(--success);
  background: var(--success-soft);
}

.status--lost {
  color: var(--danger);
  background: var(--danger-soft);
}

.status--timeout {
  color: var(--warning);
  background: var(--warning-soft);
}

.status--idle {
  color: var(--ink-muted);
  background: var(--surface-sunken);
}

.status--info {
  color: var(--info);
  background: var(--info-soft);
}

/* ---------- Feedback ---------- */

.feedback {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  margin-bottom: var(--sp-4);
}

.feedback:last-child {
  margin-bottom: 0;
}

.feedback__marker {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-inverse);
  background: var(--ink-muted);
}

.feedback__body {
  min-width: 0;
}

.feedback__title {
  margin: 0 0 var(--sp-1);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

.feedback__text {
  margin: 0;
  font-size: 15px;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.feedback--success {
  border-color: #b9d4c6;
  background: var(--success-soft);
}

.feedback--success .feedback__marker {
  background: var(--success);
}

.feedback--error {
  border-color: #e0bdbd;
  background: var(--danger-soft);
}

.feedback--error .feedback__marker {
  background: var(--danger);
}

.feedback--warning {
  border-color: #e0cfa6;
  background: var(--warning-soft);
}

.feedback--warning .feedback__marker {
  background: var(--warning);
}

.feedback--info .feedback__marker {
  background: var(--info);
}

/* ---------- Hint list ---------- */

.hint-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--sp-2);
}

.hint-list li {
  padding: var(--sp-3) var(--sp-4);
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 15px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* ---------- Constraint list on a challenge ---------- */

.constraint-list {
  margin: 0 0 var(--sp-5);
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--sp-2);
  counter-reset: constraint;
}

.constraint-list li {
  position: relative;
  padding-left: var(--sp-6);
  font-size: 16px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.constraint-list li::before {
  counter-increment: constraint;
  content: counter(constraint);
  position: absolute;
  left: 0;
  top: 2px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
}

/* ---------- Rules page ---------- */

.rules-section + .rules-section {
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}

.rule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.rule-table th,
.rule-table td {
  padding: var(--sp-3) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.rule-table th {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom-color: var(--border-strong);
}

.rule-table td:first-child {
  font-weight: 600;
  white-space: nowrap;
}

.rule-table tr:last-child td {
  border-bottom: none;
}

.callout {
  padding: var(--sp-4);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 15px;
  color: var(--ink);
  margin: var(--sp-4) 0;
}

.callout strong {
  font-weight: 700;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-block: var(--sp-5);
  margin-top: var(--sp-7);
}

.site-footer__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.site-footer__note {
  margin: 0;
  font-size: 13px;
  color: var(--ink-faint);
  max-width: 52ch;
}

.site-footer__nav {
  display: flex;
  gap: var(--sp-4);
}

.site-footer__nav a {
  color: var(--ink-muted);
  font-size: 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.site-footer__nav a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Utilities ---------- */

.stack {
  display: grid;
  gap: var(--sp-5);
}

.stack--tight {
  gap: var(--sp-3);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.meta-list {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--ink-faint);
}

.meta-list dt {
  margin: 0;
}

.meta-list dd {
  margin: 0;
  font-family: var(--font-mono);
  color: var(--ink-muted);
}

.hr {
  height: 1px;
  border: 0;
  background: var(--border);
  margin: var(--sp-5) 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .score-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-cell {
    border-bottom: 1px solid var(--border);
  }

  .score-cell:nth-child(2n) {
    border-right: none;
  }

  .score-cell:nth-last-child(-n + 2) {
    border-bottom: none;
  }
}

@media (max-width: 520px) {
  .site-header__inner {
    min-height: auto;
  }

  .main {
    padding-block: var(--sp-5) var(--sp-7);
  }

  .card {
    padding: var(--sp-4);
    border-radius: var(--radius);
  }

  .form-row {
    flex-direction: column;
  }

  .form-row .btn {
    flex: 1 1 auto;
    width: 100%;
  }

  .score-cell {
    padding: var(--sp-3);
  }

  .score-cell__value {
    font-size: 19px;
  }

  .rule-table th,
  .rule-table td {
    padding: var(--sp-2) var(--sp-2);
  }

  .rule-table td:first-child {
    white-space: normal;
  }

  .site-footer__inner {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---------- Reduced motion ---------- */

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