/* ============================================================================
   CONTINUAL - Player stylesheet
   ----------------------------------------------------------------------------
   PURPOSE:  Visual styles for the player, splash, banner, text box, gear,
             and settings panel. Built mobile-first; refined for 16:9 TVs.
   SPEC:     SPEC.md sections 6 (Player), 7 (Settings Panel), 8 (Themes),
             9 (Visual Design).
   ============================================================================ */

/* ----- CSS reset (minimal) -------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ----- Responsive type tokens (used by themes) ------------------------------ */
/* Type sizes: every size is defined twice.
     1. A plain calc(rem + vw) line that ANY browser understands. Each one is
        fitted to give exactly the clamp() result at 1280px and 1920px wide.
     2. The clamp() version, inside @supports, which wins where supported.
   Why both: custom properties are not validated when declared, so a browser
   without clamp() (Chromium before 79 - Samsung and LG TVs up to about
   2020-21) would accept the clamp() token and then discard every font-size
   that uses it, falling back to a 16px default across the whole display.
   fitTextToCard() still shrinks anything that overflows, at any width. */
:root {
    --title-size:   calc(3rem + 1.25vw);
    --body-size:    calc(2rem + 0.5vw);
    --container-pad: 2rem;     /* overridden by .padding-tight / .padding-loose */
    --line-height:  1.5;
    --textbox-bg:   rgba(0, 0, 0, 0.55);
    --textbox-fg:   #ffffff;
    --textbox-max-w: 80vw;
    --textbox-max-h: 75vh;
    --fade-duration: 0.5s;
    /* Ken Burns cycle length. Overridden inline by index.php from the PHP
       Control Panel ($ken_burns_seconds) so the knob actually does something. */
    --ken-burns-duration: 20s;
    --banner-max-h: 12vh;
    /* Settings accent color — used for value readouts, sliders, and checkboxes */
    --accent: #7ec8e3;
    --accent-on:  #4caf7d;   /* green for On/enabled */
    --accent-off: rgba(255, 255, 255, 0.35); /* muted for Off/disabled */
}
.padding-very_tight { --container-pad: 0.5rem; --line-height: 1.15; }
.padding-tight      { --container-pad: 1rem;   --line-height: 1.3; }
.padding-normal     { --container-pad: 2rem;   --line-height: 1.5; }
.padding-loose      { --container-pad: 3rem;   --line-height: 1.8; }
.padding-very_loose { --container-pad: 4.5rem; --line-height: 2.1; }

/* ----- Text size classes ----------------------------------------------------- */
/* Override --body-size and --title-size so every theme scales proportionally.
   "Small" is still designed to be readable from across a room on a TV.          */
/* Fallback sizes first (see the note above :root), clamp() versions after. */
body.text-size-small   { --body-size: calc(1.56rem + 0.45vw); --title-size: calc(2.4rem + 1vw); }
body.text-size-normal  { --body-size: calc(2rem + 0.5vw);     --title-size: calc(3rem + 1.25vw); }
body.text-size-large   { --body-size: calc(2.56rem + 0.7vw);  --title-size: calc(3.8rem + 1.75vw); }
body.text-size-xlarge  { --body-size: calc(3.4rem + 0.75vw);  --title-size: calc(5.12rem + 1.9vw); }
body.text-size-xxlarge { --body-size: calc(4.12rem + 1.15vw); --title-size: calc(6.2rem + 2.75vw); }
@supports (width: clamp(1px, 1vw, 2px)) {
    :root                  { --body-size: clamp(1.4rem, 3vw, 2.6rem);   --title-size: clamp(2.0rem, 5vw, 4.5rem); }
    body.text-size-small   { --body-size: clamp(1.1rem, 2.4vw, 2.1rem); --title-size: clamp(1.6rem, 4.0vw, 3.6rem); }
    body.text-size-normal  { --body-size: clamp(1.4rem, 3.0vw, 2.6rem); --title-size: clamp(2.0rem, 5.0vw, 4.5rem); }
    body.text-size-large   { --body-size: clamp(1.8rem, 3.9vw, 3.4rem); --title-size: clamp(2.6rem, 6.5vw, 5.9rem); }
    body.text-size-xlarge  { --body-size: clamp(2.3rem, 5.0vw, 4.3rem); --title-size: clamp(3.3rem, 8.3vw, 7.4rem); }
    body.text-size-xxlarge { --body-size: clamp(2.9rem, 6.3vw, 5.5rem); --title-size: clamp(4.2rem, 10.5vw, 9.5rem); }
}

/* ----- Container width classes ---------------------------------------------- */
/* Controls how wide the text box can grow — i.e. how much margin from screen edge. */
body.container-narrow   { --textbox-max-w: 60vw; }
/* Standard is the baseline width and is set from the PHP Control Panel
   ($textbox_max_width_pct) via --textbox-standard-w; 80vw if that is absent. */
body.container-standard { --textbox-max-w: var(--textbox-standard-w, 80vw); }   /* default */
body.container-wide     { --textbox-max-w: 90vw; }
body.container-full     { --textbox-max-w: 96vw; }

/* ----- Text entry animations ------------------------------------------------ */
/* "None" is the default: pure opacity fade (no override needed).
   Each class applies an additional transform/filter on the inactive state so
   the animation plays on fade-in (and reverses gently on fade-out).           */
body.text-anim-scale #textbox {
    transform: scale(0.93);
    transition: opacity var(--fade-duration) ease-out,
                transform calc(var(--fade-duration) * 1.4) ease-out;
}
body.text-anim-scale #textbox.active { transform: scale(1.0); }

body.text-anim-drift-up #textbox {
    transform: translateY(20px);
    transition: opacity var(--fade-duration) ease-out,
                transform calc(var(--fade-duration) * 1.4) ease-out;
}
body.text-anim-drift-up #textbox.active { transform: translateY(0); }

/* Materialize uses blur — elegant but may be slow on older TVs.
   Noted in help text. */
body.text-anim-materialize #textbox {
    filter: blur(6px);
    transition: opacity var(--fade-duration) ease-out,
                filter calc(var(--fade-duration) * 1.4) ease-out;
}
body.text-anim-materialize #textbox.active { filter: blur(0); }

/* ----- Solid background color (when background images are hidden) ----------- */
body.bg-images-hidden {
    background: var(--bg-solid, #000);
}
body.bg-images-hidden #player {
    background: var(--bg-solid, #000);
}
/* Immediately collapse both crossfade layers so the solid color shows through */
body.bg-images-hidden .bg-layer {
    opacity: 0 !important;
    transition: none !important;
}

/* ----- Splash screen -------------------------------------------------------- */
#splash {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    inset: 0;
    z-index: 200;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.4s ease-out;
    /* Failsafe: remove the splash by itself if splash.js never runs (a failed
       download). The delay comes from index.php: the normal dismissal time
       plus 8 seconds. With no fill during the delay, splash.js's own fade is
       unaffected. visibility:hidden also stops it catching clicks.
       BOTH keyframes are hidden on purpose: `visibility` animates discretely,
       and Chrome ends a `forwards` animation a hair short of 100%, where a
       visible->hidden animation still reads "visible" (the splash would be
       transparent but would still swallow every click). */
    -webkit-animation: splash-failsafe 0.01s linear var(--splash-failsafe-delay, 12s) forwards;
            animation: splash-failsafe 0.01s linear var(--splash-failsafe-delay, 12s) forwards;
}
@-webkit-keyframes splash-failsafe { from, to { opacity: 0; visibility: hidden; pointer-events: none; } }
@keyframes splash-failsafe         { from, to { opacity: 0; visibility: hidden; pointer-events: none; } }
#splash .splash-hint {
    margin: 0;
    font-family: "Palatino Linotype", Palatino, serif;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    letter-spacing: 0.15em;
    color: rgba(255, 255, 255, 0.55);
    text-transform: uppercase;
    animation: splash-pulse 2.2s ease-in-out infinite;
}
@keyframes splash-pulse {
    0%, 100% { opacity: 0.4; }
    50%       { opacity: 0.9; }
}
#splash img {
    max-width: 80vw;
    max-height: 80vh;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}
#splash .splash-fallback-text {
    display: none;
    font-size: clamp(2rem, 6vw, 5rem);
    text-align: center;
    color: #fff;
    padding: 2rem;
    font-family: "Palatino Linotype", Palatino, serif;
    letter-spacing: 0.05em;
}
#splash.splash-fallback .splash-fallback-text { display: block; }

/* ----- Player container ----------------------------------------------------- */
#player {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ----- Background image layers (A/B for crossfade + Ken Burns) -------------- */
/* Images are rendered as <img> elements inside each layer so browsers allow
   right-click → "Save Image As". The div handles opacity crossfade and Ken Burns
   transform; the img fills the div with object-fit:cover (same visual result as
   background-size:cover). pointer-events defaults to auto so right-click reaches
   the img even through the pointer-events:none overlay elements above it.       */
/* PERFORMANCE: the layer itself is NOT permanently promoted with will-change.
   Two full-screen composited layers held in GPU memory for the lifetime of the
   page is a large constant cost on a TV panel. Promotion now travels with the
   .ken-burns class, i.e. only while an animation is actually running.
   The longhand offsets accompany `inset` for older TV browsers that ignore it. */
.bg-layer {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    inset: 0;
    opacity: 0;
    transition: opacity var(--fade-duration) ease-in-out;
}
.bg-layer img {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    user-select: none;
}
.bg-layer.active { opacity: 1; }

/* Ken Burns animates the <img>, not the layer, so the layer's opacity
   crossfade and the pan/zoom are composited independently. */
.bg-layer img.ken-burns {
    animation: ken-burns var(--ken-burns-duration, 20s) ease-in-out infinite alternate;
    will-change: transform;
}
@keyframes ken-burns {
    from { transform: scale(1.0)  translate(0, 0); }
    to   { transform: scale(1.08) translate(-2%, -1%); }
}

/* ----- Banner --------------------------------------------------------------- */
/* max-height keeps it to 12vh of the viewport. max-width: 100% ensures a very
   wide image shrinks proportionally rather than overflowing horizontally.
   border-radius rounds all 4 corners; top two are visible against the
   page background since top:0 positions the image flush with the viewport.   */
#banner {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    max-height: var(--banner-max-h, 12vh);   /* set from $banner_max_height_vh */
    max-width: 100%;
    width: auto;
    height: auto;
    z-index: 50;
    pointer-events: none;
    border-radius: 12px;
}

/* ----- Text box ------------------------------------------------------------- */
#textbox-wrapper {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--container-pad);
    pointer-events: none;
}
#textbox {
    background: var(--textbox-bg);
    color: var(--textbox-fg);
    border-radius: 20px; /* default; overridden inline by applyVisualSettings() */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 2px solid transparent; /* pre-sized so layout never shifts when border effect toggles */
    padding: var(--container-pad);
    max-width: var(--textbox-max-w);
    max-height: var(--textbox-max-h);
    overflow: hidden;
    text-align: center;
    line-height: var(--line-height);
    /* --fit is set per section by fitTextToCard() in player.js: the chosen
       Text Size is the maximum, and long text is scaled down until it fits. */
    font-size: calc(var(--body-size) * var(--fit, 1));
    opacity: 0;
    transition: opacity var(--fade-duration) ease-in-out, box-shadow 0.4s ease, border-color 0.4s ease;
}
/* Never taller than the wrapper's content box, whatever --textbox-max-h says.
   Guarded because a var() inside an unsupported min() would void the whole
   declaration (no max-height at all) rather than fall back to the line above. */
@supports (max-height: min(10px, 100%)) {
    #textbox { max-height: min(var(--textbox-max-h), 100%); }
}
#textbox.active { opacity: 1; }

/* A soft shadow keeps white text legible where a bright patch of the
   background (sunlight, sky) shows through the semi-transparent card.
   Painted once per section; dropped in the minimal performance tier. */
#textbox { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55); }
body.perf-minimal #textbox { text-shadow: none; }

/* Text too long even at the minimum legible size: let the viewer swipe/scroll
   rather than lose the end of the section. */
#textbox.fit-scroll {
    overflow-y: auto;
    overflow-wrap: break-word;
    pointer-events: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

/* Gold glow (halo) — body class toggled by applyVisualSettings() */
body.textbox-glow #textbox {
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0  22px rgba(255, 215, 0, 0.45),
        0 0  55px rgba(255, 190, 0, 0.22),
        0 0  95px rgba(255, 160, 0, 0.10);
}
/* Gold border — body class toggled by applyVisualSettings() */
body.textbox-border #textbox {
    border-color: rgba(255, 215, 0, 0.60);
}

#textbox h1, #textbox h2, #textbox h3 { font-size: calc(var(--title-size) * var(--fit, 1)); margin: 0 0 0.5em 0; }
#textbox p { margin: 0 0 0.5em 0; }
#textbox blockquote { margin: 0.5em 1em; font-style: italic; }
#textbox hr { border: 0; border-top: 2px solid rgba(255, 255, 255, 0.55); margin: 0.9rem 0; transition: border-top-color 0.4s ease, box-shadow 0.4s ease; }

/* Golden HR — mirrors the textbox border / glow effects on separator lines */
body.textbox-border #textbox hr {
    border-top-color: rgba(255, 215, 0, 0.60);
}
body.textbox-glow #textbox hr {
    border-top-color: rgba(255, 215, 0, 0.70);
    box-shadow: 0 0 6px rgba(255, 215, 0, 0.45), 0 0 14px rgba(255, 190, 0, 0.22);
}

/* ----- Category label (below gear icon) ------------------------------------ */
#category-label {
    position: fixed;
    top: 50px;            /* 12px gear-top + 40px gear-height − 2px overlap = 50px */
    right: 12px;
    z-index: 100;
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: 0.62rem;
    font-style: italic;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.92);
    text-align: right;
    cursor: pointer;
    padding: 2px 6px 3px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 4px;
    /* No max-width or overflow:hidden — always shows full text, grows left from right edge */
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.7);
    transition: background 0.2s, border-color 0.2s, opacity 0.6s;
    line-height: 1.4;
    font-weight: normal;   /* a <button> since v2.2; keep the label look */
    margin: 0;
}
#category-label:hover    { background: rgba(0, 0, 0, 0.72); border-color: rgba(255, 255, 255, 0.55); }
#category-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#category-label[hidden]  { display: none; }

/* ----- Gear icon ------------------------------------------------------------ */
#gear-icon {
    position: fixed;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    z-index: 100;
    transition: background 0.2s, transform 0.2s, opacity 0.6s;
}
#gear-icon:hover  { background: rgba(0, 0, 0, 0.6); transform: rotate(30deg); }
#gear-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#gear-icon[hidden] { display: none; }

/* ============================================================================
   SETTINGS PANEL
   ============================================================================ */
/* top + bottom rather than height: 100vh. On phones 100vh is the height with
   the browser toolbar hidden, which pushed the footer buttons (Copy Link,
   Reset All) off the bottom of the visible screen. */
#settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 440px;              /* fallback pair for browsers without min() */
    max-width: 92vw;
    width: min(440px, 92vw);
    background: rgba(14, 14, 18, 0.97);
    color: #f4f4f4;
    z-index: 100;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.7);
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    overflow-y: auto;
    font-family: "Trebuchet MS", "Helvetica Neue", Arial, sans-serif;
    font-size: 1.05rem;
    /* Custom scrollbar — Webkit */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) rgba(255, 255, 255, 0.04);
}
#settings-panel::-webkit-scrollbar         { width: 5px; }
#settings-panel::-webkit-scrollbar-track   { background: rgba(255, 255, 255, 0.04); }
#settings-panel::-webkit-scrollbar-thumb   { background: rgba(255, 255, 255, 0.22); border-radius: 3px; }
#settings-panel::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.4); }

/* The panel slides in and out.
   `hidden` normally sets display:none, which cancels the transition entirely
   (the element appears instantly). Swapping display:none for visibility:hidden
   keeps the box laid out so the transform can animate, while still hiding it
   from assistive technology and removing it from the tab order. The visibility
   change is delayed by the length of the slide so it does not vanish mid-flight. */
#settings-panel[hidden] {
    display: block;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(100%);
    transition: transform 0.25s ease-in, visibility 0s linear 0.25s;
}
#settings-panel:not([hidden]) {
    visibility: visible;
    transform: translateX(0);
    transition: transform 0.25s ease-out, visibility 0s linear 0s;
}

/* ----- Panel inner padding -------------------------------------------------- */
#settings-panel-inner { padding: 1.1rem 1.2rem 1.5rem; }

/* ----- Panel header --------------------------------------------------------- */
#settings-panel header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.7rem;
    margin-bottom: 0.9rem;
}
.settings-header-title {
    flex: 1;
    min-width: 0;  /* required for text-overflow in a flex child */
    overflow: hidden;
}
#settings-panel-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
    line-height: 1.2;
}
#settings-tagline {
    margin: 0.2rem 0 0;
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.42);
    font-style: italic;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#settings-close {
    flex-shrink: 0;
    background: transparent;
    border: 0;
    color: #f4f4f4;
    font-size: 1.3rem;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;        /* anchors the enlarged hit area below */
}
/* Enlarge the touch / click target to 44px without changing the look. */
#settings-close::after {
    content: '';
    position: absolute;
    top: -5px; right: -5px; bottom: -5px; left: -5px;
}
#settings-close:hover       { background: rgba(255, 255, 255, 0.09); }
#settings-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- Now Playing bar ------------------------------------------------------ */
#now-playing-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: -0.1rem 0 0.85rem;
    padding: 0.28rem 0.4rem 0.28rem 0.5rem;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 3px;
    min-height: 1.8em;
}
#now-playing-bar[hidden] { display: none; }
#now-playing-info {
    flex: 1;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
    letter-spacing: 0.02em;
    overflow-wrap: break-word;   /* wrap between words; break-all split "Victory" into "V ictory" */
}
#now-playing-skip {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.55);
    border-radius: 4px;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
}
#now-playing-skip:hover { border-color: var(--accent); color: var(--accent); background: rgba(126,200,227,0.08); }
#now-playing-skip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ============================================================================
   SETTING ROWS
   ============================================================================ */
#settings-controls .setting {
    margin-bottom: 1.0rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

/* ----- Setting groups (related pairs share one separator) ------------------- */
/* A .setting-group wraps 2 related settings (e.g. toggle + its volume slider).
   The group itself carries the bottom border; individual settings inside have
   no bottom border and tighter spacing so they read as a single logical item.  */
.setting-group {
    margin-bottom: 1.0rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}
/* Use #settings-controls prefix to match specificity of #settings-controls .setting
   so border-bottom:none overrides it for settings inside a group. */
#settings-controls .setting-group .setting {
    border-bottom: none;
    margin-bottom: 0.45rem;
    padding-bottom: 0.1rem;
}
#settings-controls .setting-group .setting:last-child {
    margin-bottom: 0;
}

#settings-controls > .setting:last-child,
#settings-controls > .setting-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Label row: holds label name, optional value display, optional inline control,
   and the ? help button. All on one horizontal line.                            */
#settings-controls .setting .setting-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    min-height: 1.8rem;
}
.setting-label-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.05rem;
}
/* Inline current-value badge — shown for sliders, toggles, and colors */
.setting-label-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    min-width: 1.8em;
    text-align: right;
    letter-spacing: -0.01em;
}
.setting-label-value.status-on  { color: var(--accent-on); }
.setting-label-value.status-off { color: var(--accent-off); }

/* ----- ? help button -------------------------------------------------------- */
#settings-controls .help-toggle {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.65);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.75rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s;
    position: relative;        /* anchors the enlarged hit area below */
}
/* A 20px circle is hard to hit on a touchscreen; widen the target to ~40px
   without changing what is drawn. */
#settings-controls .help-toggle::after {
    content: '';
    position: absolute;
    top: -10px; right: -10px; bottom: -10px; left: -10px;
}
#settings-controls .help-toggle:hover    { border-color: var(--accent); color: var(--accent); }
#settings-controls .help-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- Help text ------------------------------------------------------------ */
#settings-controls .help-text {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.45rem 0.7rem;
    border-radius: 5px;
    margin-top: 0.35rem;
    font-size: 0.82rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.75);
}
#settings-controls .help-text[hidden] { display: none; }

/* ----- Sliders -------------------------------------------------------------- */
input[type=range] {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    cursor: pointer;
    accent-color: var(--accent);
    height: 4px;
}

/* ----- Radio groups --------------------------------------------------------- */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.6rem;
    margin-top: 0.2rem;
}
.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 400;
    cursor: pointer;
    font-size: 0.96rem;
}
.radio-group input[type=radio] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ----- Toggle (inline checkbox in label row) -------------------------------- */
.setting-toggle-wrap {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0 0.15rem;
}
.setting-toggle-wrap input[type=checkbox] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-on);
    margin: 0;
}
.setting-toggle-wrap:focus-within { outline: 2px solid var(--accent); border-radius: 3px; }

/* ----- Color picker (inline in label row) ----------------------------------- */
.setting-color-inline {
    flex-shrink: 0;
    width: 34px;
    height: 24px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}
.setting-color-inline:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- Text inputs ---------------------------------------------------------- */
#settings-controls input[type=text] {
    display: block;
    width: 100%;
    margin-top: 0.3rem;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 5px;
    color: #f4f4f4;
    padding: 0.35rem 0.6rem;
    font-size: 0.88rem;
}
#settings-controls input[type=text]:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
}

/* ----- Category checkboxes (2-column grid, auto-collapses to 1 when names are long) */
.categories-group {
    margin-top: 0.3rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));   /* fits "Decrees for Government" */
    gap: 0.05rem 0.5rem;
}
.categories-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.18rem 0;
    font-weight: 400;
    font-size: 0.96rem;
    cursor: pointer;
    min-width: 0;
}
.categories-group label span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.categories-group input[type=checkbox] {
    accent-color: var(--accent-on);
    cursor: pointer;
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}
/* The "none selected" warning note should span all columns */
.categories-group .categories-none-note {
    grid-column: 1 / -1;
    font-size: 0.8rem;
    color: rgba(255, 200, 50, 0.85);
    margin: 0.35rem 0 0;
}
.categories-group .categories-none-note[hidden] { display: none; }

/* ============================================================================
   PANEL FOOTER
   ============================================================================ */
#settings-panel footer {
    margin-top: 1.4rem;
    padding-top: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}
#settings-footer-actions {
    display: flex;
    gap: 0.55rem;
    align-items: center;
}
#settings-copy-link {
    flex: 1;
    background: rgba(35, 95, 170, 0.85);
    color: #fff;
    border: 0;
    padding: 0.55rem 0.9rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    transition: background 0.15s;
}
#settings-copy-link:hover       { background: rgba(50, 115, 200, 0.95); }
#settings-copy-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#settings-reset {
    background: rgba(170, 55, 55, 0.8);
    color: #fff;
    border: 0;
    padding: 0.55rem 0.9rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    transition: background 0.15s;
}
#settings-reset:hover       { background: rgba(200, 65, 65, 0.95); }
#settings-reset:focus-visible { outline: 2px solid #f99; outline-offset: 2px; }
/* Armed: the first click of the two-step reset. */
#settings-reset.armed {
    background: #c62828;
    box-shadow: 0 0 0 2px rgba(255, 160, 160, 0.7);
}

/* ----- Support row: Copy diagnostics + version ------------------------------ */
#settings-support-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.7rem;
}
#settings-copy-diag {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    transition: border-color 0.15s, color 0.15s;
}
#settings-copy-diag:hover { border-color: var(--accent); color: var(--accent); }
#settings-copy-diag:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#settings-version {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.04em;
}
#settings-diag-text {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.5rem;
    background: rgba(0, 0, 0, 0.45);
    color: #dfe;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    font: 0.72rem/1.4 "Courier New", Courier, monospace;
    padding: 0.4rem;
    resize: vertical;
}
#settings-diag-text[hidden] { display: none; }

/* ----- QR code button ------------------------------------------------------- */
#settings-qr-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 6px;
    padding: 0.28rem 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
    /* Match height of sibling buttons (0.55rem padding + font line = ~2.1rem total) */
    height: 2.1rem;
}
#settings-qr-btn:hover { background: rgba(255,255,255,0.15); border-color: var(--accent); }
#settings-qr-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#settings-qr-thumb {
    width: auto;
    height: 1.1rem;
    display: block;
    border-radius: 2px;
    opacity: 0.85;
}

/* ----- About button (ℹ️ icon link in footer) -------------------------------- */
#settings-about-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    height: 2.1rem;
    width: 2.1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 1.15rem;
    line-height: 1;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#settings-about-btn:hover { background: rgba(255,255,255,0.15); border-color: var(--accent); color: var(--accent); }
#settings-about-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----- Links dropdown ------------------------------------------------------- */
.settings-links-dd {
    position: relative;
    flex-shrink: 0;
}
.settings-links-toggle {
    background: rgba(60, 120, 80, 0.8);
    color: #fff;
    border: 0;
    padding: 0.55rem 0.75rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s;
}
.settings-links-toggle:hover { background: rgba(75, 145, 95, 0.95); }
.settings-links-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-links-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 180px;
    background: rgba(18, 22, 32, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    z-index: 200;
}
.settings-links-menu[hidden] { display: none; }
.settings-links-item {
    display: block;
    padding: 0.55rem 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.88rem;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}
.settings-links-item:hover {
    background: rgba(126, 200, 227, 0.15);
    color: var(--accent);
    text-decoration: none;
}

/* ----- QR popup ------------------------------------------------------------- */
.qr-popup-overlay {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;   /* `inset` fallback for older TV browsers */
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: qr-fade-in 0.2s ease-out;
}
@keyframes qr-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.qr-popup-box {
    position: relative;
    background: rgba(14, 16, 26, 0.97);
    border: 1px solid rgba(126, 200, 227, 0.35);
    border-radius: 14px;
    padding: 1.6rem 1.6rem 1.2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(126,200,227,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    max-width: 90vw;
}
.qr-popup-close {
    position: absolute;
    top: 0.6rem;
    right: 0.75rem;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.55);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.qr-popup-close:hover { color: #fff; background: rgba(255,255,255,0.09); }
.qr-popup-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.qr-popup-error {
    width: 300px;
    max-width: 70vw;
    margin: 0;
    padding: 2rem 1rem;
    text-align: center;
    color: rgba(255, 200, 120, 0.9);
    font-size: 0.9rem;
    line-height: 1.5;
}
.qr-popup-img {
    width: 300px;
    height: 300px;
    border-radius: 8px;
    display: block;
    background: #fff; /* fallback while loading */
}
.qr-popup-url {
    margin: 0;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.45);
    font-style: italic;
    letter-spacing: 0.02em;
    max-width: 300px;
    overflow-wrap: break-word;
    word-break: break-all;
    text-align: center;
    line-height: 1.4;
}

/* ----- Error indicator & list ----------------------------------------------- */
#settings-error-indicator {
    margin: 0.7rem 0 0;
    color: #ffb84d;
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    border-radius: 4px;
    padding: 0.2rem 0;
    /* A <button> since v2.2: strip the default button chrome. */
    background: transparent;
    border: 0;
    text-align: left;
    width: 100%;
}
#settings-error-indicator:hover { color: #ffd080; }
#settings-error-indicator:focus-visible { outline: 2px solid #ffb84d; outline-offset: 2px; }
#settings-error-indicator[hidden] { display: none; }
#settings-error-list {
    list-style: none;
    margin: 0.4rem 0 0;
    padding: 0.45rem 0.7rem;
    background: rgba(255, 120, 0, 0.07);
    border: 1px solid rgba(255, 150, 0, 0.18);
    border-radius: 5px;
    font-size: 0.74rem;
    color: rgba(255, 185, 90, 0.9);
    max-height: 140px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,150,0,0.3) transparent;
}
#settings-error-list[hidden] { display: none; }
#settings-error-list li { padding: 0.15rem 0; border-bottom: 1px solid rgba(255,150,0,0.1); }
#settings-error-list li:last-child { border-bottom: 0; }

/* ----- Font themes (1-7) --------------------------------------------------- */
/* Theme 1 — Radiant: Gabriela (main font) for headings + Lato (lesser) for body.
   Gabriela is a graceful, display-weight serif. Lato provides clean, airy body text.
   Both are loaded from Google Fonts. */
.theme-1 #textbox h1, .theme-1 #textbox h2, .theme-1 #textbox h3 { font-family: "Gabriela", "Palatino Linotype", Palatino, serif; font-weight: 400; }
.theme-1 #textbox { font-family: "Lato", "Helvetica Neue", Arial, sans-serif; font-weight: 300; letter-spacing: 0.02em; }
.theme-2 #textbox h1, .theme-2 #textbox h2, .theme-2 #textbox h3 { font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif; }
.theme-2 #textbox { font-family: "Book Antiqua", "Times New Roman", serif; }
.theme-3 #textbox h1, .theme-3 #textbox h2, .theme-3 #textbox h3 { font-family: Georgia, "Times New Roman", serif; }
.theme-3 #textbox { font-family: Georgia, "Times New Roman", serif; }
.theme-4 #textbox h1, .theme-4 #textbox h2, .theme-4 #textbox h3 { font-family: "Trebuchet MS", "Helvetica Neue", Arial, sans-serif; }
.theme-4 #textbox { font-family: Verdana, "Helvetica Neue", sans-serif; }
.theme-5 #textbox h1, .theme-5 #textbox h2, .theme-5 #textbox h3 { font-family: "Copperplate Gothic Light", "Palatino Linotype", serif; }
.theme-5 #textbox { font-family: Garamond, "Times New Roman", serif; }

/* Theme 6 — Devotional: Cinzel (Roman-inscription headers) + Crimson Text (oldstyle body).
   Classical-liturgical; suits proclamations and declarations.
   Cinzel and Crimson Text load from Google Fonts (index.php); graceful serif fallbacks. */
.theme-6 #textbox h1, .theme-6 #textbox h2, .theme-6 #textbox h3 {
    font-family: "Cinzel", "Trajan Pro", "Palatino Linotype", serif;
    letter-spacing: 0.07em;
    font-weight: 700;
}
.theme-6 #textbox { font-family: "Crimson Text", "Palatino Linotype", "Times New Roman", serif; }

/* Theme 7 — Radiance: Playfair Display (high-contrast editorial italic headers) + Lato (airy sans body).
   Modern worship-magazine aesthetic; pairs ornate headers with ultra-clean light body text.
   Both load from Google Fonts; graceful fallbacks provided. */
.theme-7 #textbox h1, .theme-7 #textbox h2, .theme-7 #textbox h3 {
    font-family: "Playfair Display", Georgia, serif;
    font-style: italic;
    font-weight: 700;
}
.theme-7 #textbox { font-family: "Lato", "Helvetica Neue", Arial, sans-serif; font-weight: 300; letter-spacing: 0.03em; }

/* ----- Banner quick-pick chips ---------------------------------------------- */
.banner-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0.35rem 0 0.45rem;
}
.banner-chip {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    padding: 0.2rem 0.55rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    text-transform: capitalize;
}
.banner-chip:hover { border-color: var(--accent); color: var(--accent); }
.banner-chip-active {
    background: rgba(126, 200, 227, 0.15);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}
.banner-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- Audio unlock popup --------------------------------------------------- */
/* Appears at the bottom when browser blocks autoplay and settings want audio.
   Auto-dismisses after 5 s; any content-area click dismisses immediately.
   z-index sits above the player (20) but below the splash (200).              */
#audio-unlock-popup {
    position: fixed;
    bottom: 44px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 160;
    pointer-events: none;   /* the document-level click handler handles interaction */
    animation: aup-slide-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.aup-inner {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: rgba(8, 12, 28, 0.88);
    border: 1px solid rgba(126, 200, 227, 0.38);
    border-radius: 40px;
    padding: 0.65rem 1.5rem 0.65rem 1.1rem;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.65),
        0 0 0 1px rgba(126, 200, 227, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.07);
    white-space: nowrap;
}
.aup-icon {
    font-size: 1.45rem;
    line-height: 1;
    animation: aup-pulse 1.6s ease-in-out infinite;
    display: inline-block;
    flex-shrink: 0;
}
.aup-text {
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: clamp(0.82rem, 2vw, 1.05rem);
    letter-spacing: 0.13em;
    color: rgba(255, 255, 255, 0.92);
    text-transform: uppercase;
    font-style: italic;
}
#audio-unlock-popup.aup-fade {
    animation: aup-fade-out 0.4s ease-out forwards;
}
@keyframes aup-slide-in {
    from { transform: translateX(-50%) translateY(24px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);   opacity: 1; }
}
@keyframes aup-fade-out {
    to   { transform: translateX(-50%) translateY(12px); opacity: 0; }
}
@keyframes aup-pulse {
    0%, 100% { transform: scale(1.0) rotate(0deg); }
    40%       { transform: scale(1.2) rotate(-8deg); }
    60%       { transform: scale(1.15) rotate(6deg); }
}

/* ----- Shortcut toast (bottom pill, appears when a hotkey fires outside settings) */
.shortcut-toast {
    position: fixed;
    bottom: 2.8rem;
    left: 50%;
    transform: translateX(-50%) translateY(0.8rem);
    background: rgba(8, 12, 28, 0.88);
    color: rgba(255, 255, 255, 0.92);
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: clamp(0.78rem, 1.8vw, 0.98rem);
    letter-spacing: 0.06em;
    padding: 0.45em 1.4em;
    border-radius: 40px;
    border: 1px solid rgba(126, 200, 227, 0.32);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,255,255,0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
    pointer-events: none;
    z-index: 161;   /* above audio-unlock-popup (160) */
    white-space: nowrap;
}
.shortcut-toast.shortcut-toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ----- Pause banner (Space key) -------------------------------------------- */
/* Large bottom-center overlay shown while playback is paused. Persists until
   Space is pressed again; fades in/out via .pause-banner-visible class toggle. */
#pause-banner {
    position: fixed;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 165;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}
#pause-banner.pause-banner-visible { opacity: 1; }
.pause-banner-inner {
    display: inline-block;
    background: rgba(0, 0, 0, 0.84);
    border: 2px solid rgba(126, 200, 227, 0.55);
    border-radius: 14px;
    padding: 1rem 2.6rem;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(126, 200, 227, 0.1);
}
.pause-banner-text {
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: clamp(1.5rem, 3.5vw, 2.8rem);
    letter-spacing: 0.22em;
    color: rgba(255, 255, 255, 0.96);
    text-transform: uppercase;
    font-style: italic;
    line-height: 1;
}

/* ----- Shortcuts reference overlay (? key) ----------------------------------- */
.shortcuts-overlay {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;   /* `inset` fallback for older TV browsers */
    inset: 0;
    background: rgba(0, 0, 0, 0.70);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: sc-fade-in 0.18s ease-out;
}
@keyframes sc-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.shortcuts-box {
    background: rgba(10, 13, 28, 0.97);
    border: 1px solid rgba(126, 200, 227, 0.30);
    border-radius: 14px;
    padding: 1.5rem 2rem 1.2rem;
    min-width: 20rem;
    max-width: 92vw;           /* fallback for browsers without min() */
    max-width: min(92vw, 480px);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(126,200,227,0.08);
    color: #fff;
}
.shortcuts-close {
    display: block;
    margin: 0.8rem auto 0;
    background: transparent;
    border: 1px solid rgba(126, 200, 227, 0.4);
    color: var(--accent);
    border-radius: 6px;
    padding: 0.35rem 1.2rem;
    font-size: 0.9rem;
}
.shortcuts-close:hover { background: rgba(126, 200, 227, 0.1); }
.shortcuts-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.shortcuts-title {
    margin: 0 0 0.9rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}
.shortcuts-table {
    border-collapse: collapse;
    width: 100%;
}
.shortcuts-table tr + tr td,
.shortcuts-table tr + tr th { border-top: 1px solid rgba(255, 255, 255, 0.06); }
.shortcuts-table td,
.shortcuts-table th { padding: 0.38em 0.4em; font-size: 1.05rem; vertical-align: middle; }
.shortcuts-table th { text-align: left; font-weight: normal; }   /* row headers (the keys) */
.sc-key {
    font-family: "Courier New", Courier, monospace;
    font-size: 1.0rem;
    color: var(--accent);
    white-space: nowrap;
    padding-right: 1.1em;
    min-width: 6.5rem;
}
.sc-desc { color: rgba(255, 255, 255, 0.80); }
.shortcuts-hint {
    margin: 0.9rem 0 0;
    font-size: 0.84rem;
    color: rgba(255, 255, 255, 0.35);
    text-align: center;
    letter-spacing: 0.03em;
}

/* ============================================================================
   PERFORMANCE TIERS
   ----------------------------------------------------------------------------
   Applied to <body> by PerfGovernor in player.js. Nothing here changes colour,
   type, spacing or layout — only the cost of drawing a frame. A display that
   cannot hold 60fps looks far worse with the effects on than without them.

     .perf-reduced   tier 1 — no Ken Burns pan/zoom, no blur-based animation.
     .perf-minimal   tier 2 — tier 1, plus no backdrop blur, single-pass glow,
                              and shorter transitions.

   Reached automatically (measured frame rate / device hints), by the
   Performance setting, or by ?tv=1 on the URL.
   ============================================================================ */

/* ---- Tier 1 and above ---------------------------------------------------- */
body.perf-reduced  .bg-layer img.ken-burns,
body.perf-minimal  .bg-layer img.ken-burns {
    animation: none;
    will-change: auto;
}
/* Blur is the single most expensive text effect; fall back to a pure fade. */
body.perf-reduced.text-anim-materialize  #textbox,
body.perf-minimal.text-anim-materialize  #textbox {
    filter: none;
    transition: opacity var(--fade-duration) ease-out;
}
body.perf-reduced  .aup-icon,
body.perf-minimal  .aup-icon,
body.perf-reduced  #splash .splash-hint,
body.perf-minimal  #splash .splash-hint {
    animation: none;
}

/* ---- Tier 2 only --------------------------------------------------------- */
body.perf-minimal { --fade-duration: 0.35s; }

/* backdrop-filter forces the compositor to re-read and blur everything behind
   the element on every frame — the most expensive property in this stylesheet. */
body.perf-minimal .aup-inner,
body.perf-minimal .shortcut-toast,
body.perf-minimal .pause-banner-inner,
body.perf-minimal .shortcuts-overlay,
body.perf-minimal .qr-popup-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
/* One shadow instead of four stacked large-radius passes. Visually very close;
   dramatically cheaper to rasterise at 4K. */
body.perf-minimal.textbox-glow #textbox {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 26px rgba(255, 205, 0, 0.38);
}
body.perf-minimal.textbox-glow #textbox hr {
    box-shadow: none;
}
body.perf-minimal #gear-icon:hover { transform: none; }

/* ----- Idle: pointer hidden, controls dimmed --------------------------------- */
/* body.idle is set by player.js after idle_hide_seconds without mouse, touch
   or key activity, and removed by the next one. A dimmed control is still
   fully clickable, and keyboard focus always shows it at full strength. */
body.idle,
body.idle * { cursor: none !important; }
body.idle #gear-icon,
body.idle #category-label { opacity: 0.12; }
body.idle #gear-icon:focus-visible,
body.idle #category-label:focus-visible { opacity: 1; }

/* ----- Keyboard focus, everywhere ------------------------------------------- */
/* Controls above have their own focus styles; this catches anything else
   (links in the Links menu, controls added later) so keyboard users can
   always see where they are. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#settings-controls input[type=text]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- Respect the OS "reduce motion" preference ---------------------------- */
/* PerfGovernor also reads this, but honouring it in CSS means it holds even if
   JavaScript never runs. */
@media (prefers-reduced-motion: reduce) {
    .bg-layer img.ken-burns { animation: none; will-change: auto; }
    #splash .splash-hint,
    .aup-icon,
    #audio-unlock-popup { animation: none; }
    body.text-anim-materialize #textbox { filter: none; }
}

/* ----- Diagnostics overlay (?diag=1) ---------------------------------------- */
/* Deliberately plain and unstyled-looking: it is a service tool, not part of
   the display. Nothing is created unless ?diag=1 is present in the URL. */
#diag-overlay {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 300;
    max-width: 46vw;
    padding: 0.5rem 0.7rem;
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(126, 200, 227, 0.35);
    border-radius: 6px;
    color: #9fe6ff;
    font-family: "Courier New", Courier, monospace;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre;
    pointer-events: none;
    user-select: none;
}

/* ----- Phones --------------------------------------------------------------- */
/* The padding and width tokens are re-declared on the same body classes that
   set them above (a :root override would lose to body.padding-normal etc.).
   Every step stays relative to its neighbours, so the settings still behave
   the same way - just scaled to a small screen. fitTextToCard() then sizes
   the text to whatever space this leaves. */
@media (max-width: 600px) {
    body.padding-very_tight { --container-pad: 0.4rem;  --line-height: 1.15; }
    body.padding-tight      { --container-pad: 0.65rem; --line-height: 1.25; }
    body.padding-normal     { --container-pad: 0.9rem;  --line-height: 1.35; }
    body.padding-loose      { --container-pad: 1.25rem; --line-height: 1.55; }
    body.padding-very_loose { --container-pad: 1.6rem;  --line-height: 1.75; }

    body.container-narrow   { --textbox-max-w: 84vw; }
    body.container-standard { --textbox-max-w: 92vw; }
    body.container-wide     { --textbox-max-w: 95vw; }
    body.container-full     { --textbox-max-w: 98vw; }

    /* Top padding clears the gear and category label; the card may then use
       all of the remaining height (100% of the wrapper, not a vh fraction -
       vh on a phone includes the area behind the browser toolbar). */
    #textbox-wrapper { padding: 3.6rem 0 0.9rem; }
    #textbox { max-height: 100%; }
    #textbox hr { margin: 0.6rem 0; }

    #gear-icon { top: 8px; right: 8px; width: 36px; height: 36px; }
    #banner { max-height: 8vh; }
    #category-label { top: 46px; right: 8px; }

    /* Overlays: wrap instead of running off the edge of a narrow screen. */
    #audio-unlock-popup { bottom: 28px; width: max-content; max-width: 92vw; }
    .aup-inner { white-space: normal; padding: 0.6rem 1.1rem 0.6rem 0.9rem; }
    .aup-text { letter-spacing: 0.07em; }
    .shortcut-toast { white-space: normal; max-width: 92vw; text-align: center; }
    #pause-banner { white-space: normal; width: 92vw; bottom: 2rem; }
    .pause-banner-inner { padding: 0.8rem 1.2rem; }
    .pause-banner-text { font-size: 1.25rem; letter-spacing: 0.12em; line-height: 1.3; }
    .shortcuts-box { min-width: 0; padding: 1.2rem 1.1rem 1rem; }
    .qr-popup-img { width: 70vw; height: 70vw; max-width: 300px; max-height: 300px; }
}

/* ----- Landscape phones and other short screens ----------------------------- */
/* Height is the scarce dimension here, so the gear moves into the side margin
   instead of taking a band off the top. */
@media (max-height: 500px) {
    body.padding-very_tight { --container-pad: 0.35rem; --line-height: 1.15; }
    body.padding-tight      { --container-pad: 0.55rem; --line-height: 1.2; }
    body.padding-normal     { --container-pad: 0.8rem;  --line-height: 1.3; }
    body.padding-loose      { --container-pad: 1.1rem;  --line-height: 1.45; }
    body.padding-very_loose { --container-pad: 1.4rem;  --line-height: 1.6; }

    #textbox-wrapper { padding: 0.5rem 3.6rem; }
    #textbox { max-height: 100%; }
    #textbox h1, #textbox h2, #textbox h3 { margin-bottom: 0.3em; }
    #textbox hr { margin: 0.45rem 0; }
    #gear-icon { top: 8px; right: 8px; width: 36px; height: 36px; }
    #category-label { top: 46px; right: 8px; }
    #banner { max-height: 10vh; }
}
