:root {
    --bg: #eff3f0;
    --ink: #101615;
    --muted: #66726d;
    --surface: rgba(255, 255, 255, 0.82);
    --solid: #ffffff;
    --line: rgba(16, 22, 21, 0.1);
    --green: #276d55;
    --green-deep: #123f31;
    --mint: #dceee6;
    --gold: #c4974b;
    --blue: #486f9f;
    --rose: #c76661;
    --error: #b42318;
    --shadow: 0 22px 56px rgba(20, 29, 26, 0.14);
    --soft-shadow: 0 12px 30px rgba(20, 29, 26, 0.09);
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background:
            radial-gradient(circle at 22% 0%, rgba(196, 151, 75, 0.18), transparent 32%),
            radial-gradient(circle at 100% 18%, rgba(72, 111, 159, 0.18), transparent 34%),
            linear-gradient(155deg, #eef6f0 0%, #fbf8ef 44%, #edf4f6 100%);
    color: var(--tg-theme-text-color, var(--ink));
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    width: min(100%, 820px);
    margin: 0 auto;
    padding: 14px 12px calc(34px + env(safe-area-inset-bottom));
}

.app-header {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 6px 2px 14px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(39, 109, 85, 0.22);
    border-radius: 8px;
    background: linear-gradient(145deg, #f9fff9, #dceee6);
    color: var(--green-deep);
    font-size: 14px;
    font-weight: 950;
    letter-spacing: 0;
    box-shadow: var(--soft-shadow);
}

.brand-copy p,
.metric-card p,
.wide-card p,
.lunar-hero p,
.section-label,
.process-copy p {
    margin: 0;
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    margin-top: 2px;
    font-size: 28px;
    line-height: 1.02;
    font-weight: 950;
    letter-spacing: 0;
}

h2 {
    font-size: 21px;
    line-height: 1.12;
    font-weight: 950;
}

.status-pill {
    max-width: 108px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid rgba(39, 109, 85, 0.22);
    border-radius: 8px;
    background: rgba(232, 244, 237, 0.92);
    color: var(--green-deep);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 950;
    text-align: center;
}

.status-pill.error {
    border-color: rgba(180, 35, 24, 0.18);
    background: #fff0ed;
    color: var(--error);
}

.service-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.service-tab {
    position: relative;
    min-height: 78px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.68);
    color: inherit;
    padding: 12px;
    overflow: hidden;
    text-align: left;
    box-shadow: var(--soft-shadow);
    cursor: pointer;
}

.service-tab::after {
    content: "";
    position: absolute;
    inset: auto 12px 9px 12px;
    height: 3px;
    border-radius: 999px;
    background: transparent;
}

.service-tab span {
    display: block;
    margin-bottom: 5px;
    overflow-wrap: anywhere;
    font-size: 15px;
    font-weight: 950;
}

.service-tab small {
    display: block;
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 11px;
    line-height: 1.25;
}

.service-tab.active {
    border-color: rgba(39, 109, 85, 0.4);
    background: rgba(255, 253, 247, 0.92);
    box-shadow: 0 15px 34px rgba(39, 109, 85, 0.16);
}

.service-tab.active::after {
    background: linear-gradient(90deg, var(--green), var(--gold));
}

.stage-panel,
.process-panel,
.empty-state,
.diagram-card,
.metric-card,
.wide-card,
.message-panel,
.lunar-hero {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--tg-theme-secondary-bg-color, var(--surface));
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.date-panel {
    position: sticky;
    top: 0;
    z-index: 6;
    margin-bottom: 12px;
    padding: 12px;
}

.panel-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

label,
.panel-topline span {
    display: block;
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 13px;
    font-weight: 900;
}

.input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 9px;
}

input,
.primary-action {
    min-height: 52px;
    border-radius: 8px;
}

input {
    width: 100%;
    border: 1px solid rgba(16, 22, 21, 0.14);
    background: rgba(255, 255, 255, 0.88);
    color: inherit;
    padding: 0 15px;
    outline: none;
    font-size: 18px;
    font-weight: 850;
}

input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 4px rgba(39, 109, 85, 0.13);
}

.primary-action {
    border: 0;
    background: var(--tg-theme-button-color, var(--green));
    color: var(--tg-theme-button-text-color, #ffffff);
    padding: 0 14px;
    font-weight: 950;
    cursor: pointer;
    box-shadow: 0 13px 25px rgba(39, 109, 85, 0.28);
}

.primary-action:disabled {
    cursor: progress;
    opacity: 0.72;
}

.process-panel {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    padding: 14px;
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
}

.process-panel.active {
    animation: slideIn 420ms cubic-bezier(.2, .86, .2, 1) forwards;
    pointer-events: auto;
}

.process-orbit {
    position: relative;
    width: 54px;
    height: 54px;
    border: 1px solid rgba(39, 109, 85, 0.2);
    border-radius: 50%;
    background: #f8fff9;
}

.process-orbit::before {
    content: "";
    position: absolute;
    inset: 8px;
    border: 3px solid rgba(39, 109, 85, 0.16);
    border-top-color: var(--green);
    border-right-color: var(--gold);
    border-radius: 50%;
    animation: spin 1.05s linear infinite;
}

.process-orbit span {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold);
}

.process-orbit span:first-child {
    top: 9px;
    right: 10px;
}

.process-orbit span:last-child {
    left: 11px;
    bottom: 10px;
    background: var(--blue);
}

.process-copy strong {
    display: block;
    margin-top: 4px;
    font-size: 18px;
    line-height: 1.15;
    font-weight: 950;
}

.process-steps {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    margin: 2px 0 0;
    padding: 0;
    list-style: none;
}

.process-steps li {
    min-height: 42px;
    border: 1px solid rgba(16, 22, 21, 0.08);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.62);
    color: var(--muted);
    padding: 8px;
    font-size: 11px;
    font-weight: 850;
    line-height: 1.15;
}

.process-steps li.active {
    border-color: rgba(39, 109, 85, 0.34);
    background: #e9f5ee;
    color: var(--green-deep);
}

.process-steps li.done {
    border-color: rgba(196, 151, 75, 0.34);
    background: #fff8e9;
    color: #6e4f1c;
}

.service-view {
    display: none;
}

.service-view.active {
    display: block;
}

.empty-state {
    min-height: 310px;
    padding: 28px 20px;
    overflow: hidden;
}

.empty-ring {
    width: 112px;
    height: 112px;
    margin-bottom: 22px;
    border: 18px solid #dbeadf;
    border-right-color: #f0d9a8;
    border-bottom-color: #d2e2ef;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(16, 22, 21, 0.08), var(--soft-shadow);
}

.empty-ring.moon {
    border-color: #d7e0ef;
    border-left-color: #f0d9a8;
    border-top-color: #e8ccc9;
}

.empty-state h2 {
    margin-bottom: 9px;
}

.empty-state p {
    max-width: 430px;
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 15px;
    line-height: 1.45;
}

.card-result,
.lunar-result {
    display: grid;
    gap: 12px;
}

.diagram-card {
    overflow: hidden;
    padding-top: 12px;
}

.section-label {
    padding: 0 14px 10px;
}

.diagram-card img {
    display: block;
    width: 100%;
    aspect-ratio: 2 / 1;
    object-fit: contain;
    background: #ffffff;
}

.metric-row,
.lunar-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.metric-card,
.wide-card {
    padding: 16px;
}

.metric-card {
    min-height: 168px;
}

.metric-card strong,
.wide-card strong {
    display: block;
    margin: 8px 0 14px;
    color: var(--ink);
    overflow-wrap: anywhere;
    font-size: 24px;
    line-height: 1.05;
    font-weight: 950;
}

.metric-card.strong {
    border-color: rgba(196, 151, 75, 0.24);
    background: rgba(255, 249, 237, 0.9);
}

.metric-card.weak {
    border-color: rgba(72, 111, 159, 0.22);
    background: rgba(243, 247, 251, 0.92);
}

.wide-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    background: rgba(247, 251, 248, 0.9);
}

dl {
    display: grid;
    gap: 10px;
    margin: 0;
}

dl div {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 9px;
    align-items: baseline;
}

dt {
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 12px;
    font-weight: 850;
}

dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 15px;
    font-weight: 900;
}

#missingQi {
    color: var(--green-deep);
}

.lunar-hero {
    min-height: 198px;
    padding: 20px;
    overflow: hidden;
    background: linear-gradient(145deg, rgba(255, 253, 248, 0.96), rgba(230, 238, 244, 0.92));
}

.lunar-hero strong {
    display: block;
    margin: 10px 0 6px;
    color: var(--green-deep);
    font-size: 86px;
    line-height: 0.9;
    font-weight: 950;
}

.lunar-hero span {
    color: var(--tg-theme-hint-color, var(--muted));
    font-size: 15px;
    font-weight: 850;
}

.message-panel {
    overflow: hidden;
}

summary {
    min-height: 48px;
    padding: 14px 16px;
    cursor: pointer;
    color: var(--muted);
    font-size: 14px;
    font-weight: 900;
}

pre {
    margin: 0;
    padding: 0 16px 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--tg-theme-hint-color, var(--muted));
    font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.reveal-panel {
    opacity: 0;
    transform: translateY(22px) scale(0.985);
}

.reveal-panel.visible {
    animation: panelRise 560ms cubic-bezier(.2, .86, .2, 1) forwards;
}

[hidden] {
    display: none !important;
}

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes panelRise {
    from {
        opacity: 0;
        transform: translateY(22px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 640px) {
    .app-header {
        grid-template-columns: 44px minmax(0, 1fr) auto;
        gap: 10px;
    }

    .brand-mark {
        width: 44px;
        height: 44px;
    }

    h1 {
        font-size: 25px;
    }

    .status-pill {
        max-width: 88px;
    }

    .service-tab {
        min-height: 86px;
        padding: 11px;
    }

    .input-row,
    .metric-row,
    .lunar-grid {
        grid-template-columns: 1fr;
    }

    .process-steps {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .primary-action {
        min-height: 50px;
    }

    .empty-state {
        min-height: 280px;
    }

    .metric-card {
        min-height: 146px;
    }

    .lunar-hero strong {
        font-size: 78px;
    }
}
