@font-face {
  font-family: "Tiempos";
  src: url("../../fonts/tiempos-headline-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sohne";
  src: url("../../fonts/soehne-buch.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sohne";
  src: url("../../fonts/soehne-halbfett.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #050713;
  --bone: #f3efe7;
  --paper: #d9d3c6;
  --muted: #9a958a;
  --line: rgba(243, 239, 231, 0.14);
  --glass: rgba(5, 7, 19, 0.72);
  --gold: #e7c84b;
  --cyan: #00b7a8;
  --red: #ff5a4d;
  --blue: #7db4ff;
  --green: #9cc76c;
  --accent: var(--gold);
  --viscosity: 0.7;
  --font-display: "Tiempos", Georgia, "Times New Roman", serif;
  --font-body: "Sohne", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
a,
input {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

#qwenStage,
.grain,
.gate-noise {
  position: fixed;
  inset: 0;
}

#qwenStage {
  z-index: 0;
  filter: saturate(calc(1 + var(--viscosity) * 0.36)) contrast(calc(1 + var(--viscosity) * 0.12));
}

.grain {
  z-index: 1;
  pointer-events: none;
  opacity: 0.52;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 240 240' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.18'/%3E%3C/svg%3E");
}

.gate-noise {
  z-index: 1;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(231, 200, 75, 0.055) 31px 32px, transparent 32px 64px),
    repeating-linear-gradient(0deg, transparent 0 43px, rgba(0, 183, 168, 0.04) 43px 44px, transparent 44px 88px);
  mask-image: radial-gradient(circle at 50% 42%, black, transparent 72%);
}

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

.topbar,
.qwen-wing {
  position: relative;
  z-index: 2;
}

.topbar {
  display: grid;
  grid-template-columns: 120px 1fr 120px;
  gap: 14px;
  align-items: start;
  padding: 22px 24px;
}

.backlink,
.directorate-link {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 7, 19, 0.42);
  color: var(--paper);
  text-align: center;
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--bone);
  font-family: var(--font-display);
  font-size: clamp(40px, 8vw, 124px);
  font-weight: 400;
  line-height: 0.86;
  text-align: center;
  text-wrap: balance;
}

h2 {
  color: var(--bone);
  font-family: var(--font-display);
  font-size: clamp(30px, 4.7vw, 70px);
  font-weight: 400;
  line-height: 0.94;
}

p {
  color: var(--paper);
}

.qwen-wing {
  display: grid;
  grid-template-columns: minmax(300px, 0.92fr) minmax(320px, 1.08fr);
  gap: 16px;
  padding: 18px 24px 96px;
}

.thesis,
.customs-oracle,
.terminal,
.choir,
.ledger,
.governance,
.studio-labor,
.trace-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 0% 0%, rgba(231, 200, 75, 0.11), transparent 36%),
    linear-gradient(135deg, rgba(0, 183, 168, 0.08), rgba(255, 90, 77, 0.055)),
    var(--glass);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.4),
    0 0 58px rgba(231, 200, 75, 0.07);
  backdrop-filter: blur(20px);
}

.thesis {
  min-height: 520px;
  padding: clamp(16px, 3vw, 28px);
}

.thesis h2 {
  margin: 38px 0 18px;
}

.thesis p {
  max-width: 68ch;
  font-size: 18px;
}

.viscosity-dial {
  display: grid;
  gap: 8px;
  margin-top: 32px;
}

.viscosity-dial label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.customs-oracle {
  display: grid;
  align-content: start;
  gap: 18px;
  min-height: 520px;
  padding: 18px;
}

.sigil-field {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sigil-field span {
  position: relative;
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 1px solid rgba(231, 200, 75, 0.34);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 34%, rgba(231, 200, 75, 0.18), transparent 32%),
    rgba(243, 239, 231, 0.035);
  color: rgba(243, 239, 231, 0.78);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  overflow: hidden;
  text-transform: uppercase;
}

.sigil-field span::before,
.sigil-field span::after {
  content: "";
  position: absolute;
  border: 1px solid currentColor;
  opacity: 0.38;
}

.sigil-field span::before {
  width: 54%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: rotate(24deg);
}

.sigil-field span::after {
  content: attr(data-code);
  inset: auto 8px 8px;
  border: 0;
  color: rgba(0, 183, 168, 0.82);
  font-size: 10px;
  opacity: 0;
}

.sigil-field span.is-linting {
  animation: qwen-wing-lint 420ms steps(2, end) both;
}

.sigil-field span.is-linting::after {
  opacity: 1;
}

.terminal,
.choir,
.ledger,
.governance,
.studio-labor,
.trace-panel {
  padding: 16px;
}

.terminal {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(240px, 0.42fr) minmax(320px, 1fr);
  gap: 14px;
}

.terminal-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.terminal-controls input {
  min-height: 44px;
  width: 100%;
  border: 1px solid rgba(243, 239, 231, 0.14);
  border-radius: 8px;
  background: rgba(5, 7, 19, 0.72);
  padding: 9px 11px;
}

button,
.directorate-link {
  border: 1px solid rgba(231, 200, 75, 0.4);
  border-radius: 8px;
  background: rgba(231, 200, 75, 0.09);
  padding: 9px 12px;
  color: var(--bone);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

button:hover,
button:focus-visible,
.directorate-link:hover,
.directorate-link:focus-visible {
  background: rgba(231, 200, 75, 0.16);
}

.palimpsest-output {
  display: flex;
  grid-column: 2;
  min-height: 100px;
  flex-wrap: wrap;
  align-content: start;
  gap: 7px;
  border: 1px solid rgba(243, 239, 231, 0.12);
  border-radius: 8px;
  background: rgba(243, 239, 231, 0.04);
  padding: 10px;
}

.palimpsest-output span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid rgba(0, 183, 168, 0.32);
  border-radius: 7px;
  background: rgba(0, 183, 168, 0.08);
  padding: 7px 9px;
  color: var(--bone);
  font-size: 12px;
}

.palimpsest-output span:nth-child(3n) {
  border-color: rgba(255, 90, 77, 0.34);
  background: rgba(255, 90, 77, 0.08);
}

.probability-log {
  grid-column: 2;
  max-height: 220px;
  overflow: auto;
  border: 1px solid rgba(243, 239, 231, 0.12);
  border-radius: 8px;
  background: rgba(5, 7, 19, 0.74);
  color: rgba(243, 239, 231, 0.76);
  font-size: 11px;
  line-height: 1.45;
  padding: 10px;
  white-space: pre-wrap;
}

.choir {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.choir-bars {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  min-height: 86px;
}

.choir-bars span {
  align-self: end;
  min-height: 18px;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, rgba(231, 200, 75, 0.82), rgba(0, 183, 168, 0.32));
  transform-origin: bottom;
}

body[data-choir="on"] .choir-bars span {
  animation: qwen-choir 840ms ease-in-out infinite alternate;
}

body[data-choir="on"] .choir-bars span:nth-child(2n) {
  animation-duration: 620ms;
}

body[data-choir="on"] .choir-bars span:nth-child(3n) {
  animation-duration: 1110ms;
}

.ledger {
  display: grid;
  gap: 12px;
}

.scar-ledger {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.scar-ledger li {
  border: 1px solid rgba(243, 239, 231, 0.12);
  border-left: 3px solid var(--red);
  border-radius: 8px;
  background: rgba(243, 239, 231, 0.045);
  padding: 9px;
  color: rgba(243, 239, 231, 0.78);
  font-size: 13px;
}

.scar-ledger li.is-stamped {
  border-left-color: var(--gold);
  background:
    linear-gradient(90deg, rgba(231, 200, 75, 0.12), rgba(243, 239, 231, 0.045));
}

.scar-ledger strong {
  color: var(--bone);
}

.scar-ledger span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.governance,
.studio-labor,
.trace-panel {
  grid-column: 1 / -1;
}

.studio-labor {
  display: grid;
  grid-template-columns: minmax(220px, 0.42fr) minmax(280px, 1fr) auto;
  gap: 12px;
  align-items: end;
  border-color: rgba(156, 199, 108, 0.28);
}

.studio-labor h2,
.studio-labor p {
  margin-bottom: 0;
}

.labor-meter {
  grid-column: 2;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(243, 239, 231, 0.1);
}

.labor-meter span {
  display: block;
  width: 46%;
  height: 100%;
  border-radius: inherit;
  background: var(--labor-color, var(--gold));
  box-shadow: 0 0 18px var(--labor-color, var(--gold));
  transition: width 420ms var(--ease), background 420ms var(--ease);
}

.labor-button {
  grid-row: 1 / span 3;
  grid-column: 3;
}

.dispatch-note {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

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

@keyframes qwen-wing-lint {
  0%,
  100% {
    filter: none;
    transform: translate(0, 0);
  }
  42% {
    filter: blur(1.4px) contrast(1.8);
    transform: translate(-3px, 2px) skewX(-12deg);
  }
  68% {
    filter: hue-rotate(86deg);
    transform: translate(3px, -2px) skewX(12deg);
  }
}

@keyframes qwen-choir {
  from {
    transform: scaleY(0.24);
  }
  to {
    transform: scaleY(1);
  }
}

@media (max-width: 960px) {
  .qwen-wing,
  .terminal,
  .choir,
  .studio-labor {
    grid-template-columns: 1fr;
  }

  .palimpsest-output,
  .probability-log,
  .labor-meter,
  .labor-button {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  h1 {
    text-align: left;
  }

  .qwen-wing {
    padding: 12px 18px 96px;
  }

  .terminal-controls,
  .sigil-field {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sigil-field span.is-linting,
  body[data-choir="on"] .choir-bars span {
    animation: none;
  }
}
