/* =========================================================
   CRICKET DRS
   Desktop + dedicated mobile layout
========================================================= */

* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;

    --bg: #070a0f;
    --surface: #0d121a;
    --surface-2: #141b26;
    --surface-3: #1b2431;

    --text: #ffffff;
    --muted: #91a0b5;

    --blue: #2588ff;
    --blue-hover: #479cff;

    --green: #0f9651;
    --red: #e72e36;

    --border: rgba(255, 255, 255, 0.12);
}

html,
body {
    margin: 0;
    padding: 0;

    width: 100%;
    min-height: 100%;

    background: var(--bg);
    color: var(--text);

    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

body {
    overflow-x: hidden;
}

button,
input {
    font: inherit;
}

button {
    color: inherit;
}

/* =========================================================
   APP
========================================================= */

.app {
    width: min(1000px, calc(100% - 30px));

    margin: 0 auto;

    padding: 16px 0 24px;
}

/* =========================================================
   HEADER
========================================================= */

.app-header {
    display: flex;

    align-items: baseline;

    gap: 9px;

    margin-bottom: 7px;
}

.title {
    margin: 0;

    font-size: 23px;
    font-weight: 900;

    letter-spacing: -0.6px;
}

.subtitle {
    color: var(--muted);

    font-size: 10px;
    font-weight: 800;

    letter-spacing: 1px;

    text-transform: uppercase;
}

/* =========================================================
   PROGRESS
========================================================= */

.progress {
    display: flex;

    width: 100%;

    gap: 4px;

    margin: 7px 0 15px;
}

.dot {
    flex: 1;

    height: 4px;

    border-radius: 100px;

    background: rgba(255, 255, 255, 0.10);
}

.dot.active {
    background: var(--blue);
}

/* =========================================================
   STEPS
========================================================= */

.step {
    display: none;

    width: 100%;

    min-height: 0;
    height: auto;
}

.step.active {
    display: block;

    min-height: 0;
    height: auto;
}

.step h1 {
    margin: 0 0 3px;

    font-size: clamp(22px, 4vw, 32px);
    font-weight: 900;

    letter-spacing: -0.7px;
}

.step > p {
    max-width: 700px;

    margin: 0 0 10px;

    color: var(--muted);

    font-size: 12px;

    line-height: 1.35;
}

/* =========================================================
   BUTTONS
========================================================= */

button,
.upload-button {
    min-height: 40px;

    padding: 8px 13px;

    border: 1px solid var(--border);

    border-radius: 8px;

    background: var(--surface-2);
    color: white;

    font-weight: 800;

    cursor: pointer;

    transition:
        background 120ms ease,
        transform 80ms ease;
}

button:hover:not(:disabled) {
    background: var(--surface-3);
}

button:active:not(:disabled) {
    transform: scale(0.985);
}

button:disabled {
    opacity: 0.38;

    cursor: default;
}

.primary,
.upload-button {
    background: var(--blue);

    border-color: transparent;
}

.primary:hover:not(:disabled),
.upload-button:hover {
    background: var(--blue-hover);
}

.primary {
    display: block;

    min-width: 130px;

    margin-top: 9px;
}

.upload-button {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    margin-bottom: 8px;
}

/* =========================================================
   SELECTION SCREENS
========================================================= */

.segments,
.decision-buttons {
    display: flex;

    flex-wrap: wrap;

    gap: 7px;
}

.segments button.selected {
    background: var(--blue);

    border-color: var(--blue);
}

.decision-buttons button {
    min-width: 145px;

    min-height: 46px;
}

#customPitchBox {
    margin-top: 8px;
}

#customPitch {
    width: min(100%, 280px);

    padding: 9px 11px;

    border: 1px solid var(--border);

    border-radius: 8px;

    outline: none;

    background: var(--surface);

    color: white;
}

.hidden {
    display: none !important;
}

/* =========================================================
   PREVIEW VIDEO
========================================================= */

#previewVideo {
    display: block;

    width: min(100%, 820px);

    max-height: 480px;

    object-fit: contain;

    border-radius: 9px;

    background: black;
}

/* =========================================================
   VIDEO STAGES
========================================================= */

.video-stage,
.drs-stage {
    position: relative;

    width: min(100%, 900px);

    aspect-ratio: 16 / 9;

    overflow: hidden;

    margin: 0;

    border: 1px solid var(--border);

    border-radius: 9px;

    background: black;
}

.video-stage video,
.drs-stage video {
    position: absolute;

    inset: 0;

    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;

    background: black;
}

.marker-stage {
    cursor: crosshair;

    touch-action: none;
}

/* =========================================================
   FRAME CONTROLS
========================================================= */

.frame-controls {
    display: grid;

    grid-template-columns:
        minmax(100px, 1fr)
        80px
        minmax(100px, 1fr);

    align-items: center;

    width: min(100%, 520px);

    gap: 7px;

    margin-top: 6px;
}

.frame-controls button {
    min-height: 36px;

    padding: 6px 9px;
}

.frame-time {
    color: var(--muted);

    text-align: center;

    font-size: 11px;

    font-variant-numeric: tabular-nums;
}

/* =========================================================
   STUMP SIZE CONTROLS
========================================================= */

.stump-controls {
    display: grid;

    grid-template-columns: 1fr 1fr;

    width: min(100%, 600px);

    gap: 10px;

    margin-top: 6px;

    padding: 7px 9px;

    border: 1px solid var(--border);

    border-radius: 8px;

    background: var(--surface);
}

.slider-header {
    display: flex;

    align-items: center;
    justify-content: space-between;

    margin-bottom: 2px;

    color: var(--muted);

    font-size: 10px;
    font-weight: 750;
}

.stump-control input {
    display: block;

    width: 100%;
}

/* =========================================================
   VIRTUAL WICKET
========================================================= */

.virtual-wicket {
    position: absolute;

    z-index: 8;

    transform: translate(-50%, -50%);

    opacity: 0.75;

    cursor: grab;

    touch-action: none;

    user-select: none;
}

.virtual-wicket:active {
    cursor: grabbing;
}

.virtual-stump {
    position: absolute;

    top: 6%;

    width: 12%;
    height: 94%;

    border-radius:
        999px
        999px
        3px
        3px;

    background:
        linear-gradient(
            90deg,
            #8d949b 0%,
            #e9edf0 30%,
            #ffffff 48%,
            #d4d8dc 70%,
            #858c93 100%
        );

    box-shadow:
        0 0 3px rgba(255, 255, 255, 0.45);
}

.stump-left {
    left: 0;
}

.stump-middle {
    left: 50%;

    transform: translateX(-50%);
}

.stump-right {
    right: 0;
}

.virtual-bail {
    position: absolute;

    top: 1%;

    height: 7%;

    border-radius: 999px;

    background:
        linear-gradient(
            180deg,
            white,
            #aab0b6
        );
}

.bail-left {
    left: 3%;

    width: 48%;
}

.bail-right {
    right: 3%;

    width: 48%;
}

/*
   No OFF / MIDDLE / LEG labels.
*/

.virtual-stump-label,
.stump-label {
    display: none !important;
}

/* =========================================================
   BALL MARKER
========================================================= */

.ball-marker {
    position: absolute;

    z-index: 20;

    width: 15px;
    height: 15px;

    transform: translate(-50%, -50%);

    border: 2px solid white;

    border-radius: 50%;

    background: rgba(255, 255, 255, 0.18);

    box-shadow:
        0 0 0 3px rgba(0, 0, 0, 0.45);

    pointer-events: none;
}

/* =========================================================
   REVIEW
========================================================= */

#reviewVideo {
    z-index: 1;
}

#reviewStumps {
    z-index: 4;

    opacity: 0.5;

    pointer-events: none;
}

#reviewCanvas {
    position: absolute;

    inset: 0;

    z-index: 6;

    display: block;

    width: 100%;
    height: 100%;

    pointer-events: none;
}

/* =========================================================
   BROADCAST PANEL
========================================================= */

.broadcast-panel {
    position: absolute;

    top: 8px;
    left: 8px;

    z-index: 20;

    text-align: left;

    pointer-events: none;
}

.drs-logo {
    display: inline-flex;

    align-items: center;

    padding: 5px 9px;

    border-left: 3px solid var(--blue);

    background: rgba(0, 0, 0, 0.92);

    font-size: 13px;
    font-weight: 950;

    letter-spacing: 0.7px;
}

.drs-rows {
    display: flex;

    flex-direction: column;

    gap: 2px;

    margin-top: 4px;
}

.drs-row {
    display: grid;

    grid-template-columns:
        76px
        minmax(90px, auto);

    overflow: hidden;

    border-radius: 2px;
}

.drs-row-label,
.drs-row-value {
    display: flex;

    align-items: center;

    min-height: 27px;

    padding: 4px 7px;

    font-size: 9px;
    font-weight: 950;
}

.drs-row-label {
    background: rgba(0, 0, 0, 0.92);
}

.drs-row-value {
    justify-content: center;

    background: #303844;

    text-align: center;
}

.drs-row-value.good {
    background: var(--green);
}

.drs-row-value.bad {
    background: #c7222b;
}

/* =========================================================
   FINAL DECISION
========================================================= */

.review-decision {
    width: min(100%, 900px);

    margin-top: 6px;

    text-align: center;
}

.decision-caption {
    color: var(--muted);

    font-size: 9px;
    font-weight: 900;

    letter-spacing: 1px;
}

.decision-result {
    margin-top: 1px;

    font-size: clamp(34px, 7vw, 56px);
    font-weight: 1000;

    line-height: 0.95;
}

.decision-result.out {
    color: #ff4149;
}

.decision-result.not-out {
    color: #32d878;
}

.decision-reason {
    margin-top: 3px;

    color: var(--muted);

    font-size: 11px;
}

/* =========================================================
   MOBILE
   Deliberately different from desktop.
========================================================= */

@media (max-width: 650px) {

    html,
    body {
        width: 100%;

        min-height: 100%;
        height: auto;
    }

    body {
        min-height: 100dvh;
    }

    /*
       The app ends when its content ends.
       No giant black basement.
    */

    .app {
        width: 100%;

        min-height: 0;
        height: auto;

        margin: 0;

        padding:
            5px
            7px
            8px;

        text-align: center;
    }

    /* HEADER */

    .app-header {
        justify-content: center;

        align-items: center;

        height: 22px;

        margin: 0;
    }

    .title {
        font-size: 14px;

        letter-spacing: -0.2px;
    }

    .subtitle {
        display: none;
    }

    /* PROGRESS */

    .progress {
        width: min(68%, 285px);

        gap: 2px;

        margin:
            1px auto
            5px;
    }

    .dot {
        height: 3px;
    }

    /* STEP */

    .step,
    .step.active {
        width: 100%;

        min-height: 0 !important;
        height: auto !important;
    }

    .step.active {
        display: flex;

        flex-direction: column;

        align-items: center;
        justify-content: flex-start;
    }

    .step h1 {
        margin: 0 0 2px;

        font-size: 17px;

        line-height: 1.08;

        text-align: center;
    }

    .step > p {
        width: min(94%, 430px);

        margin:
            0 auto
            5px;

        font-size: 9px;

        line-height: 1.2;

        text-align: center;
    }

    /* VIDEO DOMINATES */

    .video-stage,
    .drs-stage {
        flex: none;

        width: 100%;

        max-width: none;

        aspect-ratio: 16 / 9;

        margin: 0 auto;

        border-radius: 7px;
    }

    #previewVideo {
        width: 100%;

        max-width: none;

        max-height: 57dvh;

        margin: 0 auto;

        border-radius: 7px;
    }

    /* UPLOAD */

    .upload-button {
        display: flex;

        width: min(94%, 390px);

        min-height: 38px;

        margin:
            2px auto
            6px;

        font-size: 11px;
    }

    /* CHOICE SCREENS */

    .segments,
    .decision-buttons {
        justify-content: center;

        width: min(96%, 440px);

        margin: 3px auto;

        gap: 5px;
    }

    .segments button {
        flex: 1 1 60px;

        min-width: 0;
        min-height: 39px;

        padding: 5px;

        font-size: 10px;
    }

    .decision-buttons button {
        flex: 1 1 120px;

        min-width: 0;
        min-height: 43px;

        padding: 5px;

        font-size: 11px;
    }

    #customPitchBox {
        width: 100%;

        margin-top: 4px;
    }

    #customPitch {
        width: min(90%, 280px);

        text-align: center;
    }

    /* FRAME CONTROLS */

    .frame-controls {
        grid-template-columns:
            minmax(78px, 1fr)
            58px
            minmax(78px, 1fr);

        width: min(96%, 440px);

        gap: 4px;

        margin:
            4px auto
            0;
    }

    .frame-controls button {
        min-height: 32px;

        padding: 4px 5px;

        font-size: 9px;
    }

    .frame-time {
        font-size: 8px;
    }

    /* CALIBRATION CONTROLS */

    .stump-controls {
        grid-template-columns:
            1fr
            1fr;

        width: min(96%, 440px);

        gap: 7px;

        margin:
            4px auto
            0;

        padding: 5px 7px;

        border-radius: 7px;
    }

    .slider-header {
        margin-bottom: 0;

        font-size: 8px;
    }

    .stump-control input {
        height: 16px;
    }

    /* NEXT */

    .primary {
        width: min(96%, 440px);

        min-height: 36px;

        margin:
            5px auto
            0;

        padding: 5px 9px;

        border-radius: 7px;

        font-size: 10px;
    }

    /* REVIEW PANEL */

    .broadcast-panel {
        top: 4px;
        left: 4px;
    }

    .drs-logo {
        padding:
            3px
            5px;

        border-left-width: 2px;

        font-size: 9px;
    }

    .drs-rows {
        gap: 1px;

        margin-top: 2px;
    }

    .drs-row {
        grid-template-columns:
            53px
            minmax(62px, auto);
    }

    .drs-row-label,
    .drs-row-value {
        min-height: 19px;

        padding: 2px 3px;

        font-size: 6.5px;
    }

    /* FINAL */

    .review-decision {
        flex: none;

        width: 100%;

        margin:
            4px auto
            0;
    }

    .decision-caption {
        font-size: 7px;
    }

    .decision-result {
        margin: 0;

        font-size: 29px;

        line-height: 0.95;
    }

    .decision-reason {
        margin-top: 2px;

        font-size: 8px;
    }

    /*
       Kill the huge bottom area.
    */

    #step5,
    #step6,
    #step7,
    #step8,
    #step9 {
        min-height: 0 !important;

        height: auto !important;

        padding-bottom: 6px;
    }
}

/* =========================================================
   VERY NARROW PHONES
========================================================= */

@media (max-width: 390px) {

    .app {
        padding-left: 5px;
        padding-right: 5px;
    }

    .title {
        font-size: 13px;
    }

    .step h1 {
        font-size: 16px;
    }

    .frame-controls {
        grid-template-columns:
            1fr
            54px
            1fr;
    }

    .stump-controls {
        gap: 5px;

        padding: 4px 5px;
    }
}

/* =========================================================
   PHONE LANDSCAPE
========================================================= */

@media (max-height: 600px) and (max-width: 950px) {

    .app {
        padding-top: 2px;
    }

    .app-header {
        height: 18px;
    }

    .title {
        font-size: 12px;
    }

    .progress {
        width: 52%;

        margin:
            1px auto
            3px;
    }

    .step h1 {
        font-size: 14px;
    }

    .step > p {
        display: none;
    }

    .video-stage,
    .drs-stage {
        width: min(78vw, 700px);

        max-height: 66dvh;
    }

    .frame-controls,
    .stump-controls,
    .primary {
        margin-top: 3px;
    }
}