@font-face {
  font-family: "Chakra Petch";
  src: url("assets/fonts/ChakraPetch-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Chakra Petch";
  src: url("assets/fonts/ChakraPetch-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --void: #0b0c0f;
  --well: #0d0f14;
  --panel: #101218;
  --panel-raised: #1a1e25;
  --hairline: #1e222a;
  --hairline-mid: #262b34;
  --hairline-strong: #2a2f3a;

  --text-glance: #eceef3;
  --text-primary: #dfe3ea;
  --text-secondary: #c9cdd6;
  --text-tertiary: #98a0ac;
  --text-muted: #838da1;

  --alarm-red: #e5484d;
  --alarm-red-soft: #ff8589;
  --ready-green: #3fae6a;
  --caution-amber: #d9a441;

  --locked-surface: #15161a;
  --locked-border: #343a45;
  --locked-edge: #4a5160;
  --locked-text: #79808d;
  --locked-label: #8b919e;

  --display: "Chakra Petch", system-ui, sans-serif;
  --system: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;

  /* Key size: fits the deck to both the width and the height of the window. */
  --k: clamp(84px, min(9.4vw, calc((100svh - 590px) / 3)), 128px);
  --gap: calc(var(--k) * 0.15);
  --deck-pad: calc(var(--k) * 0.2);
  --deck-w: calc(var(--cols) * var(--k) + (var(--cols) - 1) * var(--gap) + 2 * var(--deck-pad) + 2px);
  --cols: 5;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  background: var(--void);
  color: var(--text-primary);
  font-family: var(--system);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--hairline-strong) var(--void);
}

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(20px, 4svh, 44px) 16px;
}

::selection { background: rgba(96, 165, 250, 0.32); color: var(--text-glance); }

:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 3px;
}

a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--hairline-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.3em;
  transition: text-decoration-color 0.2s var(--ease-out), color 0.2s var(--ease-out);
}
a:hover { color: var(--text-glance); text-decoration-color: var(--text-muted); }


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

/* ───────── Masthead ───────── */

.stage {
  width: 100%;
  max-width: 1080px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.masthead { display: flex; flex-direction: column; align-items: center; }

.wordmark { margin: 0; line-height: 0; }
.wordmark img {
  display: block;
  width: clamp(240px, 34vw, 460px);
  height: auto;
}

.tagline {
  margin: clamp(12px, 2svh, 20px) 0 0;
  font: 600 clamp(19px, 2vw, 25px)/1.1 var(--display);
  letter-spacing: 0.05em;
  color: var(--text-glance);
}

.lede {
  margin: 10px 0 0;
  max-width: 68ch;
  font-size: clamp(14.5px, 1.1vw, 15.5px);
  line-height: 1.5;
  color: var(--text-tertiary);
  text-wrap: balance;
}

/* ───────── The deck ───────── */

.console {
  margin-top: clamp(22px, 3.6svh, 36px);
  width: min(100%, var(--deck-w));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.deck {
  padding: var(--deck-pad);
  border-radius: calc(var(--k) * 0.26);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 40%),
    #111318;
  border: 1px solid var(--hairline-mid);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5);
}

.keys {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--k));
  gap: var(--gap);
}

/* Recessed well each key sits in. */
.key {
  --tint: var(--text-tertiary);
  --dur: 4s;
  --cool: 3s;
  position: relative;
  width: var(--k);
  height: var(--k);
  padding: calc(var(--k) * 0.09) calc(var(--k) * 0.09) calc(var(--k) * 0.1) calc(var(--k) * 0.09 + 5px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr auto;
  align-items: start;
  text-align: left;
  border-radius: calc(var(--k) * 0.11);
  border: 1px solid color-mix(in srgb, var(--tint) 38%, transparent);
  background:
    linear-gradient(color-mix(in srgb, var(--tint) 7%, transparent), color-mix(in srgb, var(--tint) 7%, transparent)),
    var(--well);
  box-shadow:
    0 0 0 calc(var(--k) * 0.035) #07080a,
    0 0 0 calc(var(--k) * 0.035 + 1px) #1c1f26;
  color: var(--text-glance);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.25s var(--ease-out),
    border-color 0.25s var(--ease-out),
    box-shadow 0.35s var(--ease-out),
    transform 0.08s ease-out;
}
.key:active { transform: translateY(1px) scale(0.985); }
.key:focus-visible { outline-offset: calc(var(--k) * 0.035 + 3px); }

.key .edge {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--tint);
  transition: background-color 0.25s var(--ease-out);
}

.key .glyph {
  width: clamp(16px, calc(var(--k) * 0.18), 23px);
  height: clamp(16px, calc(var(--k) * 0.18), 23px);
  color: var(--tint);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.key .name {
  grid-column: 1 / -1;
  align-self: end;
  font: 700 clamp(12px, calc(var(--k) * 0.125), 16px)/1.02 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-glance);
  transition: color 0.25s var(--ease-out);
}

.key .state {
  grid-column: 1 / -1;
  margin-top: calc(var(--k) * 0.05);
  font: 600 10px/1 var(--system);
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: color-mix(in srgb, var(--tint) 80%, var(--text-glance) 20%);
}

/* Bottom progress bar (running) */
.key .bar {
  position: absolute;
  left: 5px; right: 0; bottom: 0;
  height: clamp(4px, calc(var(--k) * 0.045), 6px);
  opacity: 0;
}
.key .bar i {
  display: block;
  height: 100%;
  background: var(--tint);
  box-shadow: 0 0 6px var(--tint);
  transform-origin: left;
  transform: scaleX(0);
}

/* Draining right edge (cooling down, the deck's own treatment) */
.key .drain {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 4px;
  background: var(--caution-amber);
  transform-origin: bottom;
  transform: scaleY(0);
  opacity: 0;
}

/* ── running ── */
.key.is-running {
  border-color: var(--tint);
  background:
    linear-gradient(color-mix(in srgb, var(--tint) 20%, transparent), color-mix(in srgb, var(--tint) 20%, transparent)),
    var(--well);
  box-shadow:
    0 0 0 calc(var(--k) * 0.035) #07080a,
    0 0 0 calc(var(--k) * 0.035 + 1px) #1c1f26,
    0 0 16px color-mix(in srgb, var(--tint) 34%, transparent);
}
.key.is-running .bar { opacity: 1; }
.key.is-running .bar i {
  transform: scaleX(1);
  transition: transform var(--dur) linear;
}
.key.is-running.is-loop .bar { opacity: 0.75; }
.key.is-running.is-loop .bar i { transform: scaleX(1); transition: none; }

/* ── cooling down ── */
.key.is-cooling {
  padding-right: calc(var(--k) * 0.09 + 4px);
  border-color: var(--locked-border);
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 0 8px, transparent 8px 16px),
    var(--locked-surface);
}
.key.is-cooling .edge { background: var(--locked-edge); }
.key.is-cooling .glyph { color: var(--locked-text); }
.key.is-cooling .name { color: var(--locked-text); }
.key.is-cooling .state { color: var(--locked-label); }
.key.is-cooling .drain {
  opacity: 1;
  transform: scaleY(1);
  animation: drain var(--cool) linear forwards;
}
@keyframes drain { to { transform: scaleY(0); } }

/* ── disabled: cold, no hatch, reads as chosen ── */
.key.is-disabled {
  border-color: var(--locked-border);
  background: var(--locked-surface);
  cursor: default;
}
.key.is-disabled .edge { background: var(--locked-edge); }
.key.is-disabled .glyph,
.key.is-disabled .name { color: var(--locked-text); }
.key.is-disabled .state { color: var(--locked-label); }

/* ── refused press (lockout / disabled) ── */
.key.is-refused { animation: refuse 0.32s var(--ease-out); }
@keyframes refuse {
  20% { transform: translateX(-2px); }
  45% { transform: translateX(2px); }
  70% { transform: translateX(-1px); }
}

/* ── STOP ALL ── */
.key.stop {
  --tint: var(--alarm-red);
  padding: calc(var(--k) * 0.1);
  grid-template-rows: 1fr auto;
  grid-template-columns: 1fr;
  justify-items: center;
  align-items: center;
  text-align: center;
  border: 1.5px solid var(--alarm-red);
  background:
    linear-gradient(rgba(229, 72, 77, 0.16), rgba(229, 72, 77, 0.16)),
    var(--well);
}
.key.stop .glyph {
  width: calc(var(--k) * 0.26);
  height: calc(var(--k) * 0.26);
  align-self: end;
  color: var(--alarm-red-soft);
  fill: currentColor;
  stroke: none;
}
.key.stop .name {
  align-self: start;
  margin-top: calc(var(--k) * 0.08);
  font: 700 clamp(11px, calc(var(--k) * 0.1), 13px)/1 var(--system);
  letter-spacing: 0.1em;
  color: var(--alarm-red-soft);
}
.key.stop:active {
  background:
    linear-gradient(rgba(229, 72, 77, 0.26), rgba(229, 72, 77, 0.26)),
    var(--well);
}

/* The deck goes briefly cold after STOP ALL. */
.deck.is-stopped .key:not(.stop) { transition-duration: 0.05s; }

/* ───────── Strip: trigger log ───────── */

.strip {
  display: grid;
  padding: 12px 14px 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--panel);
  text-align: left;
}

.log {
  list-style: none;
  margin: 0;
  padding: 0 0 0 4px;
  display: grid;
  grid-template-rows: repeat(3, 20px);
  gap: 3px;
  min-width: 0;
  font-size: 13px;
}

.log li {
  display: grid;
  grid-template-columns: 62px 84px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  color: var(--text-muted);
  transition: opacity 0.4s var(--ease-out), color 0.4s var(--ease-out);
}
.log li:first-child { color: var(--text-secondary); }
.log li:not(:first-child) { color: var(--text-muted); }
.log li:nth-child(n + 4) { display: none; }
.log li.is-new { animation: log-in 0.45s var(--ease-out); }
@keyframes log-in {
  from { opacity: 0; transform: translateY(-6px); filter: blur(3px); }
}

.log time { color: inherit; }

.log .src {
  justify-self: start;
  padding: 3px 6px;
  border: 1px solid var(--hairline-mid);
  border-radius: 4px;
  font: 600 9.5px/1 var(--system);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.log .src.is-auto { color: #fb923c; border-color: rgba(251, 146, 60, 0.45); }
.log .src.is-go   { color: #5ede8f; border-color: rgba(63, 174, 106, 0.45); }
.log .src.is-stop { color: var(--alarm-red-soft); border-color: rgba(229, 72, 77, 0.5); }

.log .msg { overflow: hidden; text-overflow: ellipsis; }
.log .msg b { font-weight: 600; color: var(--text-glance); }
.log li:not(:first-child) .msg b { color: inherit; }

/* ───────── Availability + colophon ───────── */

.availability {
  margin: clamp(14px, 2.2svh, 20px) 0 0;
  padding: 6px 16px 6px 6px;
  border: 1px solid var(--hairline-mid);
  border-radius: 12px;
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font: 600 clamp(15px, 1.4vw, 17px)/1.2 var(--display);
  letter-spacing: 0.05em;
  color: var(--text-glance);
}
.availability img { width: 34px; height: 34px; }

.colophon { margin-top: clamp(18px, 3svh, 28px); }

.contact {
  margin: 0;
  font-size: 14px;
  color: var(--text-tertiary);
}

/* ───────── Narrow screens: the deck stands on end ───────── */

@media (max-width: 720px) {
  :root {
    --cols: 3;
    --k: min(calc((100vw - 32px - 2 * 22px - 2 * 14px) / 3), 124px);
    --gap: 14px;
    --deck-pad: 22px;
  }
  .deck { border-radius: 26px; }
  .strip { padding: 12px; }
  .log { padding-left: 0; }
  .log { grid-template-rows: none; gap: 7px; }
  .log li { grid-template-columns: 58px 80px minmax(0, 1fr); align-items: start; gap: 8px; font-size: 12.5px; line-height: 1.35; white-space: normal; }
  .log li .src { margin-top: -1px; }
  .log .msg { overflow: visible; }
}


/* Wide but short windows: the strip stands beside the deck so the log stays in view. */
@media (min-width: 1000px) and (max-height: 840px) {
  :root { --k: clamp(84px, calc((100svh - 420px) / 3.2), 128px); }
  .console {
    width: auto;
    flex-direction: row;
    align-items: stretch;
    gap: 14px;
  }
  .strip {
    position: relative;
    width: 340px;
    overflow: hidden;
  }
  /* The deck sets the height; the log fills it and older rows fade out at the bottom edge. */
  .log {
    position: absolute;
    inset: 12px;
    overflow: hidden;
    grid-template-rows: none;
    align-content: start;
    gap: 8px;
    padding-left: 0;
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 48px), transparent);
            mask-image: linear-gradient(to bottom, #000 calc(100% - 48px), transparent);
  }
  .log li:nth-child(n + 4) { display: grid; }
  .log li { grid-template-columns: 58px 84px minmax(0, 1fr); align-items: start; line-height: 1.35; white-space: normal; }
  .log .msg { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .key, .key .edge, a, .log li { transition: none; }
  .key.is-running .bar i { transition: none; transform: scaleX(0.6); }
  .key.is-cooling .drain { animation: none; transform: scaleY(0.5); }
  .key.is-refused, .log li.is-new { animation: none; }
  .key:active { transform: none; }
}
