/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #1a1a2e;
    --panel: #16213e;
    --accent: #0f3460;
    --highlight: #e94560;
    --text: #eeeeee;
    --text-muted: #8892a4;
    --ready: #00d26a;
    --compressing: #f9a825;
    --recording: #42a5f5;
    --error: #e94560;
    --radius: 8px;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    padding: 0;
}

/* ===== App Shell ===== */
.app {
    width: 100%;
    max-width: 640px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--accent);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 90px;
}

.live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.live-dot.active {
    background: var(--highlight);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.6); }
    50% { opacity: 0.8; box-shadow: 0 0 0 6px rgba(233, 69, 96, 0); }
}

.live-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.live-label.active {
    color: var(--highlight);
}

.header-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* ===== Buttons ===== */
.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s;
}

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

.btn-live {
    background: var(--highlight);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--radius);
    letter-spacing: 0.02em;
}

.btn-live:hover {
    background: #d13654;
}

.btn-live.active {
    background: #d13654;
    animation: pulse-btn 1.5s ease-in-out infinite;
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(233, 69, 96, 0); }
}

.btn-arrow {
    background: var(--accent);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-arrow:hover {
    background: #1a4a8a;
}

/* ===== Date Navigation ===== */
.date-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--accent);
}

.date-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.date-display {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    min-width: 110px;
    text-align: center;
}

.date-picker {
    background: var(--accent);
    color: var(--text);
    border: 1px solid #2a4a7a;
    border-radius: var(--radius);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
}

.date-picker::-webkit-calendar-picker-indicator {
    filter: invert(0.8);
    cursor: pointer;
}

/* ===== Segment List ===== */
.segment-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.loading {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 60px 16px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state .empty-text {
    font-size: 0.95rem;
}

/* ===== Segment Row ===== */
.segment {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--panel);
    border-radius: var(--radius);
    cursor: default;
    transition: background 0.12s;
}

.segment:hover {
    background: var(--accent);
}

.segment.now-active {
    background: var(--accent);
    border-left: 3px solid var(--highlight);
    padding-left: 9px;
}

.seg-play {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}

.seg-play:hover {
    background: rgba(255, 255, 255, 0.1);
}

.seg-play.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.seg-time {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.seg-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.ready { background: var(--ready); }
.status-dot.compressing { background: var(--compressing); animation: blink 1.2s ease-in-out infinite; }
.status-dot.recording { background: var(--recording); animation: blink 1.2s ease-in-out infinite; }
.status-dot.raw { background: var(--compressing); }
.status-dot.error { background: var(--error); }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.seg-size {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.seg-download {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
    text-decoration: none;
}

.seg-download:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* ===== Player ===== */
.player {
    background: var(--panel);
    border-top: 1px solid var(--accent);
    padding: 12px 16px 14px;
}

.player audio {
    width: 100%;
    height: 40px;
    border-radius: var(--radius);
    outline: none;
}

/* Style the native audio element for dark theme (Webkit) */
.player audio::-webkit-media-controls-panel {
    background: var(--accent);
}

.now-playing {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-playing.live {
    color: var(--highlight);
    font-weight: 600;
}

/* ===== Status Bar ===== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: #111627;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.refresh-timer {
    opacity: 0.6;
}

/* ===== Scrollbar ===== */
.segment-list::-webkit-scrollbar {
    width: 6px;
}

.segment-list::-webkit-scrollbar-track {
    background: transparent;
}

.segment-list::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.segment-list::-webkit-scrollbar-thumb:hover {
    background: #1a4a8a;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
    .header-title {
        font-size: 0.95rem;
    }

    .date-display {
        font-size: 0.9rem;
    }

    .seg-time {
        font-size: 0.8rem;
    }

    .seg-status .status-text {
        display: none;
    }

    .header {
        padding: 10px 12px;
    }

    .date-nav {
        padding: 10px 12px;
    }

    .segment {
        padding: 8px 10px;
        gap: 6px;
    }
}

/* ===== Safe area for notched devices ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .status-bar {
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }
}
