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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, Cantarell, sans-serif;
    line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────────*/

header {
    padding: 1rem 2rem;
    border-bottom: 2px solid var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

header h1 {
    font-size: 1.6rem;
    color: var(--accent-primary);
    letter-spacing: 0.02em;
}

.time-display { font-size: 0.85rem; color: var(--text-secondary); }

.header-nav {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-btn {
    padding: 0.35rem 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.player-header { display: flex; align-items: center; gap: 1rem; width: 100%; }
.spacer        { flex: 1; }

/* ── Layout ──────────────────────────────────────────────────────────────────*/

main             { padding: 1.5rem 2rem; }
main.guide-main  { padding: 0; }


/* ── Guide wrapper ───────────────────────────────────────────────────────────*/

.guide-wrapper { display: flex; flex-direction: column; position: relative; }

/* Sticky time ruler row */
.guide-time-row {
    display: flex;
    height: 38px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-primary);
    border-bottom: 2px solid var(--accent-primary);
}

.channel-label-spacer {
    flex: 0 0 150px;
    border-right: 1px solid var(--border-color);
}

.time-ruler {
    flex: 1;
    position: relative;
    overflow: visible;
}

.time-marker {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    padding-left: 0.3rem;
    pointer-events: none;
}

.current-time-bubble {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--accent-primary);
    color: var(--accent-on-primary);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.18rem 0.45rem;
    border-radius: 3px;
    white-space: nowrap;
    z-index: 2;
    pointer-events: none;
}

/* Channel rows container */
.guide-rows {
    position: relative;
}

#guide-container {
    position: relative;
}

/* Subtle vertical lines at each time interval */
.guide-grid-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border-color);
    opacity: 0.5;
    z-index: 1;
    pointer-events: none;
}

/* Vertical current-time indicator */
.current-time-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent-primary);
    opacity: 0.8;
    z-index: 6;
    pointer-events: none;
}

/* ── Guide rows ──────────────────────────────────────────────────────────────*/

.guide-row {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    height: 150px;
}

.channel-label {
    flex: 0 0 150px;
    padding: 0.75rem 1rem;
    border-right: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-primary);
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    z-index: 2;
    background: var(--bg-secondary);
}

.guide-row.active-channel .channel-label {
    border-left-color: var(--accent-tertiary);
    color: var(--accent-tertiary);
    background: var(--current-program-bg);
}

.timeline {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ── Program boxes ───────────────────────────────────────────────────────────*/

.program-box {
    position: absolute;
    top: 2px;
    bottom: 2px;
    padding: 0.35rem 0.55rem;
    background: var(--program-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    overflow: hidden;
    box-sizing: border-box;
    z-index: 2;
}

.program-bg-image {
    position: absolute;
    inset: -10px;
    background-size: cover;
    background-position: center;
    filter: blur(4px);
    opacity: 0.25;
    z-index: 0;
    pointer-events: none;
}

.program-title,
.program-time {
    position: relative;
    z-index: 1;
}

.program-box:hover {
    background: var(--program-hover-bg);
    border-color: var(--accent-primary);
    box-shadow: 0 2px 10px var(--shadow);
}

.program-box.now-playing {
    border-left: 3px solid var(--accent-primary);
    background: var(--current-program-bg);
}

.program-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.program-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ── Global tooltip (fixed, escapes overflow containers) ─────────────────────*/

#global-tooltip {
    position: fixed;
    z-index: 9999;
    display: none;
    pointer-events: none;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    border: 1px solid var(--accent-primary);
    border-radius: 8px;
    padding: 1rem;
    min-width: 270px;
    max-width: 360px;
    box-shadow: 0 8px 32px var(--shadow);
    font-size: 0.88rem;
    line-height: 1.45;
}

#global-tooltip h3 {
    color: var(--accent-primary);
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

.tip-channel {
    font-size: 0.75rem;
    color: var(--accent-tertiary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#global-tooltip img {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

#global-tooltip p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.tip-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    padding-top: 0.4rem;
    margin-top: 0.4rem;
}

/* ── Player page ─────────────────────────────────────────────────────────────*/

.back-button {
    padding: 0.45rem 0.9rem;
    background: var(--button-bg);
    color: var(--button-text);
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.15s;
}

.back-button:hover { background: var(--button-hover-bg); color: var(--accent-on-primary); }

.player-section { margin-bottom: 2rem; }

.video-wrapper {
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    margin: 0 auto 0.75rem;
    aspect-ratio: 16 / 9;
    max-height: calc(100vh - 120px);
    max-width: calc((100vh - 120px) * 16 / 9);
    border: 1px solid var(--border-color);
}

video { width: 100%; height: 100%; display: block; object-fit: contain; }

.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--controls-bg);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.reload-btn {
    padding: 0.6rem 1.25rem;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.reload-btn:hover:not(:disabled) { background: var(--button-hover-bg); transform: scale(1.04); }
.reload-btn:disabled              { opacity: 0.55; cursor: not-allowed; }

.pip-btn {
    padding: 0.6rem 1.25rem;
    background: transparent;
    color: var(--accent-primary);
    border: 1.5px solid var(--accent-primary);
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    white-space: nowrap;
    touch-action: manipulation;
}

.pip-btn:hover       { background: var(--accent-primary); color: var(--accent-on-primary); transform: scale(1.04); }
.pip-btn.pip-active  { background: var(--accent-primary); color: var(--accent-on-primary); }

.stream-info     { flex: 1; padding: 0 0.5rem; min-width: 0; }
#current-program { font-size: 0.92rem; color: var(--accent-secondary); font-weight: 500;
                   white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.guide-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.guide-section h2 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--accent-secondary);
    letter-spacing: 0.03em;
}

/* ── Error ───────────────────────────────────────────────────────────────────*/

.error {
    padding: 2rem;
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-text);
    border-radius: 8px;
    text-align: center;
    font-size: 1rem;
}

/* ── Tablet ───────────────────────────────────────────────────────────────────*/

@media (max-width: 768px) {
    .channel-label-spacer { flex: 0 0 90px; }
    .channel-label        { flex: 0 0 90px; font-size: 0.82rem; }
    #global-tooltip       { min-width: 220px; max-width: 280px; }
}

/* ── Mobile — guide rows become vertical cards ───────────────────────────────*/

@media (max-width: 600px) {
    header {
        padding: 0.65rem 0.9rem;
        gap: 0.65rem;
    }
    header h1 { font-size: 1.15rem; }
    .header-nav { display: none; }

    /* Hide time ruler and indicator on mobile */
    .guide-time-row     { display: none; }
    .current-time-line  { display: none !important; }
    .guide-grid-line    { display: none; }

    /* ---- Guide rows become cards ---- */
    .guide-row {
        flex-direction: column;
        height: auto;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        overflow: hidden;
        margin-bottom: 0.4rem;
    }

    .channel-label {
        flex: none;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        border-left-width: 4px;
        padding: 0.55rem 0.9rem;
        font-size: 0.95rem;
        background: var(--bg-secondary);
    }

    /* Reset timeline to vertical static flow */
    .timeline {
        position: static;
        height: auto;
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        background: transparent;
    }

    /* Reset program boxes to tappable cards */
    .program-box {
        position: relative !important;
        width: 100% !important;
        left: auto !important;
        top: auto !important;
        bottom: auto !important;
        overflow: hidden;
        border-radius: 0;
        border: none;
        border-left: 4px solid var(--accent-primary) !important;
        padding: 1.5rem 5.5rem 1.5rem 1rem;
        min-height: 180px;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        cursor: pointer;
        background: var(--current-program-bg);
        transition: background 0.15s;
    }

    .program-box:active {
        background: var(--program-hover-bg);
    }

    .program-bg-image {
        position: absolute;
        inset: 0;
        filter: blur(2px);
        opacity: 0.3;
        z-index: 0;
    }

    .program-box::after {
        content: '▶ Watch';
        position: absolute;
        right: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--accent-primary);
        z-index: 1;
    }

    .program-title {
        flex: 1;
        white-space: normal;
        font-size: 1.05rem;
        font-weight: 600;
        color: var(--accent-primary);
        z-index: 1;
    }

    .program-time {
        white-space: nowrap;
        font-size: 0.78rem;
        flex-shrink: 0;
        z-index: 1;
    }

    /* ---- Player page layout ---- */
    main { padding: 0; }

    .player-section { margin-bottom: 0; }

    .video-wrapper {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        margin-bottom: 0;
    }

    /* ---- Player controls ---- */
    .player-controls {
        flex-direction: column;
        gap: 0.4rem;
        padding: 0.5rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .stream-info {
        width: 100%;
        padding: 0 0 0.4rem;
        border-bottom: 1px solid var(--border-color);
    }

    #current-program { font-size: 0.88rem; }

    .reload-btn, .pip-btn {
        flex: 1;
        padding: 0.6rem 0.4rem;
        font-size: 0.82rem;
        min-width: 0;
        touch-action: manipulation;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
    }

    /* ---- Player header ---- */
    .player-header { gap: 0.6rem; }

    .player-header h1 {
        font-size: 1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .back-button { padding: 0.45rem 0.7rem; font-size: 0.85rem; }

    /* ---- Guide section ---- */
    .guide-section { padding-top: 0; }
}

/* ── Config page ─────────────────────────────────────────────────────────────*/

.config-wrap {
    max-width: 620px;
    margin: 0 auto;
}

.config-intro {
    padding: 1.25rem 1.5rem;
    background: var(--bg-secondary);
    border-left: 4px solid var(--accent-primary);
    border-radius: 6px;
    margin-bottom: 1.5rem;
}

.config-intro h2 {
    font-size: 1rem;
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
}

.config-intro ol {
    padding-left: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.config-section {
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
}

.config-section h3 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-primary);
    margin-bottom: 1rem;
}

.field-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.9rem;
}

.field-row:last-child { margin-bottom: 0; }

.field-row--inline {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.field-row--inline input { width: 80px; text-align: center; }

.field-row label {
    font-size: 0.83rem;
    color: var(--text-secondary);
}

.field-row input[type="text"],
.field-row input[type="number"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: monospace;
    transition: border-color 0.15s;
}

.field-row input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.input-group { display: flex; gap: 0.5rem; }
.input-group input { flex: 1; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    cursor: pointer;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
    accent-color: var(--accent-primary);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
}

.hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-bottom: 1rem;
    padding-left: 1.7rem;
}

.hint:last-child { margin-bottom: 0; }

.hint code, .config-intro code {
    background: var(--bg-primary);
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-size: 0.9em;
    color: var(--accent-tertiary);
}

.config-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.connection-status {
    font-size: 0.83rem;
    margin-top: 0.6rem;
    min-height: 1.1em;
    color: var(--text-secondary);
}

.connection-status.ok    { color: #6dcc6d; }
.connection-status.error { color: var(--error-text); }
