:root {
  --bg: #f6f6f8; --panel: #fff; --sunk: #f0f0f4; --text: #1c1c22; --muted: #6b6b78; --line: #dcdce3;
  --accent: #6d4aff; --accent-soft: #ece7ff; --accent-text: #fff; --ok: #14804a; --warn: #b45309; --err: #c62828;
  --check-a: #e9e9ee; --check-b: #fff;
  --checker: conic-gradient(var(--check-a) 25%, var(--check-b) 0 50%, var(--check-a) 0 75%, var(--check-b) 0) 0 0 / 16px 16px;
}
body { --preview: var(--checker); }
body[data-bg=black] { --preview: #000; }
body[data-bg=white] { --preview: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141418; --panel: #1d1d23; --sunk: #17171c; --text: #ececf1; --muted: #9b9ba8; --line: #33333d;
    --accent: #8b74ff; --accent-soft: #2a2544; --accent-text: #101014; --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
    --check-a: #2a2a32; --check-b: #22222a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", sans-serif; }
main { max-width: 1000px; margin: 0 auto; padding: 16px 16px 48px; }
main:has(> #opts) { max-width: none; }
main:has(> #opts) > :not(#list, #opts) { max-width: 1000px; margin-inline: auto; } /* 목록은 넓게, 제목·설명 글은 가운데 */
a { color: var(--accent); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0 20px; font-size: 14px; }
.brand { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; }
.menu { margin-left: auto; display: flex; gap: 12px; } /* 가이드·소개는 언어 메뉴 바로 왼쪽 */
.menu a { color: var(--text); font-weight: 600; text-decoration: none; }
.menu a:hover { color: var(--accent); }
.lang a, .lang span { padding: 2px 4px; }
.lang span { font-weight: 600; }
h1 { font-size: 24px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.drop { position: relative; display: block; text-align: center; padding: 36px 16px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; background: var(--panel); margin-bottom: 16px; }
.drop.over { border-color: var(--accent); }
.drop input { display: none; }
.drop b { color: var(--accent); }
.drop label[for=file]::after { content: ""; position: absolute; inset: 0; } /* 칸 어디를 눌러도 파일 선택 */
.drop .dir { position: relative; z-index: 1; } /* '폴더 선택'만 그 위로 */
.drop .hint { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }

/* 설정 */
.basic { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px 24px; }
.lbl { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.help { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.var { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; font-weight: 400; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg label { flex: 1 1 auto; text-align: center; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.keypick { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.keypick[hidden] { display: none; }
input[type=color] { width: 40px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

details.adv { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
details.adv > summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
details.adv > summary .changed { font-weight: 400; font-size: 13px; color: var(--accent); order: 2; }
/* flex라 기본 삼각형이 사라져서 펼침 표시를 직접 그린다(사파리 기본 표시는 숨김) */
details.adv > summary { list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::after { content: "▼"; order: 1; font-size: 10px; color: var(--muted); }
details.adv[open] > summary::after { content: "▲"; }
.group { margin-top: 18px; }
.group[hidden] { display: none; }
.group h3 { font-size: 14px; margin: 0 0 2px; }
.group > .help { margin: 0 0 10px; }
.ctrls { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ctrl { background: var(--sunk); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.ctrl.dim { opacity: .45; }
.ctrl.dim input { pointer-events: none; }
.ctrl .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ctrl .top label, .ctrl .top .name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.num { width: 76px; padding: 4px 6px; font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: right; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
input[type=range] { width: 100%; margin: 10px 0 2px; accent-color: var(--accent); }
.ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-weight: 600; font-size: 14px; }
.switch input { appearance: none; width: 40px; height: 22px; border-radius: 11px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hue { position: relative; height: 16px; border-radius: 8px; margin-top: 10px; }
.hue .sel { position: absolute; top: -3px; bottom: -3px; border: 2px solid var(--text); border-radius: 6px; }
.hue .mid { position: absolute; left: 50%; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; background: var(--text); }
.hue-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hue-row input[type=range] { margin-top: 6px; }
.reset-row { margin-top: 16px; display: flex; justify-content: flex-end; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.actions .main { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; } /* 변환·zip·선택 해제는 왼쪽, 비우기는 오른쪽 끝(자리가 모자라면 다음 줄 오른쪽) */
.actions .main > #clear { margin-left: auto; }
.actions .main > button { flex: none; white-space: nowrap; padding-inline: 10px; }
.actions .main > #run { flex: 0 1 auto; min-width: 0; white-space: normal; } /* 길이가 바뀌는 변환 버튼만 줄어든다 */
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
#status { color: var(--muted); font-size: 14px; }
#list { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card, 200px), 1fr)); gap: 12px; }
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.thumb { aspect-ratio: 1; display: grid; place-items: center; background: var(--preview); }
.thumb { cursor: pointer; }
.pick { position: absolute; top: 8px; left: 8px; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.card:has(.pick:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rm, .zbtn { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 18px; line-height: 1; }
.thumb img { grid-area: 1 / 1; max-width: 100%; max-height: 100%; object-fit: contain; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.zbtn { top: 40px; display: grid; place-items: center; }
.card:not(.show-orig) .orig, .card.show-orig .res, #zoom:not(.show-orig) .orig, #zoom.show-orig .res { visibility: hidden; } /* 원본·결과를 겹쳐 두고 한쪽만 보인다 */
.meta { padding: 8px 10px; font-size: 13px; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.st { color: var(--muted); }
.st.ok { color: var(--ok); } .st.skip { color: var(--warn); } .st.err { color: var(--err); }
.meta a { color: var(--accent); }
.detected { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-top: 2px; }
/* 내려받을 크기: 전체 한 줄과 카드마다 같은 칸 */
.export { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.export .lbl { margin: 0; }
.export .help { flex-basis: 100%; margin: 0; }
.qual { display: inline-flex; align-items: center; gap: 8px; } /* 화질 이름과 칸이 갈라지지 않게 */
.qual[hidden] { display: none; }
.out { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.out[hidden] { display: none; }
.side, .fmt, .q { font: inherit; font-size: 13px; padding: 3px 6px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 13px; }
.dims { color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); flex: none; }

/* 넓은 화면: 옵션은 항상 사이드바(기본 오른쪽, body.side-left면 왼쪽). 맨 윗줄(변환 버튼)은 사이드바를 스크롤해도 위에 고정.
   사이드바 폭(--sw)은 평소 1열이고, '세부 조절'을 펼치면 화면이 넓을 때만 2열·3열로 넓어져 안의 설정 칸들이 알아서 여러 열로 놓인다.
   1600px·1900px 기준은 사이드바가 넓어져도 카드가 4열 남는 폭이다 */
@media (min-width: 900px) {
  body { --sw: 360px; }
  main:has(> #opts) { padding-right: calc(var(--sw) + 32px); }
  body.side-left main:has(> #opts) { padding-right: 16px; padding-left: calc(var(--sw) + 32px); }
  #opts { position: fixed; z-index: 10; top: 16px; right: 16px; width: var(--sw); max-height: calc(100vh - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 0 12px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 24px rgb(0 0 0 / .15); }
  body.side-left #opts { right: auto; left: 16px; }
  #opts .actions { position: sticky; top: 0; z-index: 1; margin: 0; padding: 12px 0; background: var(--bg); border-bottom: 1px solid var(--line); }
  #opts .export, #opts .panel { margin: 0; }
}
@media (min-width: 1600px) { body:has(#adv[open]) { --sw: 680px; } }
@media (min-width: 1900px) { body:has(#adv[open]) { --sw: 980px; } }
/* 좁은 화면(휴대폰): 사이드바 자리가 없어 옵션은 위에 쌓고, 변환 버튼 줄만 화면 아래에 고정 */
@media (max-width: 899px) {
  .actions { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; margin: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(0 0 0 / .08); }
  body:has(.actions) { padding-bottom: calc(var(--bar, 120px) + 16px); } /* 버튼 줄 실제 높이(app.js가 잼)만큼 비워 둔다 */
  #swap { display: none; }
}

/* 보기: 원본 보기, 미리보기 배경, 카드 크기, 사이드바 위치 */
.view { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 16px; font-size: 14px; }
.grp { display: inline-flex; align-items: center; gap: 4px; }
.grp button, #swap { padding: 4px 10px; }
.tail { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; } /* 카드 크기와 ⇄는 같은 줄 */
.bgopt { position: relative; display: inline-flex; cursor: pointer; }
.bgopt input { position: absolute; opacity: 0; pointer-events: none; }
.chip { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); }
.bgopt input[value=check] + .chip { background: var(--checker); background-size: 8px 8px; }
.bgopt input[value=black] + .chip { background: #000; }
.bgopt input[value=white] + .chip { background: #fff; }
.bgopt input:checked + .chip { outline: 2px solid var(--accent); outline-offset: 1px; }
.bgopt input:focus-visible + .chip { outline: 2px solid var(--accent); outline-offset: 3px; }

/* 크게 보기 */
#zoom { width: min(96vw, 1400px); height: 94vh; max-width: none; max-height: none; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); overflow: hidden; }
#zoom[open] { display: flex; flex-direction: column; }
#zoom:focus-visible { outline: none; }
#zoom::backdrop { background: rgb(0 0 0 / .7); }
.zbar { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; font-size: 14px; }
.zbar .help { margin: 0; }
#zname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#zpos { color: var(--muted); font-variant-numeric: tabular-nums; }
#zclose { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1; }
.zstage { position: relative; flex: 1; min-height: 0; display: flex; }
.zimg { flex: 1; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; background: var(--preview); cursor: pointer; }
.zimg img { grid-area: 1 / 1; width: 100%; height: 100%; object-fit: contain; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.znav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 26px; line-height: 1; opacity: .9; }
#zprev { left: 12px; } #znext { right: 12px; }
@media (max-width: 599px) { .zbar .help { display: none; } }

/* 광고: 버튼·드롭존과 떨어뜨려 두고, 뜰 때 아래 내용이 밀리지 않게 높이를 잡아 둔다 */
.ad { margin: 40px 0; min-height: 120px; text-align: center; }
.ad[hidden] { display: none; }
.ad .ad-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
@media (min-width: 700px) { .ad { min-height: 250px; } }

/* 설명 글 */
.guide { margin-top: 48px; }
.guide > * { max-width: 760px; }
.guide h2 { font-size: 20px; margin: 40px 0 8px; }
.guide h3 { font-size: 16px; margin: 20px 0 4px; }
.guide p, .guide li, .guide dd { color: var(--text); }
.guide li { margin: 4px 0; }
.guide dt { font-weight: 600; margin-top: 16px; }
.guide dd { margin: 4px 0 0; }
.guide code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.doc { max-width: 760px; }
.doc h1 { margin-bottom: 4px; }
.doc h2 { font-size: 18px; margin: 28px 0 6px; }
.doc h3 { font-size: 16px; margin: 20px 0 4px; }
.doc .byline { color: var(--muted); font-size: 13px; margin: -16px 0 24px; }
.doc figure { margin: 20px 0; }
.doc figure img { display: block; max-width: 100%; height: auto; }
.doc figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.doc .table { overflow-x: auto; margin: 12px 0; } /* 좁은 화면에서는 표만 가로로 밀린다 */
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc th, .doc td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.doc th { background: var(--sunk); }
.doc td:first-child { min-width: 7em; } /* 숫자 칸이 줄바꿈되지 않아 첫 칸이 한 글자씩 쪼개지는 것 방지 */
.doc .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc pre { background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
.doc code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.doc :not(pre) > code { background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.guide-list { list-style: none; padding: 0; }
.guide-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.guide-list a { font-weight: 600; }
.guide-list span { display: block; color: var(--muted); font-size: 14px; }
.related { margin-top: 40px; border-top: 1px solid var(--line); }
.contact-mail { font-size: 18px; font-weight: 600; }
footer { border-top: 1px solid var(--line); margin-top: 56px; padding-top: 16px; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px 16px; }
