/*
 * app.css — 편집 화면 스타일. 색은 구멍이 클래스 style.css 변수를 그대로 따른다.
 * 완성 상세페이지 모양은 page.css 에 있다.
 */
:root {
  --primary: #2563eb; --primary-dark: #1d4ed8; --primary-soft: #eff6ff;
  --ink: #111827; --ink-soft: #4b5563; --ink-faint: #9ca3af;
  --bg: #f7f8fa; --card: #fff; --border: #e5e7eb;
  --danger: #dc2626;
  --brand-title: #1000de;   /* 구멍이 실행열차 로고 글자색과 맞춤 */
  --top-h: 56px; --bottom-h: 76px;
}
* { box-sizing: border-box; }
/* display 를 지정한 요소(.busy 등)에도 hidden 속성이 먹도록. 빠지면 투명 막이 화면 전체를 덮어 아무것도 안 눌린다. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Pretendard Variable', 'Pretendard', -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-font-smoothing: antialiased; word-break: keep-all;
  padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* 상단 */
.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); }
.top-in { height: var(--top-h); max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 21px; font-weight: 800; letter-spacing: -0.5px; color: var(--brand-title); text-decoration: none; white-space: nowrap; }
.brand-logo { height: 34px; width: auto; display: block; }
@media (max-width: 360px) { .brand { font-size: 18px; } .brand-logo { height: 28px; } }
.btn-text { border: 0; background: none; color: var(--ink-soft); font-size: 15px; font-weight: 600; min-height: 44px; padding: 0 8px; border-radius: 10px; }
.btn-text:hover { background: #f2f4f6; }
.tabs { display: flex; padding: 0 16px 8px; gap: 6px; }
.tab { flex: 1; min-height: 44px; border: 0; border-radius: 12px; background: #f2f4f6; color: var(--ink-soft); font-size: 15px; font-weight: 600; }
.tab.on { background: var(--ink); color: #fff; }

/* 본문: 모바일은 한 화면에 하나만 */
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }
.wrap[data-tab="edit"] .preview { display: none; }
.wrap[data-tab="preview"] .editor { display: none; }

@media (min-width: 1024px) {
  .tabs { display: none; }
  .wrap { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 24px; align-items: start; padding: 24px; }
  .wrap[data-tab] .preview, .wrap[data-tab] .editor { display: block; }
  .preview { position: sticky; top: calc(var(--top-h) + 24px); }
  .pv-scroll { max-height: calc(100vh - var(--top-h) - var(--bottom-h) - 48px); }
}

/* 카드 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 20px; margin-bottom: 12px; }
.card-h { margin: 0 0 16px; font-size: 20px; font-weight: 700; }
.fld { display: block; margin-bottom: 14px; }
.fld-l { display: block; font-size: 14px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.fld-l .cnt { float: right; font-weight: 500; color: var(--ink-faint); }
.fld input[type=text], .fld textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; background: #fff;
  padding: 12px 14px; font-size: 16px; min-height: 48px; outline: none; transition: border-color .15s;
}
.fld textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.fld input:focus, .fld textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.hint { margin: 4px 0 0; font-size: 14px; color: var(--ink-faint); line-height: 1.5; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.sw { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border); padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }

/* 블록 카드 */
.blk { background: var(--card); border: 1px solid var(--border); border-radius: 18px; margin-bottom: 10px; overflow: hidden; }
.blk.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px rgba(37,99,235,.35); } 100% { box-shadow: none; } }
.blk-h { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 16px; }
.blk-toggle { flex: 1; min-width: 0; min-height: 52px; border: 0; background: none; text-align: left; padding: 6px 0; display: flex; flex-direction: column; justify-content: center; }
.blk-name { font-size: 16px; font-weight: 700; }
.blk-name .num { color: var(--primary); margin-right: 6px; }
.blk-desc { font-size: 13px; color: var(--ink-faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blk-warn { font-size: 12px; font-weight: 600; color: #ea580c; background: #fff7ed; border-radius: 6px; padding: 2px 6px; margin-left: 6px; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: none; color: var(--ink-soft); font-size: 18px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:hover { background: #f2f4f6; }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.blk-b { padding: 4px 16px 16px; border-top: 1px solid #f2f4f6; }
.blk:not(.open) .blk-b { display: none; }

/* 사진 칸 */
.img-empty { width: 100%; min-height: 96px; border: 2px dashed #cbd5e1; border-radius: 14px; background: #f8fafc; color: var(--ink-soft); font-size: 15px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.img-empty:hover { border-color: var(--primary); color: var(--primary); }
.img-empty small { font-weight: 500; color: var(--ink-faint); }
.img-has { display: flex; align-items: center; gap: 12px; }
.img-thumb { width: 88px; height: 88px; border-radius: 12px; background: #eee center/cover no-repeat; flex: none; border: 1px solid var(--border); }
.img-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: #fff; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.chip:hover { border-color: #cbd5e1; }
.chip.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.chip.danger { color: var(--danger); }

/* 목록 칸 (Q&A, 후기) */
.li { border: 1px solid var(--border); border-radius: 14px; padding: 12px 12px 0; margin-bottom: 10px; }
.li-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.btn-sub { width: 100%; min-height: 48px; border: 1px dashed #cbd5e1; border-radius: 12px; background: #fff; font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.notice-note { font-size: 13px; color: #b45309; background: #fffbeb; border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; line-height: 1.5; }

.btn-add { width: 100%; min-height: 56px; border: 1px dashed #cbd5e1; border-radius: 18px; background: #fff; font-size: 16px; font-weight: 700; color: var(--primary); }
.editor-end { height: 24px; }

/* 미리보기 */
.preview { background: #e9ecf0; border-radius: 18px; padding: 12px; }
.pv-scroll { overflow-y: auto; overflow-x: hidden; border-radius: 10px; }
.pv-scale { transform-origin: 0 0; }
.pv-scale .dp-block { cursor: pointer; }
.pv-scale .dp-block:hover { outline: 4px solid rgba(37,99,235,.5); outline-offset: -4px; }

/* 하단 고정 버튼 */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(255,255,255,.97); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bottom-in { max-width: 1280px; margin: 0 auto; height: var(--bottom-h); padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.save-state { flex: 1; font-size: 13px; color: var(--ink-faint); min-width: 0; }
.btn-primary { min-height: 52px; padding: 0 24px; border: 0; border-radius: 14px; background: var(--primary); color: #fff; font-size: 17px; font-weight: 700; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #93b4f5; cursor: default; }
.btn-ghost { min-height: 52px; padding: 0 20px; border: 0; border-radius: 14px; background: #f2f4f6; color: var(--ink); font-size: 17px; font-weight: 700; }
@media (max-width: 480px) { .bottom .btn-primary { flex: 2; } }

/* 바텀시트 (토스식 확인창) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: #fff; border-radius: 24px 24px 0 0; padding: 24px 20px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
@media (min-width: 640px) { .sheet { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 50%); width: 480px; border-radius: 24px; } }
.sheet-h { font-size: 20px; font-weight: 700; margin: 0 0 8px; padding-right: 44px; }
.sheet-x { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; border-radius: 12px; background: none; color: var(--ink-soft); display: inline-flex; align-items: center; justify-content: center; }
.sheet-x:hover { background: #f2f4f6; }
.sheet-p { font-size: 15px; color: var(--ink-soft); line-height: 1.6; margin: 0 0 20px; }
.sheet-btns { display: flex; gap: 8px; }
.sheet-btns > * { flex: 1; min-width: 0; padding: 0 12px; white-space: nowrap; }
@media (max-width: 480px) { .sheet-btns > * { font-size: 16px; } }
.type-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.type-item { min-height: 64px; text-align: left; border: 1px solid var(--border); border-radius: 14px; background: #fff; padding: 10px 14px; }
.type-item b { display: block; font-size: 15px; }
.type-item span { font-size: 13px; color: var(--ink-faint); }
.type-item:hover { border-color: var(--primary); }

/* 저장 결과 */
.result-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 16px; -webkit-overflow-scrolling: touch; }
.result-item { margin: 0; flex: none; width: 140px; }
.result-item img { display: block; width: 140px; height: 220px; object-fit: cover; object-position: top; border-radius: 10px; border: 1px solid var(--border); background: #fff; }
.result-item figcaption { font-size: 13px; color: var(--ink-faint); text-align: center; margin-top: 4px; }

/* 사진 편집 */
.crop-box { position: relative; background: #111; border-radius: 14px; overflow: hidden; touch-action: none; user-select: none; cursor: grab; margin-bottom: 14px; }
.crop-box canvas { display: block; width: 100%; height: auto; }
.crop-tip { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; font-size: 13px; padding: 5px 10px; border-radius: 999px; pointer-events: none; white-space: nowrap; }
.ratio-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.slider { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; min-height: 44px; }
.slider span { width: 44px; font-size: 14px; font-weight: 600; color: var(--ink-soft); flex: none; }
.slider input { flex: 1; accent-color: var(--primary); height: 44px; }

/* 진행 중·알림 */
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(255,255,255,.85); display: flex; align-items: center; justify-content: center; }
.busy-box { text-align: center; font-size: 16px; font-weight: 600; color: var(--ink); }
.spinner { width: 40px; height: 40px; margin: 0 auto 14px; border: 4px solid #dbeafe; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: rgba(17,24,39,.92); color: #fff; font-size: 15px; font-weight: 500; padding: 12px 18px; border-radius: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 70; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 저장용 무대: 화면 밖이 아니라 제자리에 두되 뒤로 숨긴다. (화면 밖에 두면 일부 브라우저가 그리지 않는다) */
.export-stage { position: fixed; left: 0; top: 0; width: 780px; height: 0; overflow: visible; z-index: -1; pointer-events: none; opacity: 1; }
