:root {
  color-scheme: light;
  --ink: #202422;
  --muted: #68706c;
  --line: #d8ddd9;
  --line-strong: #b8c1bc;
  --canvas: #f2f3f0;
  --panel: #ffffff;
  --soft: #f8f8f6;
  --accent: #286f61;
  --accent-dark: #1d5148;
  --accent-soft: #e6f0ed;
  --danger: #a4434d;
  --danger-soft: #f7e9eb;
  --shadow: 0 8px 24px rgba(27, 36, 32, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

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

h1,
h2,
h3,
p,
figure {
  margin: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  min-height: 68px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 9px;
  height: 34px;
  border-radius: 3px;
  background: var(--accent);
}

.brand h1 {
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.view-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.view-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.view-tab.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(32, 36, 34, 0.12);
}

.count-badge {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 8px;
  background: #e3e6e3;
  font-size: 10px;
  text-align: center;
}

.icon-button {
  justify-self: end;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 18px;
}

.app-view {
  display: none;
}

.app-view.is-active {
  display: block;
}

.optimize-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  max-width: 1680px;
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  padding: 14px;
}

.editor,
.inspector,
.reference-content,
.collection-nav {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor {
  min-width: 0;
  overflow: hidden;
}

.mobile-preview-switch,
.mobile-scheme-notes {
  display: none;
}

.desktop-compare-switch {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-height: 42px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
}

.desktop-compare-switch > div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.desktop-compare-switch button {
  min-width: 62px;
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}

.desktop-compare-switch button.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(32, 36, 34, 0.12);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  min-height: 55vh;
  background: var(--line);
}

.preview-panel {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 480px;
  overflow: hidden;
  background: #e9e9e5;
}

.preview-panel figcaption {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 5px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  font-size: 11px;
  font-weight: 700;
}

.preview-panel img {
  display: none;
  width: 100%;
  height: 100%;
  max-height: 68vh;
  object-fit: contain;
}

.preview-panel.has-image img {
  display: block;
}

.preview-panel.has-image .preview-empty {
  display: none;
}

.preview-empty {
  padding: 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.preview-render-state {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 7px;
  padding: 20px;
  background: rgba(31, 36, 33, 0.52);
  color: #fff;
  text-align: center;
  backdrop-filter: blur(2px);
}

.preview-render-state strong {
  font-size: 13px;
}

.preview-render-state small {
  color: rgba(255, 255, 255, 0.82);
  font-size: 11px;
}

.render-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: render-spin 800ms linear infinite;
}

.preview-panel.is-preview-updated {
  box-shadow: inset 0 0 0 3px var(--accent);
}

@keyframes render-spin {
  to { transform: rotate(360deg); }
}

.candidate-section {
  padding: 16px;
}

.direction-section,
.used-reference-section {
  padding: 16px;
  border-top: 1px solid var(--line);
}

.direction-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.direction-card {
  display: grid;
  gap: 6px;
  min-height: 118px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.direction-card strong {
  font-size: 13px;
}

.direction-card span,
.direction-card small {
  line-height: 1.5;
}

.direction-card span {
  color: var(--ink);
  font-size: 12px;
}

.direction-card small {
  color: var(--muted);
  font-size: 11px;
}

.direction-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.direction-card:disabled {
  cursor: progress;
  opacity: 0.7;
}

.direction-section > .primary-button {
  width: 100%;
  margin-top: 12px;
}

.used-reference-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.used-reference-heading strong {
  font-size: 12px;
}

.used-reference-heading span {
  color: var(--muted);
  font-size: 11px;
}

.used-reference-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.used-reference {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.used-reference img {
  width: 54px;
  height: 54px;
  border-radius: 5px;
  object-fit: cover;
  background: #e5e6e2;
}

.used-reference span {
  display: -webkit-box;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.section-heading,
.collection-header,
.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2,
.library-toolbar h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.section-heading p,
.library-toolbar p,
.collection-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.collection-chip {
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 650;
}

.candidate-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.candidate-card,
.candidate-placeholder {
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.candidate-placeholder {
  display: grid;
  place-items: center;
  color: #979d99;
  font-size: 12px;
}

.candidate-card {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.candidate-card.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.candidate-card img {
  width: 104px;
  height: 100%;
  min-height: 124px;
  object-fit: cover;
  background: #e5e6e2;
}

.candidate-copy {
  align-self: center;
  min-width: 0;
  padding: 11px;
}

.candidate-copy strong,
.candidate-copy span {
  display: block;
}

.candidate-copy strong {
  font-size: 13px;
}

.candidate-copy span {
  display: -webkit-box;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.inspector {
  align-self: start;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.upload-control {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: var(--soft);
  cursor: pointer;
}

.upload-control input,
.primary-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-symbol {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
}

.upload-control strong,
.upload-control small {
  display: block;
}

.upload-control strong {
  font-size: 13px;
}

.upload-control small {
  max-width: 220px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button,
.secondary-button,
.quiet-button {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled {
  border-color: #b5bdb8;
  background: #b5bdb8;
  cursor: not-allowed;
}

.generation-progress {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.generation-progress.is-error {
  border-color: #d9aeb3;
  background: var(--danger-soft);
}

.generation-context {
  display: grid;
  gap: 7px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.generation-context > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.generation-context > div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.generation-context strong {
  padding: 5px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 10px;
}

.progress-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.progress-heading strong {
  font-size: 12px;
  line-height: 1.45;
}

.progress-heading output {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: #dfe4e0;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.progress-note {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.generation-progress.is-error .progress-track span {
  background: var(--danger);
}

.progress-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.progress-steps li {
  position: relative;
  min-width: 0;
  padding-left: 13px;
  overflow: hidden;
  color: #929995;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-steps li::before {
  position: absolute;
  top: 4px;
  left: 1px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c5cbc7;
  content: "";
}

.progress-steps li.is-current {
  color: var(--accent-dark);
  font-weight: 700;
}

.progress-steps li.is-current::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.progress-steps li.is-done {
  color: #59645f;
}

.progress-steps li.is-done::before {
  background: var(--accent);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.secondary-button:disabled {
  border-color: #c6ccc8;
  background: #e1e4e2;
  color: #777f7b;
  cursor: not-allowed;
}

.download-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.strength-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.beauty-controls {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.beauty-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.beauty-heading > div {
  display: grid;
  gap: 2px;
}

.beauty-heading strong {
  font-size: 13px;
}

.beauty-heading small,
.beauty-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.switch-control {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 24px;
  cursor: pointer;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-control > span:first-of-type {
  position: absolute;
  inset: 0;
  border: 1px solid #aeb7b2;
  border-radius: 12px;
  background: #d8ddda;
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-control > span:first-of-type::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 30, 26, 0.24);
  content: "";
  transition: transform 160ms ease;
}

.switch-control input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
}

.switch-control input:checked + span::after {
  transform: translateX(16px);
}

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

.switch-control input:disabled + span {
  cursor: progress;
  opacity: 0.55;
}

.beauty-settings,
.beauty-detail-grid {
  display: grid;
  gap: 8px;
}

.beauty-details summary {
  width: fit-content;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.beauty-apply-button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: not-allowed;
  font-weight: 700;
}

.beauty-apply-button.is-pending {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.beauty-apply-button:disabled {
  opacity: 0.58;
}

.beauty-detail-grid {
  padding-top: 10px;
}

.beauty-detail-grid .slider-heading label,
.beauty-detail-grid .slider-heading output {
  font-size: 11px;
}

.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;
}

.control-block.is-rendering input[type="range"] {
  cursor: progress;
  opacity: 0.55;
}

.control-block.is-rendering .beauty-apply-button {
  cursor: progress;
}

.compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
}

.analysis-block,
.control-block,
.feedback-block {
  display: grid;
  gap: 9px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.block-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.analysis-block > strong {
  font-size: 13px;
}

.analysis-block p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  padding: 4px 6px;
  border-radius: 5px;
  background: #eef0ed;
  color: #5b625e;
  font-size: 10px;
}

.slider-heading {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

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

.feedback-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quiet-button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 11px;
}

.quiet-button.is-negative {
  color: var(--danger);
}

.quiet-button.is-recorded {
  border-color: #d2d6d3;
  background: #e3e6e4;
  color: #858c88;
  cursor: default;
}

.task-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.library-toolbar {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 20px 14px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.library-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 14px;
  max-width: 1500px;
  min-height: calc(100vh - 150px);
  margin: 0 auto;
  padding: 0 20px 20px;
}

.collection-nav {
  align-self: start;
  display: grid;
  gap: 4px;
  padding: 8px;
}

.collection-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}

.collection-button.is-active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.collection-button span:last-child {
  color: var(--muted);
  font-size: 10px;
}

.reference-content {
  min-width: 0;
  padding: 16px;
}

.collection-header {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.collection-header h3 {
  font-size: 15px;
}

.collection-header > span {
  color: var(--muted);
  font-size: 11px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.reference-empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 280px;
  color: var(--muted);
  font-size: 13px;
}

.reference-card {
  display: grid;
  grid-template-rows: 190px auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.reference-card.is-disabled {
  opacity: 0.58;
}

.reference-card > img {
  width: 100%;
  height: 190px;
  object-fit: cover;
  background: #e8e9e6;
}

.reference-body {
  display: grid;
  gap: 9px;
  padding: 11px;
}

.reference-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.reference-title-row strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-title-row button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
}

.reference-traits {
  display: -webkit-box;
  min-height: 34px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

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

.reference-controls select {
  min-width: 0;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
}

.weight-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 28px;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 13px;
  border-radius: 7px;
  background: #202422;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.result-ready-action {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 45;
  min-height: 46px;
  border: 1px solid var(--accent-dark);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(21, 56, 49, 0.24);
  font-weight: 700;
}

.is-busy {
  cursor: progress;
}

@media (max-width: 1050px) {
  .optimize-layout {
    grid-template-columns: 1fr;
  }

  .inspector {
    order: -1;
    grid-template-columns: minmax(240px, 1fr) minmax(180px, 260px);
    align-items: start;
  }

  .analysis-block,
  .control-block,
  .feedback-block,
  .task-status {
    grid-column: 1 / -1;
  }

  .candidate-card {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .candidate-card img {
    width: 80px;
  }
}

@media (max-width: 760px) {
  .generation-progress,
  .candidate-section,
  .direction-section,
  .mobile-preview-switch {
    scroll-margin-top: 118px;
  }

  .app-header {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 9px 10px;
  }

  .brand p,
  .icon-button {
    display: none;
  }

  .view-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .view-tab {
    flex: 1;
    justify-content: center;
  }

  .optimize-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
  }

  .editor,
  .inspector {
    display: contents;
  }

  .upload-control,
  #optimizeButton,
  .generation-progress,
  .analysis-block,
  .control-block,
  .feedback-block,
  .task-status,
  .direction-section,
  .candidate-section,
  .used-reference-section,
  .preview-grid,
  .mobile-preview-switch,
  .mobile-scheme-notes {
    width: 100%;
  }

  .preview-grid,
  .direction-section,
  .candidate-section,
  .used-reference-section,
  .generation-progress,
  .analysis-block,
  .control-block,
  .feedback-block,
  .task-status {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }

  body[data-workflow="empty"] .upload-control,
  body[data-workflow="ready"] .upload-control {
    order: 0;
  }

  body[data-workflow="empty"] #optimizeButton,
  body[data-workflow="ready"] #optimizeButton {
    order: 1;
  }

  body[data-workflow="empty"] .task-status,
  body[data-workflow="ready"] .task-status {
    order: 2;
  }

  body[data-workflow="empty"] .preview-grid,
  body[data-workflow="ready"] .preview-grid {
    order: 3;
  }

  body[data-workflow="analyzing"] .upload-control,
  body[data-workflow="analyzing"] #optimizeButton,
  body[data-workflow="generating"] .upload-control,
  body[data-workflow="generating"] #optimizeButton,
  body[data-workflow="generating"] .preview-grid,
  body[data-workflow="generating"] .used-reference-section,
  body[data-workflow="generating"] .direction-section,
  body[data-workflow="generating"] .candidate-section,
  body[data-workflow="results"] .upload-control,
  body[data-workflow="results"] #optimizeButton,
  body[data-workflow="results"] .used-reference-section,
  body[data-workflow="results"] .generation-progress {
    display: none !important;
  }

  body[data-workflow="analyzing"] .task-status,
  body[data-workflow="generating"] .task-status,
  body[data-workflow="directions"] .task-status {
    display: none;
  }

  body[data-workflow="analyzing"] .generation-progress,
  body[data-workflow="generating"] .generation-progress {
    order: 0;
    min-height: 260px;
    align-content: center;
    padding: 20px 16px;
  }

  body[data-workflow="analyzing"] .preview-grid {
    order: 1;
  }

  body[data-workflow="generating"] .analysis-block {
    order: 1;
  }

  body[data-workflow="directions"] .preview-grid {
    order: 0;
  }

  body[data-workflow="directions"] .direction-section {
    order: 1;
  }

  body[data-workflow="directions"] .analysis-block {
    order: 2;
  }

  body[data-workflow="directions"] .used-reference-section {
    order: 3;
  }

  body[data-workflow="directions"] .task-status {
    order: 4;
  }

  body[data-workflow="directions"] .generation-progress:not([hidden]) {
    order: -1;
  }

  body[data-workflow="directions"] .upload-control,
  body[data-workflow="directions"] #optimizeButton {
    display: none;
  }

  body[data-workflow="results"] .mobile-preview-switch {
    order: 0;
  }

  body[data-workflow="results"] .preview-grid {
    order: 1;
  }

  body[data-workflow="results"] .mobile-scheme-notes {
    order: 2;
  }

  body[data-workflow="results"] .candidate-section {
    order: 3;
  }

  body[data-workflow="results"] .control-block {
    order: 4;
  }

  body[data-workflow="results"] .feedback-block {
    order: 5;
  }

  body[data-workflow="results"] .analysis-block {
    order: 6;
  }

  body[data-workflow="results"] .task-status {
    order: 7;
  }

  .analysis-block,
  .control-block,
  .feedback-block,
  .task-status {
    grid-column: auto;
  }

  .preview-grid {
    grid-template-columns: 1fr;
    min-height: 0;
    background: #e9e9e5;
  }

  .preview-panel {
    display: none;
    min-height: min(64vh, 680px);
  }

  body[data-workflow="directions"] .preview-panel {
    min-height: min(46vh, 480px);
  }

  .preview-panel.is-mobile-visible {
    display: grid;
  }

  .preview-panel img {
    max-height: min(68vh, 720px);
  }

  .mobile-preview-switch {
    display: grid;
    width: calc(100% - 20px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
    margin: 10px 10px 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--soft);
  }

  .desktop-compare-switch {
    display: none !important;
  }

  .mobile-preview-switch button {
    min-height: 36px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 650;
  }

  .mobile-preview-switch button.is-active {
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 1px 4px rgba(32, 36, 34, 0.12);
  }

  .mobile-scheme-notes {
    display: block;
    padding: 12px 12px 2px;
  }

  .mobile-scheme-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .mobile-scheme-heading strong {
    font-size: 14px;
  }

  .mobile-scheme-heading span {
    color: var(--muted);
    font-size: 11px;
  }

  .mobile-scheme-notes > p,
  .mobile-scheme-notes details p {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }

  .mobile-scheme-notes > p {
    margin-top: 6px;
  }

  .mobile-scheme-notes details {
    margin-top: 7px;
  }

  .mobile-scheme-notes summary {
    width: fit-content;
    cursor: pointer;
    font-size: 12px;
    font-weight: 650;
  }

  .mobile-scheme-notes details p {
    margin-top: 6px;
  }

  .candidate-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .candidate-card,
  .candidate-placeholder {
    min-height: 102px;
  }

  .candidate-section {
    padding: 10px 12px 14px;
  }

  .direction-section,
  .used-reference-section {
    padding: 12px;
  }

  .direction-section > .primary-button {
    position: sticky;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 5;
    box-shadow: 0 8px 22px rgba(21, 56, 49, 0.2);
  }

  .direction-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .direction-card {
    min-height: 0;
    padding: 11px;
  }

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

  .candidate-section .section-heading {
    display: none;
  }

  .candidate-card {
    display: block;
  }

  .candidate-card img {
    width: 100%;
    height: auto;
    min-height: 76px;
    aspect-ratio: 4 / 3;
  }

  .candidate-copy {
    display: block;
    padding: 7px 5px 8px;
    text-align: center;
  }

  .candidate-copy strong {
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .candidate-copy span {
    display: none;
  }

  .library-toolbar {
    align-items: flex-start;
    padding: 14px 10px 10px;
  }

  .toolbar-actions {
    flex-direction: column;
  }

  .library-layout {
    grid-template-columns: 1fr;
    padding: 0 10px 10px;
  }

  .collection-nav {
    display: flex;
    overflow-x: auto;
  }

  .collection-button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

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