/* VT323 is served locally (SIL Open Font License, see fonts/OFL.txt) so the share-card capture can embed it. */
@font-face {
  font-family: 'VT323';
  src: url('/fonts/VT323-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #030703;
  --green: #39FF6A;
  --green-dim: #22A84A;
  --green-soft: #8CFFA9;
  --amber: #FFB000;
  --glow: 0 0 6px rgba(57, 255, 106, .65), 0 0 18px rgba(57, 255, 106, .25);
  --glow-amber: 0 0 6px rgba(255, 176, 0, .65), 0 0 18px rgba(255, 176, 0, .25);
  /* Text is crisp for readability; only large display text (title, counter, wordmark) glows.
     Boxes, borders and buttons keep their glow via box-shadow. */
  --font: 'VT323', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--green);
  font-family: var(--font);
  font-size: 22px;
  line-height: 1.3;
  overflow-x: hidden;
}

/* Faint radial glow, centred */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(57, 255, 106, .09) 0%, rgba(57, 255, 106, .03) 45%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

/* Scanlines */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 2px, rgba(0, 0, 0, .45) 3px, transparent 4px);
  pointer-events: none;
  z-index: 100;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1152px;
  margin: 0 auto;
  padding: 24px 32px 32px;
}

a { color: inherit; }

:focus-visible {
  outline: 2px dashed var(--green);
  outline-offset: 4px;
}

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

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--green-dim);
  font-size: 20px;
  text-shadow: none;
}

h1 {
  margin: 24px 0 16px;
  /* The heading is ~9em wide including the cursor; shrink it so it never wraps. */
  font-size: min(96px, calc((100vw - 64px) / 9.2));
  font-weight: 400;
  text-shadow: var(--glow);
  line-height: 1;
  overflow-wrap: anywhere;
}

.cursor {
  display: inline-block;
  width: .5em;
  height: .8em;
  margin-left: .1em;
  vertical-align: -.05em;
  background: var(--green);
  box-shadow: var(--glow);
  animation: blink 1.06s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

.intro {
  max-width: 980px;
  margin: 0 0 8px;
  font-size: 28px;
}

.small-print {
  max-width: 980px;
  margin: 0;
  font-size: 20px;
  color: var(--green-dim);
  text-shadow: none;
}

.counter {
  margin: 24px 0 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.counter-label { color: var(--green-dim); text-shadow: none; font-size: 22px; }
.counter-value { color: var(--amber); text-shadow: var(--glow-amber); font-size: 56px; line-height: 1; }

/* ---------- Input panel ---------- */

.panel {
  margin: 32px 0 0;
  padding: 20px 28px 24px;
  border: 2px solid var(--green);
  box-shadow: 0 0 12px rgba(57, 255, 106, .25), inset 0 0 12px rgba(57, 255, 106, .08);
}

.panel-label {
  color: var(--green-dim);
  text-shadow: none;
  font-size: 20px;
  margin-bottom: 12px;
}

.sentence {
  margin: 0;
  font-size: 34px;
  line-height: 1.6;
}

.dd {
  position: relative;
  display: inline-block;
  max-width: 100%;
  vertical-align: baseline;
}

.dd-btn {
  display: inline-block;
  max-width: 100%;
  margin: 0;
  padding: 0 26px 0 8px;
  border: 0;
  border-radius: 0;
  font: inherit;
  line-height: 1.15;
  text-align: left;
  color: var(--bg);
  text-shadow: none;
  background-color: var(--green);
  /* Dark ▼ indicator */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0h12L6 8z' fill='%23030703'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  box-shadow: 0 0 8px rgba(57, 255, 106, .45);
  cursor: pointer;
}
.dd-btn:hover { background-color: var(--green-soft); }
.dd-btn[aria-expanded="true"] {
  /* ▲ when open */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 8h12L6 0z' fill='%23030703'/%3E%3C/svg%3E");
}
.dd-btn:focus-visible {
  outline: 2px dashed var(--green);
  outline-offset: 3px;
}

.dd-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 100%;
  width: max-content;
  max-width: calc(100vw - 32px);
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--bg);
  border: 2px solid var(--green);
  box-shadow: 0 0 14px rgba(57, 255, 106, .35);
  font-size: .8em;
  line-height: 1.3;
  white-space: normal;
}
.dd-list:focus { outline: none; }
.dd-list li {
  padding: 4px 16px 4px 32px;
  position: relative;
  cursor: pointer;
  color: var(--green);
}
.dd-list li[aria-selected="true"]::before {
  content: '>';
  position: absolute;
  left: 12px;
}
.dd-list li.is-active {
  background: var(--green);
  color: var(--bg);
  text-shadow: none;
}

.panel-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
}

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

.btn {
  min-height: 44px;
  padding: 6px 22px;
  font: inherit;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: .02em;
  cursor: pointer;
  border: 2px solid var(--green);
  border-radius: 0;
}

.btn-solid {
  background: var(--green);
  color: var(--bg);
  text-shadow: none;
  box-shadow: 0 0 12px rgba(57, 255, 106, .45);
}
.btn-solid:hover:not(:disabled) { background: var(--green-soft); border-color: var(--green-soft); }

.btn-outline {
  background: transparent;
  color: var(--green);
  text-shadow: none;
}
.btn-outline:hover:not(:disabled) { background: rgba(57, 255, 106, .12); }

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Output ---------- */

.output { margin-top: 40px; }
.output:empty { display: none; }

.loading, .error-box {
  border: 2px dashed var(--green-dim);
  padding: 40px 24px;
  text-align: center;
  font-size: 34px;
}
.loading::after { content: '_'; animation: blink 1.06s steps(1) infinite; }
@media (prefers-reduced-motion: reduce) { .loading::after { animation: none; } }

.error-box p { margin: 0 0 24px; }

.notice {
  color: var(--amber);
  text-shadow: none;
  text-align: center;
  margin: 0 0 16px;
  font-size: 26px;
}

.result { position: relative; transition: opacity .2s; }

.stale-label { display: none; }

.result.is-stale .result-body { opacity: .3; }
.result.is-stale .stale-label {
  display: block;
  position: sticky;
  top: 16px;
  z-index: 2;
  width: max-content;
  max-width: 100%;
  margin: 0 auto 16px;
  padding: 6px 16px;
  background: var(--bg);
  border: 2px solid var(--amber);
  color: var(--amber);
  text-shadow: none;
  font-size: 26px;
  text-align: center;
}

.loop {
  display: grid;
  grid-template-columns: minmax(0, 640px) minmax(0, 1fr);
  gap: 32px;
  align-items: center;
}

.ring { width: 100%; height: auto; display: block; overflow: visible; }
/* Ring text is drawn crisp: the page-wide glow blurs VT323 at these small sizes. The boxes keep their glow. */
.ring text { font-family: var(--font); text-shadow: none; }
.ring .ring-line { fill: none; stroke: var(--green-dim); stroke-width: 2; stroke-dasharray: 10 8; }
.ring .arrow { fill: var(--green-dim); }
.ring .node rect { fill: #000; stroke: var(--green); stroke-width: 2; filter: drop-shadow(0 0 5px rgba(57, 255, 106, .5)); }
.ring .node-num { fill: var(--green-dim); font-size: 20px; }
.ring .node-label { fill: var(--green); font-size: 24px; }
.ring .centre-dim { fill: var(--green-dim); font-size: 22px; }
.ring .centre-title { fill: var(--amber); font-size: 38px; }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: none;
}
.steps li { margin: 0 0 18px; }
.steps li:last-child { margin-bottom: 0; }
.step-head { margin: 0; font-size: 28px; }
.step-num { color: var(--green-dim); text-shadow: none; margin-right: 8px; }
.step-rationale { margin: 2px 0; color: var(--green-soft); font-size: 22px; }
.step-feeds { margin: 0; color: var(--green-dim); text-shadow: none; font-size: 20px; }
.steps li:last-child .step-feeds { color: var(--amber); text-shadow: none; }
.back-to { display: none; }

.collapse {
  margin: 32px 0 0;
  text-align: center;
  color: var(--amber);
  text-shadow: none;
  font-size: 30px;
}

.result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 28px;
}

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

footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-top: 56px;
  padding-top: 16px;
  border-top: 2px dashed var(--green-dim);
  color: var(--green-dim);
  text-shadow: none;
  font-size: 22px;
}
footer a { color: var(--green); text-shadow: none; text-decoration: none; }
footer a:hover { text-decoration: underline; }

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

@media (max-width: 900px) {
  .wrap { padding: 16px 16px 24px; }
  h1 { font-size: max(24px, calc((100vw - 32px) / 9.2)); margin-top: 16px; }
  .intro { font-size: 24px; }
  .small-print { font-size: 18px; }
  .panel { padding: 16px; }
  .sentence { font-size: 24px; line-height: 1.7; }
  .panel-actions, .result-actions { flex-direction: column; }
  .btn { width: 100%; }

  .loop { display: block; }
  .ring { display: none; }

  /* The step list becomes the vertical stack of nodes */
  .steps li {
    position: relative;
    border: 2px solid var(--green);
    background: #000;
    padding: 12px 14px;
    margin: 0 0 44px;
    box-shadow: 0 0 10px rgba(57, 255, 106, .25);
  }
  .steps li::after {
    content: '↓';
    position: absolute;
    left: 50%;
    bottom: -42px;
    transform: translateX(-50%);
    color: var(--green-dim);
    text-shadow: none;
    font-size: 32px;
    line-height: 40px;
  }
  .steps li:last-child { margin-bottom: 0; }
  .steps li:last-child::after { content: none; }
  .back-to {
    display: block;
    margin: 12px 0 0;
    text-align: center;
    color: var(--amber);
    text-shadow: none;
    font-size: 26px;
  }
  .collapse { font-size: 24px; }
  .loading, .error-box { font-size: 26px; padding: 32px 16px; }
}

/* ---------- Share card (captured as a PNG, never shown) ---------- */

.share-card {
  position: fixed;
  left: -20000px;
  top: 0;
  width: 1080px;
  height: 1350px;
  padding: 64px 72px 52px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(57, 255, 106, .10) 0%, rgba(57, 255, 106, .03) 45%, transparent 75%),
    var(--bg);
  color: var(--green);
  font-family: var(--font);
  text-shadow: none;
}
.share-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 2px, rgba(0, 0, 0, .45) 3px, transparent 4px);
  pointer-events: none;
}
.sc-head { font-size: 80px; line-height: 1; text-shadow: var(--glow); }
.sc-cursor {
  display: inline-block;
  width: .5em;
  height: .8em;
  margin-left: .1em;
  vertical-align: -.05em;
  background: var(--green);
  box-shadow: var(--glow);
}
.sc-sentence { margin: 28px 0 0; font-size: 36px; line-height: 1.35; }
.sc-val { color: var(--amber); text-shadow: none; }
.sc-ring {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}
.share-card .ring { display: block; width: auto; height: 100%; max-width: 100%; }
.sc-collapse {
  margin: 0 0 28px;
  text-align: center;
  font-size: 34px;
  color: var(--amber);
  text-shadow: none;
}
.sc-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 18px;
  border-top: 2px dashed var(--green-dim);
  color: var(--green-dim);
  text-shadow: none;
  font-size: 28px;
}
.sc-wordmark { color: var(--green); text-shadow: var(--glow); font-size: 48px; letter-spacing: .2em; }

.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;
}

.nowrap { white-space: nowrap; }
.nowrap .dd-list { white-space: normal; }
