:root {
    color-scheme: light;
    --bg: #f7f7f8;
    --surface: #ffffff;
    --ink: #06050C;
    --text: #06050C;
    --muted: #625d6b;
    --border: #e5deef;
    --accent: #692CFE;
    --accent-soft: #f1ebff;
    --accent-ink: #ffffff;
    --accent-shadow: rgba(105, 44, 254, 0.24);
    --panel-shadow: 0 24px 70px rgba(6, 5, 12, 0.13);
    --bad: #c83838;
    --critical: #d97706;
    --try: #b98900;
    --good: var(--accent);
    --result-color: var(--accent);
    --result-soft: var(--accent-soft);
}

body[data-sport-theme="fitness"] {
    --accent: #E336CF;
    --accent-soft: #fdeafd;
    --accent-ink: #ffffff;
    --accent-shadow: rgba(227, 54, 207, 0.24);
    --border: #eed9ee;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 22% 0%, var(--accent-soft), transparent 27rem),
        radial-gradient(circle at 88% 12%, rgba(105, 44, 254, 0.08), transparent 22rem),
        linear-gradient(135deg, #ffffff 0%, #f2f2f4 100%);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
    transition: background 220ms ease;
}

button,
input,
select {
    font: inherit;
}

.widget {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 18px 24px;
}

.hero {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    gap: 18px;
    margin: 0 0 22px;
}

.logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 18px 42px rgba(6, 5, 12, 0.12);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    max-width: 980px;
    margin-bottom: 6px;
    font-size: clamp(32px, 4vw, 48px);
    line-height: 1.04;
    letter-spacing: 0;
}

.hero-copy {
    max-width: 620px;
    min-height: 32px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 17px;
    overflow: hidden;
}

.hero-word {
    display: inline-block;
    transform-origin: 50% 80%;
    animation: heroWordBuild 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.hero-copy.is-exiting .hero-word {
    animation: heroWordExit 320ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

h2 {
    margin-bottom: 8px;
    font-size: 28px;
    line-height: 1.15;
}

.panel {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: var(--panel-shadow);
    padding: 24px;
}

.panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 7px;
    background: linear-gradient(90deg, #692CFE, #E336CF);
}

.field-group {
    border: 0;
    padding: 0;
    margin: 0;
}

legend,
.field > span {
    display: block;
    margin-bottom: 12px;
    font-weight: 900;
}

.sport-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
}

.sport-cards label {
    display: flex;
    cursor: pointer;
}

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

.sport-cards span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 74px;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: 20px;
    background: #fff;
    color: var(--text);
    transition: border 180ms ease, background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.sport-cards strong {
    font-size: 17px;
    line-height: 1.2;
    text-align: center;
}

.sport-cards small {
    display: none;
}

.sport-cards input:checked + span {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--accent-soft), #fff 72%);
    box-shadow: 0 16px 34px var(--accent-shadow);
}

.discipline-field {
    display: grid;
    gap: 10px;
    margin-top: 2px;
}

.discipline-field > span {
    font-weight: 900;
}

.discipline-field select {
    width: 100%;
    min-height: 54px;
    padding: 12px 46px 12px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background:
        linear-gradient(45deg, transparent 50%, var(--accent) 50%) right 18px center / 7px 7px no-repeat,
        linear-gradient(135deg, #fff, var(--accent-soft) 140%);
    color: var(--text);
    font-weight: 800;
    appearance: none;
}

.sport-cards input:focus-visible + span,
button:focus-visible,
input:focus-visible,
select:focus-visible,
.upload:focus-within {
    outline: 3px solid var(--accent-shadow);
    outline-offset: 3px;
}

.form-grid {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.1fr);
    gap: 18px;
    align-items: stretch;
}

.left-column,
.right-column {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.right-column {
    grid-template-rows: auto minmax(0, 1fr);
}

.field {
    display: block;
}

.field input {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    background: #fff;
}

.tempo-card {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: #fbfbfc;
}

.bpm-picker {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) 58px;
    align-items: center;
    gap: 10px;
}

.bpm-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    min-height: 58px;
    border: 1px solid color-mix(in srgb, var(--accent), #ffffff 24%);
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent), #06050C 14%));
    color: #fff;
    box-shadow: 0 12px 24px var(--accent-shadow);
    font-size: 34px;
    line-height: 1;
    padding: 0 0 4px;
}

.bpm-display {
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 58px;
    min-height: 58px;
    border: 2px solid color-mix(in srgb, var(--accent), #06050C 38%);
    border-radius: 16px;
    background: #fff;
    box-shadow: inset 0 -5px 0 var(--accent);
}

.bpm-display strong {
    font-size: 34px;
    line-height: 1;
    transform: translateY(-1px);
}

.bpm-display span {
    color: var(--muted);
    font-weight: 900;
    line-height: 1;
    transform: translateY(2px);
}

.bpm-chips {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.bpm-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-weight: 900;
    line-height: 1;
}

.bpm-chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 12px 24px var(--accent-shadow);
}

small,
.hint {
    display: block;
    margin-top: 10px;
    color: var(--muted);
    font-size: 14px;
}

.upload {
    display: grid;
    align-content: center;
    justify-items: start;
    gap: 10px;
    min-height: 260px;
    padding: 26px;
    border: 2px dashed color-mix(in srgb, var(--accent), #ffffff 28%);
    border-radius: 22px;
    background:
        linear-gradient(135deg, var(--accent-soft), #fff 62%),
        #fff;
    cursor: pointer;
    transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.upload:hover,
.upload.drag-over {
    border-color: var(--accent);
    transform: translateY(-1px);
}

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

.upload-kicker {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 900;
}

.upload-title {
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 950;
    line-height: 1;
}

.upload-text {
    max-width: 320px;
    color: var(--muted);
    font-size: 16px;
}

.notice {
    margin-top: 18px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #fff4e5;
    color: #7a4300;
    font-weight: 800;
}

.notice.error {
    background: #ffecec;
    color: #9a1f1f;
}

.notice.loading {
    background: var(--accent-soft);
    color: var(--ink);
}

.processing-card {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    margin-top: 18px;
    margin-bottom: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent-soft), #fff 74%);
    box-shadow: 0 16px 34px var(--accent-shadow);
    animation: notifyIn 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.processing-card[hidden] {
    display: none;
}

.processing-icon {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--ink);
}

.processing-icon::before,
.processing-icon::after {
    content: "";
    position: absolute;
    inset: 13px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    animation: spin 900ms linear infinite;
}

.processing-icon::after {
    inset: 19px;
    border-top-color: #fff;
    border-right-color: #fff;
    animation-duration: 1300ms;
    animation-direction: reverse;
}

.processing-card strong {
    display: block;
    margin-bottom: 2px;
    font-size: 18px;
    font-weight: 950;
}

.processing-card p {
    margin-bottom: 12px;
    color: var(--muted);
}

.processing-bar {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(6, 5, 12, 0.08);
}

.processing-bar span {
    display: block;
    width: 42%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #692CFE, #E336CF);
    animation: progressRun 1500ms ease-in-out infinite;
}

.processing-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.processing-steps span {
    min-width: 0;
    padding: 6px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
    text-align: center;
}

button {
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 950;
    transition: background 180ms ease, color 180ms ease, opacity 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

.bpm-step:disabled {
    background: color-mix(in srgb, var(--accent), #ffffff 78%);
    color: color-mix(in srgb, var(--accent), #06050C 22%);
    box-shadow: none;
}

.primary {
    width: 100%;
    margin-top: 18px;
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 16px 34px var(--accent-shadow);
}

.check-button {
    min-height: 66px;
    border-radius: 20px;
    font-size: clamp(20px, 2.2vw, 26px);
    letter-spacing: 0.01em;
}

.primary:hover:not(:disabled) {
    transform: translateY(-1px);
}

.secondary {
    background: #f2eef4;
    color: var(--text);
}

.result-card {
    min-height: 270px;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: linear-gradient(135deg, var(--result-soft), #fff 76%);
    --result-color: var(--accent);
    --result-soft: var(--accent-soft);
    animation: notifyIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.result-empty,
.result-processing {
    display: flex;
    align-items: center;
    justify-content: center;
    border-style: dashed;
    background:
        linear-gradient(135deg, #fbfaff, #fff 76%);
}

.result-empty > *,
.result-processing > * {
    display: none;
}

.result-empty::after {
    content: "";
}

.result-processing {
    align-items: stretch;
    justify-content: flex-start;
    gap: 14px;
    padding: 18px;
}

.result-processing::before,
.result-processing::after {
    display: none;
}

.result-processing .processing-card {
    display: grid;
    width: 100%;
    min-height: 100%;
    margin: 0;
    box-shadow: none;
}

.result-processing .processing-steps {
    display: none;
}

.result {
    --result-color: var(--accent);
    --result-soft: var(--accent-soft);
}

.result.status-bad {
    --result-color: #c83838;
    --result-soft: #ffe9e9;
}

.result.status-critical {
    --result-color: #d97706;
    --result-soft: #fff0d8;
}

.result.status-try {
    --result-color: #b98900;
    --result-soft: #fff6cf;
}

.result.status-good,
.result.status-excellent {
    --result-color: var(--accent);
    --result-soft: var(--accent-soft);
}

.result-head {
    position: relative;
    margin-bottom: 12px;
    padding-left: 54px;
    animation: fadeSlideUp 480ms ease both 120ms;
}

.result-head::before {
    content: "✓";
    position: absolute;
    left: 0;
    top: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--result-color);
    color: #fff;
    font-size: 24px;
    font-weight: 950;
    box-shadow: 0 12px 24px color-mix(in srgb, var(--result-color), transparent 70%);
}

.result.status-bad .result-head::before {
    content: "×";
    font-size: 28px;
}

.result-head h2 {
    margin-bottom: 6px;
    color: var(--result-color);
    font-size: clamp(26px, 3.4vw, 38px);
    line-height: 1.02;
}

.result-head p {
    max-width: 520px;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.35;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin-bottom: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--result-soft);
    color: var(--result-color);
    font-size: 13px;
    font-weight: 950;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 8px;
    animation: fadeSlideUp 500ms ease both 260ms;
}

.metrics div {
    min-width: 0;
    padding: 12px 10px;
    border: 1px solid color-mix(in srgb, var(--result-color), #ffffff 70%);
    border-radius: 14px;
    background: #fff;
    text-align: center;
}

.metrics span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
}

.metrics strong {
    display: block;
    margin-top: 5px;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1;
}

.metric-source {
    background: linear-gradient(135deg, #f1ebff, #fff 72%) !important;
    border-color: rgba(105, 44, 254, 0.24) !important;
}

.metric-target {
    background: linear-gradient(135deg, #fdeafd, #fff 72%) !important;
    border-color: rgba(227, 54, 207, 0.24) !important;
}

.metric-diff {
    background: linear-gradient(135deg, var(--result-soft), #fff 72%) !important;
    border-color: color-mix(in srgb, var(--result-color), #ffffff 68%) !important;
}

.metric-diff strong {
    color: var(--result-color);
}

audio {
    display: none;
}

.audio-player {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto 44px;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    animation: fadeSlideUp 500ms ease both 360ms;
}

.audio-play,
.audio-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 19px;
    font-weight: 950;
    text-decoration: none;
    box-shadow: 0 12px 24px var(--accent-shadow);
}

.audio-download svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.audio-wave {
    position: relative;
    height: 42px;
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    background:
        repeating-linear-gradient(90deg, color-mix(in srgb, var(--accent), #ffffff 36%) 0 4px, transparent 4px 10px),
        var(--accent-soft);
}

.audio-wave span {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background:
        repeating-linear-gradient(90deg, #ffffff 0 4px, transparent 4px 10px),
        linear-gradient(90deg, #692CFE, #E336CF);
}

.audio-time {
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    white-space: nowrap;
}

#resultPanel.result-empty > .result-head,
#resultPanel.result-empty > .metrics,
#resultPanel.result-empty > .hint,
#resultPanel.result-empty > audio,
#resultPanel.result-empty > .audio-player,
#resultPanel.result-processing > .result-head,
#resultPanel.result-processing > .metrics,
#resultPanel.result-processing > .hint,
#resultPanel.result-processing > audio,
#resultPanel.result-processing > .audio-player {
    display: none !important;
}

#resultPanel.result-processing > .processing-card {
    display: grid !important;
}

.actions {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.1fr);
    gap: 18px;
    margin-top: 18px;
    animation: fadeSlideUp 500ms ease both 460ms;
}

.actions > [hidden] {
    display: none;
}

#trackForm:not(.has-result) .actions {
    grid-template-columns: 1fr;
}

.actions .primary,
.actions .secondary {
    min-height: 64px;
    margin-top: 0;
    border-radius: 18px;
    font-size: clamp(18px, 2vw, 23px);
    letter-spacing: 0.01em;
}

.actions .secondary {
    background: #f1edf4;
}

.actions .primary {
    background: linear-gradient(90deg, #692CFE, #E336CF);
}

.order-button {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.28);
    background:
        radial-gradient(circle at 16% 20%, rgba(255, 255, 255, 0.42), transparent 18%),
        linear-gradient(100deg, #692CFE 0%, #7b2cff 34%, #E336CF 100%);
    box-shadow:
        0 20px 44px rgba(105, 44, 254, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.order-button::before {
    content: "";
    position: absolute;
    inset: -2px;
    z-index: -1;
    background: linear-gradient(120deg, transparent 0%, rgba(255, 255, 255, 0.42) 42%, transparent 58%);
    transform: translateX(-120%);
    animation: buttonShine 3200ms ease-in-out infinite;
}

.order-button:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.015);
    box-shadow:
        0 24px 58px rgba(227, 54, 207, 0.32),
        0 16px 42px rgba(105, 44, 254, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.button-label {
    position: relative;
    z-index: 2;
}

.sparkle {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    width: 22px;
    height: 22px;
    transform: rotate(45deg);
    animation: sparklePulse 1600ms ease-in-out infinite;
}

.sparkle::before,
.sparkle::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    background: #fff;
    border-radius: 999px;
}

.sparkle::before {
    width: 100%;
    height: 5px;
}

.sparkle::after {
    width: 5px;
    height: 100%;
}

.sparkle-main {
    left: 22px;
    top: 50%;
    translate: 0 -50%;
}

.sparkle-small {
    width: 10px;
    height: 10px;
    opacity: 0.9;
}

.sparkle-small::before {
    height: 3px;
}

.sparkle-small::after {
    width: 3px;
}

.sparkle-one {
    left: 54px;
    top: 22px;
    animation-delay: 420ms;
}

.sparkle-two {
    right: 52px;
    bottom: 20px;
    animation-delay: 760ms;
}

.sparkle-three {
    right: 26px;
    top: 22px;
    animation-delay: 1120ms;
}

@keyframes heroWordBuild {
    0% {
        opacity: 0;
        filter: blur(8px);
        transform: translate3d(0, 18px, 0) scale(0.96);
    }
    62% {
        opacity: 0.92;
        filter: blur(2px);
        transform: translate3d(0, -2px, 0) scale(1.01);
    }
    100% {
        opacity: 1;
        filter: blur(0);
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes heroWordExit {
    to {
        opacity: 0;
        filter: blur(8px);
        transform: translate3d(0, -14px, 0) scale(0.98);
    }
}

@keyframes notifyIn {
    from {
        opacity: 0;
        transform: translateY(34px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes growLine {
    from {
        transform: scaleY(0);
    }
    to {
        transform: scaleY(1);
    }
}

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

@keyframes progressRun {
    0% {
        transform: translateX(-110%);
    }
    55% {
        transform: translateX(86%);
    }
    100% {
        transform: translateX(250%);
    }
}

@keyframes buttonShine {
    0%,
    45% {
        transform: translateX(-120%);
    }
    78%,
    100% {
        transform: translateX(120%);
    }
}

@keyframes sparklePulse {
    0%,
    100% {
        opacity: 0.35;
        transform: rotate(45deg) scale(0.72);
    }
    45% {
        opacity: 1;
        transform: rotate(45deg) scale(1.08);
    }
}

@media (max-width: 760px) {
    .widget {
        padding: 16px;
    }

    .hero {
        grid-template-columns: 64px minmax(0, 1fr);
        gap: 14px;
        align-items: center;
    }

    .logo {
        width: 64px;
        height: 64px;
        border-radius: 16px;
    }

    h1 {
        font-size: 30px;
    }

    .hero-copy {
        font-size: 15px;
        min-height: 68px;
    }

    .panel {
        padding: 20px;
        border-radius: 22px;
    }

    .processing-card {
        grid-template-columns: 1fr;
    }

    .sport-cards,
    .form-grid,
    .metrics,
    .actions {
        grid-template-columns: 1fr;
    }

    .sport-cards span {
        min-height: 68px;
    }

    .upload {
        min-height: 190px;
    }

    .bpm-picker {
        grid-template-columns: 52px minmax(0, 1fr) 52px;
    }

    .bpm-step {
        width: 52px;
        height: 52px;
        min-height: 52px;
    }

    .bpm-display {
        height: 52px;
        min-height: 52px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}
