/* MIDI Marbles display styles — dark studio violet & warm gold palette
   matching Pipe Dream, responsive across 1920x1080, 960x540, 1080x1920 and 450x960,
   with canonical RCWeb QR panel rules and lean-paint overrides. */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #090612;
    color: #f3effa;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    user-select: none;
}

#webgl-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#webgl-canvas:active {
    cursor: grabbing;
}

.hidden,
[hidden] {
    display: none !important;
}

/* Loading Pill */
#loading-pill {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    width: 340px;
    max-width: 86%;
    padding: 15px 20px;
    border-radius: 8px;
    background: rgba(14, 10, 26, 0.94);
    border: 1px solid rgba(255, 210, 102, 0.4);
    text-align: center;
}

.progress-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
    margin-bottom: 9px;
}

#progress-bar {
    width: 0%;
    height: 100%;
    border-radius: 3px;
    background: #f5b942;
    transition: width 0.15s ease-out;
}

#loading-status {
    font-size: 13px;
    color: #d0c6e5;
}

#error-banner {
    position: fixed;
    top: 46%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    z-index: 35;
    width: 84%;
    max-width: 640px;
    padding: 26px 30px;
    border-radius: 10px;
    background: #1a1026;
    border: 2px solid #9f3e52;
    color: #fce8ec;
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
}

#error-banner .error-badge {
    display: inline-block;
    margin-bottom: 10px;
    padding: 4px 12px;
    border-radius: 4px;
    background: #2f1b3d;
    border: 1px solid #d4a64a;
    color: #ffd76a;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
}

#error-banner .error-title {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.25;
}

#error-banner .error-desc {
    margin: 0 0 14px;
    font-size: 16px;
    color: #e2d8f0;
}

#error-banner .error-detail {
    margin: 0 0 16px;
    padding: 10px 14px;
    border-radius: 6px;
    background: #2c1420;
    border: 1px solid #7c3044;
    color: #f8b4c0;
    font-size: 13px;
    word-break: break-word;
}

#error-banner .error-rc-status {
    margin: 0 0 18px;
    padding: 9px 14px;
    border-radius: 6px;
    background: #141928;
    border: 1px solid #3c4d70;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 600;
}

#error-banner .error-rc-status.connected {
    background: #0f261e;
    border-color: #2d7a5b;
    color: #a7f3d0;
}

#error-banner .error-actions {
    margin-top: 6px;
}

#error-banner .error-home-btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 6px;
    background: #d99b26;
    color: #140c1e;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

#error-banner .error-home-btn:hover,
#error-banner .error-home-btn:focus {
    background: #f5b942;
}

/* Top HUD */
#top-stack {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 20;
    pointer-events: none;
}

#banner-stack {
    margin-top: 8px;
    text-align: center;
    pointer-events: none;
}

#unmute-pill,
.notice-pill {
    display: inline-block;
    pointer-events: auto;
    border: 1px solid rgba(255, 215, 106, 0.55);
    border-radius: 6px;
    padding: 7px 14px;
    margin: 0 4px 6px;
    background: rgba(20, 13, 34, 0.92);
    color: #ffe285;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    max-width: 100%;
}

#unmute-pill {
    cursor: pointer;
}

#unmute-pill:hover {
    background: rgba(36, 24, 58, 0.96);
}

.notice-pill {
    pointer-events: none;
    border-color: rgba(167, 139, 250, 0.52);
    color: #e9ddff;
}

.hud-fade {
    transition: opacity 0.35s ease;
}

.hud-idle {
    opacity: 0;
    pointer-events: none;
}

#top-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    pointer-events: none;
}

.badge-group,
.cam-pills {
    pointer-events: auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 6px;
    background: rgba(14, 10, 26, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.16);
    max-width: 100%;
}

.title-pill {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.16em;
    color: #ffd76a;
    padding: 0 4px 0 6px;
    white-space: nowrap;
}

.info-btn {
    width: 22px;
    height: 22px;
    border: 1px solid rgba(255, 215, 106, 0.45);
    border-radius: 4px;
    background: rgba(255, 215, 106, 0.14);
    color: #ffe285;
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-weight: 700;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    flex-shrink: 0;
}

.info-btn:hover {
    background: rgba(255, 215, 106, 0.28);
    color: #fff6cf;
}

.pack-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    border: 1px solid rgba(255, 215, 106, 0.52);
    border-radius: 4px;
    padding: 0 8px;
    background: rgba(255, 215, 106, 0.16);
    color: #ffe8a3;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.pack-btn:hover {
    background: rgba(255, 215, 106, 0.30);
    border-color: #ffe285;
    color: #fff8dc;
}

.pack-btn.pack-dramatic {
    background: rgba(234, 88, 12, 0.24);
    border-color: rgba(251, 146, 60, 0.65);
    color: #fed7aa;
}

.pack-btn.pack-dramatic:hover {
    background: rgba(234, 88, 12, 0.40);
    color: #fff7ed;
}

.pack-btn.pack-lively {
    background: rgba(255, 215, 106, 0.18);
    border-color: rgba(255, 215, 106, 0.58);
    color: #ffe8a3;
}

.pack-btn.pack-lively:hover {
    background: rgba(255, 215, 106, 0.34);
    color: #fffbeb;
}

.pack-btn.pack-calm {
    background: rgba(56, 189, 248, 0.20);
    border-color: rgba(125, 211, 252, 0.58);
    color: #bae6fd;
}

.pack-btn.pack-calm:hover {
    background: rgba(56, 189, 248, 0.36);
    color: #f0f9ff;
}

.pack-btn.pack-christmas {
    background: linear-gradient(135deg, rgba(185, 28, 28, 0.72) 0%, rgba(21, 128, 61, 0.72) 100%);
    border-color: rgba(253, 224, 71, 0.78);
    color: #fffbeb;
}

.pack-btn.pack-christmas:hover {
    border-color: #fde047;
    color: #ffffff;
}

.section-pill {
    font-size: 12px;
    color: #ede6fb;
    padding: 2px 9px;
    border-radius: 4px;
    background: rgba(139, 92, 246, 0.32);
    border: 1px solid rgba(167, 139, 250, 0.42);
    white-space: nowrap;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bank-pill {
    font-size: 11px;
    color: #ffe285;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(245, 185, 66, 0.16);
    border: 1px solid rgba(255, 215, 106, 0.35);
    white-space: nowrap;
}

.fps-pill {
    font-size: 11px;
    font-family: monospace;
    color: #86efac;
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(22, 101, 52, 0.42);
    white-space: nowrap;
}

.cam-btn {
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.05);
    color: #cfc6e2;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 9px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.cam-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.cam-btn.active {
    background: #e9a533;
    color: #160e04;
    font-weight: 600;
}

#sub-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    pointer-events: none;
}

#resume-auto-btn {
    pointer-events: auto;
    margin-left: auto;
    border: 1px solid rgba(255, 215, 106, 0.52);
    background: rgba(20, 13, 34, 0.9);
    color: #ffe285;
    font-family: inherit;
    font-weight: 600;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

#resume-auto-btn:hover {
    background: rgba(38, 25, 62, 0.96);
}

/* Optional Live Telemetry Overlay (in-flow under #top-hud — zero overlap on wrap!) */
.telemetry-strip {
    width: 262px;
    padding: 9px 11px;
    border-radius: 6px;
    background: rgba(14, 10, 26, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.14);
    pointer-events: auto;
}

.telemetry-strip.hud-idle {
    pointer-events: none;
}

.tel-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 6px;
}

.tel-composer {
    font-size: 11px;
    font-weight: 600;
    color: #ffd76a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tel-meta {
    font-size: 10px;
    font-family: monospace;
    color: #b7aacf;
    white-space: nowrap;
}

.tel-meters {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tel-meter {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 3px 5px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.tel-meter:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
}

.tel-meter.is-muted {
    background: rgba(153, 27, 27, 0.22);
    border-color: rgba(248, 113, 113, 0.38);
}

.tel-meter.is-muted .tel-lbl {
    color: #9e91b8;
    text-decoration: line-through;
}

.tel-meter.is-muted .tel-bar {
    opacity: 0.35;
}

.tel-lbl {
    width: 50px;
    font-size: 10px;
    color: #cfc6e2;
    flex-shrink: 0;
}

.tel-mute-ico {
    width: 16px;
    font-size: 10px;
    line-height: 1;
    text-align: center;
    color: #a99ec2;
    opacity: 0.65;
    flex-shrink: 0;
}

.tel-meter:hover .tel-mute-ico {
    opacity: 1;
}

.tel-meter.is-muted .tel-mute-ico {
    color: #fca5a5;
    opacity: 1;
}

.tel-bar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.tel-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
}

.fill-marimba { background: #ffc84a; }
.fill-strings { background: #67e8f9; }
.fill-drums { background: #fb923c; }
.fill-rail { background: #c084fc; }
.fill-bells { background: #ffe680; }

/* Bottom Transport HUD — always leaves room for bottom-right QR panel */
#bottom-hud {
    position: fixed;
    left: 16px;
    right: 106px;
    bottom: 14px;
    z-index: 15;
    max-width: 880px;
    margin: 0 auto;
    padding: 10px 14px 9px;
    border-radius: 6px;
    background: rgba(14, 10, 26, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.timeline-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.time-label {
    font-size: 12px;
    font-family: monospace;
    color: #d8d0e8;
    min-width: 40px;
    text-align: center;
}

.scrubber-wrap {
    position: relative;
    flex: 1;
    margin: 0 10px;
    display: flex;
    align-items: center;
}

#chapter-ticks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.chapter-tick {
    position: absolute;
    top: 50%;
    width: 2px;
    height: 10px;
    transform: translate(-50%, -50%);
    background: rgba(255, 215, 106, 0.6);
    border-radius: 1px;
}

#timeline {
    width: 100%;
    appearance: none;
    height: 5px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.22);
    outline: none;
    cursor: pointer;
}

#timeline::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 14px;
    border-radius: 3px;
    background: #ffd76a;
    cursor: pointer;
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.controls-center {
    flex: 1;
    text-align: center;
    min-width: 0;
    padding: 0 6px;
}

.section-hint {
    display: block;
    font-size: 11px;
    color: #a99cc4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn,
.text-btn {
    border: 0;
    background: rgba(255, 255, 255, 0.1);
    color: #f3effa;
    font-family: inherit;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}

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

.icon-btn.primary {
    width: 38px;
    height: 36px;
    background: #f5b942;
    color: #160e04;
    font-weight: 700;
}

.text-btn {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.upload-btn {
    border: 1px solid rgba(255, 215, 106, 0.42);
    color: #ffe285;
    background: rgba(245, 185, 66, 0.15);
}

.text-btn.active {
    background: #e9a533;
    color: #160e04;
}

.icon-btn:hover,
.text-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.icon-btn.primary:hover {
    background: #ffd16b;
}

#volume-slider {
    width: 72px;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.22);
    cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 10px;
    height: 12px;
    border-radius: 2px;
    background: #e9e2f8;
}

/* Info Modal */
#info-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(5, 3, 10, 0.82);
}

.info-dialog {
    width: 620px;
    max-width: 100%;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    background: #140e24;
    border: 1px solid rgba(255, 215, 106, 0.35);
    overflow: hidden;
    user-select: text;
}

.info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
}

.info-header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.info-logo {
    width: 38px;
    height: 38px;
    border-radius: 6px;
}

.info-header h2 {
    font-size: 17px;
    letter-spacing: 0.18em;
    color: #ffd76a;
}

.info-tagline {
    font-size: 12px;
    color: #b7aacf;
}

.info-close-btn {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: #e6dff5;
    font-size: 14px;
    cursor: pointer;
}

.info-body {
    padding: 16px;
    overflow-y: auto;
}

.info-section {
    margin-bottom: 14px;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-section h3 {
    font-size: 13px;
    font-weight: 700;
    color: #ffe285;
    margin-bottom: 5px;
}

.info-section p {
    font-size: 13px;
    line-height: 1.55;
    color: #d6cde8;
}

.info-section code {
    font-family: monospace;
    font-size: 12px;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffe285;
}

.info-keys {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 12px;
    color: #c7bddb;
}

.info-keys kbd {
    display: inline-block;
    padding: 1px 5px;
    margin-right: 4px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
}

.info-footer {
    padding: 10px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 11px;
    color: #9b8eb6;
    background: rgba(0, 0, 0, 0.26);
}

/* Offline Video Export Modal */
.export-btn {
    border-color: rgba(255, 215, 106, 0.42);
    color: #ffe285;
}

.export-btn:hover {
    background: rgba(255, 215, 106, 0.18);
    border-color: #ffd76a;
}

#export-modal {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(6, 4, 14, 0.78);
}

.export-dialog {
    width: 480px;
    max-width: 100%;
    border-radius: 8px;
    background: #140e24;
    border: 1px solid rgba(255, 215, 106, 0.42);
    overflow: hidden;
}

.export-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
}

.export-header h2 {
    font-size: 14px;
    letter-spacing: 0.16em;
    color: #ffd76a;
}

.export-track-label {
    font-size: 13px;
    color: #e6dff5;
    margin-top: 2px;
}

.export-spec-pill {
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(255, 215, 106, 0.14);
    border: 1px solid rgba(255, 215, 106, 0.35);
    color: #ffe285;
    font-size: 11px;
    font-weight: 600;
}

.export-body {
    padding: 18px 16px 14px;
}

.export-progress-track {
    height: 8px;
    border-radius: 4px;
    margin-bottom: 10px;
}

#export-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: 4px;
    background: #f5b942;
    transition: width 0.12s linear;
}

.export-status {
    font-size: 13px;
    color: #d6cde8;
    min-height: 18px;
}

.export-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.24);
}

.export-hint {
    font-size: 11px;
    color: #9b8eb6;
}

/* Lean-paint path for low-power devices */
.lean-paint #progress-bar,
.lean-paint #export-progress-bar,
.lean-paint .hud-fade,
.lean-paint .cam-btn,
.lean-paint .icon-btn,
.lean-paint .text-btn {
    transition: none;
}

.lean-paint #loading-pill,
.lean-paint #unmute-pill,
.lean-paint .badge-group,
.lean-paint .cam-pills,
.lean-paint #resume-auto-btn,
.lean-paint .telemetry-strip,
.lean-paint #bottom-hud {
    background: #140e24;
    border-color: #463c63;
}

/* Bottom-right standard RCWeb QR panel, uniformly scaled */
#qrPanel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 25;
    transform: scale(0.42);
    transform-origin: bottom right;
}

/* Canonical four RCWeb QR panel rules */
.rcRoomQrCodeLink,
.rcRoomQrCodeLink * {
    box-sizing: content-box;
}

.rcRoomQrCodeLink {
    display: block;
    width: 150px;
    margin-left: auto;
    margin-right: auto;
    border: solid 8px #fff;
    border-radius: 8px;
    color: #fff;
    background-color: #fff;
    text-align: center;
    text-decoration: none;
}

.rcTechLabel {
    background-color: #000;
    color: #fff;
    font-family: monospace;
    font-size: 13px;
    font-weight: bold;
    margin: 0 0 8px 0;
    padding: 4px;
    letter-spacing: 0.2em;
    border-radius: 8px 8px 0 0;
}

.rcRoomQrCode {
    width: 150px;
    height: 150px;
}

.rcRoomId {
    background-color: #000;
    color: #fff;
    font-family: monospace;
    font-size: 16px;
    padding: 4px;
    margin: 8px 0 0 0;
    letter-spacing: 0.25em;
    border-radius: 0 0 8px 8px;
}

/* Hide QR on smartphones */
body.is-smartphone #qrPanel {
    display: none !important;
}

body.is-smartphone #bottom-hud {
    left: 10px;
    right: 10px;
}

@media screen and (pointer: coarse) and (max-width: 520px),
       screen and (pointer: coarse) and (max-height: 520px) {
    #qrPanel { display: none !important; }
    #bottom-hud { left: 10px; right: 10px; }
}

/* Responsive layouts covering 1920x1080, 960x540, 1080x1920 and 450x960 */
@media screen and (max-width: 900px) {
    .controls-center { display: none; }
    .bank-pill { display: none; }
}

@media screen and (max-width: 720px) {
    #top-stack { top: 10px; left: 10px; right: 10px; }
    .telemetry-strip { display: none !important; }
    #qrPanel {
        right: 10px;
        bottom: 10px;
        transform: scale(0.36);
    }
    #bottom-hud {
        left: 10px;
        right: 84px;
        bottom: 10px;
        padding: 8px 10px;
    }
    #volume-slider { display: none; }
    .upload-btn { display: none; }
    .export-btn { display: none; }
}

@media screen and (max-width: 520px) {
    .section-pill { max-width: 145px; }
    .cam-btn { padding: 4px 7px; font-size: 11px; }
    .icon-btn { width: 30px; height: 30px; font-size: 13px; }
    .icon-btn.primary { width: 34px; height: 32px; }
    .text-btn { height: 30px; padding: 0 8px; font-size: 11px; }
    #qrPanel { transform: scale(0.34); }
    #bottom-hud { right: 80px; }
}
