:root {
    --radius: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: only light;
        /* Pandaknit main site tokens (pandaknit.com) */
        --bg: #fbfbfb;
        --surface: #ffffff;
        --surface-hover: #ececf1;
        --grid-bg: #ececf1;
        --border: #e1e2e3;
        --border-accent: #e1e2e3;
        --text: #333333;
        --muted: #939693;
        --accent: #712aaa;
        --accent-hover: #8526c9;
        --accent-soft: rgba(113, 42, 170, 0.1);
        --folder: #712aaa;
        --header-bg: rgba(236, 236, 241, 0.92);
        --search-bg: #ececf1;
        --modal-backdrop: rgba(51, 51, 51, 0.72);
        --modal-control-bg: rgba(113, 42, 170, 0.08);
        --modal-control-hover: rgba(113, 42, 170, 0.14);
        --modal-control-fg: #333333;
        --thumb-placeholder: #ececf1;
        --success: #42a852;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: only dark;
        --bg: #1e1e24;
        --surface: #2a2a32;
        --surface-hover: #34343e;
        --grid-bg: #18181d;
        --border: #3d3d48;
        --border-accent: #5a4a6e;
        --text: #f4f4f9;
        --muted: #b1b3b7;
        --accent: #984dd3;
        --accent-hover: #b06ee8;
        --accent-soft: rgba(152, 77, 211, 0.16);
        --folder: #984dd3;
        --header-bg: rgba(30, 30, 36, 0.92);
        --modal-backdrop: rgba(0, 0, 0, 0.88);
        --modal-control-bg: rgba(255, 255, 255, 0.08);
        --modal-control-hover: rgba(255, 255, 255, 0.16);
        --modal-control-fg: #ffffff;
        --thumb-placeholder: #34343e;
        --success: #42a852;
        --logo-border: rgba(255, 255, 255, 0.14);
    }
}

/* Samsung Internet ignores prefers-color-scheme: dark and filters the light
   theme instead — see assets/theme-fix.js which toggles this class. */
html.samsung-dark {
    color-scheme: only dark;
    --bg: #1e1e24;
    --surface: #2a2a32;
    --surface-hover: #34343e;
    --grid-bg: #18181d;
    --border: #3d3d48;
    --border-accent: #5a4a6e;
    --text: #f4f4f9;
    --muted: #b1b3b7;
    --accent: #984dd3;
    --accent-hover: #b06ee8;
    --accent-soft: rgba(152, 77, 211, 0.16);
    --folder: #984dd3;
    --header-bg: rgba(30, 30, 36, 0.92);
    --modal-backdrop: rgba(0, 0, 0, 0.88);
    --modal-control-bg: rgba(255, 255, 255, 0.08);
    --modal-control-hover: rgba(255, 255, 255, 0.16);
    --modal-control-fg: #ffffff;
    --thumb-placeholder: #34343e;
    --success: #42a852;
    --logo-border: rgba(255, 255, 255, 0.14);
}

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

html, body {
    height: 100%;
}

html {
    background-color: var(--bg);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

.app {
    --app-pad-x: 2rem;
    --app-pad-top: 1.25rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--app-pad-top) var(--app-pad-x) calc(1.75rem + var(--safe-bottom));
}

.header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    margin-top: calc(-1 * var(--app-pad-top));
    margin-left: calc(-1 * var(--app-pad-x));
    margin-right: calc(-1 * var(--app-pad-x));
    margin-bottom: 0.625rem;
    padding: calc(1rem + var(--app-pad-top)) calc(1.25rem + var(--app-pad-x)) 1.25rem;
    padding-top: calc(1rem + max(var(--app-pad-top), env(safe-area-inset-top, 0px)));
    border-radius: 0 0 calc(var(--radius) + 4px) calc(var(--radius) + 4px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

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

.brand-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: stretch;
    gap: 0;
    min-width: 0;
    padding: 0;
    border: 1px solid var(--logo-border, var(--border));
    border-radius: calc(var(--radius) + 2px);
    background: #ffffff;
    overflow: hidden;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.brand:hover {
    background: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.brand:hover .brand-title {
    color: var(--accent-hover);
}

.brand-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    padding: 5px 10px;
    border: none;
    border-radius: 0;
    border-right: 1px solid var(--border);
    background: #ffffff;
    flex-shrink: 0;
}

.brand-logo {
    height: 26px;
    width: auto;
    max-width: 118px;
    object-fit: contain;
    display: block;
}

.brand-title {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--accent);
    background: #ffffff;
    transition: color 0.15s;
    white-space: nowrap;
}

.brand-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.nav-social {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-social:hover,
.nav-social:focus-visible {
    background: var(--accent);
    color: #ffffff;
    outline: none;
}

.nav-social svg {
    width: 1rem;
    height: 1rem;
    fill: none;
}

.nav-telegram svg,
.nav-viber svg {
    fill: currentColor;
}

.nav-social[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 0.45rem);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.3rem 0.55rem;
    border-radius: calc(var(--radius) - 2px);
    background: var(--text);
    color: var(--surface);
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 1;
}

.nav-social[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 0.15rem);
    left: 50%;
    transform: translateX(-50%);
    border: 0.3rem solid transparent;
    border-top-color: var(--text);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 1;
}

.nav-social[data-tooltip]:hover::after,
.nav-social[data-tooltip]:hover::before,
.nav-social[data-tooltip]:focus-visible::after,
.nav-social[data-tooltip]:focus-visible::before {
    opacity: 1;
    visibility: visible;
}

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

.lang-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface);
}

.lang-btn,
.tool-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tool-btn {
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.tool-btn:hover,
.tool-btn:focus-visible {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
    outline: none;
}

.lang-btn {
    color: var(--muted);
}

.search {
    display: block;
    width: min(100%, 28rem);
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--search-bg, var(--surface));
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search::placeholder {
    color: var(--muted);
}

.search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    color: var(--muted);
    padding: 0.375rem 0 0.875rem;
    min-height: 2rem;
}

.breadcrumb-link {
    color: var(--accent);
}

.breadcrumb-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.breadcrumb-sep {
    color: var(--muted);
    opacity: 0.6;
}

.list-wrap {
    min-height: 40vh;
}

.loading,
.empty-state {
    color: var(--muted);
    padding: 2rem 0;
    text-align: center;
}

.file-list {
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.file-row-wrap {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--border);
}

.file-row-wrap:last-child {
    border-bottom: none;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
    padding: 0.85rem 0.75rem 0.85rem 1rem;
    border: none;
    text-align: left;
    transition: background 0.12s;
}

.file-row-wrap:hover,
.file-row-wrap:focus-within {
    background: var(--surface-hover);
}

.file-row-wrap.active {
    background: var(--accent-soft);
}

.file-row:hover,
.file-row:focus-visible {
    background: transparent;
    outline: none;
}

.copy-link-btn,
.file-action-btn {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-accent);
    color: var(--muted);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 0;
    text-decoration: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    background: transparent;
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    align-self: center;
    margin-right: 0.5rem;
}

.copy-link-btn:hover,
.copy-link-btn:focus-visible,
.file-action-btn:hover,
.file-action-btn:focus-visible {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
    outline: none;
}

.copy-link-btn.copied {
    color: var(--success);
    border-color: var(--success);
}

.not-found {
    color: var(--muted);
    padding: 2rem 1rem;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.row-icon {
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.row-icon.folder { color: var(--folder); }
.row-icon.video { color: var(--accent); }
.row-icon.image { color: var(--success); }

.copy-link-btn svg,
.file-action-btn svg {
    width: 1rem;
    height: 1rem;
}

.copy-link-btn.copied svg {
    display: none;
}

.copy-link-btn.copied::after {
    content: '✓';
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--success);
}

.row-name {
    flex: 1;
    min-width: 0;
    font-size: 0.95rem;
    word-break: break-word;
}

.row-meta {
    font-size: 0.75rem;
    color: var(--muted);
    flex-shrink: 0;
    max-width: 45%;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal[hidden] {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--modal-backdrop);
}

.modal-shell {
    position: relative;
    z-index: 1;
    width: min(96vw, 1100px);
    max-height: 96vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.5rem 3rem 1rem;
}

.modal-close,
.modal-nav {
    color: var(--modal-control-fg);
    background: var(--modal-control-bg);
}

.modal-close {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    font-size: 1.75rem;
    line-height: 1;
    z-index: 3;
}

.modal-close:hover,
.modal-nav:hover {
    background: var(--modal-control-hover);
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    font-size: 2rem;
    line-height: 1;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-prev { left: 0.25rem; }
.modal-next { right: 0.25rem; }

.modal-nav:disabled {
    opacity: 0.25;
    cursor: default;
}

.modal-content {
    width: 100%;
    max-height: calc(96vh - 5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: pinch-zoom;
}

.modal-content img,
.modal-content video {
    max-width: 100%;
    max-height: calc(96vh - 5rem);
    border-radius: 6px;
    background: #000;
}

.modal-content video {
    width: 100%;
}

.modal-caption {
    margin-top: 0.75rem;
    color: var(--muted);
    font-size: 0.875rem;
    text-align: center;
    word-break: break-word;
    max-width: 100%;
}

.modal-actions {
    display: flex;
    justify-content: center;
    margin-top: 0.65rem;
}

.modal-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.95rem;
    border-radius: 999px;
    background: var(--modal-control-bg);
    color: var(--modal-control-fg);
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.15s;
}

.modal-action-btn:hover,
.modal-action-btn:focus-visible {
    background: var(--modal-control-hover);
    outline: none;
}

.modal-action-btn svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .app {
        --app-pad-x: 2.75rem;
        padding-left: var(--app-pad-x);
        padding-right: var(--app-pad-x);
    }

    .search {
        width: min(100%, 32rem);
    }
}

@media (min-width: 1024px) {
    .app {
        --app-pad-x: 3.5rem;
        padding-left: var(--app-pad-x);
        padding-right: var(--app-pad-x);
    }
}

@media (max-width: 640px) {
    .app {
        --app-pad-top: 0.75rem;
        --app-pad-x: 1rem;
        padding-top: var(--app-pad-top);
        padding-left: max(var(--app-pad-x), env(safe-area-inset-left, 0px));
        padding-right: max(var(--app-pad-x), env(safe-area-inset-right, 0px));
    }

    .header {
        margin-left: calc(-1 * max(var(--app-pad-x), env(safe-area-inset-left, 0px)));
        margin-right: calc(-1 * max(var(--app-pad-x), env(safe-area-inset-right, 0px)));
        padding-top: calc(0.5rem + max(var(--app-pad-top), env(safe-area-inset-top, 0px)));
        padding-left: calc(0.75rem + max(var(--app-pad-x), env(safe-area-inset-left, 0px)));
        padding-right: calc(0.75rem + max(var(--app-pad-x), env(safe-area-inset-right, 0px)));
        padding-bottom: 0.625rem;
        margin-bottom: 0.375rem;
    }

    .header-top {
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.375rem;
        margin-bottom: 0.5rem;
    }

    .brand-group {
        flex: 1 1 auto;
        min-width: 0;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 0.375rem;
    }

    .brand {
        min-width: 0;
    }

    .brand-logo-wrap {
        height: 30px;
        padding: 3px 7px;
    }

    .brand-logo {
        height: 20px;
        max-width: 82px;
    }

    .brand-title {
        font-size: 0.875rem;
        padding: 0 0.5rem;
    }

    .brand-nav {
        gap: 0.25rem;
        margin-left: auto;
    }

    .nav-social {
        width: 1.85rem;
        height: 1.85rem;
    }

    .header-actions {
        flex: 0 0 auto;
    }

    .tool-btn {
        width: auto;
        padding: 0.35rem 0.5rem;
        font-size: 0.6875rem;
        white-space: nowrap;
    }

    .search {
        width: 100%;
        max-width: none;
        padding: 0.5rem 0.75rem;
        font-size: 0.9375rem;
    }

    .breadcrumbs {
        padding: 0.125rem 0 0.5rem;
        font-size: 0.8125rem;
        min-height: 1.5rem;
    }

    .modal-shell {
        padding: 2.75rem 0.5rem 1rem;
        width: 100vw;
        max-height: 100vh;
    }

    .modal-nav {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.5rem;
    }

    .modal-content img,
    .modal-content video {
        max-height: calc(100vh - 6rem);
    }

    .row-meta {
        display: none;
    }
}

@media (max-width: 380px) {
    .brand-title {
        display: none;
    }

    .tool-btn {
        padding: 0.35rem 0.4rem;
        font-size: 0.625rem;
    }
}

.file-list.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    background: var(--grid-bg);
    border: none;
    padding: 1rem;
}

.file-list.grid .file-row-wrap {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.file-list.grid .file-row-wrap:hover,
.file-list.grid .file-row-wrap:focus-within {
    border-color: var(--border);
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(51, 51, 51, 0.08);
}

.file-list.grid .file-row {
    flex-direction: column;
    flex: 1;
    padding: 0.5rem 0.5rem 0.35rem;
    text-align: center;
}

.file-list.grid .file-actions {
    margin: 0.15rem 0.5rem 0.7rem;
    align-self: center;
}

.file-list.grid .row-icon {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-list.grid .row-icon svg {
    width: 2.5rem;
    height: 2.5rem;
    opacity: 0.85;
}

.thumb-wrap {
    position: relative;
    width: 100%;
    flex-shrink: 0;
}

.thumb-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: calc(var(--radius) - 2px);
    display: block;
    background: var(--thumb-placeholder);
}

.thumb-video {
    pointer-events: none;
}

.thumb-wrap.thumb-loading .thumb-img {
    background: var(--thumb-placeholder);
    min-height: 100px;
}

.thumb-play {
    position: absolute;
    right: 0.4rem;
    bottom: 0.4rem;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.thumb-play svg {
    width: 0.65rem;
    height: 0.65rem;
    margin-left: 0.1rem;
}

.file-list:not(.grid) .thumb-wrap {
    width: 2.5rem;
}

.file-list:not(.grid) .thumb-img {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.375rem;
}

.file-list:not(.grid) .thumb-play {
    width: 1rem;
    height: 1rem;
    right: 0.1rem;
    bottom: 0.1rem;
    font-size: 0.45rem;
}

@media (max-width: 640px) {
    .file-list.grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.625rem;
        padding: 0.625rem;
    }

    .file-list.grid .thumb-img,
    .file-list.grid .row-icon,
    .file-list.grid .thumb-wrap.thumb-loading .thumb-img {
        height: 72px;
        min-height: 72px;
    }

    .file-list.grid .file-row {
        padding: 0.4rem 0.35rem 0.25rem;
    }

    .file-list.grid .row-name {
        font-size: 0.7rem;
        line-height: 1.25;
    }

    .file-list.grid .file-actions {
        margin: 0.1rem 0.35rem 0.5rem;
        gap: 0.25rem;
    }

    .file-list.grid .file-action-btn {
        width: 2rem;
        height: 2rem;
    }
}
