/* InstaDown 디자인 v2 (2026-11-05)
 * 구조: C 필름 스트립 (benchmark-ui-mockup 3안 중 사용자 선택)
 * 룩: design-styles `riso` 컨셉만 차용. 미색 종이 + 두 잉크(핑크·파랑). 토큰은 직접 정함.
 * 폰트: 한글 Pretendard, 워드마크·숫자 Space Grotesk. */
:root {
  color-scheme: light;
  /* B 어스름 종이 (2026-11-05 사용자 선택). 다크는 리소 느낌이 죽어서 기각 */
  --paper: #dcd5ca;
  --surface: #f1ece4;
  --sunk: #cbc3b6;
  --ink: #1c1a22;
  --ink-2: #3f3b47;
  --muted: #5d5764;
  --rule: #c2b9ab;
  --pink: #cf2563;
  --pink-press: #b01e54;
  --pink-soft: #f3d6e1;
  --blue: #2c40a7;
  --blue-deep: #222f80;
  --blue-line: #4557bd;
  --on-ink: #ffffff;
  --scrim: rgba(18, 16, 24, 0.94);
  --shade: rgba(18, 16, 24, 0.55);
  --error: #b3233a;
  --error-soft: #f0d9da;

  --font: "Pretendard Variable", Pretendard, system-ui, sans-serif;
  --font-latin: "Space Grotesk", "Pretendard Variable", Pretendard, system-ui, sans-serif;

  --r-lg: 18px;
  --r-md: 12px;
  --r-pill: 999px;
  --shell: 1232px;
  --gutter: 24px;
  --card: 320px;
  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { overflow-x: clip; }
html { scroll-behavior: smooth; }
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
img, video { display: block; max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
svg { flex-shrink: 0; }

.container { width: 100%; max-width: calc(var(--shell) + var(--gutter) * 2); margin: 0 auto; padding: 0 var(--gutter); }

/* ── Top bar ── */
.topbar { padding-top: 20px; }
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--ink); color: var(--paper); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { font: 700 21px/1 var(--font-latin); letter-spacing: -0.02em; }

/* ── Hero: the link field ── */
.hero { padding: 64px 0 32px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; justify-items: center; text-align: center; }
.lead { font-size: 24px; line-height: 1.35; font-weight: 700; letter-spacing: -0.025em; max-width: 22em; text-wrap: balance; }

.field {
  width: calc(100% - 4px); max-width: 760px;
  display: flex; align-items: center; gap: 8px;
  height: 64px;
  padding: 0 8px 0 20px;
  background: var(--surface);
  border-radius: var(--r-pill);
  box-shadow: inset 0 0 0 1.5px var(--ink), 4px 4px 0 var(--pink);
}
.field:focus-within { box-shadow: inset 0 0 0 2px var(--blue), 4px 4px 0 var(--pink); }
.field-icon { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#urlInput { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 17px; }
#urlInput::placeholder { color: var(--muted); }
.field.is-empty { box-shadow: inset 0 0 0 2px var(--error), 4px 4px 0 var(--pink); }

.btn-paste, .btn-download {
  height: 48px; border: 0; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-paste { padding: 0 16px; background: var(--sunk); color: var(--ink); font-size: 15px; }
.btn-paste:hover { background: var(--rule); }
.btn-paste:active { background: var(--ink); color: var(--paper); }
.btn-download { padding: 0 24px; background: var(--pink); color: var(--on-ink); font-size: 16px; }
.btn-download:hover { background: var(--pink-press); }
.btn-download:active { background: var(--blue); }
.btn-download:disabled { background: var(--sunk); color: var(--muted); cursor: progress; }
.btn-paste svg, .btn-download svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.paste-hint { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.hero .note { font-size: 13px; color: var(--muted); line-height: 1.6; margin-top: 4px; }
.paste-hint kbd { font: 600 12px/1 var(--font-latin); padding: 4px 7px; border-radius: 6px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); color: var(--ink-2); }

/* ── Empty state: where the results will land ── */

/* ── Compact hero once something is on screen ── */
body.is-active .hero { padding: 28px 0 8px; }
body.is-active .lead { font-size: 18px; }
body.is-active .paste-hint { display: none; }

/* ── Status ── */
#status { display: none; padding-bottom: 32px; }

.loading-wrap { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; padding-top: 24px; }
.loading-wrap p { grid-column: 1 / -1; order: -1; font-size: 15px; color: var(--ink-2); }
.spinner { aspect-ratio: 4 / 5; border-radius: var(--r-lg); background: var(--sunk); animation: pulse 1.2s var(--ease) infinite alternate; }
.loading-wrap .spinner + .spinner { animation-delay: 0.15s; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.45; } }

.error-box { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px; margin: 24px auto 0; border-radius: var(--r-md); background: var(--error-soft); max-width: 760px; text-align: left; }
.error-box svg { width: 22px; height: 22px; fill: none; stroke: var(--error); stroke-width: 2; stroke-linecap: round; }
.error-box p { font-size: 15px; color: var(--ink); }
.error-box strong { display: block; margin-bottom: 2px; color: var(--error); font-size: 16px; }
.error-detail { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); word-break: break-all; white-space: pre-line; }
.btn-fallback { margin-top: 12px; }

.result-head { display: flex; align-items: center; justify-content: center; gap: 12px 16px; flex-wrap: wrap; padding: 24px 0 20px; text-align: center; }
.result-head h2 { font-size: 26px; line-height: 1.25; font-weight: 750; letter-spacing: -0.03em; }
.result-head h2 span { color: var(--muted); font-weight: 500; }
.result-head .sp { display: none; }
.btn-reset {
  height: 40px; padding: 0 16px; border: 0; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; box-shadow: inset 0 0 0 1px var(--rule);
  font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer;
  transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn-reset:hover { box-shadow: inset 0 0 0 1px var(--ink-2); }
.btn-reset:active { background: var(--sunk); }
.btn-reset svg { flex: none; overflow: visible; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* The strip */
.result-list {
  display: flex; gap: 16px; align-items: flex-start;
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  margin: 0 calc(var(--gutter) * -1); padding: 4px var(--gutter) 20px;
  scroll-padding-inline: var(--gutter);
  scrollbar-width: thin; scrollbar-color: var(--rule) transparent;
}
.result-item { flex: 0 0 var(--card); scroll-snap-align: start; display: grid; gap: 10px; }
/* 항목이 적으면 가운데, 넘치면 왼쪽부터 스크롤 */
.result-item:first-child { margin-left: auto; }
.result-item:last-child { margin-right: auto; }
.frame { position: relative; aspect-ratio: 4 / 5; border-radius: var(--r-lg); overflow: hidden; background: var(--sunk); }
.thumb-btn { position: absolute; inset: 0; border: 0; padding: 0; background: none; cursor: zoom-in; display: block; width: 100%; }
.thumb-btn:focus-visible { outline-offset: -4px; outline-width: 3px; }
.item-thumb { width: 100%; height: 100%; object-fit: cover; }
.item-thumb-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--ink-2); background: var(--sunk); }
.item-thumb-placeholder svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
/* 2026-11-17 넘버링: 사진 위 칩 제거, 아래 줄 "이미지 1/6"로 (종류 + 순서/전체) */
.idx { font: 700 15px/1 var(--font-latin); font-variant-numeric: tabular-nums; color: var(--ink); }
.idx-of { font-weight: 500; color: var(--muted); }
.tag { position: absolute; top: 14px; left: 14px; pointer-events: none; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: var(--r-pill); background: var(--shade); color: var(--on-ink); }

.item-check { position: absolute; top: 8px; right: 8px; width: 48px; height: 48px; display: grid; place-items: center; cursor: pointer; }
.item-check input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.check-ui { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--shade); box-shadow: 0 0 0 2px var(--on-ink); transition: background-color var(--dur) var(--ease); }
.check-ui svg { width: 16px; height: 16px; fill: none; stroke: var(--on-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.item-check input:checked + .check-ui { background: var(--pink); }
.item-check input:checked + .check-ui svg { opacity: 1; }
.item-check input:focus-visible + .check-ui { outline: 2px solid var(--blue); outline-offset: 3px; }
.result-item.unchecked .item-thumb { opacity: 0.4; filter: grayscale(0.7); }
.result-item.unchecked .idx { opacity: 0.5; }

.meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }
.item-label { font-size: 15px; color: var(--ink-2); }
.btn-dl {
  height: 40px; padding: 0 14px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 700; text-decoration: none; white-space: nowrap;
  color: var(--ink); background: transparent; border: 0; cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-dl:hover { background: var(--sunk); }
.btn-dl:active { background: var(--ink); color: var(--paper); }
.btn-dl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* The dock: selection and the save-all action */
.select-bar {
  position: sticky; bottom: 12px; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  max-width: 620px; margin: 8px auto 0; padding: 10px 10px 10px 20px;
  border-radius: var(--r-pill);
  background: var(--blue); color: var(--on-ink);
  box-shadow: 0 16px 32px -16px var(--blue-deep);
}
.select-all { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap; user-select: none; }
.select-all input { width: 20px; height: 20px; margin: 0; accent-color: var(--pink); cursor: pointer; }
.btn-all {
  margin-left: auto; height: 48px; padding: 0 22px; border: 0; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--pink); color: var(--on-ink);
  font-size: 15px; font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-all:hover:not(:disabled) { background: var(--pink-press); }
.btn-all:active:not(:disabled) { background: var(--blue-deep); }
.btn-all:disabled { background: var(--blue-line); color: var(--sunk); cursor: not-allowed; }
.btn-all svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Viewer ── */
.viewer { position: fixed; inset: 0; z-index: 1000; background: var(--scrim); display: none; flex-direction: column; align-items: center; justify-content: center; padding: 64px 16px 88px; }
.viewer.open { display: flex; }
.viewer-stage { flex: 1; width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--r-md); user-select: none; }
.viewer-top { position: absolute; top: 0; left: 0; right: 0; height: 64px; padding: 0 12px 0 24px; display: flex; align-items: center; justify-content: space-between; color: var(--on-ink); font: 700 16px/1 var(--font-latin); }
.viewer-bottom { position: absolute; bottom: 20px; left: 0; right: 0; display: flex; justify-content: center; }
.viewer-bottom .btn-dl { height: 48px; padding: 0 22px; background: var(--pink); color: var(--on-ink); }
.viewer-bottom .btn-dl:hover { background: var(--pink-press); }
.viewer-btn { width: 48px; height: 48px; border: 0; border-radius: 50%; background: var(--shade); color: var(--on-ink); cursor: pointer; display: grid; place-items: center; transition: background-color var(--dur) var(--ease); }
.viewer-btn:hover { background: var(--ink-2); }
.viewer-btn:active { background: var(--blue); }
.viewer-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viewer-prev, .viewer-next { position: absolute; top: 50%; transform: translateY(-50%); }
.viewer-prev { left: 16px; }
.viewer-next { right: 16px; }
.viewer-prev[hidden], .viewer-next[hidden] { display: none; }

/* ── Note and footer ── */
.foot { margin-top: auto; padding-top: 32px; padding-bottom: 40px; display: flex; justify-content: center; }
.site-footer a { font-size: 13px; color: var(--ink-2); text-underline-offset: 3px; }
.site-footer a:hover { color: var(--pink); }

/* ── Narrow ── */
@media (max-width: 720px) {
  :root { --gutter: 16px; --card: 78vw; }
  .hero { padding: 32px 0 20px; gap: 14px; }
  .lead { font-size: 19px; }
  .field { height: auto; flex-wrap: wrap; padding: 6px 6px 8px; border-radius: 22px; gap: 8px; box-shadow: inset 0 0 0 1.5px var(--ink), 3px 3px 0 var(--pink); }
  .field:focus-within { box-shadow: inset 0 0 0 2px var(--blue), 3px 3px 0 var(--pink); }
  .field-icon { display: none; }
  /* 1줄: 입력 + 작은 붙여넣기, 2줄: 다운로드 */
  #urlInput { flex: 1; height: 48px; padding: 0 4px 0 12px; font-size: 16px; }
  .btn-paste { flex: 0 0 auto; height: 34px; padding: 0 10px; gap: 4px; font-size: 13px; font-weight: 600; }
  .btn-paste svg { width: 14px; height: 14px; }
  .btn-download { flex: 1 0 100%; height: 50px; }
  .paste-hint { display: none; }
  body.is-active .lead { display: none; }
  .loading-wrap { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .loading-wrap .spinner:nth-child(n+4) { display: none; }
  .result-head { padding: 20px 0 14px; }
  .result-head h2 { font-size: 21px; }
  .result-head h2 span { display: none; }
  .result-list { gap: 10px; }
  .select-bar { padding: 8px 8px 8px 16px; }
  .viewer-prev, .viewer-next { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .spinner { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
