:root {
  color-scheme: dark;
  --bg: #090b0a;
  --panel: #111513;
  --panel-2: #171d1a;
  --line: #2c3932;
  --text: #e8f3ed;
  --muted: #8ba095;
  --accent: #5ee09e;
  --accent-2: #f7bf73;
  --danger: #ff716d;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(94, 224, 158, 0.08), transparent 220px),
    linear-gradient(90deg, rgba(247, 191, 115, 0.05), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  min-height: 100vh;
}

.controls {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 21, 19, 0.96), rgba(9, 11, 10, 0.96));
  padding: 24px;
  overflow-y: auto;
}

.brand {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}

.appNav {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.appNav a {
  text-align: center;
}

.appNav a[aria-current="page"] {
  border-color: var(--accent);
  color: #06120c;
  background: var(--accent);
}

.brand .appNav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
}

.accountControls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.accountControls[hidden] {
  display: none;
}

.accountControls a {
  color: var(--accent-2);
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.tab,
.primary,
.secondary,
.toolButton,
.linkButton,
.download {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  padding: 10px 12px;
  text-decoration: none;
  cursor: pointer;
}

.tab:hover,
.secondary:hover,
.toolButton:hover,
.download:hover,
.linkButton:hover {
  border-color: var(--accent-2);
}

.tab.is-active,
.primary {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
  color: #06120c;
  background: var(--accent);
}

.primary {
  width: 100%;
  margin-top: 6px;
  font-weight: 700;
}

.primary:disabled,
.primary[aria-disabled="true"],
.secondary:disabled,
.toolButton:disabled {
  cursor: wait;
  opacity: 0.62;
}

.secondary {
  min-height: 38px;
  color: var(--accent-2);
  background: #0b0f0d;
}

.toolButton {
  width: 42px;
  min-height: 38px;
  align-self: end;
  color: var(--accent-2);
  padding: 8px;
}

.toolButton.wide {
  width: auto;
  min-width: 72px;
}

.seedButton {
  min-width: 86px;
  min-height: 38px;
  align-self: end;
  border: 1px solid var(--line);
  color: var(--accent-2);
  background: var(--panel-2);
  padding: 8px 10px;
  cursor: pointer;
}

.seedButton:hover {
  border-color: var(--accent-2);
}

.linkButton {
  border: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
}

.download {
  color: var(--accent-2);
}

.download.is-disabled {
  pointer-events: none;
  opacity: 0.35;
}

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

.panel.is-hidden {
  display: none;
}

.formToolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.formToolbar .primary {
  margin-top: 0;
}

fieldset {
  display: grid;
  gap: 12px;
  margin: 0;
  border: 1px solid var(--line);
  padding: 13px;
  background: rgba(12, 16, 14, 0.6);
}

legend {
  padding: 0 7px;
  color: var(--accent-2);
  font-size: 12px;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.fieldHint {
  margin-top: -5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: #0b0f0d;
  padding: 8px 10px;
}

select[data-palette] {
  border-left-width: 5px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.row {
  display: grid;
  gap: 10px;
}

.row.two {
  grid-template-columns: 1fr 1fr;
}

.row.compact {
  align-items: end;
}

.row.seedRow {
  grid-template-columns: 1fr auto;
}

.row.range {
  grid-template-columns: 1fr 54px;
  align-items: end;
}

output {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--accent);
  background: #0b0f0d;
  font-size: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  text-transform: none;
  color: var(--text);
}

.check input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.presetGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset {
  min-height: 38px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0b0f0d;
  line-height: 1.2;
  padding: 7px 8px;
  cursor: pointer;
}

.preset:hover,
.preset.is-active {
  border-color: var(--accent);
  color: var(--text);
}

.orientationRow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.orientationRow span {
  min-height: 38px;
  display: grid;
  place-items: center start;
  border: 1px solid var(--line);
  color: var(--accent-2);
  background: #0b0f0d;
  padding: 8px 10px;
  font-size: 12px;
}

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

.artifactSet {
  display: grid;
  gap: 8px;
}

.artifactSet > span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.chip span {
  display: grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0b0f0d;
  cursor: pointer;
}

.chip input:checked + span {
  border-color: var(--accent);
  color: #06120c;
  background: var(--accent);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.actionRow {
  position: sticky;
  bottom: -24px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: end;
  padding-top: 4px;
  padding-bottom: 2px;
  background: linear-gradient(180deg, transparent, rgba(9, 11, 10, 0.95) 14px);
}

.preview {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "toolbar"
    "progress"
    "stage"
    "history";
  min-width: 0;
  min-height: 0;
}

.previewToolbar {
  grid-area: toolbar;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.metaTitle {
  color: var(--text);
  font-size: 14px;
}

.metaSub {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.toolbarActions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.compactOnly {
  display: none;
}

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

.generationProgress {
  grid-area: progress;
  display: grid;
  gap: 8px;
  padding: 12px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 16, 14, 0.94);
}

.generationProgress[hidden] {
  display: none;
}

.generationProgressHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--accent);
  font-size: 12px;
}

#generationProgressElapsed,
.generationProgressDetail {
  color: var(--muted);
}

.generationProgressDetail {
  font-size: 11px;
  line-height: 1.4;
}

.generationProgressTrack {
  position: relative;
  height: 5px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  background: #060907;
}

.generationProgressTrack span {
  display: block;
  width: 34%;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 60%, transparent);
  animation: generation-progress 1.15s ease-in-out infinite;
}

.generationProgress.is-error .generationProgressHeader,
.generationProgress.is-error .generationProgressDetail {
  color: var(--danger);
}

.generationProgress.is-error .generationProgressTrack {
  display: none;
}

@keyframes generation-progress {
  from { transform: translateX(-105%); }
  to { transform: translateX(300%); }
}

.stage {
  grid-area: stage;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  padding: 18px;
  background: rgba(9, 11, 10, 0.82);
}

#previewImage,
#previewVideo {
  display: none;
  max-width: min(100%, 1280px);
  max-height: calc(100vh - 130px);
  object-fit: contain;
  box-shadow: 0 18px 50px var(--shadow);
  background: #000;
}

#previewImage.is-visible,
#previewVideo.is-visible {
  display: block;
}

.history {
  grid-area: history;
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
  background: rgba(9, 11, 10, 0.78);
}

.historyHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.historyGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.savedLibrary {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.savedLibrary[hidden] {
  display: none;
}

.savedLibrary .historyHeader > div {
  min-width: 0;
}

.savedLibrary .historyHeader p {
  max-width: 720px;
  line-height: 1.45;
}

.libraryGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.libraryEmpty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  padding: 12px;
}

.libraryItem {
  display: grid;
  gap: 7px;
  min-width: 0;
  border: 1px solid var(--line);
  padding: 8px;
  background: #0b0f0d;
}

.libraryPreview,
.libraryConsent,
.libraryDelete {
  border: 1px solid var(--line);
  color: var(--text);
  background: #0b0f0d;
  cursor: pointer;
  font: inherit;
}

.libraryPreview {
  display: grid;
  gap: 6px;
  padding: 0;
  text-align: left;
}

.libraryPreview img,
.libraryPreview video {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: #000;
}

.libraryPreview span,
.libraryDetails {
  overflow: hidden;
  padding: 0 6px 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.libraryDetails {
  padding: 0;
  color: var(--muted);
}

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

.libraryConsent,
.libraryDelete {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 10px;
}

.libraryConsent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.libraryConsent::before {
  content: "☆";
  font-size: 16px;
  line-height: 1;
}

.libraryConsent[aria-pressed="true"] {
  border-color: var(--accent);
  color: #06120c;
  background: var(--accent);
}

.libraryConsent[aria-pressed="true"]::before {
  content: "★";
}

.libraryDelete {
  color: var(--danger);
}

.loginPage {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.loginPanel {
  width: min(100%, 520px);
  border: 1px solid var(--line);
  padding: 28px;
  background: var(--panel);
  box-shadow: 0 18px 50px var(--shadow);
}

.loginEyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  letter-spacing: 0.12em;
}

.loginAction {
  display: block;
  margin-top: 24px;
  text-align: center;
}

.loginPrivacy {
  border-top: 1px solid var(--line);
  margin-top: 24px;
  padding-top: 14px;
  line-height: 1.5;
}

.loginError {
  color: var(--danger);
}

.historyItem {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 1px solid var(--line);
  padding: 7px;
  color: var(--muted);
  background: #0b0f0d;
  cursor: pointer;
  text-align: left;
}

.historyItem:hover,
.historyItem.is-active {
  border-color: var(--accent-2);
}

.historyItem img,
.historyItem video {
  width: 100%;
  height: 72px;
  object-fit: contain;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 14px 14px;
}

.historyItem span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

@media (min-width: 861px) {
  .generatorPage {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .app {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .controls {
    height: 100%;
    overscroll-behavior: contain;
  }

  .preview {
    height: 100%;
  }
}

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

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    min-height: 48vh;
  }

  .preview {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .compactOnly {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .actionRow {
    bottom: -16px;
  }
}

@media (max-width: 460px) {
  .controls {
    padding: 16px;
  }

  .row.two {
    grid-template-columns: 1fr;
  }

  .previewToolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbarActions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #backToSettings {
    grid-column: 1 / -1;
  }

  .generationProgressHeader {
    align-items: start;
    flex-direction: column;
    gap: 4px;
  }

  .presetGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chipGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .generationProgressTrack span {
    width: 100%;
    animation: none;
    background: repeating-linear-gradient(
      90deg,
      var(--accent) 0 12px,
      color-mix(in srgb, var(--accent) 36%, transparent) 12px 20px
    );
  }
}
