:root {
  --bg: #f6f7fb; --card: #fff; --card-2: #f1f2f6; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #4f46e5; --brand-2: #9333ea; --brand-soft: #eef2ff; --on-brand: #fff;
  --yt: #ef4444; --pin: #e60023; --ok: #059669; --err: #dc2626;
  --radius: 18px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(17,24,39,.06);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12; --card: #151821; --card-2: #1c2030; --text: #f3f4f6; --muted: #9ca3af; --line: #262a36;
    --brand: #6366f1; --brand-soft: #1e1b4b; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-b)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* app bar */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }
.iconbtn { position: relative; border: 0; background: transparent; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.iconbtn:active { background: var(--card-2); }
.dot { position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); border: 2px solid var(--bg); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--err); }

/* hero */
.hero { text-align: center; padding: 22px 0 16px; }
.hero h1 { font-size: clamp(22px, 6vw, 34px); line-height: 1.3; margin: 0 0 14px; letter-spacing: -0.02em; }
.hero em { font-style: normal; background: linear-gradient(90deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 13px; font-weight: 700; transition: all .15s; }
.chip svg { width: 15px; height: 15px; }
.chip.active[data-p="twitter"] { color: var(--text); border-color: var(--text); }
.chip.active[data-p="youtube"] { color: var(--yt); border-color: var(--yt); }
.chip.active[data-p="pinterest"] { color: var(--pin); border-color: var(--pin); }

/* search */
.search { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; align-items: center; background: var(--card-2); border-radius: 12px; padding: 0 6px 0 12px; }
.field .lead { color: var(--muted); flex-shrink: 0; }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; padding: 14px 10px; }
.clear { border: 0; background: var(--line); color: var(--muted); width: 28px; height: 28px; border-radius: 50%; font-size: 12px; flex-shrink: 0; }
.primary { border: 0; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--on-brand); font-weight: 800; font-size: 16px; min-height: 52px; padding: 0 20px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .65; }
.secondary { border: 1px solid var(--line); background: var(--card-2); color: var(--text); font-weight: 700; font-size: 16px; min-height: 52px; border-radius: 14px; width: 100%; }
.text { border: 0; background: transparent; color: var(--muted); font-weight: 600; min-height: 44px; width: 100%; }
.link { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 8px; }
@media (min-width: 640px) {
  .search { flex-direction: row; align-items: stretch; }
  .search .field { flex: 1; }
  .search .primary { width: auto; min-width: 170px; }
}

.spinner { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* result */
#result { margin-top: 18px; }
.meta { display: flex; gap: 12px; align-items: center; margin: 0 2px 12px; }
.meta .avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; background: var(--card-2); }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; color: #fff; margin-bottom: 2px; }
.badge.youtube { background: var(--yt); } .badge.twitter { background: #000; } .badge.pinterest { background: var(--pin); }
@media (prefers-color-scheme: dark) { .badge.twitter { background: #333; } }
.meta .t { font-weight: 700; font-size: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.meta .a { color: var(--muted); font-size: 13px; }
.saveall { width: 100%; margin-bottom: 12px; border: 1px dashed var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 800; min-height: 48px; border-radius: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; }

.items { display: grid; gap: 14px; }
.item { overflow: hidden; }
.thumb { position: relative; background: #000; display: grid; place-items: center; max-height: 56vh; min-height: 160px; }
.thumb img { width: 100%; height: 100%; max-height: 56vh; object-fit: contain; display: block; }
.thumb .tag { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 7px; backdrop-filter: blur(6px); }
.thumb .dur { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 5px; }
.opts { padding: 4px 0; }
.opt { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; overflow: hidden; }
.opt:first-child { border-top: 0; }
.opt:active { background: var(--card-2); }
.opt .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.ic.video { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.ic.audio { background: color-mix(in srgb, #0891b2 14%, transparent); color: #0891b2; }
.ic.gif { background: color-mix(in srgb, #d946ef 14%, transparent); color: #d946ef; }
.ic.image { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.opt .lbl { flex: 1; min-width: 0; }
.opt .lbl b { display: block; font-size: 15px; font-weight: 700; }
.opt .lbl small { color: var(--muted); font-size: 12px; }
.opt .act { flex-shrink: 0; color: var(--brand); font-weight: 800; font-size: 13px; display: flex; align-items: center; gap: 6px; min-width: 48px; justify-content: flex-end; }
.opt .bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .2s; }
.opt.busy { pointer-events: none; }
.opt.done .act { color: var(--ok); } .opt.fail .act { color: var(--err); }
@media (min-width: 768px) {
  .item { display: grid; grid-template-columns: 300px 1fr; }
  .thumb { max-height: none; min-height: 100%; }
}

.gifmaker { padding: 16px; margin-top: 14px; }
.gifmaker h3 { margin: 0 0 4px; font-size: 16px; }
.gifmaker p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .fields { grid-template-columns: repeat(4, 1fr); } }
.fields label, .input-label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.fields input, .fields select, .input-label input { font: inherit; font-size: 16px; color: var(--text); background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; }

/* home */
#home { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 6px; }
.section-head h2, .howto h2 { font-size: 15px; margin: 0; }
.history { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.history button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-align: left; }
.history button:active { background: var(--card-2); }
.history img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--card-2); flex-shrink: 0; }
.history .hx { flex: 1; min-width: 0; }
.history .hx b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .hx small { color: var(--muted); font-size: 12px; }
.howto { padding: 16px 18px; }
.howto ol { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; display: grid; gap: 6px; }
.howto b { color: var(--text); }
.tip { margin: 12px 0 0; font-size: 13px; color: var(--muted); background: var(--card-2); padding: 10px 12px; border-radius: 10px; }
.tip:empty { display: none; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 28px 0 0; }

/* sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; animation: fade .2s; }
.sheet { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 20px calc(16px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: up .25s cubic-bezier(.2,.9,.3,1); max-height: 90dvh; overflow: auto; }
@media (min-width: 640px) { .sheet { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 50%); width: 420px; border-radius: 22px; animation: fade .2s; padding-bottom: 16px; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
@media (min-width: 640px) { .grip { display: none; } }
.sheet h3 { margin: 4px 0 4px; font-size: 18px; text-align: center; }
.sheet .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; text-align: center; word-break: break-all; }
#settingsSheet .sub { text-align: left; word-break: keep-all; }
.sheet .input-label { margin-bottom: 12px; }
.sheet-actions { display: grid; gap: 8px; margin-top: 6px; }
.done-preview { display: grid; place-items: center; margin-bottom: 10px; }
.done-preview img, .done-preview video { max-width: 100%; max-height: 34dvh; border-radius: 12px; background: #000; }
.status-line { font-size: 13px; margin: 0 0 8px; min-height: 1.2em; }
.status-line.ok { color: var(--ok); } .status-line.bad { color: var(--err); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px); background: #111827; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); width: max-content; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--err); }
