:root {
    --bg: #121216;
    --surface: #1c1c22;
    --surface-2: #26262e;
    --text: #ececf1;
    --muted: #9a9aa8;
    --accent: #f5a524;
    --accent-text: #1a1a1f;
    --border: #2e2e38;
    --radius: 10px;
    color-scheme: dark;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f6f8;
        --surface: #ffffff;
        --surface-2: #ececf1;
        --text: #18181d;
        --muted: #62626e;
        --accent: #d98a00;
        --accent-text: #ffffff;
        --border: #dcdce3;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;
}

a { color: inherit; }

button { font: inherit; color: inherit; }

/* ---------- шапка ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.brand::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    border-radius: 3px;
    background: var(--accent);
}

.crumbs {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
}

.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { margin: 0 8px; opacity: 0.5; }

.user {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    color: var(--muted);
}

.user img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.user a { font-size: 13px; }

/* ---------- страница ---------- */

.page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

h1 { font-size: 26px; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 18px; margin: 32px 0 14px; }

.sub { color: var(--muted); margin: 0 0 20px; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin: 0 0 20px;
}

.search {
    flex: 1;
    min-width: 200px;
    max-width: 420px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.empty, .loading {
    padding: 48px 0;
    text-align: center;
    color: var(--muted);
}

/* ---------- сетки ---------- */

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

.card {
    display: block;
    text-decoration: none;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: transform 0.12s, border-color 0.12s;
}

.card:hover { transform: translateY(-2px); border-color: var(--accent); }

.card .cover {
    position: relative;
    aspect-ratio: 3 / 4;
    background: var(--surface-2);
}

.card .cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card .badge {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 12px;
}

.card .meta { padding: 10px 12px 12px; }

.card .title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-weight: 600;
    line-height: 1.35;
}

.card .info { color: var(--muted); font-size: 13px; margin-top: 4px; }

.grid.creators { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid.creators .cover { aspect-ratio: 4 / 3; }

/* ---------- пост ---------- */

.post-head { max-width: 900px; margin: 0 auto 24px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }

.tag {
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 13px;
}

.post-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 20px 0 0;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
}

.post-text.collapsed { max-height: 220px; overflow: hidden; mask-image: linear-gradient(#000 70%, transparent); }

.link-btn {
    margin-top: 8px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    cursor: pointer;
}

.images {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.images img {
    display: block;
    max-width: min(100%, 1100px);
    height: auto;
    border-radius: 6px;
    background: var(--surface-2);
    cursor: zoom-in;
}

.videos {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin: 0 0 20px;
}

.videos figure {
    margin: 0;
    width: min(100%, 1100px);
}

.videos video {
    display: block;
    width: 100%;
    max-height: 80vh;
    border-radius: 6px;
    background: #000;
}

.videos figcaption {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 6px;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.videos figcaption a { color: var(--accent); }

.video-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 44px;
    color: var(--muted);
}

.files {
    max-width: 900px;
    margin: 32px auto 0;
    padding: 0;
    list-style: none;
}

.files li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    margin-bottom: 8px;
}

.files .size { color: var(--muted); white-space: nowrap; }

.pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 900px;
    margin: 40px auto 0;
}

.pager a {
    display: block;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.pager a:hover { border-color: var(--accent); }
.pager .older { text-align: right; grid-column: 2; }
.pager small { display: block; color: var(--muted); }

/* ---------- вход и сообщения ---------- */

.message {
    max-width: 460px;
    margin: 18vh auto 0;
    padding: 0 16px;
    text-align: center;
}

.message p { color: var(--muted); }

.button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 11px 20px;
    border: 0;
    border-radius: var(--radius);
    background: #5865f2;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.button:hover { background: #4752c4; }

/* ---------- загрузка (админ) ---------- */

.admin-link {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    font-size: 13px;
    color: var(--text);
}

.admin-link.busy { border-color: var(--accent); color: var(--accent); }

.panel {
    max-width: 900px;
    margin: 0 0 20px;
    padding: 18px 20px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.panel h2 { margin: 0 0 14px; font-size: 17px; }
.panel[hidden] { display: none; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.panel-head h2 { margin: 0; }

.drop {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 110px;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.drop:hover, .drop.over { border-color: var(--accent); color: var(--text); }

.summary {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface-2);
}

.summary[hidden] { display: none; }

.options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
    margin: 14px 0 0;
}

.options label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.options input { accent-color: var(--accent); width: 16px; height: 16px; }

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

.button.accent { background: var(--accent); color: var(--accent-text); margin-top: 0; }
.button.accent:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.button.ghost { background: var(--surface-2); color: var(--text); margin-top: 0; }
.button.ghost:hover { background: var(--border); }
.button[disabled] { opacity: 0.5; cursor: not-allowed; }
.button[hidden] { display: none; }

.search.wide { max-width: none; flex: 1 1 280px; }

.error { color: #f06a6a; margin: 10px 0 0; }
.error[hidden] { display: none; }
.ok { color: #4cc38a; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.pill.running { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.pill.done { background: color-mix(in srgb, #4cc38a 20%, transparent); color: #4cc38a; }
.pill.failed { background: color-mix(in srgb, #f06a6a 20%, transparent); color: #f06a6a; }

.job-title {
    font-weight: 600;
    margin-bottom: 12px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bar-label { font-size: 13px; color: var(--muted); margin: 10px 0 5px; }

.bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.bar[hidden] { display: none; }

.bar-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.4s ease;
}

.job-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 14px;
    font-size: 14px;
}

.job-stats a { color: var(--accent); }

details { margin-top: 16px; }
summary { cursor: pointer; color: var(--muted); }

.log {
    max-height: 320px;
    overflow: auto;
    margin: 8px 0 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bg);
    font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.log-warn { color: var(--accent); }
.log-error { color: #f06a6a; }

.history { list-style: none; margin: 0; padding: 0; }

.history li {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    align-items: center;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.history li:first-child { border-top: 0; }

/* ---------- управление: вкладки, люди, настройки ---------- */

.tabs {
    display: flex;
    gap: 4px;
    margin: 12px 0 20px;
    border-bottom: 1px solid var(--border);
    max-width: 900px;
}

.tabs a {
    padding: 8px 14px;
    text-decoration: none;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.people { list-style: none; margin: 0; padding: 0; }

.people li {
    display: grid;
    grid-template-columns: 36px minmax(0, 1.3fr) 120px minmax(0, 1fr) 130px 170px;
    gap: 6px 14px;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}

.people li.short { grid-template-columns: 36px minmax(0, 1fr) 170px 210px; }
.people li:first-child { border-top: 0; }
.people li.muted { display: block; }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-2);
    display: block;
}

.who { min-width: 0; }
.who .name { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-weight: 600; overflow-wrap: anywhere; }
.when { line-height: 1.35; }

.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.mono-wrap { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }

.select, .note {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    min-width: 0;
}

.select[disabled] { opacity: 0.6; }

.actions { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: flex-end; }
.actions .link-btn { margin: 0; font-size: 13px; }
.link-btn.danger { color: #f06a6a; }

.button.small { padding: 6px 12px; font-size: 13px; margin-top: 0; }

.inline { font-size: 14px; }
.error.inline { margin: 0; }

.events { list-style: none; margin: 10px 0 0; padding: 0; font-size: 14px; }
.events li { padding: 4px 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; max-width: 560px; }
.field > span:first-child { font-weight: 600; font-size: 14px; }
.field .search { flex: none; max-width: none; }
.field .search.narrow { max-width: 140px; }
textarea.search { resize: vertical; font-family: inherit; }
.search.narrow { max-width: 140px; min-width: 0; }

.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 18px;
    font-size: 14px;
}

.spacer { height: 18px; }

.invite-result {
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.invite-result[hidden] { display: none; }
.invite-result .row { margin-top: 0; }
.invite-result p { margin: 8px 0 0; }
.invites { margin-top: 14px; }
.message form { margin-top: 18px; }

@media (max-width: 760px) {
    .people li, .people li.short { grid-template-columns: 36px 1fr; }
    .people li > :nth-child(n + 3) { grid-column: 2; }
    .actions { justify-content: flex-start; }
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv > .muted { margin-top: 8px; }
}

/* ---------- просмотр ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.94);
    touch-action: pan-y;
}

.lightbox[hidden] { display: none; }

.lightbox img {
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    user-select: none;
}

.lb-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 96px;
    border: 0;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 40px;
    cursor: pointer;
}

.lb-btn:hover { background: rgba(255, 255, 255, 0.16); }
.lb-prev { left: 0; border-radius: 0 8px 8px 0; }
.lb-next { right: 0; border-radius: 8px 0 0 8px; }

.lb-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: center;
    padding: 12px;
    color: #ddd;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

.lb-link {
    border: 0;
    background: none;
    color: #fff;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

@media (max-width: 640px) {
    .topbar { padding: 10px 16px; gap: 10px; }
    .user span { display: none; }
    .page { padding: 16px 16px 48px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .grid.creators { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    h1 { font-size: 21px; }
    .lb-btn { width: 40px; height: 72px; font-size: 30px; }
}
