:root {
  color-scheme: light;
  --bg: #f6f7f7;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #1b2420;
  --muted: #68756f;
  --line: #e3e8e5;
  --line-strong: #cfd8d4;
  --brand: #0a6c63;
  --brand-strong: #07524b;
  --brand-soft: #e7f4f1;
  --blue: #315f9f;
  --amber: #9a6419;
  --rose: #a33b58;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 30, 26, 0.05), 0 8px 24px rgba(20, 30, 26, 0.05);
  --focus-ring: 0 0 0 3px rgba(10, 108, 99, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(10, 108, 99, 0.05), transparent 180px),
    var(--bg);
  font-family:
    "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
}

button,
select {
  min-height: 36px;
}

button {
  cursor: pointer;
  padding: 0 12px;
  font-weight: 700;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

button:hover,
select:hover {
  border-color: var(--line-strong);
  background: #fbfcfc;
}

button:active {
  transform: translateY(1px);
}

input,
select,
textarea {
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

button:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

h1,
h2,
p {
  margin: 0;
}

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

h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

h2 {
  color: #3d4a44;
  font-size: 0.85rem;
  font-weight: 800;
}

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 18px 20px 40px;
}

.tool {
  min-height: calc(100vh - 36px);
}

.topbar,
.search-band,
.workspace-grid {
  width: 100%;
}

/* ---------- 상단 브랜드 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  min-height: 52px;
}

.brand-logo {
  display: block;
  width: min(330px, 72vw);
  height: auto;
  flex: none;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

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

.status-pill,
.status-muted,
.panel-subtext {
  color: var(--muted);
  font-size: 0.82rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 0 11px;
  border: 1px solid #cbe2dd;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 700;
}

.status-pill.error {
  border-color: #efc8d3;
  background: #fff0f4;
  color: var(--rose);
}

/* ---------- 검색 밴드 ---------- */

.search-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-box label,
.settings-block label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

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

#searchInput {
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.98rem;
}

.search-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.search-actions select {
  min-height: 44px;
  padding: 0 10px;
}

.search-actions button {
  min-height: 44px;
}

.primary-button {
  border-color: transparent;
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  border-color: transparent;
  background: var(--brand-strong);
}

.primary-button.is-loading {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-button.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

@keyframes loading-slide {
  0% {
    transform: translateX(-110%);
  }
  55% {
    transform: translateX(90%);
  }
  100% {
    transform: translateX(245%);
  }
}

/* ---------- LLM 보조 밴드 ---------- */

.assist-band {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 18px;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.assist-input,
.assist-output {
  display: grid;
  gap: 10px;
  min-width: 0;
  align-content: start;
}

#descriptionInput {
  min-height: 132px;
  resize: vertical;
  padding: 11px 13px;
  line-height: 1.55;
}

.assist-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.assist-controls .primary-button {
  min-height: 40px;
  margin-left: auto;
  padding: 0 18px;
}

.checkbox-label.inline {
  display: inline-flex;
  gap: 7px;
  min-height: 36px;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.checkbox-label.nsfw-toggle:has(input:checked) {
  color: var(--rose);
  font-weight: 700;
}

.suggested-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 82px;
  align-content: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.suggestion-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  min-height: 32px;
  max-width: 100%;
  padding: 4px 11px;
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
  font-size: 0.84rem;
  text-align: left;
}

.suggestion-chip .chip-reason {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
}

.suggestion-chip.is-selected {
  border-color: rgba(10, 108, 99, 0.4);
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.suggestion-chip.is-selected .chip-reason {
  color: inherit;
  opacity: 0.72;
}

.analysis-loading {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  overflow: hidden;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid #c3ddd8;
  border-radius: var(--radius-sm);
  background: #f2faf8;
  color: var(--brand-strong);
}

.analysis-loading[hidden] {
  display: none;
}

.analysis-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(10, 108, 99, 0.2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.analysis-loading-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.analysis-loading-copy strong {
  font-size: 0.88rem;
}

.analysis-loading-copy span {
  color: #52645e;
  font-size: 0.79rem;
  line-height: 1.35;
}

.analysis-progress {
  grid-column: 1 / -1;
  overflow: hidden;
  height: 4px;
  border-radius: 999px;
  background: rgba(10, 108, 99, 0.12);
}

.analysis-progress span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #315f9f);
  animation: loading-slide 1.05s ease-in-out infinite;
}

.natural-heading {
  margin-top: 2px;
}

/* ---------- 연출 프리셋 밴드 ---------- */

.scene-band {
  display: block;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scene-band summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  border-radius: var(--radius);
}

.scene-band summary::-webkit-details-marker {
  display: none;
}

.scene-band summary:hover {
  background: var(--surface-soft);
}

.scene-band summary .panel-subtext {
  overflow: hidden;
  margin-left: auto;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.scene-band[open] .summary-chevron {
  transform: rotate(-135deg);
}

.scene-groups {
  display: grid;
  grid-template-columns: 0.8fr 0.8fr 1.4fr;
  gap: 16px;
  padding: 4px 16px 16px;
}

.scene-group {
  display: grid;
  gap: 9px;
  align-content: start;
  min-width: 0;
}

.scene-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.scene-group-label {
  width: 100%;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
}

.scene-chip {
  min-height: 30px;
  font-size: 0.82rem;
}

/* ---------- 3단 작업 영역 ---------- */

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(420px, 1.55fr) minmax(330px, 1fr);
  gap: 14px;
  align-items: start;
}

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

.filter-panel,
.builder-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.filter-panel::-webkit-scrollbar,
.builder-panel::-webkit-scrollbar {
  width: 8px;
}

.filter-panel::-webkit-scrollbar-thumb,
.builder-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line-strong);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.sub-heading {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.results-heading {
  align-items: center;
}

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

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 12px 14px;
}

.chip-list.compact {
  gap: 6px;
}

.filter-chip {
  min-height: 31px;
  padding: 0 12px;
  border-radius: 999px;
  color: #414f49;
  font-size: 0.84rem;
  font-weight: 600;
}

.filter-chip.is-active {
  border-color: transparent;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

/* ---------- 결과 목록 ---------- */

.results-list {
  min-height: 500px;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  transition: background-color 0.1s ease;
}

.result-row:hover {
  background: #fafcfb;
}

.result-row.is-selected {
  background: #f2faf7;
  box-shadow: inset 3px 0 0 var(--brand);
}

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

.result-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}

.tag-name {
  font-weight: 800;
  word-break: break-word;
}

.tag-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.tag-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef3fb;
  color: var(--blue);
  font-size: 0.73rem;
  font-weight: 700;
}

.meta-pill.type-artist {
  background: #fdf3e3;
  color: var(--amber);
}

.meta-pill.type-character {
  background: #fdf0f4;
  color: var(--rose);
}

.tag-desc {
  margin: 0;
  color: #414e48;
  font-size: 0.89rem;
  line-height: 1.5;
}

.tag-keywords {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.add-button {
  align-self: start;
  min-width: 72px;
}

.result-row.is-selected .add-button {
  border-color: transparent;
  background: var(--brand);
  color: #fff;
}

.empty-state {
  padding: 44px 16px;
  color: var(--muted);
  text-align: center;
}

.load-more {
  display: none;
  width: calc(100% - 28px);
  margin: 14px;
  min-height: 40px;
}

.load-more.is-visible {
  display: block;
}

/* ---------- 빌더 패널 ---------- */

.selected-tags {
  display: grid;
  gap: 7px;
  min-height: 110px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.selected-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto;
  gap: 5px;
  align-items: center;
  min-height: 38px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.selected-name {
  min-width: 0;
  padding-left: 6px;
  font-size: 0.9rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.weight-value {
  min-width: 38px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.small-square {
  width: 32px;
  min-height: 32px;
  padding: 0;
  color: var(--muted);
}

.small-square:hover {
  color: var(--ink);
}

.settings-block,
.output-block,
.booster-block {
  display: grid;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.settings-block input,
.settings-block select {
  min-height: 38px;
  padding: 0 10px;
}

.settings-block.split {
  grid-template-columns: 1fr 1fr;
}

.checkbox-label {
  align-content: end;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 38px;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.settings-block.embedded {
  padding: 0;
  border-bottom: 0;
}

/* ---------- NAI 부스터 (접이식) ---------- */

details.booster-block {
  display: block;
  padding: 0;
  background: var(--surface-soft);
}

details.booster-block summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

details.booster-block summary::-webkit-details-marker {
  display: none;
}

details.booster-block summary:hover {
  background: #f1f5f3;
}

.summary-title {
  color: #3d4a44;
  font-size: 0.85rem;
  font-weight: 800;
}

.summary-chevron {
  width: 9px;
  height: 9px;
  margin-right: 3px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

details.booster-block[open] .summary-chevron {
  transform: rotate(-135deg);
}

details.booster-block > :not(summary) {
  margin: 0 14px 12px;
}

details.booster-block > .settings-block.embedded {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.negative-help {
  padding: 10px 12px;
  border: 1px solid #d9e4df;
  border-radius: var(--radius-sm);
  background: #f1f7f4;
  color: #48564f;
  font-size: 0.8rem;
  line-height: 1.55;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

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

.booster-actions button {
  font-size: 0.85rem;
}

/* ---------- 출력 ---------- */

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.section-title-row > h2 {
  flex: none;
}

.section-title-row > .panel-subtext {
  min-width: 0;
  max-width: 68%;
  overflow: hidden;
  text-align: right;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.section-title-row select {
  min-height: 30px;
  max-width: 46%;
  margin-left: auto;
  padding: 0 8px;
  font-size: 0.79rem;
}

.output-block[hidden] {
  display: none;
}

.copy-small {
  min-height: 29px;
  padding: 0 11px;
  font-size: 0.8rem;
}

.output-text {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  padding: 10px 11px;
  background: var(--surface-soft);
  font-size: 0.88rem;
  line-height: 1.5;
}

.output-text:focus {
  background: var(--surface);
}

.output-text.compact {
  min-height: 72px;
}

/* ---------- 태그 툴팁 ---------- */

.tag-tooltip {
  position: fixed;
  z-index: 40;
  display: grid;
  gap: 6px;
  max-width: 330px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(20, 30, 26, 0.16);
  pointer-events: none;
  font-size: 0.84rem;
  line-height: 1.5;
}

.tag-tooltip[hidden] {
  display: none;
}

.tip-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.tip-title strong {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.tip-count {
  color: var(--muted);
  font-size: 0.78rem;
}

.tip-meta {
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 700;
}

.tip-desc {
  margin: 0;
  color: #414e48;
}

.tip-keywords {
  color: var(--muted);
  font-size: 0.78rem;
}

.tip-footer {
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  color: var(--brand-strong);
  font-size: 0.78rem;
  font-weight: 600;
}

.quality-toggle.is-active {
  border-color: transparent;
  background: var(--brand);
  color: #fff;
}

/* ---------- 토스트 ---------- */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  padding: 11px 15px;
  border: 0;
  border-radius: 10px;
  background: #132e29;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(19, 46, 41, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

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

/* ---------- 반응형 ---------- */

@media (max-width: 1180px) {
  .workspace-grid {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .builder-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px 12px 32px;
  }

  h1 {
    font-size: 1.15rem;
  }

  .brand-logo {
    width: min(244px, 82vw);
    height: auto;
  }

  .topbar,
  .search-band,
  .assist-band,
  .search-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

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

  .filter-panel {
    position: static;
    max-height: none;
  }

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

  .add-button {
    width: 100%;
  }

  .settings-block.split,
  details.booster-block > .settings-block.embedded,
  .preview-grid,
  .scene-groups {
    grid-template-columns: 1fr;
  }
}
