@font-face {
    font-family: "Bungee";
    src: url("/static/fonts/Bungee-Regular.ttf") format("truetype");
    font-display: swap;
}

:root {
    --bg: #1e1e1e;
    --bg-2: #141414;
    --bg-3: #101010;
    --panel: #262626;
    --border: #333;
    --text: #fff;
    --muted: #aaa;
    --accent: #ff0066;
    --accent-2: #e60052;
    --ok: #2ecc71;
    --live: #ff2b2b;
    --gold: darkgoldenrod;
}

* { box-sizing: border-box; }

/* Иначе display: flex у .player-offline/.chat-form перебивает атрибут hidden */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- шапка ---------- */
header.top {
    background: var(--accent);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 16px;
    flex-wrap: wrap;
}
.logo { display: flex; align-items: flex-end; font-family: "Bungee", sans-serif; color: #fff; }
.logo:hover { text-decoration: none; }
.logo .big { font-size: 34px; line-height: 1.1; }
.logo .small { font-size: 15px; margin: 0 0 6px 2px; }
header.top nav { display: flex; gap: 14px; align-items: center; flex: 1; flex-wrap: wrap; }
header.top nav a, header.top nav button.linklike { color: #fff; font-weight: 600; }
header.top nav .spacer { flex: 1; }
header.top form { margin: 0; }
button.linklike { background: none; border: none; padding: 0; font: inherit; cursor: pointer; }
button.linklike:hover { text-decoration: underline; }

main { flex: 1; padding: 20px 16px; width: 100%; max-width: 1400px; margin: 0 auto; }
main.wide { max-width: none; padding: 0; display: flex; }

footer { text-align: center; font-size: 13px; color: var(--muted); padding: 18px; }

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin-top: 26px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- flash ---------- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash.ok { background: rgba(46, 204, 113, .15); border: 1px solid var(--ok); }
.flash.err { background: rgba(255, 0, 102, .15); border: 1px solid var(--accent); }

/* ---------- кнопки и формы ---------- */
.btn, button.btn {
    display: inline-block;
    padding: 8px 16px;
    font-size: 15px;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color .2s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--accent-2); text-decoration: none; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: #8b1c1c; }
.btn.danger:hover { background: #a82222; }
.btn.sm { padding: 4px 10px; font-size: 13px; }

input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], textarea, select {
    width: 100%;
    background: var(--bg-3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 8px 10px;
    font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 14px; }
form.inline { display: inline; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { width: auto; flex: 1; min-width: 120px; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}
.auth-card { max-width: 400px; margin: 40px auto; }
.auth-card .btn { width: 100%; margin-top: 18px; }

/* ---------- сетка стримов ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.stream-card {
    display: block;
    background: var(--bg-3);
    border: 1px solid var(--gold);
    color: var(--text);
}
.stream-card:hover { border-color: var(--accent); text-decoration: none; }
.stream-card .thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.stream-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stream-card .meta { padding: 8px 10px; }
.stream-card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-live {
    position: absolute; top: 8px; left: 8px;
    background: var(--live); color: #fff; font-weight: 700; font-size: 12px;
    padding: 2px 6px; border-radius: 3px;
}
.badge-viewers {
    position: absolute; bottom: 8px; left: 8px;
    background: rgba(0, 0, 0, .7); font-size: 12px; padding: 2px 6px; border-radius: 3px;
}
.channel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.channel-chip {
    display: block; background: var(--panel); border: 1px solid var(--border);
    border-radius: 6px; padding: 10px 12px; color: var(--text);
}
.channel-chip:hover { border-color: var(--accent); text-decoration: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #555; margin-right: 6px; }
.dot.on { background: var(--live); }

/* ---------- страница канала ---------- */
.watch { display: flex; flex: 1; min-height: 0; width: 100%; }
.watch .player-col { flex: 1; min-width: 0; overflow-y: auto; }
.player-box { position: relative; background: #000; aspect-ratio: 16 / 9; max-height: calc(100vh - 160px); width: 100%; }
.player-box video, .player-box iframe { width: 100%; height: 100%; border: 0; display: block; background: #000; }
.player-offline {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: var(--muted); gap: 8px;
}
.player-offline .big { font-family: "Bungee", sans-serif; color: var(--accent); font-size: 40px; }
.channel-info { padding: 14px 18px; display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.channel-info .grow { flex: 1; min-width: 240px; }
.channel-info .name { font-size: 20px; font-weight: 700; }
.channel-info .stats { color: var(--muted); font-size: 14px; margin-top: 4px; }
.channel-desc { padding: 0 18px 18px; white-space: pre-wrap; color: #ddd; }

/* ---------- плеер ---------- */
.player-box { overflow: hidden; outline: none; user-select: none; }
/* .fs ставит скрипт — в старом Safari нет :fullscreen */
.player-box.fs { max-height: none; aspect-ratio: auto; }
.player-box.idle { cursor: none; }
.player-box svg { width: 22px; height: 22px; fill: currentColor; display: block; }

.player-bar {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; gap: 4px;
    padding: 28px 10px 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .85));
    transition: opacity .25s ease;
}
.player-box.idle .player-bar { opacity: 0; pointer-events: none; }
.pspacer { flex: 1; }
.pbtn {
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    background: transparent; color: #fff; border: 0; border-radius: 5px; cursor: pointer; padding: 0;
    transition: background-color .2s ease, color .2s ease;
}
/* Только с мышью: на тач-экране :hover «залипает» после тапа */
@media (hover: hover) {
    .pbtn:hover { background: rgba(255, 255, 255, .12); color: var(--accent); }
}
.pbtn .i-play, .player-box.paused .pbtn .i-pause,
.pbtn .i-muted, .player-box.muted .pbtn .i-vol,
.pbtn .i-fs-exit, .player-box.fs .pbtn .i-fs { display: none; }
.player-box.paused .pbtn .i-play, .player-box.muted .pbtn .i-muted, .player-box.fs .pbtn .i-fs-exit { display: block; }

.pvol { display: flex; align-items: center; gap: 2px; }
.pvol input[type=range] { width: 80px; accent-color: var(--accent); cursor: pointer; }

.plive {
    margin-left: 6px; padding: 3px 9px 3px 8px; border: 0; border-radius: 3px;
    background: var(--live); color: #fff; font: inherit; font-size: 12px; font-weight: 700; letter-spacing: .5px;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.plive::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.plive.behind { background: #444; }
.plive.behind::before { background: #888; }
.plive.behind:hover { background: var(--accent); }

.pmenu-wrap { position: relative; }
.pmenu {
    position: absolute; right: 0; bottom: 44px; min-width: 230px; padding: 6px;
    background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .6);
}
.pmenu-h { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 8px 10px 4px; }
.pmenu button {
    display: flex; justify-content: space-between; width: 100%; padding: 7px 10px;
    background: none; border: 0; border-radius: 5px; color: var(--text); font: inherit; font-size: 14px;
    text-align: left; cursor: pointer;
}
.pmenu button:hover { background: var(--panel); }
.pmenu button.active { color: var(--accent); font-weight: 600; }
.pmenu button.active::after { content: "✓"; }

.player-big-play {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--accent); color: #fff; display: none; align-items: center; justify-content: center;
    box-shadow: 0 0 0 8px rgba(255, 0, 102, .25); transition: background-color .2s ease, transform .2s ease;
}
.player-big-play:hover { background: var(--accent-2); transform: translate(-50%, -50%) scale(1.06); }
.player-box.paused .player-big-play { display: flex; }
.player-box .player-big-play svg { width: 40px; height: 40px; margin-left: 4px; }

.player-unmute { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px; }
.player-box .player-unmute svg { width: 18px; height: 18px; }

.player-spinner {
    position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
    border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--accent); border-radius: 50%;
    animation: ptv-spin .8s linear infinite; pointer-events: none;
}
@keyframes ptv-spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
    .pvol input[type=range] { display: none; }
}

.chat-col {
    width: 340px; flex-shrink: 0; background: var(--bg-2);
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
    height: calc(100vh - 50px); position: sticky; top: 0;
}
.chat-head { padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 700; text-transform: uppercase; font-size: 13px; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; font-size: 14px; line-height: 1.45; word-wrap: break-word; }
.chat-log .m { padding: 2px 0; position: relative; }
.chat-log .m:hover { background: rgba(255, 255, 255, .04); }
.chat-log .u { font-weight: 700; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log .b { font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 3px; margin-right: 4px; vertical-align: 1px; }
.b.streamer { background: var(--accent); }
.b.mod { background: #1f8b4c; }
.b.admin { background: #b8860b; }
.chat-log .tools { display: none; position: absolute; right: 0; top: 0; background: var(--bg-2); }
.chat-log .m:hover .tools { display: inline-flex; gap: 2px; }
.chat-log .tools button { background: #333; border: 0; color: #fff; font-size: 11px; cursor: pointer; padding: 1px 5px; border-radius: 3px; }
.chat-log .tools button:hover { background: var(--accent); }
.chat-form { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 6px; }
.chat-form input { flex: 1; }
.chat-note { padding: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; text-align: center; }

@media (max-width: 900px) {
    /* Колонкой: плеер в полную высоту, страница прокручивается. Иначе плеер делит экран с чатом
       и обрезается снизу вместе с панелью кнопок */
    .watch { flex-direction: column; flex: none; }
    .watch .player-col { flex: none; overflow-y: visible; }
    .chat-col { width: 100%; height: 60vh; position: static; border-left: 0; border-top: 1px solid var(--border); }
}

/* ---------- панель/админка ---------- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; align-items: center; }
.kv > div:nth-child(odd) { color: var(--muted); font-size: 14px; }
code, .mono { font-family: Consolas, 'Courier New', monospace; font-size: 13px; }
.copy-field { display: flex; gap: 6px; }
.copy-field input { font-family: Consolas, monospace; font-size: 13px; }
.secret { -webkit-text-security: disc; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:hover td { background: rgba(255, 255, 255, .02); }
.table-wrap { overflow-x: auto; }

.admin-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.admin-nav a { color: var(--muted); padding: 8px 14px; border-bottom: 2px solid transparent; }
.admin-nav a:hover { color: #fff; text-decoration: none; }
.admin-nav a.active { color: #fff; border-bottom-color: var(--accent); }

.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 10px; background: #333; }
.tag.red { background: #8b1c1c; }
.tag.green { background: #1f6b3c; }
.tag.pink { background: var(--accent); }

.perm-table select { width: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { background: var(--bg-3); color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 5px 12px; cursor: pointer; }
.tabs button.active { color: #fff; border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.pager { display: flex; gap: 8px; margin-top: 14px; }

.error-page { text-align: center; padding: 60px 20px; }
.error-page .code { font-family: "Bungee", sans-serif; font-size: 100px; color: var(--accent); }
.error-page .msg { font-size: 22px; margin: 16px 0 30px; }
