:root {
  color-scheme: light;
  --ink: black;
  --muted: #716d64;
  --box: #d8d1c4;
  --rule: red;
  --paper: white;
  --input: white;
  --accent: #2548d8;
  --accent-dark: #1734ad;
  --soft-blue: #e9ecfb;
  --success: #25714c;
}

* {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Libertinus Serif", Georgia, serif;
}

button,
input,
select,
textarea {
  font: inherit;
}
button,
select {
  cursor: pointer;
}
a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: .18em;
}
a:hover {
  color: var(--accent);
}

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

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: clamp(2.5rem, 6vw, 7rem);
  width: min(1480px, calc(100% - 3rem));
  margin: 0 auto;
  padding: 1rem 0 3rem;
  align-items: start;
}

.editor-panel {
  min-width: 0;
}
.editor-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
}
h1 {
  width: fit-content;
  margin: 0;
  border-bottom: 1px solid currentColor;
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: clamp(1.75rem, 2.5vw, 2.5rem);
  font-weight: 400;
  line-height: 1.08;
}
#editor {
  display: block;
  width: 100%;
  min-height: min(61vh, 700px);
  resize: vertical;
  padding: clamp(1.2rem, 3vw, 2.25rem);
  border: 1px solid var(--box);
  border-radius: 3px;
  outline: 0;
  background: color-mix(in srgb, var(--input) 92%, transparent);
  color: var(--ink);
  font: clamp(1.15rem, 1.8vw, 1.42rem)/1.65 "Libertinus Serif", Georgia, serif;
}

#editor::placeholder {
  color: #9a958b;
  font-style: italic;
}
#editor:focus {
  border-color: var(--accent);
}
#editor[readonly] {
  cursor: progress;
}
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: .8rem;
  color: var(--muted);
  font-size: .75rem;
}
.editor-footer p {
  margin: 0;
}
kbd {
  padding: .08rem .3rem;
  border: 1px solid var(--box);
  border-radius: 2px;
  background: var(--input);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .68rem;
}
.text-button {
  padding: .3rem .6rem;
  border: 1px solid var(--box);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
}
.text-button:hover {
  border-color: var(--rule);
  color: var(--rule);
}
.text-button:focus-visible {
  border-color: var(--rule);
  outline: 2px solid color-mix(in srgb, var(--rule) 20%, transparent);
  outline-offset: 2px;
}

.controls {
  position: sticky;
  top: 1.5rem;
  min-width: 0;
  padding: 1.4rem;
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 96%, white);
}

.control-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
.control-heading h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 400;
}
.control-heading-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: .65rem;
}
.status-dot {
  flex: 0 0 auto;
  width: .62rem;
  height: .62rem;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: transparent;
}
.status-dot.loading {
  border-color: var(--accent);
  border-top-color: transparent;
  animation: spin .8s linear infinite;
}
.status-dot.ready {
  border-color: var(--success);
  background: var(--success);
}
.status-dot.error {
  border-color: var(--rule);
  background: var(--rule);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.field {
  min-width: 0;
}
.field label {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .35rem;
  color: var(--muted);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .045em;
}
.field label span {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
input,
select {
  width: 100%;
  height: 2.35rem;
  padding: .45rem .55rem;
  border: 1px solid var(--box);
  border-radius: 2px;
  outline: 0;
  background: var(--input);
  color: var(--ink);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .82rem;
}
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}
.model-field input {
  font-size: .76rem;
}
.model-input-shell {
  position: relative;
}
.model-suggestions {
  position: absolute;
  z-index: 4;
  top: calc(100% + 2px);
  left: 0;
  width: 100%;
  padding: .2rem;
  border: 1px solid var(--box);
  border-radius: 2px;
  background: var(--input);
}
.model-suggestions[hidden] {
  display: none;
}
.model-suggestions button {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  width: 100%;
  padding: .45rem .4rem;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .76rem;
  text-align: left;
  cursor: pointer;
}
.model-suggestions button:hover,
.model-suggestions button:focus-visible {
  outline: 0;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.model-suggestions small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .65rem;
}
.field-note {
  margin-top: .38rem;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.4;
}
.model-links {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}
.model-format-note {
  margin: .3rem 0 0;
  font-style: italic;
}
.load-row {
  display: grid;
  grid-template-columns: 1fr 2.7rem;
  gap: .35rem .55rem;
  margin-bottom: 1rem;
}
.select-label {
  grid-column: 2;
  justify-self: end;
}
.primary-button,
.play-button {
  min-height: 2.7rem;
  border: 1px solid var(--ink);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .8rem;
  font-weight: 600;
}
.primary-button:hover,
.play-button:hover {
  border: 1px solid var(--rule);
  color: var(--rule);
}
.primary-button:focus-visible,
.play-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--rule) 25%, transparent);
  outline-offset: 2px;
}
.primary-button:disabled,
.play-button:disabled {
  border-color: var(--box);
  background: transparent;
  color: var(--muted);
  cursor: not-allowed;
  opacity: .55;
}
.control-icon {
  display: grid;
  width: 1.25rem;
  height: 1.25rem;
  margin: auto;
  place-items: center;
}
.control-icon svg {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.stop-symbol,
.regen-symbol,
.play-button.is-stopping .play-symbol {
  display: none;
}
.regen-symbol {
  grid-area: 1 / 1;
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1;
}
.play-button.is-regenerating:not(.is-stopping) .play-symbol {
  display: none;
}
.play-button.is-regenerating:not(.is-stopping) .regen-symbol {
  display: block;
}
.play-button.is-stopping .stop-symbol {
  display: block;
}
.download {
  margin-top: .72rem;
}
.progress-track {
  height: 3px;
  overflow: hidden;
  background: var(--box);
}
.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width .15s ease;
}
.status-line {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: .35rem;
  color: var(--muted);
  font-size: .68rem;
}
.rule {
  margin: 1.25rem 0;
  border-top: 1px solid var(--box);
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem .55rem;
}
.parameter-grid > .field > label {
  min-height: 1.55rem;
  align-items: end;
  line-height: 1.15;
}
.final-grid {
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr));
  margin-top: .75rem;
}
.final-grid > .field:not(.stop-field) > label {
  min-height: 1.55rem;
  align-items: end;
}
.stop-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: .25rem;
  min-height: 1.55rem;
  margin-bottom: .35rem;
}
.stop-heading > label {
  margin-bottom: 0;
}
.stop-heading > label:first-child {
  white-space: nowrap;
}
.stop-heading .check-label,
.select-label {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: start;
  gap: .35rem;
  color: var(--muted);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .58rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}
.check-label input {
  width: .72rem;
  height: .72rem;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent);
}
.privacy-note {
  display: flex;
  gap: .5rem;
  margin: 1.25rem 0 0;
  padding-top: .9rem;
  border-top: 1px solid var(--box);
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.45;
}
.privacy-note span {
  color: var(--success);
  font-weight: 700;
}
details {
  margin-top: .7rem;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.5;
}
summary {
  cursor: pointer;
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
}
details p {
  margin: .55rem 0 0;
}

.toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: max(1.2rem, env(safe-area-inset-bottom));
  max-width: calc(100% - 2rem);
  padding: .7rem 1rem;
  transform: translate(-50%, 1rem);
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-family: "Libertinus Sans", Helvetica, Arial, sans-serif;
  font-size: .78rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 840px) {
  main {
    width: min(100% - 2rem, 680px);
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 1.25rem;
    height: 100dvh;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  }
  .controls {
    position: static;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    align-self: stretch;
    -webkit-overflow-scrolling: touch;
  }
  #editor {
    min-height: 50vh;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  .editor-footer {
    display: none;
  }
  #editor-help {
    display: none;
  }
  body {
    height: 100dvh;
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  main {
    width: calc(100% - 1.25rem);
    gap: 1rem;
    padding-top: 1rem;
  }
  .editor-heading {
    align-items: baseline;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
  }
  .controls {
    padding: .8rem;
  }
  .control-heading {
    margin-bottom: .85rem;
  }
  #editor {
    min-height: 48vh;
    padding: .85rem;
    font-size: 1.13rem;
  }
  .field-grid {
    gap: .6rem .35rem;
  }
  .final-grid {
    grid-template-columns: minmax(0, 1.25fr) repeat(2, minmax(0, 1fr));
    margin-top: .6rem;
  }
  .field label {
    font-size: .62rem;
    letter-spacing: .02em;
  }
  .parameter-grid > .field > label {
    min-height: 1.45rem;
  }
  .parameter-grid .field label span,
  .stop-heading > label:first-child span {
    display: none;
  }
  .final-grid > .field:not(.stop-field) > label,
  .stop-heading {
    min-height: 1.45rem;
  }
  .rule {
    margin: .85rem 0;
  }
  .load-row {
    margin-bottom: .7rem;
  }
  .privacy-note {
    margin-top: .9rem;
    padding-top: .7rem;
  }
  input,
  select {
    min-height: 2.5rem;
    padding-inline: .4rem;
    font-size: .76rem;
  }
  .primary-button,
  .play-button {
    min-height: 3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
