@import url('https://fonts.googleapis.com/css2?family=Syncopate:wght@400;700&family=Inter:wght@300;500;700;900&display=swap');

:root {
    --bg-main: #050505;
    --text-light: #ffffff;
    --text-muted: #888888;
    --brand-accent: #EB0A1E;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text-light);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* -------------------------------------
 * STACKED LAYOUT (config-driven brand sections)
 * ------------------------------------- */
.stacked-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
}

.brand-section {
    flex: var(--flex-grow, 1) 1 auto;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1.5rem;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(135deg, #111111, #000000);
}

.brand-section:last-child {
    border-bottom: none;
}

.brand-section::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: linear-gradient(90deg, transparent, var(--brand-accent), transparent);
    opacity: 0.9;
}

/* Brand Headers */
.brand-header {
    text-align: center;
    margin-bottom: 0.5rem;
    height: auto;
    display: flex;
    flex-direction: row;
    gap: 1rem;
    align-items: baseline;
    justify-content: center;
}

.brand-header h1 {
    font-family: 'Syncopate', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #ffffff;
    text-shadow: 0px 4px 20px var(--brand-accent);
}

.brand-header p {
    font-size: 1rem;
    letter-spacing: 2px;
    font-weight: 300;
    color: var(--text-muted);
    margin-top: 0;
    text-transform: uppercase;
}

/* -------------------------------------
 * QUEUE GRID
 * ------------------------------------- */
.queue-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-content: stretch;
    flex: 1;
}

/* The Number Card */
.unit-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    position: relative;
    overflow: hidden;
    flex: 1 1 calc(25% - 0.75rem);
    max-width: calc(25% - 0.75rem);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;
}

.unit-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--brand-accent), transparent);
}

.unit-label {
    font-size: clamp(1.2rem, 1.6vw, 2rem);
    font-weight: 500;
    letter-spacing: 1px;
    color: var(--text-muted);
    z-index: 2;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    max-width: 100%;
}

.unit-number-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.unit-number {
    font-size: clamp(4rem, 6.5vw, 8rem);
    font-weight: 900;
    line-height: 1;
    z-index: 2;
    transition: all 0.3s ease;
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: center;
    color: #ffffff;
    text-shadow: 0 0 20px var(--brand-accent);
}

.prefix {
    font-size: 0.75em;
    opacity: 0.85;
    margin-right: 4px;
}

/* -------------------------------------
 * ANIMATIONS
 * ------------------------------------- */
@keyframes numberPop {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.15); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}

.animate-pop {
    animation: numberPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes flashBrand {
    0% { box-shadow: inset 0 0 0 rgba(255, 255, 255, 0); }
    50% { box-shadow: inset 0 0 50px var(--brand-accent); }
    100% { box-shadow: inset 0 0 0 rgba(255, 255, 255, 0); }
}

.flash-brand {
    animation: flashBrand 0.6s ease;
}

/* -------------------------------------
 * DASHBOARD SPECIFIC STYLES
 * ------------------------------------- */
body.dashboard {
    overflow-y: auto;
    padding: 1rem 2rem;
    height: 100vh;
}

.dashboard-header {
    text-align: center;
    margin-bottom: 1rem;
}

.dashboard-header h1 {
    font-size: 2.2rem;
    margin-bottom: 0.2rem;
}

.header-links {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.link-button {
    background: rgba(255,255,255,0.1);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    display: inline-block;
    transition: background 0.2s;
    border: 1px solid rgba(255,255,255,0.2);
}

.link-button:hover {
    background: rgba(255,255,255,0.2);
}

.controls-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
}

.controls-brand-section {
    flex: 1 1 45%;
    min-width: 320px;
    background: rgba(0,0,0,0.4);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--glass-border);
    border-top: 5px solid var(--brand-accent);
}

/* 2x6 dashboard: 2 columns, up to 6 rows */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.control-card {
    background: var(--glass-bg);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    position: relative;
}

.control-card h3 {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    letter-spacing: 1px;
    line-height: 1.4;
}

.input-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: var(--brand-accent);
    transform: scale(1.05);
}

.number-input {
    width: 80px;
    height: 50px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 2rem;
    font-weight: bold;
    text-align: center;
    border-radius: 8px;
}

.number-input:focus {
    outline: none;
    border-color: var(--text-light);
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

#reset-all-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    background: rgba(220,38,38,0.8);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: Inter, sans-serif;
    font-size: 0.8rem;
    transition: background 0.2s, opacity 0.2s;
}

#reset-all-btn:hover {
    background: rgba(220,38,38,1);
}

/* -------------------------------------
 * RESPONSIVE
 * ------------------------------------- */
@media (max-width: 768px) {
    .controls-wrapper {
        flex-direction: column;
    }

    .controls-brand-section {
        min-width: auto;
    }

    .header-links {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-header h1 {
        font-size: 1.5rem;
    }
}

/* -------------------------------------
 * PHONE DISPLAY
 * Two cards per row in portrait. Rows run from a 2-row minimum to a
 * 6-row maximum (--rows, written by buildDisplay). Every row is an equal
 * slice of the viewport, so the grid fills the screen with no dead space
 * and never scrolls: past 6 rows the cards simply get shorter, and
 * --rows-scale shrinks the type to stay legible.
 *
 * `pointer: coarse` is load-bearing, not decoration. Width alone also
 * matches the desktop app's 640x400 preview window, which would silently
 * get the phone layout. Coarse pointer = real touch device, so the TV and
 * the preview keep the desktop grid.
 * ------------------------------------- */
@media (max-width: 768px) and (orientation: portrait) and (pointer: coarse) {
    html,
    body {
        height: 100%;
    }

    body {
        /* Display boards are fixed-size: cards shrink, the page never scrolls. */
        overflow: hidden;
        height: 100vh;
        height: 100dvh;
    }

    .stacked-container {
        height: 100vh;
        height: 100dvh;
        width: 100vw;
        display: flex;
        flex-direction: column;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        box-sizing: border-box;
    }

    .brand-section {
        flex: var(--flex-grow, 1) 1 auto;
        min-height: 0;
        padding: 0.45rem 0.5rem 0.5rem;
        border-bottom: 2px solid rgba(255, 255, 255, 0.08);
        display: flex;
        flex-direction: column;
    }

    .brand-section::before {
        height: 3px;
    }

    .brand-header {
        flex: 0 0 auto;
        flex-direction: column;
        align-items: center;
        gap: 0.15rem;
        margin-bottom: 0.4rem;
    }

    .brand-header h1 {
        font-size: calc(clamp(0.95rem, 4.4vw, 1.5rem) * var(--rows-scale, 1));
        letter-spacing: 2px;
        text-shadow: 0px 2px 10px var(--brand-accent);
    }

    .brand-header p {
        font-size: calc(clamp(0.55rem, 2.4vw, 0.7rem) * var(--rows-scale, 1));
        letter-spacing: 1px;
    }

    .queue-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(var(--rows, 4), minmax(0, 1fr));
        gap: calc(0.5rem * var(--rows-scale, 1));
        align-content: stretch;
        justify-content: stretch;
        flex: 1 1 auto;
        min-height: 0;
    }

    .unit-card {
        flex: none;
        width: auto;
        max-width: none;
        min-width: 0;
        min-height: 0;
        padding: calc(0.35rem * var(--rows-scale, 1));
        border-radius: 12px;
        gap: 0.1rem;
    }

    .unit-card::before {
        height: 3px;
    }

    /* Long model names wrap to two lines instead of truncating to nothing. */
    .unit-label {
        font-size: calc(clamp(0.55rem, 2.5vw, 0.8rem) * var(--rows-scale, 1));
        letter-spacing: 0.5px;
        line-height: 1.15;
        white-space: normal;
        overflow-wrap: anywhere;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .unit-number {
        font-size: calc(clamp(1.7rem, 8.5vw, 3rem) * var(--rows-scale, 1));
        text-shadow: 0 0 12px var(--brand-accent);
    }

    .unit-number-wrapper {
        min-height: 0;
    }

    .prefix {
        font-size: 0.62em;
        margin-right: 2px;
    }

    /* Touch-sized controls instead of the desktop fullscreen affordances. */
    #fs-prompt {
        bottom: max(12px, env(safe-area-inset-bottom));
        right: max(12px, env(safe-area-inset-right));
        padding: 12px 16px;
        font-size: 0.85rem;
    }

    #start-overlay h1 {
        font-size: clamp(1.5rem, 8vw, 2.2rem);
        margin-bottom: 0.75rem;
    }

    #start-overlay p {
        font-size: clamp(0.9rem, 4vw, 1.1rem);
        padding: 0 1.5rem;
    }
}

/* Landscape phone: three cards per row, same equal-slice rows. Touch only,
   for the same reason as the portrait block above. */
@media (max-width: 1024px) and (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
    .stacked-container {
        height: 100vh;
        height: 100dvh;
    }

    .brand-section {
        min-height: 0;
        padding: 0.35rem 0.5rem;
    }

    .brand-header {
        margin-bottom: 0.25rem;
    }

    .brand-header h1 {
        font-size: clamp(0.85rem, 2.4vh, 1.15rem);
        letter-spacing: 2px;
    }

    .queue-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: repeat(var(--rows-landscape, 2), minmax(0, 1fr));
        gap: 0.4rem;
        align-content: stretch;
        justify-content: stretch;
        flex: 1 1 auto;
        min-height: 0;
    }

    .unit-card {
        flex: none;
        width: auto;
        max-width: none;
        min-width: 0;
        min-height: 0;
        padding: 0.25rem;
        border-radius: 10px;
    }

    .unit-label {
        font-size: 0.7rem;
    }

    .unit-number {
        font-size: 2rem;
    }
}
/* -------------------------------------
 * NO LOCATION SELECTED
 * Shown by afRenderNoLocation() on a cloud viewer opened without an
 * instance id. Deliberately a dead end until the user supplies one.
 * ------------------------------------- */
.no-location {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem 1.25rem;
    text-align: center;
    font-family: 'Inter', sans-serif;
    box-sizing: border-box;
}

.no-location h2 {
    font-family: 'Syncopate', sans-serif;
    font-size: clamp(1.3rem, 5vw, 2rem);
    letter-spacing: 2px;
    color: var(--brand-accent, #EB0A1E);
}

.no-location p {
    max-width: 34rem;
    font-size: clamp(0.85rem, 3.4vw, 1rem);
    line-height: 1.5;
    color: var(--text-muted, #888);
}

.no-location-hint strong {
    color: var(--text-light, #fff);
}

.no-location-form {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    max-width: 30rem;
    margin-top: 0.25rem;
}

.no-location-form input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
    border-radius: 10px;
}

.no-location-form input:focus {
    outline: none;
    border-color: var(--brand-accent, #EB0A1E);
}

.no-location-form button {
    flex: 0 0 auto;
    padding: 0.85rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    color: #fff;
    background: var(--brand-accent, #EB0A1E);
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

.no-location-form button:hover {
    filter: brightness(1.15);
}

.no-location-err {
    color: #ff6b6b;
    font-size: 0.8rem;
}
