:root {
    --ink: #17142a;
    --muted: #6b6780;
    --line: #eceaf3;
    --paper: #ffffff;
    --wash: #f7f5fb;
    --dasha: #ff4f9a;
    --dasha-deep: #e11d74;
    --dasha-soft: #ffe0ee;
    --adam: #3b82f6;
    --adam-deep: #1d4ed8;
    --adam-soft: #dbeafe;
    --red: #ef4444;
    --red-soft: #fee2e2;
    --shadow: 0 18px 50px rgba(23, 20, 42, 0.08);
    --radius: 28px;
    --font: "Nunito", system-ui, sans-serif;
    --display: "Fraunces", Georgia, serif;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
}

h1,
h2,
h3 {
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: -0.03em;
}

button,
input {
    font: inherit;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Login */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #fff;
    overflow: hidden;
    position: relative;
}

.login-orb {
    position: absolute;
    width: 42vw;
    height: 42vw;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.22;
    pointer-events: none;
}

.login-orb-pink {
    background: #ff4f9a;
    top: -12vw;
    left: -10vw;
}

.login-orb-blue {
    background: #3b82f6;
    bottom: -14vw;
    right: -10vw;
}

.login-wrap {
    width: min(420px, calc(100% - 32px));
    position: relative;
    z-index: 1;
}

.login-card {
    background: #fff;
    border-radius: 32px;
    padding: 42px 36px 36px;
    text-align: center;
    box-shadow: 0 0 0 1px rgba(23, 20, 42, 0.04), var(--shadow);
}

.login-mark {
    display: grid;
    place-items: center;
    margin-bottom: 8px;
}

.login-kicker {
    margin: 0;
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 800;
}

.login-card h1 {
    margin: 8px 0 0;
    font-size: 34px;
}

.login-sub {
    margin: 6px 0 28px;
    color: var(--muted);
}

.login-error {
    background: var(--red-soft);
    color: #b91c1c;
    border-radius: 14px;
    padding: 10px 12px;
    margin: 0 0 16px;
    font-weight: 700;
}

.field {
    display: block;
    text-align: left;
    margin-bottom: 14px;
}

.field span {
    display: block;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 16px;
    padding: 14px 16px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
    border-color: #c4b5fd;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
}

.login-btn {
    width: 100%;
    margin-top: 8px;
    border: 0;
    border-radius: 999px;
    padding: 15px 18px;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.login-btn:hover {
    transform: translateY(-1px);
    background: #2a2544;
}

.login-btn:active {
    transform: translateY(0);
}

/* App */

.app-page {
    background:
        radial-gradient(900px 400px at 0% -10%, rgba(255, 79, 154, 0.12), transparent 50%),
        radial-gradient(900px 400px at 100% 0%, rgba(59, 130, 246, 0.12), transparent 50%),
        var(--wash);
    min-height: 100vh;
    min-height: 100svh;
}

.app {
    padding: 0 0 48px;
}

.logout {
    position: fixed;
    top: 8px;
    right: 12px;
    z-index: 20;
    color: var(--muted);
    text-decoration: none;
    font-weight: 700;
    font-size: clamp(11px, 1.6vh, 14px);
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(8px);
}

.logout:hover {
    color: var(--ink);
}

.arena {
    height: 100vh;
    height: 100svh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 5px 0 8px;
    min-height: 0;
}

.weighin-card,
.log-wrap {
    width: min(720px, calc(100% - 24px));
    margin-left: auto;
    margin-right: auto;
}

.log-wrap {
    width: min(1100px, calc(100% - 24px));
    margin-top: 18px;
    margin-bottom: 18px;
}

.weighin-card {
    width: min(1080px, calc(100% - 24px));
    flex: 0 0 auto;
    margin: 0 auto 8px;
    background: var(--paper);
    border-radius: 18px;
    padding: clamp(8px, 1.2vh, 12px) 16px clamp(6px, 1vh, 10px);
    box-shadow: var(--shadow);
    text-align: center;
}

.weighin-form {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.weighin-card h1 {
    margin: 0;
    padding: 0;
    font-size: clamp(14px, 2vh, 20px);
    line-height: 1.15;
    white-space: nowrap;
    flex: 0 1 auto;
}

.weight-box input {
    width: clamp(84px, 14vw, 120px);
    text-align: center;
    font-size: clamp(16px, 2.4vh, 24px);
    font-weight: 800;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: clamp(4px, 0.7vh, 7px) 8px;
    outline: none;
}

.weight-box input::placeholder {
    color: #c3bfd0;
    font-weight: 800;
}

.weight-box input:focus {
    border-color: #c4b5fd;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
}

.units {
    border: 0;
    margin: 0;
    padding: 3px;
    display: flex;
    background: var(--wash);
    border-radius: 999px;
    gap: 2px;
    flex: 0 0 auto;
}

.unit {
    cursor: pointer;
}

.unit input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.unit span {
    display: block;
    min-width: 42px;
    text-align: center;
    padding: clamp(4px, 0.7vh, 7px) 10px;
    border-radius: 999px;
    font-weight: 800;
    font-size: clamp(12px, 1.5vh, 14px);
    color: var(--muted);
}

.unit input:checked + span {
    background: var(--ink);
    color: #fff;
}

.send-btn {
    border: 0;
    border-radius: 999px;
    padding: clamp(5px, 0.9vh, 9px) 14px;
    background: linear-gradient(90deg, var(--dasha), var(--adam));
    color: #fff;
    font-weight: 800;
    font-size: clamp(12px, 1.6vh, 14px);
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 8px 18px rgba(59, 130, 246, 0.22);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.send-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.send-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.weighin-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-weight: 700;
    font-size: clamp(11px, 1.4vh, 13px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 1.2em;
}

.weighin-hint.ok {
    color: #047857;
}

.weighin-hint.bad {
    color: #b91c1c;
}

/* Races */

.races {
    flex: 1 1 auto;
    min-height: 0;
    width: 80vw;
    max-width: calc(100% - 16px);
    margin: 0 auto;
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: clamp(8px, 1.4vh, 16px);
}

.racer {
    --pic: clamp(72px, 12vh, 108px);
    --bar: clamp(28px, 4.4vh, 42px);
    --flag: clamp(52px, 8vh, 72px);
    width: 100%;
    min-height: 0;
    margin: 0;
    background: var(--paper);
    border-radius: 22px;
    padding: clamp(10px, 1.6vh, 18px) clamp(14px, 1.8vw, 22px) clamp(10px, 1.4vh, 16px);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.racer.dasha {
    --team: var(--dasha);
    --team-deep: var(--dasha-deep);
    --team-soft: var(--dasha-soft);
}

.racer.adam {
    --team: var(--adam);
    --team-deep: var(--adam-deep);
    --team-soft: var(--adam-soft);
}

.racer-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 4px;
    flex: 0 0 auto;
}

.racer-head h2 {
    margin: 0;
    font-size: clamp(22px, 3.4vh, 32px);
}

.racer-meta {
    color: var(--muted);
    font-weight: 700;
    text-align: right;
    font-size: clamp(14px, 2vh, 18px);
}

.track {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.avatar-lane {
    position: relative;
    height: calc(var(--pic) + 14px);
    flex: 0 0 auto;
}

.avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--pic);
    transform: translateX(-50%);
    display: grid;
    justify-items: center;
    transition: left 1.15s cubic-bezier(0.22, 1.15, 0.36, 1);
    z-index: 3;
}

.avatar.intro {
    transition-duration: 1.6s;
}

.avatar.bounce .pic {
    animation: pop 0.7s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.pic {
    width: var(--pic);
    height: var(--pic);
    border-radius: 50%;
    object-fit: cover;
    object-position: 50% 30%;
    border: 4px solid #fff;
    box-shadow: 0 0 0 3px var(--team), 0 10px 20px rgba(23, 20, 42, 0.18);
    background: var(--team-soft);
}

.racer.dasha .pic {
    object-position: 52% 32%;
}

.stem {
    width: 3px;
    height: 10px;
    background: var(--team);
    margin-top: -2px;
}

.bar-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex: 0 0 auto;
}

.bar-col {
    flex: 1;
    min-width: 0;
}

.bar {
    position: relative;
    height: var(--bar);
    background: #eef1f6;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(23, 20, 42, 0.08);
}

.bar-ticks {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

.bar-tick {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    margin-left: -1px;
    background: rgba(23, 20, 42, 0.16);
}

.fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 999px;
    transition: width 1.15s cubic-bezier(0.22, 1.15, 0.36, 1), left 1.15s cubic-bezier(0.22, 1.15, 0.36, 1);
}

.fill.best {
    background: linear-gradient(90deg, var(--team), var(--team-deep));
    z-index: 1;
}

.fill.setback {
    background: repeating-linear-gradient(
        135deg,
        #ef4444 0 10px,
        #f87171 10px 20px
    );
    z-index: 2;
    box-shadow: inset 0 0 0 1px rgba(127, 29, 29, 0.15);
}

.flag {
    flex: 0 0 auto;
    width: var(--flag);
    height: var(--flag);
    display: grid;
    place-items: center;
    filter: drop-shadow(0 8px 10px rgba(23, 20, 42, 0.15));
    margin-top: calc((var(--bar) - var(--flag)) / 2);
}

.flag svg {
    width: 100%;
    height: 100%;
    transform-origin: 8px 48px;
    animation: wave 1.6s ease-in-out infinite;
}

.goal-hit .flag svg {
    animation: celebrate-flag 0.7s ease-in-out infinite;
}

.milestones {
    position: relative;
    height: clamp(38px, 5.6vh, 48px);
    margin-top: 1px;
}

.milestone {
    position: absolute;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateX(-50%);
    pointer-events: none;
}

.milestone.is-start {
    transform: translateX(0);
    align-items: flex-start;
}

.milestone.is-end {
    transform: translateX(-100%);
    align-items: flex-end;
}

.tick {
    display: block;
    width: 2px;
    height: 8px;
    background: #b4b1c3;
    border-radius: 1px;
}

.milestone.is-10 .tick {
    height: 10px;
    background: #8b879a;
}

.milestone.is-start .tick,
.milestone.is-end .tick {
    height: 12px;
    background: var(--ink);
}

.milestone-label {
    margin-top: 3px;
    font-size: clamp(9px, 1.25vh, 11px);
    font-weight: 800;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1;
}

.milestone-pct {
    margin-top: 2px;
    font-size: clamp(8px, 1.1vh, 10px);
    font-weight: 800;
    color: #9a96a8;
    line-height: 1;
}

.milestone.is-start .milestone-label,
.milestone.is-end .milestone-label {
    color: var(--ink);
}

.milestone.is-start .milestone-pct,
.milestone.is-end .milestone-pct {
    color: var(--ink);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 10px;
}

.chip {
    background: var(--team-soft);
    color: var(--team-deep);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: clamp(13px, 1.8vh, 16px);
    font-weight: 800;
    white-space: nowrap;
}

.chip.red {
    background: var(--red-soft);
    color: #b91c1c;
}

.chip.gold {
    background: #fef3c7;
    color: #b45309;
}

/* Board + log */

.board {
    width: 80vw;
    max-width: calc(100% - 16px);
    margin: 18px auto 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat-card {
    background: var(--paper);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow);
    container-type: inline-size;
}

.stat-card h3 {
    margin: 0 0 6px;
    font-size: 20px;
}

.stat-card.dasha h3 { color: var(--dasha-deep); }
.stat-card.adam h3 { color: var(--adam-deep); }

.prediction {
    font-family: var(--display);
    font-size: clamp(11px, 3.6cqi, 30px);
    margin: 8px 0 10px;
    line-height: 1.25;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
}

.stat-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-grid strong {
    font-size: 18px;
}

.log-wrap h2 {
    margin: 0 0 12px;
}

.log {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.log-col {
    background: var(--paper);
    border-radius: 20px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.log-col h3 {
    margin: 0 0 8px;
}

.log-start {
    margin: 0 0 12px;
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
}

.log-start strong {
    color: var(--ink);
}

.start-row td {
    font-weight: 800;
}

.log-col table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.log-col th,
.log-col td {
    text-align: left;
    padding: 8px 6px 8px 0;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.log-col th:nth-child(n+2),
.log-col td:nth-child(n+2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.log-col th:last-child,
.log-col td:last-child {
    text-align: right;
    width: 40px;
    padding-right: 0;
}

.delete-entry {
    border: 0;
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 8px;
}

.delete-entry:hover,
.delete-entry:focus {
    color: #fff;
    background: #ef4444;
}

.delete-entry:disabled {
    opacity: 0.4;
    cursor: wait;
}

.log-col th {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.empty {
    color: var(--muted);
    font-weight: 600;
}

.confetti-layer {
    pointer-events: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 50;
}

.confetti-bit {
    position: absolute;
    top: -12px;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    animation: fall linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(110vh) rotate(540deg);
        opacity: 0.2;
    }
}

@keyframes wave {
    0%, 100% { transform: rotate(-8deg); }
    50% { transform: rotate(10deg); }
}

@keyframes celebrate-flag {
    0%, 100% { transform: rotate(-18deg) scale(1.05); }
    50% { transform: rotate(16deg) scale(1.12); }
}

@keyframes pop {
    0% { transform: scale(1); }
    35% { transform: scale(1.12) translateY(-6px); }
    100% { transform: scale(1); }
}

@media (max-width: 1100px) {
    .milestone:not(.is-10) .milestone-label,
    .milestone:not(.is-10) .milestone-pct {
        visibility: hidden;
    }
}

@media (max-width: 720px) {
    .milestone:not(.is-25) .milestone-label,
    .milestone:not(.is-25) .milestone-pct {
        visibility: hidden;
    }
}

@media (max-width: 800px) {
    .races,
    .board {
        width: calc(100% - 16px);
    }

    .board,
    .log {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .weighin-form {
        gap: 6px;
    }

    .send-btn {
        padding-left: 10px;
        padding-right: 10px;
    }
}
