:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #263449;
  --bg-input: #0b1120;
  --border: #334155;
  --text: #f8fafc;
  --text-sub: #94a3b8;
  --sky: #38bdf8;
  --sky-soft: rgba(56, 189, 248, 0.16);
  --indigo: #818cf8;
  --emerald: #34d399;
  --danger: #f87171;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

button, input {
  font-family: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.header, .container {
  max-width: 1120px;
  margin-inline: auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(129, 140, 248, 0.22));
  border: 1px solid rgba(56, 189, 248, 0.35);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.brand-meta { min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-pill, .accent-pill {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
}

.accent-pill.active {
  background: var(--sky-soft);
  border-color: var(--sky);
  color: var(--sky);
}

.container {
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toolbar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 13px;
}

.crumb-btn {
  border: none;
  background: transparent;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--text-sub);
  font-weight: 600;
}

.crumb-btn:hover { background: var(--bg-card-hover); color: var(--text); }
.crumb-btn.current { color: var(--sky); background: var(--sky-soft); }
.crumb-sep { color: var(--text-sub); opacity: 0.5; font-size: 12px; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.search-input {
  flex: 1 1 180px;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

.search-input:focus { border-color: var(--sky); }

.kind-pills {
  display: flex;
  gap: 6px;
}

.kind-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
}

.kind-btn.active {
  background: var(--sky-soft);
  border-color: var(--sky);
  color: var(--sky);
}

.setup-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 13px;
  line-height: 1.5;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 8px;
  display: inline-block;
}

.section-head .section-label { margin-bottom: 0; }

.mini-link {
  border: none;
  background: transparent;
  color: var(--sky);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 8px;
}

.folder-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  transition: background 0.12s;
}

.folder-chip:hover { background: var(--bg-card-hover); border-color: rgba(56, 189, 248, 0.5); }
.folder-chip-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

@media (min-width: 640px) {
  .media-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
}

@media (min-width: 900px) {
  .media-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
  }
}

.media-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  padding: 0;
}

.media-tile.selected {
  border-color: var(--sky);
}

.media-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #111827;
}

.media-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
}

.select-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 2px solid #cbd5e1;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}

.media-tile.selected .select-check {
  background: var(--sky);
  border-color: var(--sky);
  color: #0f172a;
}

.empty-state {
  text-align: center;
  color: var(--text-sub);
  padding: 40px 16px;
  font-size: 14px;
}

.select-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: min(520px, calc(100% - 24px));
  background: rgba(30, 41, 59, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--sky);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.select-count { font-size: 13px; font-weight: 700; }
.select-actions { display: flex; gap: 8px; }

.btn-primary, .btn-secondary {
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  border: none;
}

.btn-primary { background: var(--sky); color: #0f172a; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.96);
  display: flex;
  flex-direction: column;
}

.lb-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.6);
}

.lb-info { min-width: 0; }
.lb-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-meta { font-size: 12px; color: var(--text-sub); }

.lb-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.lb-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.lb-btn.download {
  background: var(--sky-soft);
  border-color: var(--sky);
  color: var(--sky);
}

.lb-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px;
}

.lb-media-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-media-wrap img,
.lb-media-wrap video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 42px;
  height: 54px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.65);
  font-size: 26px;
  display: grid;
  place-items: center;
}

.lb-nav.prev { left: 10px; }
.lb-nav.next { right: 10px; }

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.98);
  display: grid;
  place-items: center;
  padding: 16px;
}

.pin-card {
  width: min(340px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
}

.pin-icon { font-size: 30px; margin-bottom: 6px; }
.pin-title { font-size: 18px; font-weight: 800; }
.pin-sub { font-size: 13px; color: var(--text-sub); margin-top: 4px; }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 8px;
}

.pin-dots span {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: transparent;
}

.pin-dots span.filled {
  background: var(--sky);
  border-color: var(--sky);
}

.pin-error {
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
  margin-bottom: 10px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.pin-pad button {
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 18px;
  font-weight: 700;
}

.pin-pad button.fn {
  font-size: 13px;
  color: var(--text-sub);
}

.pin-pad button:active { background: var(--bg-card-hover); }
