:root {
    --page: #05070e;
    --card: #0b0e16;
    --panel: #0a0d14;
    --tile: #070910;
    --tile-foot: #0d1018;
    --border: #1a1e29;
    --border-soft: #141824;
    --border-hover: #2a3040;
    --text: #e9ebf0;
    --dim: #8b909d;
    --faint: #565b68;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.16);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.12);
    --radius: 16px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Ensure the HTML `hidden` attribute always wins over display rules below. */
[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background:
        radial-gradient(1200px circle at 50% -10%, #0f1830 0%, transparent 45%),
        var(--page);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dim { color: var(--dim); }
.inline { display: inline; }

/* App shell */
.app {
    max-width: 1160px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

/* Topbar */
.topbar { margin-bottom: 1.5rem; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--dim);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.7rem;
    transition: color 0.15s;
}
.back-link:hover { color: #fff; }

.app-title {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: #fff;
}

.app-path {
    color: var(--faint);
    font-size: 0.9rem;
    margin-top: 0.15rem;
}

/* Storage */
.storage-card {
    background: var(--card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.5rem;
}

.storage-bar {
    height: 4px;
    background: #161a25;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.85rem;
}
.storage-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    border-radius: 999px;
    min-width: 2%;
    transition: width 0.4s;
}

.storage-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--dim);
}
.storage-meta strong { color: #fff; }

/* Alerts */
.alert {
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.88rem;
}
.alert-error { background: #2a1416; border: 1px solid #532225; color: #f8a5a5; }
.alert-success { background: #10231a; border: 1px solid #1d5638; color: #6ee7a8; }

/* Panel */
.panel {
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.2s;
}
.panel.drop { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft) inset; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

/* Breadcrumb */
.crumbs { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }

.crumb-back {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tile);
    border: 1px solid var(--border);
    color: var(--dim);
    text-decoration: none;
    flex-shrink: 0;
    transition: all 0.15s;
}
.crumb-back:hover { color: #fff; border-color: var(--border-hover); }

.crumb-path {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.95rem;
    min-width: 0;
    overflow: hidden;
}
.crumb-path a { color: var(--dim); text-decoration: none; transition: color 0.15s; white-space: nowrap; }
.crumb-path a:hover { color: #fff; }
.crumb-path .sep { color: var(--faint); }
.crumb-path .current { color: #fff; font-weight: 600; white-space: nowrap; }

/* Tools */
.tools { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.tool {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: all 0.15s;
}
.tool:hover { border-color: var(--border-hover); background: #10131c; }
.tool.active { border-color: var(--accent); color: #fff; background: var(--accent-soft); }
.tool svg { opacity: 0.85; }
.tool.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.tool.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.sort { display: inline-flex; align-items: center; gap: 0.45rem; }
.sort-label { color: var(--faint); font-size: 0.8rem; }
.sort-select {
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.5rem 0.65rem;
    cursor: pointer;
    font-family: inherit;
    outline: none;
}
.sort-select:hover { border-color: var(--border-hover); }
.sort-select option { background: #10131c; }

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.85rem;
}

.tile {
    position: relative;
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all 0.16s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}
.tile:hover { border-color: var(--border-hover); transform: translateY(-2px); }

/* Drag & drop: image -> folder */
.file-tile[draggable="true"] { cursor: grab; }
.file-tile.dragging { opacity: 0.4; transform: scale(0.97); }
.drop-folder.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
    background: var(--accent-soft);
}
.drop-folder.drag-over .tile-thumb { color: #6ea2ff; }

.tile-hit { display: block; text-decoration: none; color: inherit; }

.tile-thumb {
    aspect-ratio: 1 / 0.82;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #04050a;
    color: #2f6bd8;
    position: relative;
    overflow: hidden;
}
.tile-thumb.img { color: transparent; background: #04050a; }
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; }

.folder-tile .tile-thumb { color: #2f6bd8; }
.folder-tile:hover .tile-thumb { color: #4f8bf5; }

.tile-foot {
    padding: 0.6rem 0.75rem 0.7rem;
    background: var(--tile-foot);
    border-top: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.tile-name {
    color: #f1f2f5;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile-meta {
    color: var(--faint);
    font-size: 0.73rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Parent tile */
.parent-tile { border-color: var(--accent); background: var(--accent-soft); }
.parent-tile .tile-thumb { color: #6ea2ff; background: transparent; }
.parent-tile .tile-foot { background: transparent; border-top-color: rgba(37, 99, 235, 0.25); }
.parent-tile .tile-name { color: #8fb6ff; }
.parent-tile .tile-meta { color: #5f7bb5; }

/* Copy button on image tiles */
.tile-copy {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: rgba(6, 8, 14, 0.7);
    backdrop-filter: blur(4px);
    color: #cfd4de;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s;
}
.tile:hover .tile-copy { opacity: 1; }
.tile-copy:hover { background: var(--accent); color: #fff; }

/* Folder options button */
.tile-menu {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: rgba(6, 8, 14, 0.6);
    color: #cfd4de;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s;
    z-index: 2;
}
.folder-tile:hover .tile-menu { opacity: 1; }
.tile-menu:hover { background: #10131c; color: #fff; }

/* Select mode */
.tile-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: rgba(6, 8, 14, 0.7);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    color: transparent;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
.grid.selecting .file-tile .tile-check { display: flex; }
.grid.selecting .file-tile .tile-copy { display: none; }
.file-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.file-tile.selected .tile-check { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Panel foot */
.panel-foot {
    text-align: center;
    color: var(--faint);
    font-size: 0.82rem;
    margin-top: 1.5rem;
    padding-top: 0.5rem;
}

/* Empty */
.empty {
    text-align: center;
    padding: 3.5rem 1rem;
    color: var(--faint);
}

/* App foot */
.app-foot { text-align: center; margin-top: 1.5rem; }
.foot-link { color: var(--dim); font-size: 0.85rem; text-decoration: none; }
.foot-link:hover { color: #fff; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--tile);
    color: var(--text);
    font-size: 0.83rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: all 0.15s;
}
.btn:hover { border-color: var(--border-hover); background: #10131c; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: transparent; border-color: rgba(239, 68, 68, 0.35); color: #f87171; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.78rem; }
.btn.icon-only { padding: 0.55rem; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 3, 8, 0.72);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 100;
    animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
    width: 100%;
    max-width: 880px;
    background: #090b12;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: pop 0.18s ease;
}
.modal-sm { max-width: 400px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    color: var(--dim);
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-soft);
}
.modal-x {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s;
}
.modal-x:hover { color: #fff; }

.modal-preview {
    margin: 1.25rem;
    border-radius: var(--radius-md);
    background: #04050a;
    border: 1px solid var(--border-soft);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 46vh;
}
.modal-preview img { max-width: 100%; max-height: 46vh; object-fit: contain; }

.modal-body { padding: 0 1.25rem 1.25rem; }

.modal-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--faint);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
}

.url-row { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
.url-row input {
    flex: 1;
    background: #04050a;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: #dfe3ea;
    padding: 0.6rem 0.8rem;
    font-size: 0.83rem;
    min-width: 0;
}

.modal-input {
    width: 100%;
    background: #04050a;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: #fff;
    padding: 0.7rem 0.85rem;
    font-size: 0.92rem;
    font-family: inherit;
    margin-bottom: 1rem;
}
.modal-input:focus { outline: none; border-color: var(--accent); }

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

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.82rem;
}
.modal-foot-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Popover (folder menu) */
.popover {
    position: fixed;
    z-index: 120;
    background: #0d1018;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 0.3rem;
    min-width: 150px;
}
.popover button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}
.popover button:hover { background: #161a25; }
.popover button.danger { color: #f87171; }
.popover button.danger:hover { background: var(--danger-soft); }

/* Bulk bar */
.bulkbar {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #0d1018;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.6rem 0.9rem;
    box-shadow: var(--shadow);
    z-index: 90;
}
.bulk-count { font-size: 0.85rem; color: var(--dim); padding-left: 0.4rem; }
.bulk-count span { color: #fff; font-weight: 600; }
.bulk-select {
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    padding: 0.45rem 0.8rem;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
    outline: none;
}
.bulk-select option { background: #10131c; }

/* Audio */
.audio-list { display: flex; flex-direction: column; gap: 0.7rem; }
.audio-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}
.audio-card:hover { border-color: var(--border-hover); }
.audio-icon {
    flex-shrink: 0;
    width: 46px; height: 46px;
    border-radius: 11px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
}
.audio-info { flex: 1; min-width: 0; }
.audio-name { font-size: 0.9rem; color: #eee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.15rem; }
.audio-meta { font-size: 0.75rem; color: var(--faint); margin-bottom: 0.5rem; }
.audio-player { width: 100%; height: 32px; }
.audio-player::-webkit-media-controls-panel { background: #10131c; }
.audio-actions { flex-shrink: 0; display: flex; flex-direction: column; gap: 0.4rem; }

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent);
    color: #fff;
    padding: 0.7rem 1.4rem;
    border-radius: 999px;
    font-size: 0.88rem;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    z-index: 200;
    box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ===== Login ===== */
.login-page { display: flex; align-items: center; justify-content: center; padding: 1.5rem; min-height: 100vh; }
.login-wrapper { width: 100%; max-width: 400px; }
.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2.5rem 2rem 2rem;
    box-shadow: var(--shadow);
    text-align: center;
    animation: pop 0.35s ease;
}
.login-logo {
    width: 60px; height: 60px;
    margin: 0 auto 1.25rem;
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.4);
}
.login-title { font-size: 1.6rem; color: #fff; margin-bottom: 0.35rem; }
.login-subtitle { color: var(--dim); font-size: 0.9rem; margin-bottom: 1.75rem; }
.login-alert { text-align: left; margin-bottom: 1.25rem; }
.login-form { text-align: left; }
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; margin-bottom: 0.45rem; font-size: 0.82rem; color: var(--dim); font-weight: 500; }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon svg { position: absolute; left: 0.85rem; color: var(--faint); pointer-events: none; transition: color 0.15s; }
.input-icon input {
    width: 100%;
    padding: 0.75rem 0.9rem 0.75rem 2.6rem;
    background: var(--tile);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}
.input-icon input::placeholder { color: var(--faint); }
.input-icon input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-icon:focus-within svg { color: var(--accent); }
.btn-upload {
    width: 100%;
    padding: 0.8rem;
    font-size: 1rem;
    justify-content: center;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    margin-top: 0.5rem;
}
.btn-upload:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.login-footer { text-align: center; color: var(--faint); font-size: 0.78rem; margin-top: 1.5rem; }

/* Responsive */
@media (max-width: 720px) {
    .app { padding: 1.5rem 1rem 2.5rem; }
    .panel-head { flex-direction: column; align-items: stretch; }
    .tools { justify-content: flex-start; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
    .modal-foot-actions { width: 100%; }
    .bulkbar { flex-wrap: wrap; justify-content: center; width: calc(100% - 2rem); border-radius: var(--radius); }
}
