:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #1a1d26; --muted: #6e7385; --line: #e4e6ee;
  --accent: #4f5bd5; --accent-soft: #e8eafc; --danger: #c0392b; --danger-soft: #fbe6e3; --ok: #1f8a4c;
  --btn-text: #fff; --shadow: 0 8px 30px rgba(20, 24, 40, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a; --card: #1b1e27; --text: #eceef5; --muted: #8d93a6; --line: #2a2e3a;
    --accent: #8b94ff; --accent-soft: #23264a; --danger: #ff7b6b; --danger-soft: #3d1f1c; --ok: #5fd08a;
    --btn-text: #12141a; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Roboto", "Malgun Gothic", sans-serif; line-height: 1.45; }
body.noscroll { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
.ico { display: inline-flex; width: 22px; height: 22px; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- top bar ---- */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; font-size: 15px; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs .brand, .crumb.last { font-weight: 700; color: var(--text); }
.crumb { color: var(--muted); }
.crumbs .sep { color: var(--muted); }
.tools { display: flex; gap: 6px; flex: none; }
.tbtn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; font-weight: 600; font-size: 14px; }
.tbtn.primary { background: var(--accent); border-color: var(--accent); color: var(--btn-text); }
.tbtn.danger { color: var(--danger); }
.tbtn:disabled { opacity: .45; cursor: default; }
.tbtn:active { opacity: .8; }
@media (max-width: 480px) { .tbtn .lbl { display: none; } .tbtn { padding: 0 10px; } .tbtn.primary .lbl { display: inline; } }

/* ---- main ---- */
.main { max-width: 1100px; margin: 0 auto; padding: 14px 14px 120px; }
.usage { display: flex; align-items: center; gap: 12px; margin: 2px 2px 14px; }
.usage .bar { position: static; flex: 1; height: 6px; padding: 0; border: 0; background: var(--line); border-radius: 999px; overflow: hidden; }
.usage .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; outline: none; transition: transform .1s, border-color .1s; }
.tile:active { transform: scale(.98); }
.tile:focus-visible { border-color: var(--accent); }
.tile .media { position: relative; aspect-ratio: 1 / 1; display: grid; place-items: center; background: var(--bg); color: var(--muted); }
.tile.folder .media { color: var(--accent); background: var(--accent-soft); }
.tile .media .ico { width: 40%; height: 40%; }
.tile .media .ico svg { stroke-width: 1.4; }
.tile.folder .media .ico svg { fill: currentColor; fill-opacity: .18; }
.tile .media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .media .ext { position: absolute; bottom: 10px; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.tile .media .play { position: absolute; width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 15px; padding-left: 3px; }
.tile .meta { padding: 8px 10px 9px; }
.tile .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.tile .dots { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255,255,255,.85); color: #333; display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s; }
.tile .dots .ico { width: 18px; height: 18px; }
.tile:hover .dots, .tile:focus-within .dots { opacity: 1; }
@media (hover: none) { .tile .dots { opacity: 1; background: rgba(255,255,255,.7); } }
.tile .shared { position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--btn-text); display: grid; place-items: center; }
.tile .shared .ico { width: 14px; height: 14px; }
.tile .checkbox { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.35); color: transparent; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.tile .checkbox .ico { width: 16px; height: 16px; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tile.sel .checkbox { background: var(--accent); color: #fff; }
.count { text-align: center; margin: 18px 0 0; }
.small { font-size: 12px; }
.muted { color: var(--muted); }

/* ---- selection bar / uploads ---- */
.selbar, .uploads { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); width: min(680px, calc(100% - 24px)); background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); z-index: 6; }
.selbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.selbar .cnt { flex: 1; font-weight: 700; }
.uploads { padding: 10px 12px; max-height: 40vh; overflow: auto; }
.uhead { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 6px; }
.urow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.uname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ust { color: var(--muted); }
.urow.done .ust { color: var(--ok); }
.urow.error .ust { color: var(--danger); }
.ubar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; }
.ufill { height: 100%; background: var(--accent); }
.urow.done .ufill { background: var(--ok); }
.dropzone { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(79, 91, 213, .18); border: 3px dashed var(--accent); font-size: 20px; font-weight: 700; color: var(--accent); pointer-events: none; }
.dropzone[hidden] { display: none; }

/* ---- overlay, dialogs, menus ---- */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(10, 12, 20, .45); display: grid; place-items: center; }
.overlay.dark { background: rgba(0, 0, 0, .96); }
.overlay.sheet { place-items: end center; }
.overlay[hidden] { display: none; }
.dialog { width: min(440px, calc(100% - 28px)); background: var(--card); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); max-height: 85vh; overflow: auto; }
.dialog h3 { margin: 0 0 12px; font-size: 17px; word-break: break-all; }
.dbtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.menu { width: min(480px, 100%); background: var(--card); border-radius: 18px 18px 0 0; padding: 8px 8px max(10px, env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
@media (min-width: 600px) { .overlay.sheet { place-items: center; } .menu { border-radius: 18px; padding-bottom: 8px; } }
.mitem { display: block; width: 100%; text-align: left; padding: 14px 14px; border: 0; background: none; color: var(--text); font-size: 16px; border-radius: 10px; cursor: pointer; }
.mitem:hover { background: var(--bg); }
.mitem.danger { color: var(--danger); }
.input { font: inherit; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn { font: inherit; font-weight: 700; padding: 11px 16px; border-radius: 12px; border: 0; background: var(--accent); color: var(--btn-text); cursor: pointer; }
.btn.secondary { background: var(--line); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { display: block; width: 100%; margin-top: 10px; }
.btn:active { opacity: .85; }
.row2 { display: flex; gap: 8px; margin-top: 8px; }
.row2 .btn { flex: 1; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0 6px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; }
.dbody label.muted { display: block; margin-bottom: 6px; }
.flist { display: flex; flex-direction: column; max-height: 50vh; overflow: auto; margin: 0 -6px; }
.fitem { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 0; background: none; color: var(--text); text-align: left; border-radius: 10px; cursor: pointer; font-size: 15px; }
.fitem .ico { color: var(--accent); flex: none; }
.fitem:hover { background: var(--bg); }
.fitem:disabled, .fitem.current { opacity: .45; cursor: default; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0 0; }

/* ---- viewer ---- */
.lightbox { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; color: #fff; }
.lb-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.lb-cap { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .9; }
.ibtn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: inherit; cursor: pointer; vertical-align: middle; }
.ibtn + .ibtn, .ibtn + a.ibtn, a.ibtn + .ibtn { margin-left: 6px; }
.uploads .ibtn { width: 30px; height: 30px; background: var(--line); color: var(--text); }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 0 max(10px, env(safe-area-inset-bottom)); }
.lb-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.lb-video { max-width: 100%; max-height: 100%; background: #000; }
.lb-audio { width: min(480px, 90%); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lb-nav.prev { left: 10px; } .lb-nav.next { right: 10px; }
@media (hover: none) { .lb-nav { opacity: .55; } }

/* ---- login ---- */
.login { max-width: 360px; margin: 60px auto 0; text-align: center; }
.login h1 { font-size: 26px; margin: 0 0 6px; }
.login .input { margin-top: 18px; text-align: center; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: max(90px, calc(env(safe-area-inset-bottom) + 90px)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: .2s; z-index: 40; pointer-events: none; max-width: calc(100% - 40px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }
