:root {
    --background: #f3f4f6;
    --surface: #ffffff;
    --text: #19191c;
    --muted: #737378;
    --line: #dedfe3;
    --rap: #cf0a38;
    --rap-dark: #a5002a;
    --rap-soft: #fff1f4;
    --picker-height: 216px;
    --picker-row: 46px;
    --page-padding: 14px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    color-scheme: light;
    background: var(--background);
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 280px;
    min-height: 100%;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 50% -180px, rgba(207, 10, 56, 0.055), transparent 420px),
        linear-gradient(180deg, #f7f7f8 0%, var(--background) 60%);
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.app {
    min-height: 100vh;
    min-height: 100svh;
}

.calculator {
    width: min(100%, 520px);
    min-height: 100svh;
    margin: 0 auto;
    padding:
        max(var(--page-padding), env(safe-area-inset-top))
        max(var(--page-padding), env(safe-area-inset-right))
        max(var(--page-padding), env(safe-area-inset-bottom))
        max(var(--page-padding), env(safe-area-inset-left));
}

.price-card {
    height: 230px;
    padding: 18px;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(145deg, #d51143 0%, var(--rap) 48%, var(--rap-dark) 100%);
    border-radius: 20px;
    box-shadow: 0 10px 24px rgba(143, 0, 35, 0.18);
    contain: layout paint;
    overflow-anchor: none;
}

.price-header {
    display: flex;
    min-height: 44px;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.price-heading {
    min-width: 0;
    padding-top: 2px;
}

.price-heading p,
.price-heading span {
    display: block;
    margin: 0;
}

.price-heading p {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.price-heading span {
    max-width: 230px;
    margin-top: 4px;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.72);
    font-size: 11px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-badge {
    display: flex;
    width: 120px;
    min-width: 120px;
    min-height: 42px;
    padding: 6px 9px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.source-line {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 5px;
}

.source-line i {
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
}

.source-line b {
    overflow: hidden;
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.source-badge time {
    min-height: 13px;
    padding-left: 11px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 9.5px;
    font-weight: 500;
    white-space: nowrap;
}

.price-card.is-loading .source-line i {
    animation: source-pulse 800ms ease-in-out infinite alternate;
}

.price-card.has-error .source-line i {
    background: #ffd16a;
}

@keyframes source-pulse {
    to {
        opacity: 0.35;
    }
}

.main-price {
    display: flex;
    height: 104px;
    padding: 5px 0 10px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.main-price > span {
    height: 14px;
    margin-bottom: 3px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: 0.1em;
    line-height: 14px;
    text-transform: uppercase;
}

.main-price > strong {
    display: block;
    height: 52px;
    flex: 0 0 52px;
    max-width: 100%;
    overflow: hidden;
    font-size: clamp(43px, 12.5vw, 56px);
    font-weight: 720;
    letter-spacing: -0.045em;
    line-height: 0.98;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main-price > strong.long {
    font-size: clamp(37px, 10.5vw, 49px);
}

.main-price > strong.xlong {
    font-size: clamp(31px, 9vw, 43px);
}

.main-price > small {
    display: block;
    max-width: 100%;
    overflow: hidden;
    height: 17px;
    flex: 0 0 17px;
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 550;
    line-height: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.price-card.is-loading .main-price > strong,
.price-card.is-loading .main-price > small {
    opacity: 0.72;
}

.price-details {
    display: grid;
    min-height: 46px;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 11px;
}

.price-details div {
    display: flex;
    min-width: 0;
    padding: 7px 11px;
    flex-direction: column;
    justify-content: center;
}

.price-details div + div {
    border-left: 1px solid rgba(255, 255, 255, 0.18);
}

.price-details span {
    color: rgba(255, 255, 255, 0.62);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.price-details strong {
    min-height: 17px;
    margin-top: 1px;
    overflow: hidden;
    font-size: 13.5px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.controls {
    margin-top: 12px;
    padding: 15px 14px 14px;
    background: var(--surface);
    border: 1px solid rgba(25, 25, 28, 0.07);
    border-radius: 16px;
    box-shadow: 0 5px 18px rgba(28, 28, 31, 0.055);
    overflow-anchor: none;
}

.carat-control label,
.picker-group > label {
    color: #626267;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.015em;
}

.carat-control label {
    display: block;
    margin: 0 0 7px 2px;
}

.carat-input-wrap {
    position: relative;
    height: 54px;
}

#carat-input {
    width: 100%;
    height: 54px;
    margin: 0;
    padding: 0 128px 0 15px;
    color: var(--text);
    background: #fff;
    border: 1.5px solid #d5d6da;
    border-radius: 12px;
    outline: 0;
    font-size: 23px;
    font-weight: 600;
    letter-spacing: -0.025em;
    caret-color: var(--rap);
    appearance: none;
    -webkit-appearance: none;
    user-select: text;
    -webkit-user-select: text;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

#carat-input:focus {
    border-color: var(--rap);
    box-shadow: 0 0 0 3px rgba(207, 10, 56, 0.1);
}

.carat-unit {
    position: absolute;
    top: 50%;
    right: 13px;
    color: #85858a;
    font-size: 13px;
    font-weight: 550;
    transform: translateY(-50%);
    pointer-events: none;
}

.carat-mm {
    position: absolute;
    top: 50%;
    right: 39px;
    min-width: 72px;
    padding: 4px 8px;
    color: var(--rap);
    background: var(--rap-soft);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    text-align: center;
    transform: translateY(-50%);
    pointer-events: none;
}

.carat-mm[hidden] {
    display: none;
}

.pickers {
    display: grid;
    margin-top: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}

.picker-group {
    min-width: 0;
}

.picker-group > label {
    display: block;
    height: 20px;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.discount-group > label {
    color: var(--rap);
}

.picker {
    position: relative;
    height: var(--picker-height);
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 11px;
    outline: 0;
    contain: layout paint;
    -webkit-tap-highlight-color: transparent;
}

.picker::before,
.picker::after {
    position: absolute;
    z-index: 4;
    right: 0;
    left: 0;
    height: 44px;
    content: "";
    pointer-events: none;
}

.picker::before {
    top: 0;
    background: linear-gradient(#fff 10%, rgba(255, 255, 255, 0));
}

.picker::after {
    bottom: 0;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff 90%);
}

.picker:focus-visible {
    border-color: var(--rap);
    box-shadow: 0 0 0 3px rgba(207, 10, 56, 0.1);
}

.picker.is-interacting {
    border-color: rgba(207, 10, 56, 0.38);
}

.picker-selection {
    position: absolute;
    z-index: 1;
    top: 50%;
    right: 3px;
    left: 3px;
    height: var(--picker-row);
    background: rgba(207, 10, 56, 0.065);
    border-top: 1px solid rgba(207, 10, 56, 0.23);
    border-bottom: 1px solid rgba(207, 10, 56, 0.23);
    border-radius: 7px;
    transform: translateY(-50%);
    pointer-events: none;
}

.picker-items {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding-block: calc((var(--picker-height) - var(--picker-row)) / 2);
    scrollbar-width: none;
    scroll-behavior: smooth;
    scroll-snap-type: y mandatory;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.picker-items::-webkit-scrollbar {
    display: none;
}

.picker-item {
    display: flex;
    width: 100%;
    height: var(--picker-row);
    align-items: center;
    justify-content: center;
    color: #77777c;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    opacity: 0.62;
    scroll-snap-align: center;
    user-select: none;
    -webkit-user-select: none;
    transition: color 100ms ease, opacity 100ms ease;
}

.picker-item.selected {
    color: var(--rap);
    font-size: 16px;
    font-weight: 700;
    opacity: 1;
}

.discount-group .picker {
    border-color: rgba(207, 10, 56, 0.22);
}

.discount-group .picker-item {
    font-size: 13px;
    letter-spacing: -0.02em;
}

.discount-group .picker-item.selected {
    font-size: 14.5px;
}

.refresh-button {
    display: flex;
    width: 100%;
    height: 46px;
    margin: 11px 0 0;
    padding: 0 15px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #6e6e73;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(25, 25, 28, 0.08);
    border-radius: 12px;
    outline: 0;
    font-size: 13px;
    font-weight: 550;
    box-shadow: 0 3px 10px rgba(28, 28, 31, 0.04);
}

.refresh-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.refresh-button:active {
    background: #fff;
    transform: scale(0.988);
}

.refresh-button:focus-visible {
    box-shadow: 0 0 0 3px rgba(207, 10, 56, 0.1);
}

.refresh-button.loading svg {
    color: var(--rap);
    animation: refresh-spin 800ms linear infinite;
}

.refresh-button:disabled {
    cursor: wait;
}

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

.toast {
    position: fixed;
    z-index: 20;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
    width: fit-content;
    max-width: min(420px, calc(100% - 32px));
    margin: auto;
    padding: 10px 14px;
    color: #fff;
    background: rgba(28, 28, 31, 0.94);
    border-radius: 11px;
    font-size: 13px;
    font-weight: 550;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.toast[hidden] {
    display: none;
}

@media (max-width: 350px) {
    :root {
        --page-padding: 10px;
        --picker-height: 198px;
        --picker-row: 44px;
    }

    .price-card {
        height: 212px;
        padding: 14px;
        border-radius: 17px;
    }

    .price-heading p {
        font-size: 13.5px;
    }

    .price-heading span {
        max-width: 145px;
        font-size: 10px;
    }

    .source-badge {
        width: 106px;
        min-width: 106px;
        min-height: 40px;
        padding-inline: 7px;
    }

    .source-line b {
        font-size: 9px;
    }

    .source-badge time {
        font-size: 8.5px;
    }

    .main-price {
        height: 94px;
        padding-block: 3px 7px;
    }

    .main-price > strong {
        height: 46px;
        flex-basis: 46px;
        font-size: 40px;
    }

    .main-price > small {
        height: 15px;
        flex-basis: 15px;
        font-size: 12.5px;
        line-height: 15px;
    }

    .controls {
        padding-inline: 10px;
    }

    .pickers {
        gap: 4px;
    }

    .picker-group > label {
        font-size: 9.5px;
    }

    .picker-item {
        font-size: 12.5px;
    }

    .picker-item.selected {
        font-size: 14px;
    }

    .discount-group .picker-item {
        font-size: 11px;
    }

    .discount-group .picker-item.selected {
        font-size: 12.5px;
    }
}

@media (max-height: 700px) {
    :root {
        --picker-height: 198px;
        --picker-row: 44px;
    }

    .price-card {
        height: 212px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .main-price {
        height: 94px;
        padding-block: 3px 7px;
    }

    .main-price > strong {
        height: 46px;
        flex-basis: 46px;
        font-size: clamp(40px, 11.5vw, 50px);
    }

    .controls {
        margin-top: 10px;
    }

    .pickers {
        margin-top: 12px;
    }

    .refresh-button {
        margin-top: 9px;
    }
}

@media (min-width: 720px) {
    :root {
        --page-padding: 20px;
    }

    .price-card {
        padding-inline: 22px;
    }

    .controls {
        padding-inline: 17px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
