/* ============================================================
   «Звенья истории» — UI-слой (шапка, кнопки, таймлайн, тост)
   ============================================================ */

/* ---------- Шапка ---------- */
#header {
    position: absolute; top: 0; left: 0; right: 0; height: 56px;
    background: rgba(255, 253, 249, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 18px; z-index: 1000;
}
#header::after {
    content: '';
    position: absolute; left: 0; bottom: -1px;
    height: 2px; width: var(--progress-pct, 0%);
    background: var(--gold);
    opacity: 0.85;
    transition: width 0.6s ease;
}
#header h1 { font-size: 15px; font-weight: 600; letter-spacing: 0.3px; }
#header h1 a { color: inherit; text-decoration: none; }
#header h1 a:hover { text-decoration: underline; text-underline-offset: 3px; }
#header h1 small { display: block; font-size: 11px; font-weight: 400; color: var(--text-secondary); }
/* Угол администратора (admin-login.js): кнопка входа/выхода справа */
#header #admin-corner { flex: 0 0 auto; }
#progress {
    font-size: 12px; color: var(--text-secondary); white-space: nowrap;
    padding: 5px 14px; background: var(--bg-soft);
    border: none; border-radius: 0;
}
#progress b { color: var(--text); font-weight: 600; }
#header .header-buttons { display: flex; gap: 8px; align-items: center; }
#header .header-buttons button {
    width: 34px; height: 34px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-soft); color: var(--text);
    border: none; border-radius: 9px;
    font-size: 15px; line-height: 1; cursor: pointer; font-family: inherit;
    transition: background 0.2s ease, border-color 0.2s ease;
}
#header .header-buttons button:hover { background: #F1ECE3; border-color: #DCD4C6; }
#header .header-buttons .mode-toggle {
    width: auto; padding: 0 14px;
    font-size: 12px; font-weight: 500; white-space: nowrap;
    border-radius: 17px;
}
#header .header-buttons .mode-toggle.admin {
    background: rgba(201, 169, 110, 0.16);
    border-color: var(--gold);
    color: #8A6F3D;
}
/* Замок блобов — активное состояние (золотая подсветка, как у .admin) */
#header .header-buttons .mode-toggle.on {
    background: rgba(201, 169, 110, 0.16);
    border-color: var(--gold);
    color: #8A6F3D;
}

/* ---------- Кнопки ---------- */
.btn {
    background: var(--btn-primary); color: #F7F4EF; border: none;
    padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
    cursor: pointer; transition: background 0.2s ease, transform 0.1s ease;
    font-family: inherit;
}
.btn:hover { background: #4A453F; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--btn-primary); color: #F7F4EF; }
.btn-secondary, .btn.secondary { background: var(--btn-secondary); color: var(--text); }
.btn-secondary:hover, .btn.secondary:hover { background: #E3DCD1; }
.btn-danger, .btn.danger { background: #F6E8E4; color: #A05A4C; }
.btn-danger:hover, .btn.danger:hover { background: #F0DCD6; }

/* ---------- Год наверху (Paradox-стиль) ---------- */
#top-year {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    font-size: 24px;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 1px 4px rgba(44,42,38,0.45);
    background: none;
    backdrop-filter: none;
    padding: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    white-space: nowrap;
    letter-spacing: 0.5px;
    pointer-events: none;
}

/* ---------- Кнопка скрыть/показать хронологию ---------- */
#btn-toggle-timeline {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 91;
    width: auto; padding: 0 14px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    color: var(--text);
    border: none;
    border-radius: 17px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.2s ease, transform 0.15s ease;
    font-family: inherit;
}
#btn-toggle-timeline:hover { background: #F1ECE3; transform: translateX(-50%) scale(1.08); }
#btn-toggle-timeline:active { transform: translateX(-50%) scale(0.95); }
#btn-toggle-timeline.hidden { display: none; }
#mode-indicator {
    display: none;
    position: absolute; top: 66px; left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: rgba(58, 53, 48, 0.92);
    color: #F7F4EF;
    font-size: 12px; font-weight: 500; letter-spacing: 0.4px;
    padding: 6px 16px; border-radius: 16px;
    box-shadow: var(--shadow-lift);
    pointer-events: none;
}
#mode-indicator.show { display: block; }

/* ============================================================
   Таймлайн
   ============================================================ */
#timeline {
    position: fixed;
    left: 50%; bottom: 48px;      /* поднята на один уровень (было 8px) */
    transform: translateX(-50%);
    z-index: 90;
    width: auto;
    max-width: 98vw;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 0;
    pointer-events: none;
}
#timeline .tl-scroll, #timeline .tl-epoch, #timeline #btn-present { pointer-events: auto; }
/* Стрелки горизонтального скролла — слева/справа от зоны кругов */
.tl-scroll {
    flex: 0 0 auto;
    width: 22px;
    background: transparent;
    border: none;
    color: var(--gold);
    font-size: 24px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s ease, transform 0.1s ease;
    pointer-events: auto;
    align-self: center;
    padding: 0;
    margin-bottom: 10px;
}
.tl-scroll:hover { opacity: 1; }
.tl-scroll:active { transform: scale(0.85); }
.tl-scroll[disabled] { opacity: 0; pointer-events: none; }
/* Зона кругов между стрелками */
#timeline-track {
    flex: 0 1 auto;
    display: block;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: none;
    padding: 2px 4px;
    align-self: flex-end; pointer-events: none;
}
#timeline-track::-webkit-scrollbar { display: none; }

/* ── Игрок: та же раскладка дорожек, что у админа, но компактнее ── */
.player-view .tl-lane { min-height: 78px; padding: 2px 2px; border-bottom: none !important; }
.player-view .tl-lane-base { border-top: none !important; }
.player-view .tl-epoch { width: 52px; }
.player-view .tl-epoch .tl-face { width: 32px; height: 32px; }
.player-view .tl-epoch .tl-name {
    font-size: 10px; max-width: 52px;
    white-space: normal; word-break: break-word; line-height: 1.1;
    color: var(--text-secondary);
}
.player-view .tl-epoch .tl-years { font-size: 10px; color: var(--gold); font-weight: 600; }

/* ── Дорожки (общие для игрока и админа; lane 0 — база внизу) ── */
.tl-canvas { position: relative; min-width: 1280px; width: max-content; }
.tl-lane {
    position: relative;
    min-height: 92px;  /* увеличено с 72 — названия и годы не обрезаются */
    padding: 2px 2px;
    border-bottom: none !important;
}
.tl-lane-base { border-top: none !important; }
/* Админу — разделители убраны, чистый вид */
#timeline-track:not(.player-view) .tl-lane { border-bottom: none; }
#timeline-track:not(.player-view) .tl-lane:last-child { border-bottom: none; }
#timeline-track:not(.player-view) .tl-lane-base { border-top: none; }
#timeline-track:not(.player-view) .tl-epoch { width: 76px; top: 4px; }
#timeline-track:not(.player-view) .tl-epoch .tl-face { width: 44px; height: 44px; border-color: var(--gold); }
#timeline-track:not(.player-view) .tl-epoch .tl-face img { width: 100%; height: 100%; }
#timeline-track:not(.player-view) .tl-epoch .tl-name {
    font-size: 12px; max-width: 76px;
    white-space: normal; word-break: break-word; line-height: 1.15;
    color: var(--text-secondary);
}
#timeline-track:not(.player-view) .tl-epoch .tl-years { font-size: 11px; color: var(--gold); font-weight: 600; }
.tl-epoch.dragging { opacity: 0.85; cursor: grabbing; box-shadow: 0 8px 20px rgba(44,42,38,0.30); }
.tl-epoch.link-src .tl-face { outline: 2px dashed var(--gold); outline-offset: 2px; }
/* Контур-призрак места, где встанет круг при отпускании */
.tl-drop-ghost {
    position: absolute; top: 4px;
    width: 80px;
    border-radius: 12px;
    border: 2px dashed var(--gold);
    background: rgba(201,169,110,0.12);
    pointer-events: none;
    animation: tl-drop-pulse 0.8s ease-in-out infinite;
}
.tl-drop-ghost .tl-face, .tl-drop-ghost .tl-name, .tl-drop-ghost .tl-years { visibility: hidden; }
@keyframes tl-drop-pulse {
    0%,100% { opacity: 0.55; }
    50% { opacity: 1; }
}
.tl-links { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tl-link { stroke: #8E1B2E; stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.tl-link:hover { stroke-width: 3.5; }

.tl-item {
    flex: 0 0 auto; width: 52px; text-align: center;
    cursor: pointer;
    opacity: 0.8;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.tl-item:hover { transform: translateY(-2px); opacity: 1; }
.tl-item .tl-face {
    width: 32px; height: 32px;
    border-radius: 50%;
    margin: 0 auto 2px;
    border: 2px solid #D8CBB5;
    background: #F0EBE3;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 11px; color: var(--text-secondary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tl-item .tl-face img {
    width: 100%; height: 100%; object-fit: cover;
    filter: sepia(0.35) saturate(0.8);
}
.tl-item .tl-name {
    font-size: 10px; color: var(--text-secondary);
    max-width: 64px;
    white-space: normal; word-break: break-word; line-height: 1.1;
}
.tl-item .tl-years { font-size: 10px; color: var(--gold); font-weight: 600; }
.tl-item.locked { opacity: 0.35; }
.tl-item.current { opacity: 1; }
.tl-item.current .tl-face {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.28);
}

#time-label {
    position: absolute;
    left: 50%; right: auto;
    transform: translateX(-50%);
    top: -24px;
    font-size: 12px; font-weight: 700;
    color: var(--gold);
    text-shadow: 0 1px 4px rgba(44,42,38,0.45);
    background: none; border: none;
    border-radius: 0; padding: 0; box-shadow: none;
    white-space: nowrap;
}
#btn-present {
    position: absolute;
    right: 36px; top: -26px;
    z-index: 5;
    background: var(--btn-primary);
    color: #F7F4EF;
    border: none; border-radius: 9px;
    padding: 4px 9px;
    font-size: 11px; font-weight: 500;
    cursor: pointer;
    box-shadow: none;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.2s ease;
}
#btn-present:hover { background: #4A453F; }
#btn-time-close {
    position: absolute; right: 4px; top: -26px;
    background: none; border: none;
    color: var(--text-secondary);
    cursor: pointer; font-size: 14px;
    text-shadow: 0 1px 4px rgba(44,42,38,0.45);
}
#btn-time-close:hover { color: var(--text); }

/* ---------- Тост ---------- */
#toast {
    position: absolute; bottom: 84px; left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(58, 53, 48, 0.94); color: #F7F4EF;
    padding: 10px 20px;
    border-radius: 12px; font-size: 13px; z-index: 3000;
    opacity: 0; pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    max-width: 90vw; text-align: center;
    box-shadow: var(--shadow-modal);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Историческая удача ---------- */
.luck-roll {
    position: absolute;
    z-index: 1000;
    transform: translate(-50%, -100%) scale(0.85);
    opacity: 0;
    background: var(--bg-elevated);
    border: 1.5px solid var(--gold);
    border-radius: 12px;
    padding: 6px 13px;
    font-size: 13px; font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--shadow-lift);
    transition: transform 0.4s ease-out, opacity 0.3s ease;
    pointer-events: none;
}
.luck-roll.luck-visible {
    transform: translate(-50%, -115%) scale(1);
    opacity: 1;
}
.luck-roll .luck-icon { font-size: 15px; margin-right: 5px; }
.luck-roll .luck-text { vertical-align: middle; }

/* ============================================================
   Мета-процессы: меню фильтра и подсветка узлов на канвасе
   ============================================================ */
.process-menu {
    position: fixed;
    z-index: 1100;
    min-width: 240px;
    max-width: 300px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-modal, 0 8px 30px rgba(44, 42, 38, 0.18));
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: modalIn 0.18s ease-out;
}
.process-menu .pm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
}
.process-menu .pm-item:hover { background: #F1ECE3; }
.process-menu .pm-item.active {
    background: color-mix(in srgb, var(--proc-color, #8B6914) 16%, var(--bg-elevated));
    box-shadow: inset 0 0 0 1.5px var(--proc-color, #8B6914);
}
.process-menu .pm-icon {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--proc-color, #8B6914);
    color: #FFFEF8;
    font-size: 13px;
}
.process-menu .pm-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.process-menu .pm-reset {
    justify-content: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid #F0EAE0;
    color: var(--text-secondary);
    font-size: 12px;
}
.process-menu .pm-reset:hover { color: var(--text); }

/* Подсветка узлов фильтром процессов.
   .node уже несёт свою рамку/тень — акцент идёт через box-shadow
   кольцом цвета процесса, чтобы не ломать существующий вид карточки. */
.node.proc-hl {
    box-shadow: 0 0 0 3px var(--proc-color, #8B6914),
                0 0 14px 2px color-mix(in srgb, var(--proc-color, #8B6914) 45%, transparent) !important;
    z-index: 5;
}
.node.proc-dim {
    filter: grayscale(0.6);
}
