/* PolyCrash viewer stylesheet: circa-2015 CSS 3, flat lean-paint, Tizen 2.4 / Mali-400 safe. */
* {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #5c7c9e;
    color: #f6f8fa;
    font-family: "Trebuchet MS", "Segoe UI", Arial, Helvetica, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#world, #world canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#world {
    cursor: grab;
    touch-action: none;
}

#world.is-dragging {
    cursor: grabbing;
}

/* Showcase clean mode (hides HUD for reference model inspection!) */
body.is-showcase #hud-bar,
body.is-showcase #hud-actions,
body.is-showcase #hud-notices,
body.is-showcase #lobby-overlay,
body.is-showcase #results-overlay,
body.is-showcase #touch-guide,
body.is-showcase #qrPanel,
body.is-showcase #connection-status {
    display: none !important;
}

/* Top-Left Title (frameless icon + PolyCrash + mode tag) + Compact Translucent Info Panel Below */
.hud-left-col {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 8;
    pointer-events: none;
}

.hud-title-bar {
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    height: 34px;
    padding: 0;
    background: transparent;
    border: none;
    white-space: nowrap;
}

.hud-brand-icon {
    display: block;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    border-radius: 6px;
    -webkit-box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.hud-brand-name {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 0.3px;
    color: #ffffff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.78), 0 1px 2px rgba(0, 0, 0, 0.68);
    line-height: 1;
}

.hud-mode-tag {
    margin-left: 8px;
    padding: 2px 7px;
    border-radius: 5px;
    background: #e59819;
    color: #18140d;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    line-height: 1.25;
}

.hud-info-panel {
    margin-top: 6px;
    width: 248px;
    max-width: 92vw;
    padding: 7px 9px;
    border-radius: 10px;
    background: rgba(16, 20, 28, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.20);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
    pointer-events: none;
}

.hud-stats {
    display: block;
    font-family: monospace;
    font-size: 12px;
    color: #f6f8fa;
    text-align: center;
    white-space: nowrap;
}

.stat-label {
    font-family: "Trebuchet MS", Arial, sans-serif;
    font-size: 9px;
    font-weight: bold;
    color: #ffd56b;
    letter-spacing: 0.6px;
    margin-right: 3px;
}

.hud-divider {
    display: inline-block;
    width: 1px;
    height: 10px;
    margin: 0 8px;
    background: rgba(255, 255, 255, 0.26);
    vertical-align: middle;
}

/* Display-only on-screen driver status row inside #hud-info-panel */
.hud-local-section {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    pointer-events: none;
}

.hud-local-row {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
}

.local-car-tag {
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e59819;
    color: #18140d;
    margin-right: 7px;
    white-space: nowrap;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    text-shadow: none;
}

.local-hp-track {
    -webkit-flex: 1;
    flex: 1;
    min-width: 44px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.18);
    overflow: hidden;
    margin-right: 7px;
}

.local-hp-fill {
    height: 100%;
    width: 100%;
    background: #4caf50;
}

.local-drag-hint {
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 213, 79, 0.18);
    border: 1px solid rgba(255, 213, 79, 0.50);
    color: #ffe082;
    font-size: 9px;
    font-weight: bold;
    letter-spacing: 0.4px;
    white-space: nowrap;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    text-shadow: none;
}

/* Top-Right Action & Utility Controls Bar (single crisp non-wrapping row!) */
.hud-actions-bar {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 8;
    height: 34px;
    padding: 0;
    background: transparent;
    border: none;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    white-space: nowrap;
    pointer-events: none;
}

.hud-btn {
    pointer-events: auto;
    display: inline-block;
    vertical-align: middle;
    margin: 0 0 0 6px;
    padding: 5px 11px;
    border-radius: 7px;
    border: 1px solid rgba(255, 255, 255, 0.34);
    background: rgba(18, 22, 30, 0.84);
    color: #ffffff;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.25;
    font-weight: bold;
    cursor: pointer;
}

.hud-btn-primary {
    background: #e59819;
    border-color: #ffd54f;
    color: #18140d;
}

.hud-btn-exit {
    background: rgba(152, 36, 42, 0.90);
    border-color: rgba(255, 138, 138, 0.65);
    color: #ffe4e6;
}

.hud-btn:active {
    opacity: 0.85;
}

/* Top-right sound & fullscreen utility buttons */
#scene-controls {
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    white-space: nowrap;
    pointer-events: none;
}

.scene-button {
    pointer-events: auto;
    display: inline-block;
    vertical-align: middle;
    width: 30px;
    height: 30px;
    margin: 0 0 0 6px;
    padding: 5px;
    border-radius: 7px;
    border: 1px solid rgba(255, 255, 255, 0.34);
    background: rgba(18, 22, 30, 0.84);
    color: #ffffff;
    cursor: pointer;
}

.scene-button svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.scene-button .sound-off,
.scene-button .fullscreen-exit {
    display: none;
}

.scene-button.is-muted .sound-on,
.scene-button.is-fullscreen .fullscreen-enter {
    display: none;
}

.scene-button.is-muted .sound-off,
.scene-button.is-fullscreen .fullscreen-exit {
    display: block;
}

/* Live 6-car Derby Standings Strip (inside #hud-info-panel, NEVER overlaps top bar!) */
.leaderboard {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    width: 100%;
    pointer-events: none;
}

.lb-row {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    margin-bottom: 4px;
    padding: 4px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.lb-row:last-child {
    margin-bottom: 0;
}

.lb-row.is-human {
    border-color: rgba(255, 213, 79, 0.78);
    background: rgba(229, 152, 25, 0.16);
}

.lb-row.is-wrecked {
    opacity: 0.58;
    background: rgba(54, 20, 22, 0.52);
}

.lb-swatch {
    width: 9px;
    height: 20px;
    border-radius: 3px;
    margin-right: 6px;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.45);
}

.lb-mid {
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
}

.lb-top {
    display: -webkit-flex;
    display: flex;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    font-size: 11px;
    font-weight: bold;
    line-height: 1.2;
    margin-bottom: 3px;
}

.lb-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-right: 5px;
}

.lb-score {
    font-family: monospace;
    color: #ffd54f;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.lb-bar {
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.18);
    overflow: hidden;
}

.lb-fill {
    height: 100%;
    background: #4caf50;
}

/* Centered Top Notice Stack (dynamically positioned clear of #hud-bar & #hud-actions!) */
.hud-notices {
    position: fixed;
    top: 52px;
    left: 8px;
    right: 8px;
    z-index: 9;
    text-align: center;
    pointer-events: none;
}

.center-banner {
    display: inline-block;
    margin: 0 auto;
    max-width: 96%;
    padding: 8px 18px;
    border-radius: 10px;
    background: rgba(18, 22, 30, 0.92);
    border: 2px solid #ffd54f;
    color: #ffd54f;
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    white-space: normal;
    word-wrap: break-word;
    pointer-events: none;
}

.center-banner.is-countdown {
    font-size: 46px;
    padding: 10px 30px;
}

/* Lobby / Attract & Results Cards */
.overlay-card {
    position: fixed;
    left: 20px;
    bottom: 20px;
    width: 440px;
    max-width: calc(100% - 220px);
    max-height: calc(100% - 86px);
    overflow-y: auto;
    z-index: 7;
    padding: 16px 18px;
    border-radius: 14px;
    background: rgba(18, 22, 30, 0.90);
    border: 2px solid rgba(255, 255, 255, 0.24);
    color: #f6f8fa;
}

.results-card {
    left: 50%;
    top: 50%;
    bottom: auto;
    width: 480px;
    max-width: calc(100% - 32px);
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    border-color: #ffd54f;
}

.overlay-header {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    margin-bottom: 10px;
}

.overlay-icon {
    width: 54px;
    height: 54px;
    border-radius: 10px;
    margin-right: 12px;
    background: #ffffff;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.overlay-eyebrow {
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 1.3px;
    color: #ffd54f;
    text-transform: uppercase;
}

.overlay-title {
    margin: 2px 0 0 0;
    font-size: 28px;
    line-height: 1.1;
    letter-spacing: 0.5px;
}

.overlay-tagline {
    margin: 0 0 12px 0;
    font-size: 13px;
    line-height: 1.38;
    color: #cad6e2;
}

.roster-grid {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    margin: 0 -4px 10px -4px;
}

.roster-slot {
    width: 50%;
    padding: 4px;
}

.roster-inner {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.roster-inner.is-human {
    background: rgba(229, 152, 25, 0.20);
    border-color: #ffd54f;
}

.roster-num {
    width: 24px;
    height: 24px;
    line-height: 22px;
    text-align: center;
    border-radius: 6px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}

.roster-name {
    font-size: 13px;
    font-weight: bold;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -webkit-flex: 1;
    flex: 1;
}

.roster-tag {
    font-size: 10px;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.14);
    color: #c5d4e2;
    margin-left: 4px;
}

.roster-inner.is-human .roster-tag {
    background: #ffd54f;
    color: #18140d;
}

.overlay-actions {
    display: -webkit-flex;
    display: flex;
    margin: 0 -4px 8px -4px;
}

.btn-big {
    -webkit-flex: 1;
    flex: 1;
    margin: 0 4px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 2px solid transparent;
    font-family: inherit;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.btn-start {
    background: #e59819;
    border-color: #ffd54f;
    color: #18140d;
}

.btn-local {
    background: #283548;
    border-color: #546a87;
    color: #ffffff;
}

.btn-muted {
    background: #222833;
    border-color: #414d62;
    color: #cbd6e2;
}

.overlay-hint {
    margin: 0;
    font-size: 12px;
    color: #b1c2d4;
}

.results-badge {
    display: inline-block;
    margin: 8px 0 12px 0;
    padding: 5px 10px;
    border-radius: 6px;
    background: #27482f;
    border: 1px solid #59b36c;
    color: #9ff0b0;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.8px;
}

.results-list {
    margin-bottom: 12px;
}

.res-row {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    padding: 7px 10px;
    margin-bottom: 5px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 14px;
}

.res-pos {
    width: 30px;
    font-weight: bold;
    color: #ffd54f;
}

.res-swatch {
    width: 12px;
    height: 18px;
    border-radius: 3px;
    margin-right: 9px;
}

.res-name {
    -webkit-flex: 1;
    flex: 1;
    font-weight: bold;
}

.res-meta {
    font-size: 12px;
    color: #b4c5d6;
    margin-right: 10px;
}

.res-pts {
    font-family: monospace;
    font-size: 15px;
    font-weight: bold;
    color: #ffd54f;
}

/* Floating Touch-Anywhere Steering Reticle (identical to PolySnake!) */
.touch-guide {
    position: fixed;
    left: 0;
    top: 0;
    width: 112px;
    height: 112px;
    margin-left: -56px;
    margin-top: -56px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.58);
    background: rgba(16, 22, 30, 0.28);
    z-index: 7;
    pointer-events: none;
}

.touch-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 42px;
    height: 42px;
    margin-left: -21px;
    margin-top: -21px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    background: #f7b824;
    pointer-events: none;
}

/* Canonical RCWeb QR Panel Placement + Exact 4 Canonical Rules from v/style.css */
#qrPanel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 8;
    -webkit-transform-origin: bottom right;
    transform-origin: bottom right;
}

#qrPanel.is-compact {
    -webkit-transform: scale(0.72);
    transform: scale(0.72);
}

.rcRoomQrCodeLink,
.rcRoomQrCodeLink * {
    -webkit-box-sizing: content-box;
    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;
    transition: opacity 1s ease;
    text-decoration: none;
    box-shadow: 0 0 32px #000;
    -webkit-transform-origin: center;
    transform-origin: center;
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-animation: pop-in 500ms ease-in-out forwards;
    animation: pop-in 500ms ease-in-out forwards;
}

@-webkit-keyframes pop-in {
    0% { -webkit-transform: scale(0.5); transform: scale(0.5); }
    66% { -webkit-transform: scale(1.1); transform: scale(1.1); }
    100% { -webkit-transform: scale(1); transform: scale(1); }
}

@keyframes pop-in {
    0% { transform: scale(0.5); }
    66% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.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;
}

/* Lean paint path for Samsung Tizen 2.4 / Mali-400 (flat colors, zero shadows/animations!) */
body.is-lean .hud-brand-icon,
body.is-lean .rcRoomQrCodeLink {
    -webkit-box-shadow: none;
    box-shadow: none;
    -webkit-animation: none;
    animation: none;
}
body.is-lean .hud-brand-name,
body.is-lean .hud-info-panel {
    text-shadow: none;
}
body.is-lean .hud-info-panel {
    background: #141922;
}
body.is-lean .overlay-card,
body.is-lean .center-banner {
    background: #141922;
}

.conn-status {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 10;
    padding: 5px 12px;
    border-radius: 8px;
    background: rgba(160, 34, 34, 0.92);
    color: #ffffff;
    font-size: 13px;
    font-weight: bold;
    pointer-events: none;
}

.conn-status:empty {
    display: none;
}

#diagnostics {
    position: fixed;
    top: 52px;
    right: 12px;
    z-index: 11;
    margin: 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(12, 16, 22, 0.88);
    color: #8bf5a8;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.35;
    pointer-events: none;
}

/* Compact landscape (e.g. 960x540 TV / tablet) */
@media (max-height: 580px) {
    .hud-left-col { top: 8px; left: 8px; }
    .hud-actions-bar { top: 8px; right: 8px; height: 30px; }
    .hud-title-bar { height: 30px; }
    .hud-brand-icon { width: 24px; height: 24px; margin-right: 6px; }
    .hud-brand-name { font-size: 18px; }
    .hud-info-panel { width: 230px; padding: 6px 8px; }
    .overlay-card {
        width: 370px;
        padding: 12px 14px;
    }
    .overlay-title { font-size: 24px; }
    #qrPanel {
        -webkit-transform: scale(0.76);
        transform: scale(0.76);
    }
    #qrPanel.is-compact {
        -webkit-transform: scale(0.58);
        transform: scale(0.58);
    }
}

/* Narrow portrait & smartphone layout (<= 720px: clean top bar, compact 2-col standings, hidden QR!) */
@media (max-width: 720px) {
    .hud-left-col {
        top: 6px;
        left: 6px;
        right: 6px;
    }
    .hud-title-bar {
        height: 28px;
    }
    .hud-brand-icon {
        width: 24px;
        height: 24px;
        margin-right: 6px;
        border-radius: 5px;
    }
    .hud-brand-name {
        font-size: 16px;
    }
    .hud-mode-tag {
        margin-left: 5px;
        padding: 2px 5px;
        font-size: 9px;
        letter-spacing: 0.4px;
    }
    .hud-actions-bar {
        top: 6px;
        right: 6px;
        height: 28px;
    }
    .hud-btn {
        padding: 4px 8px;
        font-size: 11px;
        line-height: 1.2;
        margin: 0 0 0 4px;
        border-radius: 6px;
    }
    .scene-button {
        width: 26px;
        height: 26px;
        padding: 4px;
        margin: 0 0 0 4px;
        border-radius: 6px;
    }
    .scene-button svg {
        width: 16px;
        height: 16px;
    }
    .hud-info-panel {
        margin-top: 6px;
        width: 100%;
        max-width: 100%;
        padding: 6px 8px;
        border-radius: 9px;
    }
    .hud-stats {
        font-size: 11px;
    }
    .leaderboard {
        display: -webkit-flex;
        display: flex;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
        margin: 5px -2px 0 -2px;
        padding-top: 5px;
    }
    .lb-row {
        width: calc(50% - 4px);
        margin: 0 2px 4px 2px;
        padding: 3px 5px;
    }
    .lb-row:last-child {
        margin-bottom: 4px;
    }
    .lb-swatch {
        width: 6px;
        height: 16px;
        margin-right: 5px;
    }
    .lb-top {
        font-size: 10px;
        margin-bottom: 2px;
    }
    .lb-bar {
        height: 4px;
    }
    .overlay-card {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
        max-width: none;
        max-height: calc(100% - 56px);
        padding: 12px;
    }
    .results-card {
        left: 50%;
        right: auto;
        top: 50%;
        bottom: auto;
        width: calc(100% - 20px);
        max-width: 440px;
        max-height: calc(100% - 64px);
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
    .res-row {
        padding: 6px 8px;
        font-size: 13px;
    }
    .res-pts {
        font-size: 14px;
    }
    .overlay-title {
        font-size: 22px;
    }
    .overlay-tagline {
        display: none;
    }
    .roster-slot {
        width: 50%;
    }
    .btn-big {
        padding: 10px 10px;
        font-size: 13px;
    }
    .center-banner {
        font-size: 14px;
        letter-spacing: 0.5px;
        padding: 6px 12px;
        border-radius: 8px;
    }
    .center-banner.is-countdown {
        font-size: 36px;
        padding: 8px 22px;
    }
    #qrPanel {
        display: none !important;
    }
}
