/* Is AI Down? A railway signal board.
   Big Shoulders Display (station signage) for names and the answer; Martian Mono for readings.
   Lamps and split-flap tiles are dark in both themes, like real signal heads, so the status
   colours stay the same bright set everywhere. Every status also has its own lamp shape and
   its own cell height, so nothing depends on colour alone. Colours: Okabe-Ito, colour-blind safe. */

@font-face {
  font-family: 'Big Shoulders';
  src: url('/assets/fonts/big-shoulders-display-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Martian Mono';
  src: url('/assets/fonts/martian-mono-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --display: 'Big Shoulders', 'Arial Narrow', sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* enamel signal plate */
  --ground: #e3e6df;
  --board: #f3f4ef;
  --board-2: #d6dad2;
  --ink: #101412;
  --ink-2: #3a423d;
  --link: #0a4f86;
  --head: #121614; /* signal heads, flaps and the clock: dark in both themes */
  --head-2: #232925;
  --head-ink: #eef1ea;
  --head-dim: #3a423d;

  /* lit lamps (on dark heads) */
  --lit-operational: #3ddc97;
  --lit-maintenance: #56b4e9;
  --lit-degraded: #f0e442;
  --lit-partial: #ffa31a;
  --lit-major: #ff5f1f;
  --lit-unknown: #8a918c;

  /* strip cells (on the board) */
  --cell-operational: #009e73;
  --cell-maintenance: #0072b2;
  --cell-degraded: #b39400;
  --cell-partial: #e08a00;
  --cell-major: #d55e00;
  --cell-unknown: #8a918c;
  --cell-none: #b9beb6;

  --focus: #0072b2;
  --pad: clamp(16px, 3vw, 40px);
  --gap-section: clamp(88px, 10vw, 160px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme='dark'] {
  --ground: #0c0e0d;
  --board: #151917;
  --board-2: #1f2421;
  --ink: #eceee8;
  --ink-2: #b4bcb5;
  --link: #8cc8f0;
  --head: #050606;
  --head-2: #1b1f1d;
  --head-dim: #2a302c;
  --cell-operational: #24b585;
  --cell-maintenance: #56b4e9;
  --cell-degraded: #f0e442;
  --cell-partial: #ffa31a;
  --cell-major: #ff6a2a;
  --cell-none: #333a36;
  --focus: #56b4e9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ground: #0c0e0d;
    --board: #151917;
    --board-2: #1f2421;
    --ink: #eceee8;
    --ink-2: #b4bcb5;
    --link: #8cc8f0;
    --head: #050606;
    --head-2: #1b1f1d;
    --head-dim: #2a302c;
    --cell-operational: #24b585;
    --cell-maintenance: #56b4e9;
    --cell-degraded: #f0e442;
    --cell-partial: #ffa31a;
    --cell-major: #ff6a2a;
    --cell-none: #333a36;
    --focus: #56b4e9;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.6 var(--mono);
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 800; letter-spacing: -0.01em; line-height: 0.95; text-transform: uppercase; }
p { margin: 0; }
a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
code { font-family: var(--mono); font-size: 0.86em; overflow-wrap: anywhere; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip { position: absolute; left: var(--pad); top: -60px; background: var(--head); color: var(--head-ink); padding: 10px 14px; z-index: 10; }
.skip:focus { top: 10px; }

/* top bar */
.bar { display: flex; align-items: center; gap: 24px; padding: 18px var(--pad); }
.wordmark { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font: 800 30px/1 var(--display); text-transform: uppercase; letter-spacing: 0.01em; }
.mark { width: 22px; height: 33px; }
.mark-head { fill: var(--head); }
.mark-on { fill: var(--lit-operational); }
.mark-off { fill: var(--head-dim); }
.bar-nav { display: flex; gap: 22px; margin-left: auto; }
.bar-nav a { color: var(--ink); text-decoration: none; font-size: 13px; padding: 6px 0; position: relative; }
.bar-nav a::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: currentColor; transform: scaleX(0); transform-origin: left; transition: transform 240ms var(--ease); }
.bar-nav a:hover::after, .bar-nav a:focus-visible::after { transform: scaleX(1); }
.theme { font: 500 12px/1 var(--mono); background: var(--head); color: var(--head-ink); border: 0; border-radius: 999px; padding: 9px 14px; cursor: pointer; transition: transform 120ms var(--ease); }
.theme:hover { background: var(--head-2); }
.theme:active { transform: scale(0.96); }
.theme-d { display: none; }
:root[data-theme='dark'] .theme-l { display: none; }
:root[data-theme='dark'] .theme-d { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-l { display: none; }
  :root:not([data-theme='light']) .theme-d { display: inline; }
}

main { padding: 0 var(--pad); }

/* the answer */
.answer { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(260px, 340px); gap: clamp(20px, 3vw, 48px); align-items: stretch; padding: clamp(24px, 4vw, 56px) 0 clamp(40px, 4.5vw, 72px); }
.signal { width: clamp(64px, 7vw, 108px); align-self: start; }
.signal svg { display: block; width: 100%; height: auto; }
.signal .sig-h { display: none; }
.sig-head { fill: var(--head); }
.sig-post { fill: var(--head-2); }
.sig-off { fill: var(--head-dim); }
.sig-on { transform-box: fill-box; transform-origin: center; }
.answer.is-major .sig-danger, .answer.is-degraded .sig-caution, .answer.is-unknown .sig-caution, .answer.is-operational .sig-clear { animation: lamp-on 900ms var(--ease) both; }
.sig-danger.sig-on { fill: var(--lit-major); }
.sig-caution.sig-on { fill: var(--lit-degraded); }
.sig-clear.sig-on { fill: var(--lit-operational); }
@keyframes lamp-on { 0% { opacity: 0.15; } 30% { opacity: 1; } 45% { opacity: 0.55; } 100% { opacity: 1; } }

.answer-q { font-size: 14px; color: var(--ink-2); margin-bottom: 18px; }
.answer h1 { font-size: clamp(46px, 6.6vw, 112px); max-width: 15ch; letter-spacing: -0.02em; }
.answer-sub { margin-top: 28px; font-size: clamp(15px, 1.25vw, 18px); max-width: 60ch; }

.clock { background: var(--head); color: var(--head-ink); border-radius: 6px; padding: 22px 24px 24px; display: flex; flex-direction: column; gap: 6px; align-self: start; }
.clock-label { font-size: 12px; color: #a9b1aa; }
.clock-time { font: 800 clamp(64px, 6vw, 92px)/0.9 var(--display); letter-spacing: 0.02em; display: flex; align-items: baseline; gap: 10px; }
.clock-tz { font: 500 13px/1 var(--mono); color: var(--lit-degraded); letter-spacing: 0; }
.clock-next { font-size: 13px; }
.clock-next time { color: var(--lit-operational); }
.clock-note { margin-top: 14px; padding-top: 14px; font-size: 12px; line-height: 1.55; color: #c3cac4; border-top: 2px solid var(--head-2); }

/* the board */
.board { padding-bottom: var(--gap-section); }
.board-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 32px; align-items: end; margin-bottom: 22px; }
.board-head h2 { font-size: clamp(44px, 5vw, 76px); }
.board-head p { color: var(--ink-2); font-size: 14px; max-width: 62ch; }
.board-sub { font-size: clamp(30px, 3vw, 44px); margin: 56px 0 18px; }

.board-cols, .row { display: grid; grid-template-columns: 52px minmax(170px, 1.15fr) 168px minmax(250px, 2.5fr) 84px; gap: 0 20px; align-items: center; }
.board-cols { padding: 0 18px 10px; font-size: 11px; color: var(--ink-2); }
.board-cols span:last-child { text-align: right; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.row { background: var(--board); padding: 14px 18px; border-radius: 3px; transition: background 160ms; }
.row:hover { background: var(--board-2); }
.row:first-child { border-radius: 6px 6px 3px 3px; }
.row:last-child { border-radius: 3px 3px 6px 6px; }
.row-name { font-size: clamp(24px, 2vw, 32px); letter-spacing: 0.005em; }
.row-name a { color: var(--ink); text-decoration: none; }
.row-name a:hover { text-decoration: underline; text-decoration-thickness: 2px; }
.row-note { font-size: 11.5px; color: var(--ink-2); margin-top: 6px; line-height: 1.45; overflow-wrap: anywhere; }
.row-up { font: 700 15px/1 var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.dash { font-weight: 400; color: var(--ink-2); font-size: 12px; }

/* lamps */
.lamp { display: inline-grid; place-items: center; background: var(--head); border-radius: 50%; flex: none; }
.lamp svg { fill: currentColor; }
.lamp-l { width: 44px; height: 44px; }
.lamp-l svg { width: 28px; height: 28px; }
.lamp-m { width: 32px; height: 32px; }
.lamp-m svg { width: 20px; height: 20px; }
.lamp-s { width: 22px; height: 22px; }
.lamp-s svg { width: 14px; height: 14px; }
.lamp.is-operational { color: var(--lit-operational); }
.lamp.is-maintenance { color: var(--lit-maintenance); }
.lamp.is-degraded { color: var(--lit-degraded); }
.lamp.is-partial { color: var(--lit-partial); }
.lamp.is-major { color: var(--lit-major); }
.lamp.is-unknown { color: var(--lit-unknown); }
.row.is-partial .lamp, .row.is-major .lamp { animation: blink 1.6s steps(1, end) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

/* split-flap tile */
.flap { position: relative; display: inline-block; justify-self: start; background: #0a0c0b; color: var(--lit-operational); font: 600 12px/1 var(--mono); text-transform: uppercase; letter-spacing: 0.02em; padding: 9px 10px; border-radius: 3px; white-space: nowrap; }
.flap { isolation: isolate; }
.flap::before { content: ''; position: absolute; inset: 0 0 50% 0; background: var(--head-2); border-radius: 3px 3px 0 0; z-index: -1; }
.flap::after { content: ''; position: absolute; left: 0; right: 0; top: calc(50% - 1px); height: 2px; background: var(--head); z-index: -1; }
.flap.is-maintenance { color: var(--lit-maintenance); }
.flap.is-degraded { color: var(--lit-degraded); }
.flap.is-partial { color: var(--lit-partial); }
.flap.is-major { color: var(--lit-major); }
.flap.is-unknown, .flap.is-resolved { color: var(--head-ink); }

/* the 90-day strip */
.strip { display: grid; grid-template-columns: repeat(90, minmax(0, 1fr)); gap: 2px; align-items: end; height: 44px; padding: 2px; border-radius: 3px; cursor: crosshair; }
.strip:focus-visible { outline-offset: 2px; }
.cell { display: block; height: 10px; background: var(--cell-operational); border-radius: 1px; transform-origin: bottom; transition: transform 160ms var(--ease), opacity 160ms; }
.cell.is-maintenance { height: 18px; background: var(--cell-maintenance); }
.cell.is-degraded { height: 24px; background: var(--cell-degraded); }
.cell.is-partial { height: 32px; background: var(--cell-partial); }
.cell.is-major { height: 40px; background: var(--cell-major); }
.cell.is-unknown { height: 6px; background: var(--cell-unknown); }
.cell.is-none { height: 3px; background: var(--cell-none); }
.strip:hover .cell, .strip.is-reading .cell { opacity: 0.55; }
.strip .cell.is-active { opacity: 1; transform: scaleY(1.12); outline: 2px solid var(--ink); outline-offset: 1px; }

.readout { margin-top: 18px; min-height: 3.2em; font-size: 13px; background: var(--head); color: var(--head-ink); padding: 12px 16px; border-radius: 6px; }
.readout b { color: var(--lit-degraded); font-weight: 600; }

.legend { margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.legend-h { font: 600 12px/1 var(--mono); text-transform: none; }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px 20px; font-size: 12px; }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.cell-key { display: inline-block; width: 14px; height: 3px; background: var(--cell-none); }

/* incidents */
.incidents, .log, .method { padding-bottom: var(--gap-section); }
.incidents > h2, .log > h2, .method > h2, .api > h2 { font-size: clamp(40px, 4.6vw, 72px); }
.count { display: inline-grid; place-items: center; min-width: 1.3em; padding: 0 0.15em; background: var(--head); color: var(--head-ink); border-radius: 4px; font-size: 0.7em; vertical-align: 0.12em; }
.section-lede { margin: 14px 0 28px; font-size: 14px; color: var(--ink-2); max-width: 70ch; }
.notices { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 3px; }
.notice { background: var(--board); padding: 20px 22px 22px; display: grid; gap: 12px; align-content: start; border-radius: 3px; }
.notice-who { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.notice-title { font: 700 clamp(22px, 1.8vw, 28px)/1.05 var(--display); }
.notice-meta { font-size: 12px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.notice-link a { font-size: 13px; }
.notices.is-past .notice { background: transparent; padding-left: 0; }
.notices.is-past .notice-title { font-size: 22px; }
.sub-h { font-size: 28px; margin: 48px 0 16px; }
.empty { display: flex; align-items: center; gap: 12px; background: var(--board); padding: 20px 22px; border-radius: 6px; font-size: 14px; }

/* log + tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 11px; color: var(--ink-2); padding: 0 14px 10px 0; }
td { padding: 12px 14px 12px 0; vertical-align: top; border-top: 3px solid var(--ground); }
tbody tr { background: var(--board); }
tbody td:first-child { padding-left: 14px; white-space: nowrap; }
.log td .flap { font-size: 11px; padding: 6px 8px; }

/* method */
.method-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: clamp(28px, 4vw, 64px); margin-top: 28px; }
.prose p + p { margin-top: 16px; }
.prose strong { font-weight: 700; }
.sources caption { text-align: left; font: 800 24px/1 var(--display); text-transform: uppercase; padding-bottom: 14px; }
.sources td { font-size: 12px; }
.sources code { font-size: 12px; }

/* API */
.api { padding-bottom: var(--gap-section); }
.endpoints { margin: 28px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 3px; }
.endpoints div { background: var(--head); color: var(--head-ink); padding: 18px 20px; border-radius: 3px; }
.endpoints dt code { color: var(--lit-operational); font-size: 12.5px; }
.endpoints dd { margin: 10px 0 0; font-size: 13px; color: #c9d0ca; }
.endpoints dd code { color: var(--lit-degraded); }

/* footer */
.foot { padding: 0 var(--pad) 32px; }
.foot-name { font: 900 clamp(64px, 15.5vw, 260px)/0.82 var(--display); text-transform: uppercase; letter-spacing: -0.02em; white-space: nowrap; }
.foot-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 32px; margin-top: 24px; font-size: 13px; }
.foot-row a + a { margin-left: 16px; }

/* waiting and 404 */
.waiting { min-height: 60vh; display: grid; align-content: center; gap: 22px; }
.waiting h1 { font-size: clamp(48px, 8vw, 120px); }

/* reveal (only when the script has run; content never waits on it) */
.js .reveal { opacity: 0; transform: translateY(20px); transition: opacity 600ms var(--ease), transform 600ms var(--ease); }
.js .reveal.is-in { opacity: 1; transform: none; }

/* tablet */
@media (max-width: 1080px) {
  .answer { grid-template-columns: auto minmax(0, 1fr); }
  .clock { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; column-gap: 28px; align-items: end; }
  .clock-label { grid-column: 1; }
  .clock-time { grid-column: 1; grid-row: 2 / span 2; }
  .clock-next { grid-column: 2; grid-row: 2; }
  .clock-note { grid-column: 2; grid-row: 3; margin-top: 8px; }
  .board-cols { display: none; }
  .row { grid-template-columns: 52px minmax(0, 1fr) auto 72px; grid-template-areas: 'lamp id flap up' 'strip strip strip strip'; row-gap: 14px; }
  .row > .lamp { grid-area: lamp; }
  .row-id { grid-area: id; }
  .row > .flap { grid-area: flap; }
  .row-up { grid-area: up; }
  .strip { grid-area: strip; }
  .method-cols, .board-head { grid-template-columns: 1fr; }
}

/* phone */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .bar { gap: 12px; flex-wrap: wrap; }
  .wordmark { font-size: 26px; }
  .bar-nav { order: 3; width: 100%; margin: 0; gap: 18px; }
  .theme { margin-left: auto; }
  .answer { grid-template-columns: 1fr; gap: 24px; padding-top: 12px; }
  .signal { width: 100%; }
  .signal .sig-v { display: none; }
  .signal .sig-h { display: block; width: auto; height: 56px; }
  .answer h1 { font-size: clamp(40px, 11.5vw, 56px); }
  .answer { gap: 16px; }
  .answer-sub { margin-top: 18px; font-size: 14px; }
  .answer-q { margin-bottom: 12px; }
  .clock { display: grid; grid-template-columns: auto 1fr; column-gap: 16px; row-gap: 2px; align-items: end; padding: 14px 16px; }
  .clock-label { grid-column: 1; grid-row: 1; }
  .clock-time { grid-column: 1; grid-row: 2 / span 2; font-size: 48px; gap: 6px; }
  .clock-next { grid-column: 2; grid-row: 2; font-size: 12px; }
  .clock-note { grid-column: 2; grid-row: 3; margin: 0; padding: 0; border: 0; font-size: 11px; line-height: 1.4; }
  .signal .sig-h { height: 36px; }
  .row { grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: 'lamp id up' '. flap flap' 'strip strip strip'; padding: 14px; gap: 10px 12px; }
  .lamp-l { width: 36px; height: 36px; }
  .lamp-l svg { width: 22px; height: 22px; }
  .strip { gap: 1px; height: 40px; }
  .notice { padding: 18px; }
  .log thead { display: none; }
  .log table, .log tbody, .log tr, .log td { display: block; }
  .log tbody { display: grid; gap: 3px; }
  .log tr { padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; }
  .log td { padding: 0; border: 0; }
  .log tbody td:first-child { padding: 0; grid-column: 1 / -1; font-size: 12px; }
  .log td:nth-child(4) { grid-column: 1 / -1; }
  .sources th:first-child, .sources td:first-child { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal { opacity: 1; transform: none; }
}
.sig-glyph { fill: var(--head); }
