@layer reset, base, layout, instrument, controls, states, fallback, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { color-scheme: dark; background: #070707; }
  body { margin: 0; }
  button, canvas { -webkit-tap-highlight-color: transparent; }
  button { font: inherit; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    --ink: #080808;
    --plate: #101110;
    --bone: #e7e2d5;
    --dim: #8e8c84;
    --faint: #4a4944;
    --line: rgba(231,226,213,.22);
    --red: #a42c24;
    --red-bright: #c44135;
    --serif: Georgia, 'Times New Roman', serif;
    --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  }

  html { min-width: 280px; overflow-x: hidden; }
  body {
    min-height: 100svh;
    overflow-x: clip;
    color: var(--bone);
    background:
      radial-gradient(circle at 19% 31%, #151514 0, #090909 33%, transparent 59%),
      linear-gradient(123deg, #080808, #050505 74%);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.5;
  }

  body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
      repeating-linear-gradient(104deg, transparent 0 19px, rgba(255,255,255,.012) 20px, transparent 21px 47px),
      radial-gradient(ellipse at 73% 90%, rgba(164,44,36,.08), transparent 36%);
  }

  .grain {
    position: fixed;
    inset: -50%;
    z-index: 20;
    pointer-events: none;
    opacity: .085;
    mix-blend-mode: screen;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
    animation: grain-shift .42s steps(2) infinite;
  }

  @keyframes grain-shift {
    0% { transform: translate3d(-1%, 1%, 0); }
    50% { transform: translate3d(1.5%, -.5%, 0); }
    100% { transform: translate3d(.2%, 1.5%, 0); }
  }

  a { color: inherit; }
  button { color: inherit; }
  button:focus-visible, canvas:focus-visible {
    outline: 2px solid var(--bone);
    outline-offset: 4px;
  }
  kbd {
    display: inline-grid;
    min-width: 1.5em;
    min-height: 1.5em;
    place-items: center;
    padding: 0 .25em;
    border: 1px solid rgba(231,226,213,.28);
    border-radius: 2px;
    color: #bbb7ac;
    font: 10px/1.25 var(--mono);
  }
  .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
}

@layer layout {
  .mast {
    position: relative;
    z-index: 5;
    display: grid;
    grid-template-columns: minmax(120px, .45fr) minmax(280px, 1fr) minmax(300px, .75fr);
    align-items: start;
    gap: 30px;
    width: 100%;
    padding: 22px clamp(24px, 4vw, 64px) 14px;
    border-bottom: 1px solid rgba(231,226,213,.11);
  }

  .edition {
    width: max-content;
    color: var(--bone);
    text-decoration: none;
    letter-spacing: .18em;
    font-size: 11px;
  }
  .edition span { color: var(--dim); margin-left: 10px; }
  .mast h1 {
    margin: -5px 0 0;
    max-width: 620px;
    font: 400 clamp(23px, 2.3vw, 38px)/1.05 var(--serif);
    letter-spacing: -.02em;
  }
  .truth {
    max-width: 510px;
    margin: 0;
    color: #8e8c84;
    font-size: 10px;
    line-height: 1.5;
  }

  .experience {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(300px, 27vw, 410px);
    min-height: calc(100svh - 132px);
  }

  .instrument {
    position: relative;
    min-width: 0;
    min-height: 620px;
    overflow: hidden;
    border-right: 1px solid rgba(231,226,213,.11);
  }

  .logbook {
    position: relative;
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    padding: clamp(36px, 6vw, 92px) clamp(25px, 3vw, 50px) 94px;
  }

  .panel { animation: panel-in .45s ease both; }
  .panel h2 {
    margin: 11px 0 16px;
    max-width: 12em;
    color: #eee9dc;
    font: 400 clamp(28px, 3vw, 47px)/1.02 var(--serif);
    letter-spacing: -.035em;
  }
  .panel > p:not(.eyebrow):not(.aperture-readout):not(.prediction-readout):not(.method-note) {
    max-width: 32em;
    margin: 0 0 24px;
    color: #b8b4a9;
    font-size: 12px;
    line-height: 1.65;
  }
  @keyframes panel-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }

  .eyebrow {
    margin: 0;
    color: var(--red-bright);
    font-size: 10px;
    letter-spacing: .19em;
    text-transform: uppercase;
  }
  .eyebrow span { float: right; color: var(--dim); }

  .index-mark {
    position: absolute;
    top: 26px;
    right: clamp(25px, 3vw, 50px);
    left: clamp(25px, 3vw, 50px);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    color: #66645f;
    font-size: 9px;
    letter-spacing: .15em;
  }
  .index-mark i { display: block; height: 1px; background: rgba(231,226,213,.13); }

  .status {
    position: absolute;
    right: clamp(25px, 3vw, 50px);
    bottom: 30px;
    left: clamp(25px, 3vw, 50px);
    min-height: 3em;
    margin: 0;
    border-top: 1px solid rgba(231,226,213,.12);
    padding-top: 12px;
    color: #918e85;
    font-size: 10px;
    line-height: 1.5;
  }
  .status.is-error { color: #c78880; }
  .status.is-good { color: #b9b5a9; }

  .shortcut-strip {
    position: fixed;
    z-index: 10;
    right: calc(clamp(300px, 27vw, 410px) + 24px);
    bottom: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    color: #686660;
    font-size: 9px;
    pointer-events: none;
  }
  .shortcut-strip span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
}

@layer instrument {
  .plate-stack {
    position: absolute;
    inset: 4% 6% 11% 2%;
    transform: rotate(-2.4deg);
    pointer-events: none;
  }
  .plate-stack i {
    position: absolute;
    inset: 0;
    border: 1px solid rgba(231,226,213,.15);
  }
  .plate-stack i:nth-child(1) { transform: translate(21px, 17px); opacity: .45; }
  .plate-stack i:nth-child(2) { transform: translate(11px, 8px); opacity: .7; }
  .plate-stack i:nth-child(3) { background: linear-gradient(145deg, transparent 69%, rgba(231,226,213,.018)); }

  .comparator-shell {
    position: absolute;
    top: 7%;
    left: 7%;
    width: min(72vw, calc(100svh - 170px), 850px);
    aspect-ratio: 1;
    border: 1px solid rgba(231,226,213,.34);
    border-radius: 50%;
    background: #040504;
    box-shadow:
      0 0 0 10px #0b0c0b,
      0 0 0 11px rgba(231,226,213,.12),
      0 0 0 24px #090a09,
      0 18px 80px rgba(0,0,0,.8),
      inset 0 0 65px rgba(0,0,0,.7);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .comparator-shell::before {
    content: '';
    position: absolute;
    z-index: 3;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
    background:
      radial-gradient(circle at 46% 44%, transparent 0 65%, rgba(0,0,0,.28) 77%, rgba(0,0,0,.83) 100%),
      linear-gradient(108deg, rgba(255,255,255,.03), transparent 22% 70%, rgba(255,255,255,.02));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), inset 0 0 80px rgba(0,0,0,.52);
  }
  .comparator-shell::after {
    content: '';
    position: absolute;
    z-index: 5;
    inset: 50% auto auto 50%;
    width: 11px;
    height: 11px;
    opacity: .3;
    border-top: 1px solid var(--bone);
    border-left: 1px solid var(--bone);
    transform: translate(-5px,-5px);
    pointer-events: none;
  }

  #sky {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
  }
  #sky:focus-visible { outline-offset: -8px; }

  .plate-stamp {
    position: absolute;
    z-index: 6;
    top: 7%;
    left: 18%;
    border-bottom: 1px solid rgba(231,226,213,.22);
    padding: 5px 2px;
    color: rgba(231,226,213,.55);
    font-size: 9px;
    letter-spacing: .18em;
    pointer-events: none;
  }

  .focus-reticle, .user-mark {
    position: absolute;
    z-index: 7;
    top: 0;
    left: 0;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    transform: translate(var(--px, -100px), var(--py, -100px));
    pointer-events: none;
  }
  .focus-reticle { opacity: 0; border: 1px solid rgba(231,226,213,.31); transition: opacity .15s; }
  .focus-reticle::before, .focus-reticle::after {
    content: '';
    position: absolute;
    background: rgba(231,226,213,.5);
  }
  .focus-reticle::before { top: 21px; left: 5px; width: 34px; height: 1px; }
  .focus-reticle::after { top: 5px; left: 21px; width: 1px; height: 34px; }
  .focus-reticle span { position: absolute; inset: 7px; border: 1px solid rgba(231,226,213,.18); border-radius: 50%; }
  .focus-reticle.is-visible { opacity: 1; }

  .user-mark {
    display: grid;
    place-items: start end;
    opacity: 0;
    border: 1px solid rgba(164,44,36,.85);
    transition: opacity .2s, transform .2s;
  }
  .user-mark::before, .user-mark::after {
    content: '';
    position: absolute;
    top: 21px;
    left: 8px;
    width: 28px;
    height: 1px;
    background: rgba(196,65,53,.8);
  }
  .user-mark::after { transform: rotate(90deg); }
  .user-mark span {
    margin: -6px -4px 0 0;
    padding: 0 2px;
    background: #090909;
    color: #d06a60;
    font-size: 8px;
  }
  .user-mark.is-visible { opacity: 1; }

  .seal {
    position: absolute;
    z-index: 8;
    inset: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 5px;
    border-radius: 50%;
    background: rgba(4,5,4,.48);
    pointer-events: none;
  }
  .seal span { color: #8e8c84; font-size: 10px; letter-spacing: .28em; }
  .seal strong { font-size: clamp(24px, 4vw, 52px); font-weight: 400; letter-spacing: .14em; }

  .prediction-grid {
    position: absolute;
    z-index: 10;
    inset: 15%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 1px;
    background: rgba(231,226,213,.13);
    clip-path: circle(50%);
  }
  .prediction-grid button {
    position: relative;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: rgba(7,7,7,.92);
    color: #8b8981;
    cursor: pointer;
  }
  .prediction-grid button::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid transparent;
    border-radius: 50%;
  }
  .prediction-grid button:hover::before, .prediction-grid button:focus-visible::before { border-color: rgba(231,226,213,.45); }
  .prediction-grid button[aria-pressed="true"] { color: var(--bone); background: rgba(164,44,36,.22); }
  .prediction-grid button[aria-pressed="true"]::before { border-color: var(--red-bright); }

  .sector-rail {
    position: absolute;
    z-index: 11;
    top: 15%;
    right: 18px;
    display: grid;
    gap: 5px;
  }
  .sector-rail button {
    position: relative;
    display: grid;
    width: 48px;
    min-height: 48px;
    place-items: center;
    border: 0;
    border-right: 1px solid rgba(231,226,213,.19);
    color: #65635d;
    background: transparent;
    cursor: pointer;
    font-size: 9px;
  }
  .sector-rail button::after {
    content: '';
    position: absolute;
    right: -1px;
    width: 9px;
    height: 1px;
    background: rgba(231,226,213,.34);
  }
  .sector-rail button:hover { color: #aaa69b; }
  .sector-rail button[aria-current="true"] { color: var(--bone); border-right-color: var(--red-bright); }
  .sector-rail button.is-inspected::before {
    content: '';
    position: absolute;
    left: 5px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #77756e;
  }

  .plate-controls {
    position: absolute;
    z-index: 12;
    right: max(78px, 8%);
    bottom: 50px;
    left: max(28px, 6%);
    display: grid;
    grid-template-columns: minmax(78px, 1fr) minmax(146px, 1.5fr) minmax(78px, 1fr);
    max-width: 600px;
    border: 1px solid rgba(231,226,213,.23);
    background: rgba(5,5,5,.83);
    box-shadow: 0 9px 32px rgba(0,0,0,.6);
    backdrop-filter: blur(8px);
  }
  .plate-controls button {
    min-height: 54px;
    border: 0;
    border-right: 1px solid rgba(231,226,213,.15);
    padding: 8px 13px;
    color: #aaa69c;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    touch-action: manipulation;
  }
  .plate-controls button:last-child { border-right: 0; }
  .plate-controls button:hover { color: var(--bone); background: rgba(255,255,255,.035); }
  .plate-controls button.is-active { color: var(--bone); background: rgba(231,226,213,.075); box-shadow: inset 0 -2px var(--red); }
  .plate-controls button span { font-size: 9px; color: #716f69; text-transform: uppercase; letter-spacing: .1em; }
  .plate-controls kbd { margin-left: 6px; }
  .blink-button.is-blinking { color: var(--bone); background: rgba(164,44,36,.16); }
  .blink-reduced { display: none; }
}

@layer controls {
  .action, .text-action {
    min-height: 48px;
    cursor: pointer;
    touch-action: manipulation;
  }
  .action {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    margin-top: 24px;
    border: 1px solid rgba(231,226,213,.38);
    padding: 13px 15px;
    color: var(--bone);
    background: rgba(231,226,213,.035);
    text-align: left;
    font-size: 11px;
    letter-spacing: .04em;
  }
  .action:hover:not(:disabled) { background: rgba(231,226,213,.09); }
  .action:disabled { cursor: default; opacity: .31; }
  .action-red { border-color: rgba(196,65,53,.75); background: rgba(164,44,36,.13); }
  .action-red:hover:not(:disabled) { background: rgba(164,44,36,.25); }
  .text-action {
    border: 0;
    padding: 10px 0;
    color: #77756f;
    background: transparent;
    text-decoration: underline;
    text-decoration-color: rgba(231,226,213,.19);
    text-underline-offset: 4px;
    font-size: 10px;
  }
  .text-action:hover:not(:disabled) { color: var(--bone); }
  .text-action:disabled { opacity: .28; cursor: default; }

  .calibration-meter {
    display: flex;
    gap: 7px;
    margin: 24px 0 -4px;
  }
  .calibration-meter i {
    width: 28px;
    height: 3px;
    background: #32312e;
    transition: background .2s;
  }
  .calibration-meter i.is-lit { background: var(--bone); }

  .mark-ledger {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    margin-top: 18px;
    background: rgba(231,226,213,.13);
  }
  .mark-ledger span {
    min-width: 0;
    padding: 10px;
    color: #77756e;
    background: #090909;
    font-size: 9px;
  }
  .mark-ledger span.is-set { color: #bcb8ad; }
  .mark-ledger b { margin-right: 8px; color: var(--red-bright); font-weight: 400; }
  .aperture-readout, .prediction-readout {
    min-height: 3em;
    margin: 13px 0 0;
    color: #77756e;
    font-size: 10px;
  }

  .documentary-line {
    margin: 23px 0 16px;
    border-top: 1px solid rgba(231,226,213,.24);
    border-bottom: 1px solid rgba(231,226,213,.12);
    padding: 15px 0;
  }
  .documentary-line time {
    display: block;
    margin-bottom: 7px;
    color: var(--red-bright);
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
  }
  .documentary-line p { margin: 0; color: #b1ada3; font: 16px/1.45 var(--serif); }
  .method-note { color: #716f69; font-size: 9px; line-height: 1.55; }
  .reset-action { margin-top: 12px; }
}

@layer states {
  .experience[data-phase="predict"] .plate-button,
  .experience[data-phase="predict"] .blink-button,
  .experience[data-phase="ready"] .plate-button,
  .experience[data-phase="ready"] .blink-button,
  .experience[data-phase="reveal"] .plate-button,
  .experience[data-phase="reveal"] .blink-button { opacity: .34; pointer-events: none; }

  .experience[data-phase="reveal"] .plate-controls,
  .experience[data-phase="reveal"] .sector-rail { opacity: 0; pointer-events: none; transition: opacity .7s; }
  .experience[data-phase="reveal"] .comparator-shell { box-shadow: 0 0 0 10px #080808, 0 0 0 11px rgba(231,226,213,.08), 0 0 0 24px #060606, 0 18px 80px #000; }
  .experience[data-phase="reveal"] .comparator-shell::after,
  .experience[data-phase="reveal"] .plate-stamp { opacity: 0; }
  .experience[data-phase="reveal"] .plate-stack { opacity: .25; }
}

@layer fallback {
  .noscript-fallback {
    display: grid;
    grid-template-columns: minmax(280px, 1.3fr) minmax(260px, .7fr);
    min-height: calc(100svh - 86px);
    overflow: hidden;
  }
  .fallback-plate {
    position: relative;
    align-self: center;
    width: min(73vw, 760px);
    aspect-ratio: 1;
    margin-left: -7%;
    overflow: hidden;
    border: 18px solid #0c0c0b;
    border-radius: 50%;
    outline: 1px solid rgba(231,226,213,.2);
    background-image:
      radial-gradient(circle at 12% 21%, #ddd 0 1px, transparent 2px),
      radial-gradient(circle at 24% 73%, #aaa 0 1px, transparent 2px),
      radial-gradient(circle at 39% 31%, #eee 0 1px, transparent 2px),
      radial-gradient(circle at 66% 81%, #aaa 0 1px, transparent 2px),
      radial-gradient(circle at 84% 44%, #eee 0 1px, transparent 2px),
      radial-gradient(circle at 51% 61%, #999 0 1px, transparent 2px),
      radial-gradient(#151515, #030303);
  }
  .fallback-plate i { position: absolute; left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%; background: var(--bone); box-shadow: 0 0 3px var(--bone); }
  .fallback-plate b { position: absolute; left: 58%; top: 43%; width: 4px; height: 4px; border-radius: 50%; background: white; box-shadow: -22px 16px 0 -1px rgba(255,255,255,.65), 22px -16px 0 -1px rgba(255,255,255,.65); }
  .noscript-fallback section { align-self: center; max-width: 420px; padding: 40px; }
  .noscript-fallback h2 { margin: 12px 0 20px; font: 400 clamp(30px, 4vw, 54px)/1 var(--serif); }
  .noscript-fallback section > p:not(.eyebrow) { color: #97948b; font-size: 12px; line-height: 1.7; }
}

@layer responsive {
  @media (max-width: 920px) {
    .mast { grid-template-columns: auto 1fr; gap: 15px 24px; padding: 18px 24px 14px; }
    .mast h1 { text-align: right; }
    .truth { grid-column: 1 / -1; max-width: 660px; }
    .experience { grid-template-columns: minmax(0, 1fr) minmax(275px, 38vw); }
    .comparator-shell { left: -10%; width: min(80vw, calc(100svh - 170px), 760px); }
    .sector-rail { right: 8px; }
    .plate-controls { right: 64px; left: 18px; }
    .shortcut-strip { display: none; }
  }

  @media (max-width: 680px) {
    body { font-size: 13px; }
    .mast {
      grid-template-columns: 1fr;
      gap: 10px;
      padding: max(14px, env(safe-area-inset-top)) 18px 13px;
    }
    .edition { position: absolute; top: 18px; right: 18px; }
    .mast h1 { max-width: calc(100% - 142px); margin: 0; text-align: left; font-size: 23px; }
    .truth { max-width: 92%; font-size: 8px; line-height: 1.45; }
    .experience { display: block; min-height: 0; }
    .instrument { min-height: min(105vw, 500px); border-right: 0; border-bottom: 1px solid rgba(231,226,213,.11); }
    .plate-stack { inset: 4% -8% 10% -21%; }
    .comparator-shell {
      top: 4%;
      left: -18vw;
      width: min(104vw, 500px);
      max-width: none;
    }
    .plate-stamp { left: 23%; }
    .sector-rail {
      top: 8px;
      right: 8px;
      display: grid;
      grid-template-columns: repeat(2, 46px);
      gap: 2px;
    }
    .sector-rail button { width: 46px; min-height: 46px; border: 0; border-bottom: 1px solid rgba(231,226,213,.18); background: rgba(5,5,5,.38); }
    .sector-rail button::after { right: auto; bottom: -1px; width: 8px; }
    .sector-rail button[aria-current="true"] { border-bottom-color: var(--red-bright); }
    .sector-rail button.is-inspected::before { left: 8px; }
    .plate-controls {
      right: 12px;
      bottom: 14px;
      left: 12px;
      max-width: none;
    }
    .plate-controls button { min-height: 50px; padding: 7px 8px; font-size: 11px; }
    .plate-controls kbd { display: none; }
    .logbook {
      min-height: 390px;
      justify-content: flex-start;
      padding: 62px 22px 88px;
    }
    .panel h2 { max-width: 13em; font-size: 34px; }
    .index-mark { top: 22px; right: 22px; left: 22px; }
    .status { right: 22px; bottom: 22px; left: 22px; }
    .prediction-grid { inset: 12%; }

    .noscript-fallback { display: block; min-height: 0; }
    .fallback-plate { width: 112vw; margin: 30px 0 0 -28vw; }
    .noscript-fallback section { padding: 35px 22px 70px; }
  }

  @media (max-width: 340px) {
    .mast h1 { max-width: 64%; font-size: 21px; }
    .edition span { display: none; }
    .panel h2 { font-size: 30px; }
    .plate-controls { grid-template-columns: 72px 1fr 72px; }
  }

  @media (pointer: coarse) {
    .plate-controls { opacity: 1; visibility: visible; }
    .text-action { min-height: 48px; }
    .sector-rail button { min-width: 46px; min-height: 46px; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
    .grain { animation: none; }
    .blink-default { display: none; }
    .blink-reduced { display: inline; }
  }
}
