:root {
    --bg-color: #0f0f0f;
    --card-color: #1f1f1f;
    --accent-color: #ff0000;
    --text-color: #ffffff;
    --text-secondary: #aaa;
    --nav-bg: #333;
    --nav-text: #f2f2f2;
    --nav-hover-bg: #ddd;
    --nav-hover-text: #000;
    --nav-active-bg: #555;
    --badge-bg: #333;
    --accent-text: #fff;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --brand-gold: #ffad00;
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --border-color: #333;
    --button-bg: #2a2a2a;
    --button-hover-bg: #3a3a3a;
    --button-border: #555;
    --danger-bg: #80211a;
    --warn-color: #ffad00;
    /* Charts (management page). Series colours validated for this surface
       (dataviz palette check: dark mode, surface #1f1f1f). */
    --chart-surface: #1f1f1f;
    --chart-grid: #2c2c2a;
    --chart-axis: #383835;
    --chart-muted: #898781;
    --series-1: #3987e5;
    --series-2: #d95926;
}

/* The site is dark: draw the browser's own controls (scrollbars, file and
   date pickers) to match */
:root {
    color-scheme: dark;
    scrollbar-color: var(--button-border) var(--bg-color);
}

/* Widths include padding and borders, so width: 100% never overflows */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    margin: 0;
}

.player-card {
    background-color: var(--card-color);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow-color);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.status-badge {
    display: inline-block;
    background-color: var(--badge-bg);
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

.status-badge.live {
    background-color: var(--accent-color);
    color: var(--accent-text);
    animation: pulse 1.5s infinite;
}

.player-card h1 {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
}

.player-card p {
    color: var(--text-secondary);
    margin: 0 0 25px 0;
    font-size: 0.95rem;
}

.player-card audio {
    width: 100%;
    outline: none;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Top navigation bar */
.topnav {
    background-color: var(--nav-bg);
    overflow: hidden;
}

.topnav .logo {
    height: 47px;
    float: left;
    padding-right: 3px;
}

/* Links inside the navigation bar */
.topnav a {
    float: left;
    color: var(--nav-text);
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
}

/* Change the color of links on hover */
.topnav a:hover {
    background-color: var(--nav-hover-bg);
    color: var(--nav-hover-text);
}

/* Highlight the active/current link */
.topnav a.active {
    background-color: var(--nav-active-bg);
    color: var(--text-color);
}

.index-centre {
    margin-top: 3.5rem;
    align-items: center;
    display: flex;
    justify-content: center;
    text-align: center;
}

/* Content area shared by the pages */
.page {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

.page-heading {
    font-size: 1.5rem;
    margin: 32px 0 20px;
}

.section-heading {
    font-size: 1.2rem;
    margin: 48px 0 16px;
}

/* Recent recordings on the home page: one row, at most 5 cards.
   3 on narrow screens, 4 on medium, 5 on wide. */
.recordings-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.recordings-row > .recording-card:nth-child(n+4) {
    display: none;
}

@media (min-width: 700px) {
    .recordings-row {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }
    .recordings-row > .recording-card:nth-child(4) {
        display: block;
    }
}

@media (min-width: 900px) {
    .recordings-row {
        grid-template-columns: repeat(5, 1fr);
    }
    .recordings-row > .recording-card:nth-child(5) {
        display: block;
    }
}

/* All recordings: as many columns as fit */
.recordings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

.all-recordings-link {
    display: inline-block;
    margin-top: 20px;
    color: var(--brand-gold);
}

.recordings-message {
    grid-column: 1 / -1;
    color: var(--text-secondary);
}

/* A recording: thumbnail (click to play), title, date and duration */
.recording-card {
    min-width: 0;
}

.recording-thumb {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background-color: var(--card-color);
}

.recording-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recording-thumb:focus-visible {
    outline: 3px solid var(--brand-gold);
    outline-offset: 2px;
}

.recording-card.playing .recording-thumb {
    box-shadow: 0 0 0 3px var(--brand-gold);
}

.play-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.play-icon svg {
    width: 20px;
    height: 20px;
    fill: var(--text-color);
}

.recording-thumb:hover .play-icon,
.recording-thumb:focus-visible .play-icon {
    transform: scale(1.15);
}

.recording-title {
    font-size: 0.95rem;
    margin: 8px 0 2px;
    overflow-wrap: anywhere;
}

.recording-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

/* "Now playing" bar for recordings, fixed to the bottom of the page */
.now-playing {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background-color: var(--nav-bg);
    box-shadow: 0 -4px 12px var(--shadow-color);
}

/* display: flex above would otherwise override the hidden attribute */
.now-playing[hidden] {
    display: none;
}

.now-playing-title {
    max-width: 40%;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-playing audio {
    flex: 1;
    min-width: 0;
}

/* Leave room so the bar doesn't cover the end of the page */
body.has-now-playing {
    padding-bottom: 80px;
}

@media (max-width: 600px) {
    .now-playing {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    .now-playing-title {
        max-width: none;
    }
    body.has-now-playing {
        padding-bottom: 110px;
    }
}

/* Narrow screens: tighten the nav links so they fit on one line on
   phones down to 360px wide */
@media (max-width: 480px) {
    .topnav a {
        padding: 14px 10px;
        font-size: 16px;
    }
}

/* --- Management page --- */

.admin-error {
    padding: 10px 14px;
    border-radius: 8px;
    background-color: var(--danger-bg);
    color: var(--text-color);
}

.admin-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.admin-panel {
    background-color: var(--card-color);
    border-radius: 12px;
    padding: 16px 20px 20px;
    min-width: 0;
}

.admin-panel h2 {
    font-size: 1.1rem;
    margin: 0 0 12px;
}

.admin-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin: 0 0 16px;
}

.admin-facts dt {
    color: var(--text-secondary);
}

.admin-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.admin-facts .status-badge {
    margin: 0;
    padding: 2px 10px;
    font-size: 0.75rem;
}

.warn {
    color: var(--warn-color);
}

.button {
    font: inherit;
    font-size: 0.9rem;
    padding: 6px 12px;
    border: 1px solid var(--button-border);
    border-radius: 6px;
    background-color: var(--button-bg);
    color: var(--text-color);
    cursor: pointer;
}

.button:hover:not(:disabled) {
    background-color: var(--button-hover-bg);
}

.button:disabled {
    opacity: 0.4;
    cursor: default;
}

.button:focus-visible {
    outline: 3px solid var(--brand-gold);
    outline-offset: 2px;
}

.button-danger {
    border-color: var(--danger-bg);
}

.button-danger:hover:not(:disabled) {
    background-color: var(--danger-bg);
}

/* Wide tables scroll sideways on narrow screens, not the whole page */
.table-scroll {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    padding: 8px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.admin-table th {
    color: var(--text-secondary);
    font-weight: normal;
}

.admin-table .num {
    text-align: right;
}

.admin-table .admin-title {
    white-space: normal;
    min-width: 12em;
}

.admin-thumb {
    display: block;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
}

.admin-actions {
    text-align: right;
}

.admin-actions .button + .button {
    margin-left: 6px;
}

.admin-input {
    font: inherit;
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--button-border);
    border-radius: 6px;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.about-text {
    margin-top: 2rem;
    margin-right: 3.5rem;
    margin-left: 3.5rem;
    align-items: center;
    display: flex; 
    justify-content: center;
    text-align: center;
    font-size: large;
}

.upload-form {
    display: grid;
    gap: 14px;
    max-width: 560px;
}

.upload-form label {
    display: grid;
    gap: 4px;
}

.upload-form label > span {
    color: var(--text-secondary);
}

.upload-form small {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.upload-form input[type="file"] {
    font: inherit;
    font-size: 0.9rem;
    color: var(--text-color);
}

.upload-form input[type="date"] {
    max-width: 12em;
    color-scheme: dark;
}

.upload-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.upload-actions progress {
    width: 160px;
    accent-color: var(--brand-gold);
}

.upload-status {
    font-size: 0.9rem;
}

/* --- Notices --- */

/* Text written in Markdown: the Notices page, and the editor's preview */
.notices-content {
    line-height: 1.6;
    max-width: 70ch;
    overflow-wrap: break-word;
}

.notices-content h1,
.notices-content h2,
.notices-content h3 {
    line-height: 1.25;
    margin: 1.4em 0 0.5em;
}

.notices-content h1 { font-size: 1.4rem; }
.notices-content h2 { font-size: 1.2rem; }
.notices-content h3 { font-size: 1.05rem; }

.notices-content > :first-child {
    margin-top: 0;
}

.notices-content p,
.notices-content ul,
.notices-content ol,
.notices-content blockquote,
.notices-content pre {
    margin: 0 0 1em;
}

.notices-content a {
    color: var(--brand-gold);
}

.notices-content blockquote {
    padding-left: 1em;
    border-left: 3px solid var(--brand-gold);
    color: var(--text-secondary);
}

.notices-content code {
    font-size: 0.9em;
    padding: 1px 4px;
    border-radius: 4px;
    background-color: var(--card-color);
}

.notices-content pre {
    padding: 10px 12px;
    border-radius: 8px;
    background-color: var(--card-color);
    overflow-x: auto;
}

.notices-content pre code {
    padding: 0;
}

.notices-content img {
    max-width: 100%;
    height: auto;
}

.notices-content hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
}

.notices-updated {
    margin-top: 2em;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* The editor on the management page: Markdown and preview side by side,
   one above the other on narrow screens. */
.notices-help {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 12px;
}

.notices-help a {
    color: var(--brand-gold);
}

.notices-editor {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 12px;
}

.notices-pane {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 4px;
    min-width: 0;
}

.notices-pane > span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#notices-markdown {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 20em;
}

.notices-preview {
    max-width: none;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
    min-height: 20em;
    overflow: auto;
}

.notices-preview code,
.notices-preview pre {
    background-color: var(--button-bg);
}

/* Space between the full-width panels on the management page (the
   two side by side at the top are spaced by their grid's gap) */
.page > .admin-panel + .admin-panel {
    margin-top: 16px;
}

/* --- History: listeners and network --- */

.history-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-bottom: 16px;
}

.history-presets {
    display: flex;
    gap: 4px;
}

.history-presets .button[aria-pressed="true"] {
    border-color: var(--brand-gold);
    background-color: var(--button-hover-bg);
}

.history-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.history-custom input {
    width: auto;
}

a.button {
    text-decoration: none;
    display: inline-block;
}

.button-small {
    font-size: 0.8rem;
    padding: 3px 10px;
}

.history-body {
    transition: opacity 0.2s;
}

.history-body.loading {
    opacity: 0.5;
}

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-tile {
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

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

.stat-value {
    font-size: 1.6rem;
    font-weight: 600;
    margin: 2px 0;
}

.stat-note {
    font-size: 0.8rem;
    color: var(--chart-muted);
    min-height: 1em;
}

.chart {
    margin: 0 0 20px;
}

.chart-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 16px;
    margin-bottom: 4px;
}

.chart-head figcaption {
    margin-right: auto;
}

.chart-title {
    font-weight: 600;
}

.chart-subtitle {
    margin-left: 8px;
    font-size: 0.85rem;
    color: var(--chart-muted);
}

.chart-legend {
    display: flex;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.85rem;
}

.chart-legend li {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* A short line in the series colour: identifies a series in legends and
   tooltips (the text itself stays in text colours). */
.legend-key {
    display: inline-block;
    width: 14px;
    height: 2px;
    border-radius: 1px;
    background-color: var(--key);
}

.chart-wrap {
    position: relative;
}

.chart-wrap canvas {
    display: block;
    width: 100%;
    height: 220px;
    border-radius: 6px;
}

.chart-wrap canvas:focus-visible {
    outline: 3px solid var(--brand-gold);
    outline-offset: 2px;
}

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
    font-size: 0.85rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px var(--shadow-color);
}

.tooltip-time {
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-label {
    color: var(--text-secondary);
}

.history-table summary {
    cursor: pointer;
    color: var(--text-secondary);
}

.history-table .table-scroll {
    max-height: 320px;
    overflow-y: auto;
    margin-top: 8px;
}
