:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-strong: #151923;
  --line: #dfe5ed;
  --line-strong: #c9d2de;
  --text: #17202c;
  --muted: #667386;
  --blue: #2d74e8;
  --blue-strong: #195fcf;
  --green: #13a06f;
  --amber: #c68418;
  --red: #d93a4a;
  --shadow: 0 16px 38px rgba(23, 32, 44, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

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

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 2vw, 28px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #ffffff 0%, #f7f9fc 100%);
  box-shadow: var(--shadow);
}

.eyebrow,
.panel-kicker {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 6px;
}

h1 {
  font-size: clamp(26px, 2.4vw, 38px);
  line-height: 1.18;
  font-weight: 900;
}

.subtitle {
  max-width: 780px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 900;
  white-space: nowrap;
}

.button.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 10px 20px rgba(45, 116, 232, 0.22);
}

.button.primary:hover {
  background: var(--blue-strong);
}

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

.status-pill,
.count-chip,
.prompt-meter {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 11px;
  background: #edf3ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.good {
  background: #e8f7f0;
  color: var(--green);
}

.status-pill.warn {
  background: #fff5df;
  color: var(--amber);
}

.production-grid {
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(440px, 1fr) minmax(340px, 430px);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.recipe-panel,
.result-column {
  position: sticky;
  top: 16px;
}

.recipe-panel,
.brief-panel,
.prompt-panel,
.result-panel,
.history-panel {
  padding: 16px;
}

.workbench,
.result-column {
  display: grid;
  gap: 16px;
}

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

.panel-head.compact {
  margin-bottom: 10px;
}

h2 {
  margin-top: 2px;
  font-size: 17px;
  line-height: 1.3;
  font-weight: 900;
}

h3 {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 900;
}

.divider {
  height: 1px;
  margin: 16px -16px;
  background: var(--line);
}

.recipe-grid {
  display: grid;
  gap: 9px;
}

.recipe-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  min-height: 72px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.recipe-card:hover,
.recipe-card.active {
  border-color: #9bbcf6;
  background: #f0f6ff;
}

.recipe-card img {
  grid-row: 1 / 3;
  width: 54px;
  height: 54px;
  border-radius: var(--radius);
  object-fit: cover;
}

.recipe-card span {
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe-card small,
.style-summary,
.field span small,
.result-copy p,
.history-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.token-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.token-stack span {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-soft);
  color: #425066;
  font-size: 12px;
  font-weight: 800;
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: #354052;
  font-size: 13px;
  font-weight: 850;
}

.field span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 15px;
}

input,
select {
  height: 46px;
  padding: 0 12px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 11px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #8db8fb;
  box-shadow: 0 0 0 3px rgba(45, 116, 232, 0.13);
}

.option-deck {
  display: grid;
  grid-template-columns: minmax(250px, 1.3fr) minmax(230px, 1fr) minmax(130px, .62fr) minmax(120px, .55fr);
  gap: 10px;
  align-items: end;
  margin: 14px 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  min-height: 46px;
  padding: 4px;
  border-radius: var(--radius);
  background: #edf1f6;
}

.segment,
.filter-chip,
.text-button,
.icon-action {
  cursor: pointer;
}

.segment {
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.segment.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 2px 8px rgba(23, 32, 44, 0.08);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface-soft);
  color: #354052;
  font-size: 13px;
  font-weight: 850;
}

.switch-row span {
  display: grid;
  gap: 2px;
}

.switch-row input {
  width: 42px;
  height: 24px;
  accent-color: var(--blue);
}

.text-button {
  min-height: 32px;
  border-radius: 7px;
  padding: 0 9px;
  background: #edf3ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.text-button.danger {
  background: #fff0f2;
  color: var(--red);
}

.prompt-panel {
  overflow: hidden;
}

#promptPreview {
  overflow: auto;
  min-height: 260px;
  max-height: 440px;
  margin: 0;
  border-radius: var(--radius);
  padding: 15px;
  background: #111827;
  color: #dbe7ff;
  font: 13px/1.62 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.filter-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-chip {
  min-height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.filter-chip.active {
  background: #edf3ff;
  color: var(--blue);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 178px), 1fr));
  gap: 12px;
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.result-card.kept {
  border-color: #78cba7;
}

.result-card.failed {
  border-color: #ffb7c0;
}

.thumb-wrap {
  position: relative;
  display: grid;
  aspect-ratio: 1 / 1;
  min-height: 176px;
  place-items: center;
  background:
    linear-gradient(45deg, #e7ebf0 25%, transparent 25% 75%, #e7ebf0 75%),
    linear-gradient(45deg, #e7ebf0 25%, #f9fbfd 25% 75%, #e7ebf0 75%);
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
}

.result-card.pending .thumb-wrap::after {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 3px solid rgba(45, 116, 232, 0.18);
  border-top-color: var(--blue);
  border-radius: 50%;
  content: "";
  animation: spin 760ms linear infinite;
}

.result-card.failed .thumb-wrap {
  background: #fff5f6;
}

.thumb-wrap img {
  max-width: 88%;
  max-height: 88%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 14px 18px rgba(23, 32, 44, 0.18));
}

.status-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(21, 25, 35, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.result-card.failed .status-badge {
  background: var(--red);
}

.result-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.result-copy {
  min-width: 0;
}

.result-copy h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.icon-action {
  min-height: 34px;
  border-radius: 7px;
  background: var(--surface-soft);
  color: #354052;
  font-size: 12px;
  font-weight: 900;
}

.icon-action:hover {
  background: #edf3ff;
  color: var(--blue);
}

.history-panel {
  max-height: 420px;
  overflow: auto;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 56px;
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.history-item span {
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (max-width: 1380px) {
  .production-grid {
    grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  }

  .result-column {
    position: static;
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1.3fr) minmax(280px, .7fr);
  }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .button {
    flex: 1 1 150px;
  }

  .production-grid,
  .result-column {
    grid-template-columns: 1fr;
  }

  .recipe-panel {
    position: static;
  }

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

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

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

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .recipe-panel,
  .brief-panel,
  .prompt-panel,
  .result-panel,
  .history-panel {
    padding: 12px;
  }

  .brief-grid,
  .option-deck,
  .recipe-grid {
    grid-template-columns: 1fr;
  }

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

  .filter-row,
  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .filter-chip,
  .topbar-actions .button,
  .status-pill {
    flex: 1;
    justify-content: center;
  }

  .thumb-wrap {
    min-height: 210px;
  }
}
