@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;700;900&display=swap');

:root {
  color-scheme: light dark;
  --paper: #f1f0ea;
  --ink: #11110f;
  --muted: #6e6d66;
  --line: rgba(17, 17, 15, .18);
  --faint: rgba(17, 17, 15, .055);
  --panel: rgba(255, 255, 255, .34);
  --accent: #f24e1e;
  --accent-ink: #fff8f2;
  --shadow: 0 24px 60px rgba(17, 17, 15, .12);
  --sans: "Noto Sans SC", "PingFang SC", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10100f;
    --ink: #f0efe8;
    --muted: #9d9c94;
    --line: rgba(240, 239, 232, .17);
    --faint: rgba(240, 239, 232, .055);
    --panel: rgba(255, 255, 255, .035);
    --accent: #ff5a27;
    --accent-ink: #110f0d;
    --shadow: 0 30px 70px rgba(0, 0, 0, .42);
  }
}

html[data-theme="light"] {
  --paper: #f1f0ea;
  --ink: #11110f;
  --muted: #6e6d66;
  --line: rgba(17, 17, 15, .18);
  --faint: rgba(17, 17, 15, .055);
  --panel: rgba(255, 255, 255, .34);
  --accent: #f24e1e;
  --accent-ink: #fff8f2;
  --shadow: 0 24px 60px rgba(17, 17, 15, .12);
}

html[data-theme="dark"] {
  --paper: #10100f;
  --ink: #f0efe8;
  --muted: #9d9c94;
  --line: rgba(240, 239, 232, .17);
  --faint: rgba(240, 239, 232, .055);
  --panel: rgba(255, 255, 255, .035);
  --accent: #ff5a27;
  --accent-ink: #110f0d;
  --shadow: 0 30px 70px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  transition: background-color .35s ease, color .35s ease;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background:
    linear-gradient(var(--faint) 1px, transparent 1px),
    linear-gradient(90deg, var(--faint) 1px, transparent 1px);
  background-size: clamp(42px, 5vw, 74px) clamp(42px, 5vw, 74px);
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%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");
}

button,
a,
input { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

a { color: inherit; }

.topbar {
  position: absolute;
  inset: 0 0 auto;
  height: 82px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 clamp(24px, 4vw, 72px);
  border-bottom: 1px solid var(--line);
}

.brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--ink);
  color: var(--paper);
  font: 600 12px/1 var(--mono);
  letter-spacing: -.08em;
  transform: rotate(-3deg);
}

.brand-mark span { color: var(--accent); }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .08em; }

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 28px;
  color: var(--muted);
  font: 500 10px/1 var(--mono);
  letter-spacing: .13em;
}

.live { display: flex; align-items: center; gap: 8px; }
.live i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }

.theme-switch {
  justify-self: end;
  min-width: 84px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: 500 10px/1 var(--mono);
  letter-spacing: .1em;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}

.theme-switch:hover { background: var(--ink); color: var(--paper); }
.theme-switch:active { transform: translateY(1px); }
.theme-icon { width: 12px; height: 12px; border: 1.5px solid currentColor; border-radius: 50%; background: linear-gradient(90deg, currentColor 50%, transparent 50%); }

main {
  position: absolute;
  inset: 82px 0 54px;
  display: grid;
  grid-template-columns: minmax(330px, .78fr) minmax(520px, 1.22fr);
  gap: clamp(32px, 5vw, 96px);
  align-items: center;
  padding: clamp(28px, 4vw, 68px) clamp(48px, 8vw, 150px);
}

.intro { position: relative; z-index: 1; }
.eyebrow { display: flex; align-items: center; gap: 12px; margin-bottom: clamp(18px, 3vh, 32px); color: var(--muted); font: 500 11px/1 var(--mono); letter-spacing: .14em; }
.eyebrow span { display: grid; width: 28px; height: 28px; place-items: center; border: 1px solid var(--line); color: var(--ink); }

h1 {
  margin: 0;
  font-size: clamp(56px, 6.2vw, 112px);
  font-weight: 900;
  line-height: .9;
  letter-spacing: -.075em;
}

h1 span { position: relative; color: var(--accent); }
h1 span::after { position: absolute; right: 0; bottom: -.06em; left: .06em; height: .07em; content: ""; background: var(--accent); transform: rotate(-1.5deg); }
h1 b { color: var(--accent); font-weight: inherit; }

.lede { max-width: 440px; margin: clamp(20px, 3.5vh, 38px) 0 0; color: var(--muted); font-size: clamp(13px, 1.05vw, 16px); line-height: 1.9; text-wrap: pretty; }

.control-row { display: flex; align-items: center; gap: 10px; margin-top: clamp(22px, 4vh, 42px); }
.run-button,
.icon-button {
  height: 50px;
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.run-button { display: flex; align-items: center; gap: 14px; padding: 0 24px; background: var(--ink); color: var(--paper); font-size: 13px; font-weight: 700; letter-spacing: .06em; }
.run-button:hover { transform: translate(-3px, -3px); box-shadow: 4px 4px 0 var(--accent); }
.run-button:disabled { cursor: wait; opacity: .65; transform: none; box-shadow: none; }
.play-icon { width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid currentColor; }
.icon-button { width: 50px; background: transparent; color: var(--ink); font: 400 24px/1 var(--mono); }
.icon-button:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); transform: rotate(-18deg); }

.speed-control { display: flex; align-items: center; gap: 9px; margin-left: 4px; color: var(--muted); font: 500 9px/1 var(--mono); letter-spacing: .12em; }
.speed-control input { width: clamp(54px, 6vw, 92px); accent-color: var(--accent); cursor: pointer; }

.stats { display: flex; gap: clamp(28px, 4vw, 60px); margin-top: clamp(22px, 4vh, 42px); }
.stats div { display: grid; gap: 5px; }
.stats span { font: 500 clamp(17px, 1.5vw, 24px)/1 var(--mono); letter-spacing: -.04em; }
.stats small { color: var(--muted); font-size: 10px; letter-spacing: .14em; }

.lab {
  position: relative;
  min-width: 0;
  min-height: 390px;
  height: min(58vh, 600px);
  display: grid;
  grid-template-rows: 58px 1fr 44px 64px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lab::before,
.lab::after { position: absolute; z-index: 2; width: 18px; height: 18px; content: ""; pointer-events: none; }
.lab::before { top: -6px; left: -6px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.lab::after { right: -6px; bottom: -6px; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); }

.lab-head { display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); font: 500 10px/1 var(--mono); letter-spacing: .1em; }
.lab-head div { display: flex; align-items: center; gap: 9px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.complexity { padding: 6px 9px; border: 1px solid var(--line); color: var(--muted); }

.visualizer { display: flex; align-items: end; gap: clamp(3px, .7vw, 10px); min-height: 0; padding: 32px 28px 20px; overflow: hidden; }
.bar { position: relative; flex: 1; min-width: 3px; height: calc(var(--value) * 1%); background: var(--ink); transform-origin: bottom; transition: height .22s ease, background-color .15s ease, opacity .2s ease; }
.bar::before { position: absolute; top: -17px; left: 50%; color: var(--muted); content: attr(data-value); font: 500 clamp(6px, .62vw, 10px)/1 var(--mono); transform: translateX(-50%); }
.bar.active { background: var(--accent); transform: translateY(-3px); }
.bar.sorted { opacity: .32; }

.timeline { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 0 22px; color: var(--muted); font: 500 8px/1 var(--mono); letter-spacing: .12em; }
.track { height: 2px; background: var(--line); }
.track i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s ease; }
.code-strip { min-width: 0; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 15px; padding: 0 22px; border-top: 1px solid var(--line); background: var(--faint); font: 400 clamp(9px, .8vw, 12px)/1 var(--mono); }
.line-number { color: var(--muted); }
.code-strip code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-strip em { color: var(--accent); font-style: normal; font-weight: 600; }
.code-strip b { margin: 0 6px; color: var(--accent); }
.language { color: var(--muted); font-size: 8px; letter-spacing: .14em; }

.index-mark { position: fixed; top: 50%; left: 20px; display: flex; align-items: center; gap: 12px; color: var(--muted); font: 500 8px/1 var(--mono); letter-spacing: .18em; transform: rotate(-90deg) translateX(-50%); transform-origin: left top; }
.index-mark i { width: 34px; height: 1px; background: var(--line); }

footer { position: absolute; inset: auto 0 0; height: 54px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 clamp(24px, 4vw, 72px); border-top: 1px solid var(--line); color: var(--muted); font: 500 8px/1 var(--mono); letter-spacing: .11em; }
footer a { justify-self: center; text-underline-offset: 4px; transition: color .2s ease; }
footer a:hover { color: var(--accent); }
footer span:last-child { justify-self: end; }

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

@media (max-width: 880px) {
  .topbar { height: 66px; padding-inline: 18px; }
  .topbar-meta, .brand-name, .index-mark, footer span { display: none; }
  main { inset: 66px 0 45px; grid-template-columns: 1fr; grid-template-rows: auto minmax(230px, 1fr); gap: 18px; padding: 18px; }
  .intro { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px 16px; }
  .eyebrow { grid-column: 1 / -1; margin-bottom: 3px; }
  h1 { font-size: clamp(42px, 10vw, 70px); }
  .lede { align-self: center; margin: 0; font-size: 12px; line-height: 1.65; }
  .control-row { margin-top: 8px; }
  .stats { grid-column: 2; grid-row: 3; gap: 16px; margin-top: 8px; }
  .stats small { font-size: 8px; }
  .lab { min-height: 0; height: 100%; grid-template-rows: 44px 1fr 34px 48px; }
  .visualizer { padding: 25px 18px 14px; }
  footer { height: 45px; grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .intro { display: block; }
  .lede { display: none; }
  h1 {
    font-size: clamp(38px, 10.5vw, 48px);
    white-space: nowrap;
  }
  h1 br { display: none; }
  .control-row { margin-top: 18px; }
  .speed-control { display: none; }
  .stats { position: absolute; right: 0; bottom: 2px; gap: 14px; }
  .stats div:nth-child(3) { display: none; }
  .stats span { font-size: 14px; }
  .lab { grid-template-rows: 42px 1fr 30px 46px; }
  .bar::before { display: none; }
  .code-strip { grid-template-columns: 24px 1fr; padding: 0 12px; }
  .language { display: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .topbar {
    height: 52px;
    padding-inline: 18px;
  }

  .topbar-meta,
  .brand-name,
  .index-mark,
  footer span { display: none; }

  main {
    inset: 52px 0 36px;
    grid-template-columns: minmax(190px, .7fr) minmax(280px, 1.3fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 16px;
    padding: 10px 18px;
  }

  .intro { display: block; }
  .eyebrow { margin-bottom: 8px; }
  h1 {
    font-size: clamp(34px, 5.4vw, 48px);
    white-space: normal;
  }
  h1 br { display: initial; }
  .lede,
  .speed-control { display: none; }
  .control-row { margin-top: 12px; }
  .run-button,
  .icon-button { height: 42px; }
  .icon-button { width: 42px; }
  .stats {
    position: static;
    gap: 20px;
    margin-top: 12px;
  }
  .stats div:nth-child(3) { display: grid; }
  .stats span { font-size: 14px; }

  .lab {
    min-height: 0;
    height: 100%;
    grid-template-rows: 38px minmax(0, 1fr) 26px 38px;
  }
  .visualizer { padding: 18px 16px 10px; }
  .bar::before { display: none; }
  .code-strip { grid-template-columns: 24px 1fr; padding: 0 12px; }
  .language { display: none; }

  footer {
    height: 36px;
    grid-template-columns: 1fr;
  }
}

@media (max-height: 680px) and (min-width: 881px) {
  main { padding-block: 24px; }
  .eyebrow { margin-bottom: 14px; }
  .lede { margin-top: 16px; line-height: 1.6; }
  .control-row, .stats { margin-top: 18px; }
  .lab { min-height: 330px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
