* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    background: #f4f5f6;
    color: #30241f;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.freedom-page {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    background: #f7f8f9;
}

.freedom-main,
.tool-nav {
    width: min(100%, 375px);
    margin-right: auto;
    margin-left: auto;
}

.freedom-main {
    min-height: 100vh;
    padding: 7px 13px calc(104px + env(safe-area-inset-bottom));
}

.formula-card {
    min-height: 98px;
    padding: 19px 16px 13px;
    border: 1px solid #eadfc4;
    border-radius: 15px;
    background: linear-gradient(180deg, #fff7dc 0%, #fff0c7 100%);
    box-shadow: 0 1px 7px rgba(116, 89, 42, 0.1);
}

.formula-title {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #a47120;
    font-size: 14px;
    line-height: 1;
    font-weight: 800;
}

.formula-icon {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    object-fit: contain;
}

.formula-expression {
    margin-top: 17px;
    color: #130f0e;
    font-size: 18px;
    line-height: 1;
    font-weight: 900;
}

.formula-desc {
    margin-top: 8px;
    color: #6e645f;
    font-size: 12px;
    line-height: 1;
    font-weight: 700;
}

.param-card {
    margin-top: 13px;
    padding: 16px 14px 15px;
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(46, 36, 24, 0.05);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 14px;
    color: #493b33;
    font-size: 14px;
    line-height: 1.25;
    font-weight: 900;
}

.section-icon {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    object-fit: contain;
}

.freedom-form {
    display: grid;
    gap: 12px;
}

.field-row {
    display: grid;
    gap: 7px;
}

.field-label {
    color: #786b65;
    font-size: 13px;
    line-height: 1.2;
    font-weight: 800;
}

.field-control {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    min-height: 43px;
    border: 1.5px solid #e8e2d6;
    border-radius: 9px;
    background: #fffdf8;
    box-shadow: inset 0 0 0 1px rgba(143, 111, 58, 0.04);
}

.field-control input {
    flex: 1;
    min-width: 0;
    width: 0;
    height: 41px;
    padding: 0 14px;
    border: 0;
    outline: none;
    background: transparent;
    color: #201817;
    font-size: 18px;
    line-height: 1;
    font-weight: 800;
}

.field-control input::-webkit-outer-spin-button,
.field-control input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.field-control input[type="number"] {
    -moz-appearance: textfield;
}

.field-control:focus-within {
    border-color: #e8c176;
    box-shadow: 0 0 0 3px rgba(232, 193, 118, 0.2);
}

.field-unit {
    flex: 0 0 auto;
    padding: 0 14px 0 8px;
    color: #a99f98;
    font-size: 13px;
    font-weight: 800;
}

.input-clear-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-right: 4px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #c8c0b8;
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
}

.input-clear-btn.visible {
    display: flex;
}

.unit-toggle {
    flex: 0 0 auto;
    padding: 0 14px 0 8px;
    border: 0;
    border-left: 1px solid #e8e2d6;
    background: transparent;
    color: #a99f98;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.period-field {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.period-field .field-label {
    display: block;
    margin-bottom: 7px;
}

.period-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 35px;
    overflow: hidden;
    border: 1.5px solid #e8e2d6;
    border-radius: 7px;
    background: #fffdf8;
}

.period-option {
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #6d625d;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.period-option.is-active {
    background: #e8c177;
    color: #fff;
}

.calc-button {
    width: 100%;
    height: 48px;
    margin-top: 30px;
    border: 0;
    border-radius: 8px;
    background: #e8c177;
    color: #9c6616;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0;
    cursor: pointer;
}

.calc-button:active {
    transform: translateY(1px);
}

.result-card {
    position: relative;
    margin-top: 24px;
    padding: 32px 9px 9px;
    border: 1px solid #ffe0df;
    border-radius: 8px;
    background: linear-gradient(180deg, #fff4e9 0%, #ffeadd 100%);
    box-shadow: 0 3px 12px rgba(198, 106, 42, 0.09);
}

.warning-icon {
    position: absolute;
    top: -27px;
    left: 50%;
    width: 61px;
    height: 54px;
    transform: translateX(-50%);
}

.warning-icon img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.warning-icon .result-icon-success {
    display: none;
}

.result-title {
    margin-bottom: 11px;
    color: #a86d19;
    text-align: center;
    font-size: 14px;
    line-height: 1.3;
    font-weight: 900;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.metric-item {
    min-height: 48px;
    padding: 6px 6px 5px;
    border-radius: 5px;
    background: #fff;
    text-align: center;
}

.metric-label {
    color: #948b87;
    font-size: 10px;
    line-height: 1.2;
    font-weight: 700;
}

.metric-value {
    margin-top: 1px;
    color: #1b1715;
    font-size: 17px;
    line-height: 1.15;
    font-weight: 900;
}

.deficit-box {
    margin-top: 6px;
    padding: 7px 8px 8px;
    border-radius: 7px;
    background: #E7CD9C;
    text-align: center;
}

.deficit-label {
    color: #8d6630;
    font-size: 10px;
    line-height: 1.2;
    font-weight: 800;
}

.deficit-value {
    margin-top: 1px;
    color: #f33222;
    font-size: 19px;
    line-height: 1.15;
    font-weight: 900;
}

.deficit-desc {
    margin-top: 3px;
    color: #9a7a4a;
    font-size: 10px;
    line-height: 1.3;
    font-weight: 700;
}

.result-card.is-free {
    background: linear-gradient(180deg, #fff4e9 0%, #ffeadd 100%);
    border-color: #ffe0df;
}

.result-card.is-free .warning-icon .result-icon-warning {
    display: none;
}

.result-card.is-free .warning-icon .result-icon-success {
    display: block;
}

.result-card.is-free .deficit-box {
    background: #e8c177;
}

.result-card.is-free .deficit-value {
    color: #b77709;
}

.activity-card {
    margin-top: 11px;
    padding: 9px;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 3px 12px rgba(38, 30, 24, 0.05);
    cursor: pointer;
}

.activity-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.activity-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: #1d1714;
    font-size: 14px;
    line-height: 1.3;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-signup {
    flex: 0 0 auto;
    min-width: 56px;
    height: 23px;
    padding: 0 9px;
    border-radius: 4px;
    background: #e8c177;
    color: #fff;
    font-size: 12px;
    line-height: 23px;
    font-weight: 900;
    text-align: center;
    text-decoration: none;
}

.activity-meta {
    display: grid;
    gap: 1px;
    margin-top: 3px;
    color: #6c625d;
    font-size: 12px;
    line-height: 1.55;
    font-weight: 600;
}

.activity-cover {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    margin-top: 8px;
    border-radius: 6px;
    object-fit: cover;
    background: #eee8de;
}

.activity-cover[hidden] {
    display: none;
}

.tool-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: clamp(4px, 2vw, 8px);
    max-width: 375px;
    padding: 8px clamp(8px, 2.933vw, 11px) calc(7px + env(safe-area-inset-bottom));
    background: #f7f8f9;
}

.tool-item {
    min-width: 0;
    display: grid;
    gap: 6px;
    align-items: start;
    justify-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: #a2a0a0;
    font-size: 10px;
    line-height: 1;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
}

.tool-item:disabled {
    cursor: wait;
    opacity: 0.62;
}

.tool-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(50px, 15.467vw, 58px);
    height: clamp(50px, 15.467vw, 58px);
    border-radius: 5px;
    background: #fff;
    box-shadow: 0 2px 7px rgba(39, 31, 25, 0.08);
}

.tool-icon img {
    display: block;
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.freedom-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 999;
    display: none;
    max-width: min(78vw, 300px);
    padding: 10px 14px;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 14px;
    line-height: 1.45;
    text-align: center;
    transform: translate(-50%, -50%);
}

/* 分享弹窗样式 */
.share-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.share-modal.show {
    display: flex;
}

.share-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.share-modal-content {
    position: relative;
    width: 100%;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 24px 16px 24px;
    z-index: 1;
}

.share-modal-title {
    text-align: center;
    color: #30241f;
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 20px;
}

.share-modal-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.share-modal-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.share-modal-action img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    padding: 15px;
    border-radius: 0.5rem;
    box-shadow: 0 2px 7px rgba(39, 31, 25, 0.14);
}

.share-modal-action span {
    color: #A1A1A1;
    font-size: 12px;
    font-weight: 700;
}

.share-modal-cancel {
    width: 100%;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: #E4E4E4;
    color: #995D00;
    font-size: 15px;
    font-weight: 400;
    cursor: pointer;
}

@media (max-width: 360px) {
    .freedom-main {
        padding-right: 10px;
        padding-left: 10px;
    }

    .param-card {
        padding-right: 12px;
        padding-left: 12px;
    }

    .tool-nav {
        gap: 4px;
    }

    .tool-item {
        font-size: 9px;
    }

    .tool-icon img {
        width: 30px;
        height: 30px;
    }

    .field-control input {
        padding-right: 10px;
        padding-left: 12px;
        font-size: 17px;
    }

    .field-unit {
        padding-right: 11px;
        padding-left: 6px;
    }
}

@media (min-width: 376px) {
    .tool-nav {
        left: 50%;
        transform: translateX(-50%);
    }
}

@media (min-width: 768px) {
    body {
        background: #eef0f2;
    }

    .freedom-page {
        max-width: 430px;
        background: #f7f8f9;
        box-shadow: 0 18px 46px rgba(35, 31, 25, 0.08);
    }

    .freedom-main,
    .tool-nav {
        width: min(100%, 430px);
    }

    .freedom-main {
        padding: 14px 16px calc(108px + env(safe-area-inset-bottom));
    }

    .formula-card,
    .param-card,
    .calc-button,
    .result-card,
    .activity-card {
        width: 100%;
    }

    .tool-nav {
        right: auto;
        left: 50%;
        width: min(100%, 430px);
        max-width: 430px;
        margin: 0;
        transform: translateX(-50%);
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -8px 24px rgba(39, 31, 25, 0.06);
    }
}
