/* LapViz Stopwatch, web. The tile and lap colours come from Core's ColorScheme, inline. */

:root {
    --accent: #FF6600;
    --bar-bg: #000;
    --bar-fg: #fff;
    --bg: #fff;
    --fg: #1C1B1F;
    --muted: #6E6E6E;
    --card: #F0F0F0;
    --line: #C8C8C8;
    --input-bg: #fff;
    --danger: #D32F2F;
    --go: #2E7D32;
    --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000;
        --fg: #E6E1E5;
        --muted: #ACACAC;
        --card: #212121;
        --line: #404040;
        --input-bg: #141414;
        color-scheme: dark;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

a {
    color: inherit;
}

h1, h2, h3 {
    margin: 0;
}

.page {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.center {
    text-align: center;
}

.empty {
    font-size: 1.5rem;
    text-align: center;
    margin: 20px 16px 40px;
}

.mono-small, .mono-large {
    font-family: var(--mono);
    font-weight: bold;
}

.mono-small {
    font-size: clamp(18px, 5.5vw, 25px);
}

.mono-large {
    font-size: clamp(22px, 7.5vw, 33px);
}

/* === Bar === */

.bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    padding: 6px 12px;
    padding-top: max(6px, env(safe-area-inset-top));
    background: var(--bar-bg);
    color: var(--bar-fg);
}

.bar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
    color: var(--accent);
    font-size: 20px;
    font-weight: bold;
    text-decoration: none;
}

.bar-back {
    font-size: 24px;
    text-decoration: none;
    padding: 0 8px 0 0;
}

.bar-title {
    font-size: 20px;
}

.queue {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
}

.connection {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 13px;
    color: #fff;
    text-decoration: none;
    background: #D32F2F;
}

.connection-connected {
    background: #2E7D32;
}

.connection-connecting, .connection-reconnecting {
    background: #FFC107;
    color: #000;
}

/* === Buttons and forms === */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 8px 16px;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-size: 18px;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.btn:disabled {
    opacity: .45;
    cursor: default;
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-plain {
    background: var(--card);
    color: var(--fg);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-go {
    background: var(--go);
    color: #fff;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 20px;
    font-weight: bold;
}

.form label.check {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

input:not([type=checkbox]), select {
    min-height: 48px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--fg);
    font: inherit;
    font-size: 20px;
    font-weight: normal;
    width: 100%;
}

input[type=checkbox] {
    width: 24px;
    height: 24px;
    accent-color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

/* === Main page === */

.home {
    flex: 1;
    padding-bottom: 8px;
}

.tile {
    display: block;
    padding: 10px;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.tile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    font-family: var(--mono);
    font-weight: bold;
    white-space: nowrap;
}

.tile-name, .tile-timer {
    font-size: clamp(18px, 5.5vw, 25px);
}

.tile-left, .tile-right {
    font-size: clamp(22px, 7.5vw, 33px);
    text-align: right;
}

.tile-name {
    grid-row: 1;
    grid-column: 1;
    overflow: hidden;
}

.tile-name-long {
    display: none;
}

.tile-timer {
    grid-row: 1;
    grid-column: 2;
    text-align: right;
}

.tile-left {
    grid-row: 2;
    grid-column: 1;
}

.tile-right {
    grid-row: 2;
    grid-column: 2;
}

.tile-progress {
    height: 10px;
    margin-top: 4px;
}

.tile-progress > div {
    height: 100%;
}

/* Landscape: one row per racer, like the phone app's landscape template. */
@media (orientation: landscape) and (min-width: 600px) {
    .tile-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .tile-name-short {
        display: none;
    }

    .tile-name-long {
        display: block;
        grid-column: 1 / 3;
    }

    .tile-timer {
        grid-column: 2;
    }

    .tile-left {
        grid-row: 1;
        grid-column: 3;
    }

    .tile-right {
        grid-row: 1;
        grid-column: 4;
    }

    .tile-left, .tile-right {
        font-size: 33px;
    }
}

.settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px;
}

.settings label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    font-weight: bold;
}

.actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 3px 8px 8px;
}

.press-buttons {
    position: sticky;
    bottom: 0;
    display: grid;
    gap: 3px;
    padding: 5px;
    padding-bottom: max(5px, env(safe-area-inset-bottom));
    background: var(--bg);
}

.press-buttons .btn {
    height: 60px;
}

.press-buttons .btn:active {
    filter: brightness(.85);
}

.press-buttons-grid {
    grid-template-columns: 1fr 1fr;
}

.press-buttons-grid .btn {
    font-size: 24px;
}

.press-buttons-row {
    grid-template-columns: repeat(4, 1fr);
}

.press-buttons-row .btn {
    font-size: 16px;
    padding: 4px;
}

/* === Racer page === */

.laps-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
}

.laps-header h2 {
    font-size: 22px;
}

.lap-columns, .lap-row {
    display: grid;
    grid-template-columns: 2.5em 1fr 1fr auto;
    align-items: center;
    text-align: right;
    gap: 8px;
}

.lap-columns {
    padding: 0 10px 6px;
}

.lap-columns::after {
    content: "";
    width: 36px;
}

.lap {
    padding: 10px;
    border-bottom: 2px solid gray;
}

.lap-delete {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 6px;
    background: rgba(0, 0, 0, .25);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

.sectors {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.sector {
    padding: 2px 6px;
    font-family: var(--mono);
    font-size: 16px;
    font-weight: bold;
}

.session-fastest {
    background: gray;
    color: #fff;
    text-align: center;
}

.session-fastest .lap-row {
    padding: 4px 10px;
}

.session-fastest .lap-row::before {
    content: "";
}

.lap-number {
    text-align: left;
    font-size: 18px;
}

.deleted-laps {
    padding: 10px;
}

.deleted-laps h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.deleted-lap {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    font-family: var(--mono);
    font-size: 18px;
    opacity: .6;
}

.deleted-lap .time {
    text-align: right;
    text-decoration: line-through;
}

.tile-progress-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.tile-laps {
    font-family: var(--mono);
    font-size: 14px;
    white-space: nowrap;
}

.tile-progress-row .tile-progress {
    flex: 1;
    margin-top: 0;
}

.session-fastest .lap-row::after {
    content: "";
    width: 36px;
}

.theoretical {
    font-size: 18px;
}

/* === Sharing and About === */

.sharing, .about {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 16px 24px;
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
    font-size: 17px;
}

.sharing h2 {
    font-size: 26px;
    margin-top: 6px;
}

.card {
    border: 1px solid var(--line);
    border-radius: 8px;
}

.card h3 {
    font-size: 24px;
}

.busy-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.about .version {
    font-size: 23px;
    margin-bottom: 0;
}

.about .note {
    color: var(--muted);
    font-style: italic;
}

/* === Toasts and dialogs === */

.toasts {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.toast {
    max-width: calc(100% - 32px);
    padding: 10px 16px;
    border-radius: 20px;
    background: rgba(40, 40, 40, .92);
    color: #fff;
    font-size: 15px;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(0, 0, 0, .5);
}

.dialog {
    width: 100%;
    max-width: 400px;
    padding: 20px;
    border-radius: 10px;
    background: var(--bg);
    color: var(--fg);
}

.dialog h2 {
    font-size: 20px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* === Blazor === */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #000;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--line);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
