:root {
  --green: #0b4a2d;
  --green2: #2f6f3e;
  --cream: #fbf6e8;
  --gold: #d99a27;
  --orange: #e6672f;
  --ink: #17211b;
  --muted: #6b746c;
  --line: #dbe5d7;
  --shadow: 0 20px 60px rgba(13, 74, 45, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0, rgba(217, 154, 39, .15), transparent 24rem),
    linear-gradient(180deg, #f8faf5, #edf3eb);
  color: var(--ink);
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.studio-shell {
  width: min(1440px, calc(100% - 36px));
  margin: auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.breadcrumb {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 3vw, 40px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

.topbar-actions,
.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.generate-button {
  min-height: 42px;
  padding: 0 17px;
  border: 0;
  border-radius: 12px;
  font-weight: 900;
}

.primary-button,
.generate-button {
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 24px rgba(13, 74, 45, .18);
}

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

.ghost-button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

/* ── 포맷 선택 바 ── */
.format-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.format-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 22px;
  background: rgba(255,255,255,.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(23,33,27,.04);
  transition: border-color .15s, background .15s;
}

.format-btn small {
  font-size: 11px;
  color: #87928c;
  font-weight: 600;
}

.format-btn.active {
  background: #f0faf4;
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

/* ── 입력 스택 ── */
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.template-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.tmpl-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 92px;
  padding: 14px 12px 12px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 8px 22px rgba(23, 33, 27, .04);
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.tmpl-card.active {
  background: #f0faf4;
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green), 0 8px 22px rgba(11, 74, 45, .10);
}

.tmpl-card:hover:not(.active) {
  background: #f8fbf7;
  border-color: #a8c9b4;
}

.tmpl-icon {
  font-size: 26px;
  line-height: 1;
}

.tmpl-card strong {
  display: block;
  font-size: 13px;
  font-weight: 900;
  margin-top: 2px;
}

.tmpl-card small {
  color: #87928c;
  font-size: 11px;
  line-height: 1.3;
}

.format-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.format-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-items: start;
  column-gap: 10px;
  min-height: 68px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(23, 33, 27, .04);
}

.format-card.active {
  background: #f0faf4;
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.format-card strong {
  font-size: 14px;
}

.format-card small {
  color: #87928c;
  font-size: 12px;
}

.format-ratio {
  grid-row: span 2;
  display: block;
  width: 25px;
  height: 34px;
  border: 2px solid var(--green);
  border-radius: 4px;
  background: linear-gradient(135deg, rgba(13, 74, 45, .18), transparent 55%), #fff;
}

.format-ratio.square {
  width: 31px;
  height: 31px;
}

.format-ratio.story {
  width: 22px;
  height: 38px;
}

.format-ratio.wide {
  width: 42px;
  height: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(320px, 1fr);
  gap: 16px;
  align-items: start;
}

.control-panel,
.preview-panel {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.control-panel,
.preview-panel {
  position: sticky;
  top: 14px;
}

.control-panel {
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid #edf1ed;
  margin-bottom: 16px;
}

.panel-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 11px;
}

label {
  display: grid;
  gap: 6px;
  color: #334238;
  font-size: 12px;
  font-weight: 900;
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfdfb;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.full-field,
.upload-field {
  margin-top: 11px;
}

.upload-field {
  padding: 12px;
  border: 1px dashed #b9cbb7;
  border-radius: 14px;
  background: #fbfdf8;
}

.upload-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.option-group {
  margin-top: 15px;
}

.option-title {
  margin-bottom: 9px;
  font-weight: 900;
}

.chip-row,
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.chip.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background: #f8fbf5;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.toggle-row input {
  width: auto;
}

.prompt-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  padding: 12px;
  background: #f8fbf5;
  border: 1px solid #e1e8de;
  border-radius: 14px;
}

.prompt-box p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.generate-button {
  width: 100%;
  height: 48px;
  margin-top: 15px;
  font-size: 15px;
}

.generate-status {
  min-height: 38px;
  margin-top: 12px;
  padding: 10px 12px;
  background: #f0faf4;
  border: 1px solid #cfe2d4;
  border-radius: 12px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.generate-status.is-working {
  background: #fff8e7;
  border-color: #efd18c;
  color: #8a5a00;
}

.generate-status.is-done {
  background: #eaf7ee;
  border-color: #9ed0ad;
  color: #075232;
}

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

.canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 420px;
  max-height: calc(100vh - 255px);
  padding: 14px;
  overflow: auto;
  background: #eef3eb;
  border: 1px solid var(--line);
  border-radius: 18px;
}

canvas {
  max-width: 100%;
  max-height: calc(100vh - 285px);
  height: auto;
  background: #fff;
  border-radius: 0;
  box-shadow: 0 12px 40px rgba(23, 33, 27, .18);
}

#aiHtmlPreview {
  display: none;
  width: min(100%, 800px);
  height: min(calc(100vh - 285px), 760px);
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 45px rgba(23, 33, 27, .12);
}

.variant-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-content: start;
}

.variant-card {
  padding: 13px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
}

.variant-card.active {
  background: #f0faf4;
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.variant-card strong {
  display: block;
  margin-bottom: 6px;
}

.variant-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.action-row {
  justify-content: flex-end;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid #edf1ed;
}

@media (min-width: 1120px) {
  .workspace {
    grid-template-columns: minmax(450px, 520px) minmax(600px, 1fr);
  }

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

  .preview-layout {
    grid-template-columns: minmax(0, 1fr) 190px;
  }

  .variant-list {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    min-height: 520px;
    max-height: calc(100vh - 205px);
  }

  canvas {
    max-height: calc(100vh - 235px);
  }

  #aiHtmlPreview {
    height: min(calc(100vh - 235px), 780px);
  }
}

@media (max-width: 760px) {
  .studio-shell {
    width: min(100% - 28px, 1320px);
    padding-top: 22px;
  }

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

  .control-panel,
  .preview-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .canvas-wrap {
    min-height: auto;
    max-height: none;
  }

  canvas {
    max-height: none;
  }

  #aiHtmlPreview {
    height: 760px;
  }
}

@media (max-width: 720px) {
  .studio-shell {
    width: min(100% - 22px, 1320px);
    padding-top: 18px;
  }

  .topbar {
    display: grid;
  }

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

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

  .format-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .format-card {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 104px;
    padding: 16px 10px;
    text-align: center;
  }

  .format-ratio {
    grid-row: auto;
    width: 34px;
    height: 44px;
  }

  .format-ratio.square {
    width: 42px;
    height: 42px;
  }

  .format-ratio.story {
    width: 28px;
    height: 50px;
  }

  .format-ratio.wide {
    width: 54px;
    height: 30px;
  }

  .field-grid,
  .variant-list {
    grid-template-columns: 1fr;
  }

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

  .canvas-wrap {
    padding: 10px;
  }
}

/* ── AI 시안 그리드 ── */
.image-grid {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 120px;
  align-items: flex-start;
}

.grid-item {
  flex: 1;
  position: relative;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: 14px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
  background: #eef3eb;
}

.grid-item img {
  width: 100%;
  height: auto;
  display: block;
}

.grid-item.active {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green);
}

.grid-item:hover:not(.active) {
  border-color: #a8c9b4;
}

.grid-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  letter-spacing: .02em;
}

.grid-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  padding: 20px;
  background: #f4f8f2;
  border: 1px dashed #b9cbb7;
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

.grid-loading {
  color: var(--green);
  font-weight: 900;
}

/* ── QR 합성기 전용 ── */
.field-group {
  margin-top: 18px;
}

.field-title {
  font-size: 13px;
  font-weight: 900;
  color: #334238;
  margin-bottom: 8px;
}

.field-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.toggle-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.toggle-inline input {
  width: auto;
}

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

.coord-grid label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 900;
  color: #334238;
}

.coord-grid input[type="number"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdfb;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.status-msg {
  margin-top: 8px;
  padding: 9px 12px;
  background: #f0faf4;
  border: 1px solid #cfe2d4;
  border-radius: 10px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.status-msg.is-done {
  background: #eaf7ee;
  border-color: #9ed0ad;
  color: #075232;
}

.info-box {
  margin-top: 20px;
  padding: 14px;
  background: #f8faf5;
  border: 1px solid #e1e8de;
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.65;
}

/* ── 업로드 영역 ── */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 16px;
  border: 2px dashed #b9cbb7;
  border-radius: 16px;
  background: #f8fdf5;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--green);
  background: #f0faf4;
}

.upload-icon {
  font-size: 32px;
  line-height: 1;
  color: var(--green);
}

.upload-text {
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  word-break: break-all;
}

.upload-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
