:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #eef0f6; --text: #151826; --muted: #6b7084;
  --line: #e3e5ee; --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: #e8e7fd;
  --danger: #dc2626; --ok: #16a34a; --folder: #f5b524; --shadow: 0 8px 28px rgba(20, 24, 50, .14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #181b24; --surface-2: #222632; --text: #eceef5; --muted: #9096aa;
    --line: #2b2f3c; --accent: #7c74ff; --accent-ink: #0f1117; --accent-soft: #272a4d;
    --danger: #f87171; --ok: #4ade80; --folder: #f5c04a; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #181b24; --surface-2: #222632; --text: #eceef5; --muted: #9096aa;
  --line: #2b2f3c; --accent: #7c74ff; --accent-ink: #0f1117; --accent-soft: #272a4d;
  --danger: #f87171; --ok: #4ade80; --folder: #f5c04a; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Pretendard", system-ui, sans-serif;
  min-height: 100dvh; overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.error { color: var(--danger); min-height: 1.5em; margin: 4px 0 0; font-size: 14px; }

/* 버튼 */
.btn { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--surface-2); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip.danger { color: var(--danger); }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--text); display: inline-flex; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.light { color: #fff; }

/* 로그인 */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { width: 72px; height: 72px; border-radius: 18px; }
.auth-card h1 { margin: 12px 0 4px; font-size: 22px; }
.auth-card form { text-align: left; margin-top: 16px; display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input:not([type="checkbox"]) {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 11px 12px; font-size: 16px; color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.top-logo { width: 30px; height: 30px; border-radius: 8px; }
.top-title { flex: 1; font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btn-admin.active { color: var(--accent); background: var(--accent-soft); }

#files, #admin { max-width: 860px; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom)); }

/* 경로 */
.crumbs { display: flex; gap: 2px; align-items: center; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; white-space: nowrap; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { border: 0; background: none; padding: 4px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.crumbs button:last-child { color: var(--text); }
.crumbs .sep { color: var(--muted); opacity: .6; }
.toolbar { display: flex; justify-content: space-between; align-items: center; padding: 6px 0 8px; gap: 8px; font-size: 13px; }

/* 목록 */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 6px 10px 12px; border-bottom: 1px solid var(--line); min-height: 62px; }
.item:last-child { border-bottom: 0; }
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
.item-main:active { opacity: .6; }
.thumb { width: 42px; height: 42px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--surface-2); overflow: hidden; font-size: 11px; font-weight: 700; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.folder { background: none; color: var(--folder); }
.thumb.folder svg { width: 40px; height: 40px; }
.thumb.video { background: #312e81; color: #fff; }
.thumb.audio { background: #0e7490; color: #fff; }
.thumb.doc { background: #1d4ed8; color: #fff; }
.thumb.zip { background: #92400e; color: #fff; }
.item-text { min-width: 0; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12.5px; color: var(--muted); }
.more { flex: none; }
.empty { text-align: center; padding: 48px 0; }

/* 플로팅 버튼 */
.fab {
  position: fixed; right: max(18px, calc(50% - 412px)); bottom: calc(22px + env(safe-area-inset-bottom)); width: 58px; height: 58px;
  border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center; z-index: 20;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.95); }

/* 시트 */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; box-shadow: var(--shadow);
  animation: up .18s ease-out; max-height: 85dvh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 4px 10px; font-size: 16px; word-break: break-all; }
.sheet-action { display: flex; width: 100%; align-items: center; gap: 14px; padding: 13px 8px; border: 0; background: none; border-radius: 10px; cursor: pointer; text-align: left; font-size: 15.5px; }
.sheet-action:active { background: var(--surface-2); }
.sheet-action.danger { color: var(--danger); }
.sheet-action svg { color: var(--muted); }
.sheet-action.danger svg { color: var(--danger); }
.sheet form { display: grid; gap: 10px; padding: 4px; }
.sheet .row { display: flex; gap: 8px; justify-content: flex-end; }

/* 미리보기 */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; color: #fff; }
.viewer-top span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding-bottom: env(safe-area-inset-bottom); touch-action: pan-y pinch-zoom; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-stage audio { width: min(90%, 480px); }
.viewer-stage pre { color: #e5e7eb; white-space: pre-wrap; word-break: break-all; padding: 16px; margin: 0; overflow: auto; max-height: 100%; width: 100%; font-size: 13px; place-self: stretch; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); border: 0; background: rgba(255, 255, 255, .14); color: #fff; width: 44px; height: 64px; font-size: 32px; border-radius: 12px; cursor: pointer; }
.v-nav.prev { left: 8px; } .v-nav.next { right: 8px; }

/* 업로드 */
.uploads {
  position: fixed; left: 12px; right: 12px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 30; max-width: 520px; margin: 0 auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; max-height: 40dvh; overflow-y: auto;
}
.uploads-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.uploads ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.up-name { font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.up-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-done .bar div { background: var(--ok); }
.up-fail .bar div { background: var(--danger); }
.up-fail .up-name span:last-child { color: var(--danger); }

/* 관리자 */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.tab { border: 0; border-radius: 999px; padding: 8px 14px; background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.panel { display: grid; gap: 12px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.form-row { display: grid; gap: 10px; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; }
.meter { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin-bottom: 6px; }
.meter div { height: 100%; background: var(--accent); border-radius: 5px; }
.log { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); font-size: 13px; }
.log li { padding: 9px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 1px; }
.log li:last-child { border-bottom: 0; }
.log .when { color: var(--muted); font-size: 12px; }
.log .what { word-break: break-all; }

/* 알림 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  .item { padding-left: 16px; }
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 20px; animation: none; }
  .sheet-handle { display: none; }
}
