:root {
  color-scheme: light;
  --ink: #191817;
  --paper: #f4f0e6;
  --paper-strong: #fffaf0;
  --line: #28231c;
  --muted: #736a5f;
  --rust: #c7421f;
  --rust-dark: #8f2e18;
  --green: #16745f;
  --yellow: #e2b84a;
  --blue: #276f9f;
  --shadow: rgba(25, 24, 23, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(25, 24, 23, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 24, 23, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.appShell {
  width: min(1520px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0 18px;
  border-bottom: 3px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--rust-dark);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.8rem, 6.8vw, 6.6rem);
  line-height: 0.82;
  letter-spacing: 0;
  text-transform: uppercase;
}

.runtimeCluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--paper-strong);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.good {
  background: var(--green);
  color: #fff;
}

.badge.warn {
  background: var(--yellow);
}

.badge.bad {
  background: var(--rust);
  color: #fff;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.25fr) minmax(300px, 0.72fr);
  grid-template-areas:
    "composer visualizer model"
    "composer visualizer log";
  gap: 14px;
  padding-top: 16px;
}

.panel {
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 7px 7px 0 var(--shadow);
}

.panelHeader {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--line);
  padding: 9px 12px;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.composer {
  grid-area: composer;
}

.visualizer {
  grid-area: visualizer;
}

.modelPanel {
  grid-area: model;
}

.logPanel {
  grid-area: log;
}

.primaryButton {
  min-height: 34px;
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 6px 14px;
  background: var(--rust);
  color: #fff;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: 3px 3px 0 var(--line);
}

.secondaryButton {
  min-height: 34px;
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 6px 12px;
  background: var(--paper-strong);
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: 3px 3px 0 var(--line);
}

.buttonRow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.primaryButton:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--line);
}

.iconButton {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--paper-strong);
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 900;
}

textarea {
  display: block;
  width: 100%;
  min-height: 226px;
  resize: vertical;
  border: 0;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  padding: 18px;
  background: #fffdf5;
  color: var(--ink);
  font-size: 1.42rem;
  line-height: 1.28;
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  outline: 3px solid rgba(199, 66, 31, 0.28);
  outline-offset: 0;
}

.controlGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input[type="text"],
input[type="number"],
input[type="file"] {
  width: 100%;
  min-height: 38px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--paper-strong);
  color: var(--ink);
  padding: 6px 8px;
}

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

.wideControl {
  grid-column: 1 / -1;
}

.compactTextarea {
  min-height: 78px;
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  background: var(--paper-strong);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 0.94rem;
  line-height: 1.35;
}

.referencePreview {
  display: none;
}

.referencePreview.hasAudio {
  display: block;
}

.referencePreview audio {
  width: 100%;
  margin: 0;
}

.statusText {
  color: var(--muted);
  overflow-wrap: anywhere;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1280 / 420;
  background:
    linear-gradient(90deg, rgba(25, 24, 23, 0.14) 1px, transparent 1px),
    linear-gradient(rgba(25, 24, 23, 0.10) 1px, transparent 1px),
    #12110f;
  background-size: 40px 40px;
  border-bottom: 2px solid var(--line);
}

audio {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
  accent-color: var(--rust);
}

.modelSummary,
.referenceSummary {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.metric {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.metric span:first-child {
  color: var(--muted);
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric span:last-child,
.pathText {
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric a {
  color: var(--blue);
  text-decoration: underline;
  font-size: 0.76rem;
}

.pathText {
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.76rem;
}

.modelOption {
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--paper-strong);
}

.modelOptionLabel {
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.modelOptionUrl {
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--blue);
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

.selectModelBtn {
  width: 100%;
}

.divider {
  border-top: 2px solid var(--line);
}

.notice {
  border-left: 7px solid var(--yellow);
  padding: 9px 10px;
  background: rgba(226, 184, 74, 0.2);
  line-height: 1.32;
}

.okNotice {
  border-left-color: var(--green);
  background: rgba(22, 116, 95, 0.12);
}

.badNotice {
  border-left-color: var(--rust);
  background: rgba(199, 66, 31, 0.12);
}

#logList {
  display: grid;
  max-height: 340px;
  gap: 7px;
  margin: 0;
  overflow: auto;
  padding: 12px 12px 12px 34px;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.78rem;
}

#logList li {
  padding-left: 4px;
}

@media (max-width: 1120px) {
  .workbench {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "composer visualizer"
      "model log";
  }
}

@media (max-width: 760px) {
  .appShell {
    width: min(100vw - 18px, 680px);
    padding-top: 12px;
  }

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

  .runtimeCluster {
    justify-content: flex-start;
  }

  .workbench {
    grid-template-columns: 1fr;
    grid-template-areas:
      "composer"
      "visualizer"
      "model"
      "log";
  }

  .controlGrid {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 180px;
    font-size: 1.12rem;
  }

  .metric {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* Loading spinner */
.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
button.loading {
  pointer-events: none;
  position: relative;
}
button.loading .btnLabel {
  visibility: hidden;
}
button.loading .spinner {
  display: block;
  position: absolute;
  inset: 0;
  margin: auto;
}
