:root {
  color-scheme: dark;
  --bg: #070b16;
  --panel: #0d1426;
  --panel-2: #111b31;
  --text: #eef3ff;
  --muted: #94a3b8;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #70a7ff;
  --accent-2: #9fd0ff;
  --danger: #ff6b6b;
  --radius: 22px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(112, 167, 255, 0.22), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(159, 208, 255, 0.12), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.noscript {
  padding: 1rem;
  background: #6b1111;
  color: white;
}

.app-shell {
  min-height: 100vh;
}

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.lock-card {
  width: min(100%, 500px);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 20, 38, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 1rem;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(112, 167, 255, 0.32), rgba(255, 255, 255, 0.08));
  color: var(--accent-2);
  font-size: 2rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.lock-card h1,
.topbar h1 {
  margin-bottom: 0.35rem;
}

.muted,
#storageInfo,
#viewerMeta {
  color: var(--muted);
}

.auth-panel {
  margin-top: 1.4rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line);
}

.primary-btn,
.ghost-btn,
.danger-btn,
.file-picker,
.filter-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.65rem 0.95rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.primary-btn,
.file-picker {
  margin-top: 0.9rem;
  border-color: transparent;
  background: linear-gradient(135deg, #4f8cff, #77c4ff);
  color: #07101f;
  font-weight: 700;
}

.danger-btn {
  color: white;
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.16);
}

.message {
  min-height: 1.4rem;
  margin-top: 1rem;
  color: var(--accent-2);
}

.auth-note {
  margin-top: 1.2rem;
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  line-height: 1.45;
}

.main-app {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 0 1.2rem;
}

.top-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.library-controls {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 0.8rem 0;
  background: linear-gradient(to bottom, var(--bg) 76%, transparent);
  backdrop-filter: blur(10px);
}

input[type="search"],
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 1rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  outline: none;
}

select {
  appearance: none;
}

input:focus,
select:focus {
  border-color: rgba(112, 167, 255, 0.9);
  box-shadow: 0 0 0 4px rgba(112, 167, 255, 0.16);
}

.control-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.select-label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.filters {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.8rem 0 0.25rem;
}

.filter-btn {
  white-space: nowrap;
}

.filter-btn.active {
  color: #07101f;
  background: var(--accent-2);
  border-color: transparent;
  font-weight: 700;
}

.empty-state {
  margin-top: 2rem;
  padding: 2rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  background: rgba(255, 255, 255, 0.035);
}

.library-view {
  display: grid;
  gap: 1.25rem;
  padding-top: 1rem;
}

.file-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
}

.file-section-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.file-section-title {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0;
  font-size: 1.05rem;
}

.file-section-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.file-card {
  display: grid;
  gap: 0.65rem;
  align-content: start;
  min-height: 164px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0.9rem;
  background: rgba(17, 27, 49, 0.78);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.18);
  text-align: left;
}

.file-card:hover {
  border-color: rgba(112, 167, 255, 0.7);
}

.file-icon {
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 2.2rem;
}

.file-name {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.file-details {
  color: var(--muted);
  font-size: 0.85rem;
}

.viewer-dialog {
  width: min(1100px, calc(100vw - 1.5rem));
  height: min(860px, calc(100vh - 1.5rem));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.viewer-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.viewer-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

.viewer-header h2 {
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
}

.viewer-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.viewer-body {
  min-height: 0;
  overflow: auto;
  padding: 1rem;
}

.viewer-body img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: 0 auto;
  border-radius: 14px;
}

.viewer-body video,
.viewer-body audio {
  width: 100%;
}

.viewer-body iframe {
  width: 100%;
  min-height: 72vh;
  border: 0;
  border-radius: 14px;
  background: white;
}

.text-viewer {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: #dbeafe;
  line-height: 1.55;
}

.unsupported {
  display: grid;
  place-items: center;
  min-height: 280px;
  padding: 2rem;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .lock-card {
    padding: 1.25rem;
  }

  .topbar,
  .viewer-header {
    flex-direction: column;
  }

  .top-actions,
  .viewer-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions > *,
  .viewer-actions > * {
    flex: 1;
    text-align: center;
  }

  .control-row {
    grid-template-columns: 1fr;
  }

  .file-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
