:root {
    --bg: #F7F2E0;
    --ink: #3D3A33;
    --ink-soft: #8A8474;
    --surface: #FFFFFF;
    --surface-dark: #33363E;
    --accent: #E2572A;
    --accent-soft: rgba(226, 87, 42, 0.14);
    --line: rgba(61, 58, 51, 0.12);
    --player-h: 128px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ── 페이지 레이아웃 ─────────────────────────── */

.page {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: env(safe-area-inset-top, 0px) 16px 0 16px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    margin: 8px 0 10px;
    background-color: var(--surface-dark);
    border-radius: 16px;
    box-shadow: 0 2px 6px rgba(61, 58, 51, 0.18);
}

.brand {
    font-family: 'Jua', cursive;
    font-size: clamp(23px, 6.6vw, 29px);
    line-height: 1.2;
    color: white;
    margin: 0;
    padding-top: 2px;
}

.header-actions .icon-btn {
    color: rgba(255, 255, 255, 0.75);
}

.header-actions .icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: white;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--ink-soft);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, transform 0.15s;
}

.icon-btn:hover {
    background-color: var(--accent-soft);
    color: var(--accent);
}

.icon-btn:active svg {
    transform: rotate(90deg);
}

/* ── 채널 그리드 ─────────────────────────── */

.table-wrapper {
    position: relative;
}

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

.channel-card {
    position: relative;
    display: block;
    width: 100%;
    padding-bottom: 100%;
    height: 0;
    border: none;
    border-radius: 16px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(61, 58, 51, 0.08);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.channel-card img {
    position: absolute;
    top: 12%;
    left: 12%;
    width: 76%;
    height: 76%;
    object-fit: contain;
    border-radius: 8px;
}

.channel-card:active {
    transform: scale(0.94);
}

.channel-card.is-active {
    box-shadow: 0 0 0 2.5px var(--accent), 0 4px 10px rgba(226, 87, 42, 0.25);
}

/* ── 채널 선택 모달 ─────────────────────────── */

.modal {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(51, 54, 62, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    border-radius: 16px;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.btn-play-modal {
    font-family: 'Jua', cursive;
    font-size: 21px;
    padding: 12px 32px;
    border: none;
    border-radius: 999px;
    background-color: var(--accent);
    color: white;
    cursor: pointer;
}

.btn-play-modal:active {
    transform: scale(0.96);
}

/* ── 오디오 엘리먼트 숨김 (재생은 계속 동작) ── */

.audio-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* ── 하단 고정 커스텀 재생기 (헤더와 동일한 박스 기준) ── */

.player-bar {
    position: sticky;
    bottom: 10px;
    z-index: 20;
    margin: 10px 0 0 0;
    background-color: var(--surface-dark);
    color: white;
    border-radius: 16px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    padding: 9px 16px calc(7px + env(safe-area-inset-bottom, 0px));
}

.player-bar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-art {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 0.08);
    object-fit: cover;
    flex-shrink: 0;
}

.player-meta {
    flex: 1;
    min-width: 0;
}

.player-title-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

#playingChannel {
    font-size: 19px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playing-status {
    font-size: 14px;
    color: var(--accent);
    text-transform: capitalize;
    flex-shrink: 0;
}

.player-epg {
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 15px;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quality-select {
    flex-shrink: 0;
    font-size: 14px;
    padding: 6px 9px;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    appearance: none;
}

.player-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 7px;
}

.mute-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    flex-shrink: 0;
}

.volume-slider {
    flex: 1;
    accent-color: var(--accent);
    height: 20px;
}

.play-pause-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background-color: var(--accent);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 3px 8px rgba(226, 87, 42, 0.4);
}

.play-pause-btn:active {
    transform: scale(0.94);
}

/* ── 큰 화면 (폴드 펼친 화면, 태블릿) 보정 ── */

@media (min-width: 640px) {
    .page {
        max-width: 600px;
    }

    .channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
        gap: 14px;
    }
}

/* ── 매우 좁은 커버 스크린 보정 ── */

@media (max-width: 400px) {
    .brand {
        font-size: clamp(16px, 5.4vw, 21px);
    }

    .page-header {
        gap: 6px;
        padding: 10px 12px;
    }

    .header-actions {
        gap: 0;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
    }
}

@media (max-width: 340px) {
    .channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
        gap: 8px;
    }

    .player-art {
        width: 38px;
        height: 38px;
    }
}
