/* Kid-first theme: big targets, high contrast, nothing smaller than 16px.
   Every interactive element is at least 56px tall so an 8-year-old hits it first try. */
:root {
    --pink: #ff5fa2;
    --blue: #37c6ff;
    --yellow: #ffc53d;
    --purple: #8b5cf6;
    --green: #3ddc97;
    --ink: #1b1033;
    --ink-soft: #5b4b7a;
    --card: #ffffff;
    --bg: #fdf3ff;
    --radius: 26px;
    --shadow: 0 10px 30px rgba(90, 40, 140, .16);
    --tap: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Remote-control focus. A 1px default outline is invisible from three metres away, so
   anything reachable by remote gets a thick ring and a lift. */
:focus { outline: none; }
.btn:focus, .person:focus, .key:focus, a:focus, button:focus, input:focus, .song:focus {
    outline: 5px solid #ffd23d;
    outline-offset: 4px;
    box-shadow: 0 0 0 9px rgba(255, 210, 61, .35), var(--shadow);
    transform: scale(1.04);
}
/* The owner asked for ORANGE on song cards specifically: with dozens of white cards
   on screen, the remote's position must be unmissable from the sofa. */
.song:focus {
    outline: 5px solid #ff8a00;
    outline-offset: 3px;
    box-shadow: 0 0 0 9px rgba(255, 138, 0, .35), var(--shadow);
    transform: scale(1.02);
}

/* Five per row when the container is wide enough for it. Set by fitSongGrids() in JS,
   not a container query - the living-room TV is Chrome 67 and has never heard of
   @container. */
.songs.cols5 { grid-template-columns: repeat(5, 1fr); }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Noto Sans Thai", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 17px;
    min-height: 100%;
}

body.bg-fun {
    background:
        radial-gradient(1100px 700px at 8% -10%, #ffd9ef 0%, transparent 60%),
        radial-gradient(900px 600px at 100% 0%, #d6f1ff 0%, transparent 55%),
        radial-gradient(700px 700px at 50% 115%, #fff0c9 0%, transparent 60%),
        var(--bg);
    background-attachment: fixed;
}

body.bg-stage {                       /* the TV screen: dark so lyrics pop */
    background: radial-gradient(1200px 800px at 50% 0%, #2a1b52 0%, #150c2c 60%, #0c0719 100%);
    color: #fff;
}

a { color: inherit; text-decoration: none; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 16px 120px; }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; }
.hide { display: none !important; }

h1 { font-size: 30px; margin: 10px 0 4px; font-weight: 800; }
h2 { font-size: 21px; margin: 26px 0 12px; font-weight: 700; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
    min-height: var(--tap);
    padding: 14px 22px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--pink), var(--purple));
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.blue { background: linear-gradient(135deg, var(--blue), #4f8bff); }
.btn.green { background: linear-gradient(135deg, var(--green), #16b981); }
.btn.yellow { background: linear-gradient(135deg, var(--yellow), #ff9f43); color: #3a2600; }
.btn.ghost { background: #fff; color: var(--ink); border: 2px solid #e9dcff; box-shadow: none; }
.btn.big { font-size: 22px; padding: 20px 30px; min-height: 76px; }
.btn.block { width: 100%; }

/* ---------- cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.input {
    min-height: var(--tap);
    width: 100%;
    padding: 14px 20px;
    border-radius: 999px;
    border: 3px solid #eadcff;
    font-size: 19px;
    font-family: inherit;
    outline: none;
    background: #fff;
}
.input:focus { border-color: var(--purple); }

/* ---------- who-am-i cards (login) ---------- */
.people { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; margin-top: 22px; }
.person {
    width: 168px;
    padding: 22px 14px;
    border-radius: 30px;
    background: #fff;
    box-shadow: var(--shadow);
    border: 4px solid transparent;
    cursor: pointer;
    transition: transform .15s ease, border-color .15s ease;
}
.person:hover, .person:focus-visible { transform: translateY(-6px); }
.person.on { border-color: var(--purple); }
.person .face { font-size: 62px; line-height: 1.1; }
.person .name { font-size: 21px; font-weight: 800; margin-top: 6px; }

/* ---------- numeric keypad ---------- */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 0 auto; }
.key {
    height: 72px; border-radius: 22px; border: none; background: #fff;
    font-size: 30px; font-weight: 800; font-family: inherit; color: var(--ink);
    box-shadow: var(--shadow); cursor: pointer;
}
.key:active { transform: scale(.94); }
.key.wide { grid-column: span 1; font-size: 22px; }
.dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: #e6d8ff; }
.dot.on { background: var(--purple); }

/* ---------- song rows / grid ---------- */
.songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.song {
    background: #fff; border-radius: 22px; overflow: hidden; box-shadow: var(--shadow);
    cursor: pointer; display: flex; flex-direction: column; transition: transform .12s ease;
    /* The card is always white, so it must set its own text colour. Inside the dark TV
       picker it used to inherit white-on-white and the titles vanished completely. */
    color: var(--ink);
}
.song:active { transform: scale(.97); }
.song .thumb-wrap { position: relative; }
.song .thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #eee; display: block; }
/* Status rides the picture's corner - the card body stays three lines tall. */
.song .thumb-wrap .badge {
    position: absolute; right: 6px; bottom: 6px; margin: 0;
    font-size: 11px; padding: 3px 9px; box-shadow: 0 1px 6px rgba(0, 0, 0, .35);
}
.song .thumb-wrap .badge:empty { display: none; }
.song .body { padding: 10px 12px 12px; }
.song .title { font-weight: 700; font-size: 16px; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.song .by { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.badge {
    display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700;
    padding: 5px 12px; border-radius: 999px; background: #f1e9ff; color: var(--purple); margin-top: 8px;
}
.badge.ok { background: #e2fbef; color: #0f9d63; }
.badge.work { background: #fff2d8; color: #b06a00; }
.badge.err { background: #ffe4e4; color: #d13c3c; }

.bar { height: 8px; border-radius: 999px; background: #eee; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--purple)); }

/* With a video behind, lyrics drop to the lower third and get a heavier shadow so they
   stay legible over bright scenes. */
body.with-video .lyrics { justify-content: flex-end; padding-bottom: 6vh; }
body.with-video .lyric-line {
    text-shadow: 0 2px 14px rgba(0, 0, 0, .95), 0 0 40px rgba(0, 0, 0, .8);
    color: rgba(255, 255, 255, .58);
}
body.with-video .lyric-line.next { color: rgba(255, 255, 255, .7); }
body.with-video .lyric-line .w > .fill { text-shadow: 0 0 24px rgba(255, 197, 61, .9); }
body.with-video .stage-top, body.with-video .stage-bottom {
    text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}

/* ---------- lyrics stage ---------- */
.stage { display: flex; flex-direction: column; min-height: 100vh; }
/* While the song panel floats on the right, the lyrics centre themselves in the space
   that is actually visible instead of running underneath it. */
body.panel-open .stage { margin-right: var(--panel-w, 46%); transition: margin-right .2s ease; }
/* The music video itself steps aside too - the owner wants the picture SQUEEZED beside
   the panel, not buried underneath it. left+width pins the box; the inset right is
   over-constrained and ignored, exactly as intended. */
body.panel-open #bg-video { width: calc(100% - var(--panel-w, 46%)) !important; transition: width .2s ease; }

#btn-home {
    display: flex; align-items: center; justify-content: center;
    width: 52px; height: 52px; border-radius: 16px; color: rgba(255, 255, 255, .85);
    margin-right: 4px;
}
#btn-home:hover, #btn-home:focus { background: rgba(255, 255, 255, .15); color: #fff; }
.lyrics {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; padding: 20px; text-align: center;
}
.lyric-line {
    /* Sized for how far away the reader SITS, not just how wide the window is:
       a TV is read from the sofa (double size, body.is-tv), a tablet or PC from an
       arm's length (the moderate base below). --lyr-scale is the user's own dial on
       top of either - the ก- / ก+ buttons, remembered per device. */
    font-size: calc(clamp(24px, 4.6vw, 64px) * var(--lyr-scale, 1));
    font-weight: 800; line-height: 1.3;
    color: rgba(255, 255, 255, .34); transition: color .2s ease, transform .2s ease;
}
.lyric-line.next {
    color: rgba(255, 255, 255, .55);
    font-size: calc(clamp(18px, 3vw, 40px) * var(--lyr-scale, 1));
}
/* iPad: the owner found the base size a touch large held at arm's length - 10% off. */
body.is-tablet .lyric-line { font-size: calc(clamp(24px, 4.6vw, 64px) * 0.9 * var(--lyr-scale, 1)); }
body.is-tablet .lyric-line.next { font-size: calc(clamp(18px, 3vw, 40px) * 0.9 * var(--lyr-scale, 1)); }
body.is-tv .lyric-line { font-size: calc(clamp(30px, 8.8vw, 108px) * var(--lyr-scale, 1)); }
body.is-tv .lyric-line.next { font-size: calc(clamp(22px, 5vw, 62px) * var(--lyr-scale, 1)); }
.lyric-line.active { color: rgba(255, 255, 255, .55); transform: scale(1); }
.lyric-line .w { position: relative; display: inline-block; white-space: pre; }
.lyric-line .w > .fill {
    position: absolute; left: 0; top: 0; white-space: pre; overflow: hidden; width: 0;
    color: var(--yellow); text-shadow: 0 0 22px rgba(255, 197, 61, .55);
}
.lyric-none { font-size: 22px; color: rgba(255, 255, 255, .5); }

.stage-top { display: flex; align-items: center; gap: 16px; padding: 16px 22px; }
.stage-bottom { padding: 14px 22px 26px; }
.progress { height: 10px; background: rgba(255, 255, 255, .16); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), var(--pink)); }

.mic-chip {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
    background: rgba(255, 255, 255, .12); font-weight: 700; font-size: 15px;
}
.mic-chip .lvl { width: 44px; height: 8px; border-radius: 999px; background: rgba(255,255,255,.2); overflow: hidden; }
.mic-chip .lvl > i { display: block; height: 100%; width: 0; background: var(--green); }

/* ---------- mic remote (phone) ---------- */
.remote { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }
.giant {
    width: 100%; min-height: 132px; border-radius: 34px; border: none; cursor: pointer;
    font-size: 26px; font-weight: 800; font-family: inherit; color: #fff;
    background: linear-gradient(135deg, #ff7ab5, #a855f7); box-shadow: var(--shadow);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.giant.off { background: linear-gradient(135deg, #cfc3e6, #a99cc4); }
.giant.on { background: linear-gradient(135deg, var(--green), #12a97a); }
.slider { width: 100%; height: 44px; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 44px; background: transparent; width: 100%; }
input[type=range]::-webkit-slider-runnable-track { height: 16px; border-radius: 999px; background: #ece0ff; }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 40px; height: 40px; border-radius: 50%; margin-top: -12px;
    background: #fff; border: 4px solid var(--purple); box-shadow: var(--shadow);
}
input[type=range]::-moz-range-track { height: 16px; border-radius: 999px; background: #ece0ff; }
input[type=range]::-moz-range-thumb { width: 34px; height: 34px; border: 4px solid var(--purple); background: #fff; border-radius: 50%; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: #1b1033; color: #fff; padding: 14px 22px; border-radius: 999px;
    box-shadow: var(--shadow); z-index: 90; font-weight: 700; max-width: 92vw;
}

.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 0 10px; }
.avatar { font-size: 34px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eee; font-size: 15px; }

@media (max-width: 560px) {
    .wrap { padding: 12px 12px 110px; }
    .songs { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .person { width: 44%; }

    /* On a phone the buttons used to squeeze the greeting into a one-word-per-line
       column. Give the name the whole first row and let the buttons share the next. */
    .topbar { flex-wrap: wrap; row-gap: 8px; }
    .topbar .grow { flex-basis: calc(100% - 58px); }
    .topbar .btn { flex: 1 1 auto; font-size: 15px; padding: 10px 12px; }
}

/* Lyrics on the phone: same highlighter, smaller stage. */
#lyrics-mini .lyric-line { font-size: 19px; line-height: 1.55; margin: 2px 0; }
#lyrics-mini .lyric-line.active { font-size: 22px; font-weight: 800; }

/* A number printed white-on-black reads as "press this on the remote". Used on the
   rooms panel: rooms 1-8 join with one key press; later rooms need the arrows. */
.key-tag {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 26px; height: 26px; padding: 0 7px; margin-right: 10px;
    background: #111; color: #fff; border-radius: 7px;
    font-size: 15px; font-weight: 800; font-family: monospace;
}

/* Artist chips: one scrollable row, remote-focusable, the active one filled in. */
.artist-chips {
    display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chip {
    flex: 0 0 auto; border: 2px solid var(--purple); background: #fff;
    color: var(--purple); border-radius: 999px; padding: 7px 14px;
    font-size: 15px; font-weight: 700; cursor: pointer;
}
.chip.on { background: var(--purple); color: #fff; }
.chip .n { opacity: .7; font-size: 12px; }
