/* BLACK BOX installer
   Concept: a flight recorder that is also a live terminal — an international-orange
   shell with stencilled markings, a memory dump scrolling inside the sealed unit,
   and one big moment when the unit seals itself. */

@font-face {
    font-family: "BB Stencil";
    src: url("fonts/big-shoulders-stencil.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
}

:root {
    color-scheme: dark;

    --black: #000000;
    --plate: #16171a;       /* the recorder body */
    --plate-edge: #2c2e33;
    --orange: #ff5500;      /* international orange */
    --orange-hot: #ff6e24;
    --orange-deep: #c94300;
    --orange-wash: rgba(255, 85, 0, 0.12);
    --orange-glow: rgba(255, 85, 0, 0.32);
    --bone: #ecebe6;
    --steel: #9a9ea6;
    --steel-dim: #5d6168;
    --alarm: #ff3d6e;
    --glitch-a: rgba(255, 85, 0, 0.75);
    --glitch-b: rgba(0, 229, 255, 0.6);
    --scan: rgba(255, 255, 255, 0.028);
    --grid-dot: rgba(154, 158, 166, 0.09);
    --dump-dim: rgba(154, 158, 166, 0.13);
    --dump-hot: rgba(255, 85, 0, 0.55);

    --stencil: "BB Stencil", "Impact", "Arial Narrow", sans-serif;
    --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --gutter: clamp(16px, 4vw, 40px);
    --measure: 760px;
}

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

[hidden] { display: none !important; }

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

body {
    margin: 0;
    background-color: var(--black);
    background-image: radial-gradient(var(--grid-dot) 1px, transparent 1.2px);
    background-size: 22px 22px;
    color: var(--bone);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.75;
}

.page {
    max-width: calc(var(--measure) + var(--gutter) * 2);
    margin: 0 auto;
    padding-block: 20px 48px;
    padding-inline: var(--gutter);
}

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

a { color: var(--steel); text-underline-offset: 3px; }
a:hover { color: var(--bone); }

:focus-visible {
    outline: 3px solid var(--orange);
    outline-offset: 3px;
}

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

/* ── masthead ─────────────────────────────────────────── */
.masthead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.wordmark {
    position: relative;
    margin: 0;
    font-family: var(--stencil);
    font-weight: 900;
    font-size: 34px;
    line-height: 1;
    letter-spacing: 0.02em;
    color: var(--orange);
}
.wordmark.is-glitch { animation: wordmark-glitch 280ms steps(2) 1; }
@keyframes wordmark-glitch {
    0%   { text-shadow: 3px 0 var(--glitch-b); transform: translateX(-2px); clip-path: inset(0 0 55% 0); }
    35%  { text-shadow: -3px 0 var(--glitch-b); transform: translateX(3px) skewX(-8deg); clip-path: inset(45% 0 0 0); }
    70%  { text-shadow: 2px 0 var(--glitch-b); transform: translateX(-1px); clip-path: none; }
    100% { text-shadow: none; transform: none; clip-path: none; }
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.app-tag {
    padding: 2px 7px 1px;
    border: 1.5px solid var(--orange);
    border-radius: 3px;
    font-family: var(--stencil);
    font-weight: 900;
    font-size: 14px;
    line-height: 1.2;
    letter-spacing: 0.08em;
    color: var(--orange);
}

/* ── install as an app ────────────────────────────────── */
.install {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 14px 16px;
    border: 1px solid var(--plate-edge);
    border-radius: 6px;
    background: var(--plate);
    overflow: hidden;
}
.install::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: repeating-linear-gradient(-45deg, var(--orange) 0 6px, var(--black) 6px 12px);
}
.install-icon {
    display: block;
    width: 56px;
    height: 56px;
}
.install-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
}
.install-text p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--steel);
}

.link-state {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--steel);
}
.link-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1.5px solid var(--steel-dim);
}
.link-state[data-state="linked"] { color: var(--bone); }
.link-state[data-state="linked"] .link-dot {
    background: var(--orange);
    border-color: var(--orange);
    animation: ping 1.8s ease-out infinite;
}
.link-state[data-state="lost"] .link-dot { border-color: var(--alarm); animation: blink 0.8s steps(1) infinite; }
@keyframes ping {
    0%   { box-shadow: 0 0 0 0 var(--orange-glow); }
    80%  { box-shadow: 0 0 0 9px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── the sealed unit (the one loud thing) ─────────────── */
.unit {
    position: relative;
    background: var(--plate);
    border: 1px solid var(--plate-edge);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 400ms, box-shadow 600ms;
}
/* CRT scanlines over the whole unit */
.unit::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom, var(--scan) 0 1px, transparent 1px 3px);
    z-index: 3;
}
.unit[data-sealed="true"] {
    border-color: var(--orange);
    box-shadow: 0 0 0 1px var(--orange), 0 0 48px var(--orange-glow);
}

.unit-band {
    position: relative;
    height: 14px;
    overflow: hidden;
    background: var(--black);
    transition: height 300ms ease-out, background-color 300ms;
}
.band-stripes {
    position: absolute;
    inset: 0 -40px 0 0;
    background: repeating-linear-gradient(-45deg, var(--orange) 0 14px, var(--black) 14px 28px);
}
.unit[data-busy="true"] .band-stripes { animation: march 0.7s linear infinite; }
@keyframes march { to { transform: translateX(-39.598px); } }

.band-text {
    position: absolute;
    top: 50%;
    left: 0;
    display: none;
    white-space: nowrap;
    font-family: var(--stencil);
    font-weight: 900;
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--black);
    transform: translateY(-50%);
}
.unit[data-sealed="true"] .unit-band { height: 24px; background: var(--orange); }
.unit[data-sealed="true"] .band-stripes { display: none; }
.unit[data-sealed="true"] .band-text { display: block; animation: marquee 14s linear infinite; }
@keyframes marquee {
    from { transform: translate(0, -50%); }
    to   { transform: translate(-50%, -50%); }
}

.unit-body {
    position: relative;
    isolation: isolate;
    padding: 22px clamp(18px, 4vw, 32px) 26px;
}
.unit-dump {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    -webkit-mask-image: linear-gradient(100deg, rgba(0, 0, 0, 0.35), #000 55%);
    mask-image: linear-gradient(100deg, rgba(0, 0, 0, 0.35), #000 55%);
}

.readout {
    margin: 0;
    font-family: var(--stencil);
    font-weight: 850;
    font-size: clamp(76px, 21vw, 172px);
    line-height: 0.86;
    letter-spacing: 0.01em;
    color: var(--steel-dim);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.readout[data-state="linked"],
.readout[data-state="open"],
.readout[data-state="writing"],
.readout[data-state="written"] { color: var(--bone); }
.readout[data-state="confirm"] { color: var(--orange); }
.readout[data-state="sealed"] { color: var(--orange); text-shadow: 0 0 28px var(--orange-glow); }
.readout[data-state="fault"] { color: var(--alarm); }
.readout.is-glitch { animation: readout-glitch 560ms steps(3) 1; }
@keyframes readout-glitch {
    0%   { text-shadow: 5px 0 var(--glitch-a), -5px 0 var(--glitch-b); transform: translateX(0); }
    20%  { transform: translateX(-4px) skewX(-7deg); clip-path: inset(8% 0 40% 0); }
    40%  { text-shadow: -4px 0 var(--glitch-a), 4px 0 var(--glitch-b); transform: translateX(3px); clip-path: inset(52% 0 6% 0); }
    60%  { transform: translateX(-1px); clip-path: inset(0 0 22% 0); }
    80%  { text-shadow: 2px 0 var(--glitch-a), -2px 0 var(--glitch-b); clip-path: none; }
    100% { text-shadow: none; transform: none; clip-path: none; }
}

.specs {
    margin: 22px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--plate-edge);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.specs div { min-width: 0; }
.specs dt { font-size: 12px; color: var(--steel); }
.specs dd {
    margin: 2px 0 0;
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.unit.is-shake { animation: shake 420ms steps(7) 1; }
@keyframes shake {
    0%, 100% { transform: none; }
    15% { transform: translate(-6px, 2px); }
    30% { transform: translate(5px, -2px); }
    45% { transform: translate(-4px, 1px); }
    60% { transform: translate(3px, 0); }
    75% { transform: translate(-1px, -1px); }
}

.flash-veil {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: var(--orange);
    opacity: 0;
    z-index: 40;
}
.flash-veil.is-on { animation: veil 650ms ease-out 1; }
@keyframes veil {
    0%   { opacity: 0.55; }
    100% { opacity: 0; }
}

/* ── now: what to do right now ────────────────────────── */
.now {
    position: relative;
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 4px 26px;
    align-items: center;
    margin-top: 16px;
    padding: 22px clamp(18px, 4vw, 28px) 22px;
    border-radius: 6px;
    background: var(--plate);
    border: 1.5px solid var(--plate-edge);
    overflow: hidden;
}
.now::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: -40px;
    height: 6px;
    background: repeating-linear-gradient(-45deg, var(--orange) 0 12px, transparent 12px 24px);
    opacity: 0;
}
.now-figure {
    align-self: start;
    width: 160px;
}
.now-figure svg { display: block; width: 100%; height: auto; }
.now-figure:empty { display: none; }
.now:has(.now-figure:empty) { grid-template-columns: minmax(0, 1fr); }
.now-body { min-width: 0; }

.now-where {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
    background: var(--bone);
    color: var(--black);
}
.now-where::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.now-title {
    margin: 0;
    font-size: clamp(21px, 3.4vw, 27px);
    font-weight: 800;
    line-height: 1.35;
    text-wrap: balance;
}
.now-text {
    margin-top: 8px;
    font-size: 15px;
    line-height: 1.75;
    color: var(--bone);
    max-width: 38em;
}
.now-text p { margin: 0; }
.now-text p + p { margin-top: 6px; }
.now-text ol {
    margin: 4px 0 0;
    padding-left: 1.5em;
}
.now-text li { padding-left: 2px; }
.now-text li + li { margin-top: 4px; }
.now-text li::marker { color: var(--orange); font-weight: 800; }
.now-text .muted { color: var(--steel); font-size: 14px; }
.now-text b { color: var(--orange); font-weight: 800; }
.now-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-top: 16px;
}
.now-actions:not(:has(.btn:not([hidden]))) { display: none; }
.btn-primary {
    min-height: 52px;
    padding: 12px 28px;
    font-size: 17px;
}
.btn-primary:not(:disabled) { animation: nudge 1.8s ease-out infinite; }

/* where the action happens: PC (white), phone (orange), waiting, done, error */
.now[data-kind="phone"] {
    background: var(--orange);
    border-color: var(--orange);
    color: var(--black);
    animation: call-pulse 1.4s ease-in-out infinite;
}
.now[data-kind="phone"]::before {
    opacity: 1;
    background: repeating-linear-gradient(-45deg, var(--black) 0 12px, transparent 12px 24px);
    animation: march 0.7s linear infinite;
}
.now[data-kind="phone"] .now-where { background: var(--black); color: var(--orange); }
.now[data-kind="phone"] .now-where::before { animation: blink 0.8s steps(1) infinite; }
.now[data-kind="phone"] .now-text,
.now[data-kind="phone"] .now-text .muted { color: var(--black); }
.now[data-kind="phone"] .now-text b { color: var(--black); text-decoration: underline; text-underline-offset: 3px; }
.now[data-kind="phone"] .now-text li::marker { color: var(--black); }
.now[data-kind="phone"] .btn-ghost { color: var(--black); box-shadow: inset 0 0 0 1.5px var(--black); }
.now[data-kind="phone"] .btn-ghost:hover:not(:disabled) { background: var(--orange-hot); }
.now[data-kind="phone"] :focus-visible { outline-color: var(--black); }

.now[data-kind="wait"] .now-where { background: transparent; color: var(--orange); box-shadow: inset 0 0 0 1.5px var(--orange); }
.now[data-kind="wait"] .now-where::before { animation: blink 0.6s steps(1) infinite; }
.now[data-kind="wait"]::before { opacity: 1; animation: march 0.7s linear infinite; }

.now[data-kind="done"] { border-color: var(--orange); }
.now[data-kind="done"] .now-where { background: var(--orange); color: var(--black); }

.now[data-kind="error"] { border-color: var(--alarm); }
.now[data-kind="error"] .now-where { background: var(--alarm); color: var(--black); }
.now[data-kind="error"] .now-title { color: var(--alarm); }

@keyframes call-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--orange-glow); }
    50% { box-shadow: 0 0 0 8px transparent; }
}

/* phone illustration */
.ph-body { fill: var(--plate-edge); stroke: var(--steel-dim); stroke-width: 1.5; }
.ph-screen { fill: var(--black); }
.ph-key { fill: var(--steel-dim); }
.ph-key.on { fill: var(--orange); }
.ph-label { font: 700 11px var(--sans); fill: var(--bone); }
.ph-label.on { fill: var(--orange); }
.ph-text { font: 600 7px var(--mono); fill: var(--steel); }
.ph-text.big { font-size: 8.5px; fill: var(--bone); }
.ph-text.red { fill: var(--alarm); }
.ph-opt { fill: none; stroke: var(--steel-dim); stroke-width: 1; }
.ph-opt.on { fill: var(--orange); stroke: var(--orange); }
.ph-text.on { fill: var(--black); }
.ph-warn { fill: var(--alarm); }
.ph-arrow { fill: none; stroke: var(--orange); stroke-width: 2; stroke-linecap: round; }
.ph-sel { animation: blink 1s steps(1) infinite; }
.ph-tick { stroke-width: 1.2; }
.now[data-kind="phone"] .ph-body { fill: var(--black); stroke: var(--black); }
.now[data-kind="phone"] .ph-key { fill: var(--plate-edge); }
.now[data-kind="phone"] .ph-key.on { fill: var(--bone); }
.now[data-kind="phone"] .ph-label { fill: var(--black); }
.now[data-kind="phone"] .ph-label.on { fill: var(--black); }
.now[data-kind="phone"] .ph-arrow { stroke: var(--black); }

.notice {
    margin: 16px 0 0;
    padding: 14px 18px;
    border: 1px solid var(--alarm);
    border-radius: 6px;
    color: var(--bone);
}

/* ── steps: overview tracker ─────────────────────────── */
.steps {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    margin: 16px 0 0;
    padding: 0;
    border: 1px solid var(--plate-edge);
    border-radius: 6px;
    overflow: hidden;
}
.step {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 10px;
    align-items: start;
    padding: 12px 14px 13px;
    border-left: 1px solid var(--plate-edge);
    border-top: 3px solid transparent;
}
.step:first-child { border-left: 0; }
.step[data-state="current"] {
    border-top-color: var(--orange);
    background: linear-gradient(180deg, var(--orange-wash), transparent 80%);
}
.step[data-state="done"] { border-top-color: var(--orange-deep); }
.step[data-state="todo"] .step-title,
.step[data-state="todo"] .step-no { color: var(--steel-dim); }
.step[data-state="done"] .step-no { color: var(--orange); }

.step-no {
    font-family: var(--stencil);
    font-weight: 900;
    font-size: 34px;
    line-height: 0.95;
    color: var(--bone);
}
.step-main { min-width: 0; }
.step-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.4;
}
.step[data-state="done"] .step-title::after {
    content: " ✓";
    color: var(--orange);
}
.step-status {
    margin: 2px 0 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--steel);
}
.step[data-state="current"] .step-status { color: var(--bone); }
.step-status:empty { display: none; }

.meter {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
}
.meter-blocks {
    display: grid;
    grid-template-columns: repeat(32, minmax(0, 1fr));
    gap: 2px;
}
.meter-blocks span {
    height: 12px;
    background: var(--plate-edge);
}
.meter-blocks span.on { background: var(--orange); }
.meter-blocks span.head { background: var(--orange); animation: blink 0.45s steps(1) infinite; }
.meter-pct {
    min-width: 3.6ch;
    text-align: right;
    font-family: var(--stencil);
    font-weight: 900;
    font-size: 30px;
    line-height: 1;
    color: var(--orange);
    font-variant-numeric: tabular-nums;
}

/* ── buttons ──────────────────────────────────────────── */
.btn {
    position: relative;
    appearance: none;
    min-height: 44px;
    padding: 10px 20px;
    border: 0;
    border-radius: 4px;
    background: var(--orange);
    color: var(--black);
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: transform 80ms, background-color 120ms;
}
.btn:hover:not(:disabled) { background: var(--orange-hot); }
.btn:active:not(:disabled) { background: var(--orange-deep); transform: scale(0.97); }
.btn:disabled {
    background: transparent;
    color: var(--steel-dim);
    box-shadow: inset 0 0 0 1px var(--plate-edge);
    cursor: not-allowed;
}
@keyframes nudge {
    0%   { box-shadow: 0 0 0 0 var(--orange-glow); }
    70%  { box-shadow: 0 0 0 10px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.btn-ghost {
    background: transparent;
    color: var(--orange);
    box-shadow: inset 0 0 0 1.5px var(--orange);
}
.btn-ghost:hover:not(:disabled) { background: var(--orange-wash); }

/* ── terminal ─────────────────────────────────────────── */
.term {
    margin-top: 28px;
    border: 1px solid var(--plate-edge);
    border-radius: 6px;
    overflow: hidden;
    background: var(--plate);
}
.term-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--plate-edge);
    font-size: 13px;
}
.term-title { font-weight: 700; }
.term-live {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--steel);
}
.term-live::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--steel-dim);
}
.term-live[data-state="busy"] { color: var(--orange); }
.term-live[data-state="busy"]::before { background: var(--orange); animation: blink 0.6s steps(1) infinite; }
.term-live[data-state="done"] { color: var(--orange); }
.term-live[data-state="done"]::before { background: var(--orange); }

.log {
    margin: 0;
    padding: 12px 14px 14px;
    height: 220px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.65;
    color: var(--steel);
    white-space: pre-wrap;
    word-break: break-all;
}
.log::after {
    content: "▌";
    color: var(--orange);
    animation: blink 1s steps(1) infinite;
}
.log-line { display: block; }
.log-line.is-ok { color: var(--bone); }
.log-line.is-hot { color: var(--orange); }
.log-line.is-error { color: var(--alarm); }
.log-line.is-stream { color: var(--steel-dim); }

/* ── panels ───────────────────────────────────────────── */
.panel {
    margin-top: 28px;
    border-top: 1px solid var(--plate-edge);
}
.panel summary {
    padding: 14px 0;
    font-weight: 700;
    cursor: pointer;
}
.prep-list {
    margin: 0 0 8px;
    padding-left: 1.6em;
    color: var(--bone);
}
.prep-list li { margin-bottom: 6px; padding-left: 4px; }
.prep-list li::marker { color: var(--orange); font-weight: 700; }

.foot {
    margin-top: 40px;
    font-size: 12px;
    color: var(--steel-dim);
}
.foot p { margin: 0 0 4px; }

/* ── small screens ────────────────────────────────────── */
@media (max-width: 600px) {
    .wordmark { font-size: 28px; }
    .install { grid-template-columns: auto minmax(0, 1fr); }
    .install-icon { width: 44px; height: 44px; }
    .install > .btn { grid-column: 1 / -1; }
    .specs { grid-template-columns: 1fr 1fr; }
    .specs div:first-child { grid-column: 1 / -1; }
    .now { grid-template-columns: 76px minmax(0, 1fr); gap: 0 14px; align-items: start; }
    .now:has(.now-figure:empty) { grid-template-columns: minmax(0, 1fr); }
    .now-body { display: contents; }
    .now-figure { width: 76px; grid-row: 1 / span 2; }
    .now-where { justify-self: start; }
    .now-title { font-size: 20px; }
    .now-text,
    .meter,
    .now-actions { grid-column: 1 / -1; }
    .now-actions .btn { flex: 1 1 100%; white-space: normal; }
    .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .step:nth-child(odd) { border-left: 0; }
    .step:nth-child(n + 3) { box-shadow: inset 0 1px 0 var(--plate-edge); }
    .step:last-child { grid-column: 1 / -1; }
    .meter-blocks { grid-template-columns: repeat(20, minmax(0, 1fr)); }
    .meter-blocks span:nth-child(n + 21) { display: none; }
    .log { height: 180px; font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
