/* ============================================================
   奇门遁甲 · 括囊局（手机端）
   设计基调：宣纸底 / 松烟墨 / 朱砂印章 / 细金线
   ============================================================ */

:root {
    --paper: #F6F1E6;
    --paper-deep: #EDE5D3;
    --paper-mid: #F1EAD9;
    --card: #FFFDF8;
    --card-alt: #F8F2E6;
    --line: #D8CDB4;
    --line-soft: #E6DCC8;
    --grid-line: #C9B996;
    --sub-grid: #D8C6A6;

    --ink: #2B2721;
    --ink-soft: #6F6558;
    --ink-faint: #9C9282;

    --accent: #9C2B2B;
    --accent-dark: #7A2020;
    --gold: #B08A3E;
    --gold-deep: #8F6B2C;
    --gold-soft: #E9DAB9;

    --dong-bg: #FCF5EF;
    --ming-tint: rgba(231, 196, 106, 0.20);

    --wood: #2F6B3A;
    --fire: #B2352C;
    --earth: #8A6236;
    --metal: #8C7A2F;
    --water: #24557F;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow-card: 0 1px 2px rgba(43, 39, 33, 0.04), 0 10px 28px rgba(43, 39, 33, 0.06);
    --shadow-float: 0 6px 24px rgba(43, 39, 33, 0.16);

    --font: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Hiragino Sans GB",
        system-ui, -apple-system, sans-serif;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* 键盘高度（由 index.html 用 visualViewport 实时写入），用于把底部弹层顶到键盘上方 */
    --kb: 0px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
    overflow-x: hidden;
}

/* 弹性容器必须显式允许收缩，否则长内容会把整页撑宽（小程序/手机浏览器特有问题） */
.app,
.app-main,
.page,
.card,
.ctl-card,
.chart-card,
.calendar-card,
.meta-bar,
.section-head,
.ctl-row,
.ctl-seg,
.ctl-time-actions,
.ctl-inline,
.pillars,
.facts,
.brand,
.brand-copy {
    min-width: 0;
}

body {
    /* 极淡的纸纹：两层大范围径向渐变，避免纯色发闷 */
    background-image:
        radial-gradient(1200px 700px at 12% -8%, rgba(176, 138, 62, 0.055), transparent 62%),
        radial-gradient(900px 620px at 108% 4%, rgba(156, 43, 43, 0.035), transparent 60%);
}

/* iOS Safari 聚焦 input/textarea 时，字号 <16px 会自动放大页面；
   统一兜底到 16px，避免点开输入框整页缩放。 */
textarea,
input[type="text"] {
    font-size: 16px !important;
}

h1,
h2,
h3,
p {
    margin: 0;
}

button {
    font-family: inherit;
    color: inherit;
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
}

select {
    font-family: inherit;
    color: inherit;
}

/* ---------------- 应用骨架 ---------------- */

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
}

.app-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(var(--safe-top) + 12px) 16px 11px;
    background: linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(246, 241, 230, 0.55));
    border-bottom: 1px solid var(--line-soft);
    position: relative;
    z-index: 5;
}

.app-header::after {
    /* 金色细线：从品牌印章延伸到右侧 */
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, rgba(176, 138, 62, 0) 0%, rgba(176, 138, 62, 0.55) 18%,
            rgba(176, 138, 62, 0.18) 62%, rgba(176, 138, 62, 0) 100%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-seal {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(160deg, #A93131, #8A2323);
    color: #FFF6E6;
    font-size: 22px;
    font-weight: 700;
    font-family: "Kaiti SC", "STKaiti", "KaiTi", var(--font);
    box-shadow: inset 0 0 0 1.5px rgba(233, 218, 185, 0.55), 0 2px 6px rgba(122, 32, 32, 0.22);
    transform: rotate(-1.5deg);
}

.brand-copy {
    min-width: 0;
}

.brand-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.14em;
    line-height: 1.2;
    color: var(--ink);
}

.brand-sub {
    margin-top: 2px;
    font-size: 9.5px;
    letter-spacing: 0.16em;
    color: var(--ink-faint);
    text-transform: uppercase;
}

.brand-side {
    flex: 0 0 auto;
    text-align: right;
}

.brand-pillars {
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
}

.app-main {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* 关键：把内容区显式抬成高于顶部栏(5)/底部页签(6)的层，
       否则 iOS Safari 会把可滚动区域当独立图层，弹窗的居中对话框会被标题栏/页签盖住，
       导致右上角 ✕ 和底部按钮点不到。 */
    position: relative;
    z-index: 7;
}

.page {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 12px calc(20px + var(--safe-bottom));
}

/* ---------------- 卡片与栏目标题 ---------------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.kicker {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.section-head {
    display: flex;
    align-items: center;
    gap: 7px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line-soft);
    margin-bottom: 10px;
}

.section-head::before {
    content: "";
    width: 3px;
    height: 12px;
    border-radius: 1px;
    background: linear-gradient(180deg, var(--gold), rgba(176, 138, 62, 0.35));
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
}

.section-note {
    margin-left: auto;
    font-size: 10px;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
}

/* ---------------- 按钮 ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 40px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn:active {
    transform: scale(0.985);
    opacity: 0.86;
}

.btn:disabled {
    opacity: 0.38;
}

.btn-primary {
    background: linear-gradient(180deg, #A93131, #8E2626);
    color: #FFF8EA;
    box-shadow: 0 4px 12px rgba(122, 32, 32, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.16);
    font-size: 14.5px;
    letter-spacing: 0.18em;
}

.btn-ghost {
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--ink-soft);
}

.btn-quiet {
    background: transparent;
    border: 1px solid transparent;
    color: var(--ink-faint);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.btn-sm {
    height: 30px;
    padding: 0 10px;
    font-size: 11.5px;
    font-weight: 500;
    border-radius: 6px;
}

.btn-danger {
    color: var(--accent);
    border-color: rgba(156, 43, 43, 0.28);
    background: rgba(156, 43, 43, 0.045);
}

/* ---------------- 起局控件 ---------------- */

.ctl-card {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ctl-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctl-head .kicker {
    flex: 1 1 auto;
}

.ctl-now {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 9px;
    border-radius: 13px;
    border: 1px solid var(--line);
    background: var(--card-alt);
    font-size: 10.5px;
    color: var(--ink-soft);
    letter-spacing: 0.06em;
}

.ctl-now:active {
    background: var(--paper-deep);
}

.ctl-row {
    display: grid;
    gap: 6px;
}

.ctl-row-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.ctl-field {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.ctl-label {
    font-size: 9px;
    letter-spacing: 0.14em;
    color: var(--ink-faint);
    padding-left: 2px;
}

.ctl-select-wrap {
    position: relative;
    display: block;
    min-width: 0;
}

.ctl-select-wrap::after {
    content: "";
    position: absolute;
    right: 9px;
    top: 50%;
    width: 5px;
    height: 5px;
    margin-top: -4px;
    border-right: 1.4px solid var(--ink-faint);
    border-bottom: 1.4px solid var(--ink-faint);
    transform: rotate(45deg);
    pointer-events: none;
}

.ctl-select {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 36px;
    padding: 0 22px 0 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: linear-gradient(180deg, #FFFDF8, #FBF6EC);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    text-overflow: ellipsis;
}

.ctl-select:disabled {
    opacity: 0.45;
    background: var(--paper-mid);
}

.ctl-select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(176, 138, 62, 0.14);
}

.ctl-seg {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper-mid);
}

.ctl-seg-btn {
    height: 32px;
    border-radius: 5px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-soft);
    letter-spacing: 0.06em;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.ctl-seg-btn.active {
    background: var(--card);
    color: var(--ink);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(43, 39, 33, 0.14), inset 0 0 0 1px rgba(176, 138, 62, 0.45);
}

.ctl-inline {
    display: flex;
    align-items: center;
    gap: 9px;
}

.ctl-inline .ctl-label {
    padding: 0;
    white-space: nowrap;
    letter-spacing: 0.08em;
}

.ctl-inline .ctl-select-wrap {
    flex: 1 1 auto;
}

/* 开关 */
.ctl-switch {
    position: relative;
    flex: 0 0 auto;
    width: 40px;
    height: 23px;
    border-radius: 12px;
    background: #DCD2BF;
    border: 1px solid rgba(140, 122, 98, 0.28);
    transition: background 0.18s ease;
}

.ctl-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #FFFDF7;
    box-shadow: 0 1px 3px rgba(43, 39, 33, 0.28);
    transition: transform 0.18s ease;
}

.ctl-switch.on {
    background: linear-gradient(180deg, #A93131, #8E2626);
    border-color: rgba(122, 32, 32, 0.5);
}

.ctl-switch.on::after {
    transform: translateX(17px);
}

.ctl-time-actions {
    display: grid;
    grid-template-columns: 1fr 1.25fr 1fr;
    gap: 6px;
    align-items: stretch;
}

.ctl-time-actions .btn {
    height: 42px;
    padding: 0 6px;
    letter-spacing: 0.04em;
}

/* ---------------- 局信息条 ---------------- */

.chart-card {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.meta-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 0;
    padding: 0 2px 8px;
    border-bottom: 1px solid var(--line-soft);
}

.meta-ju {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    margin-right: 10px;
    white-space: nowrap;
}

.meta-ju-name {
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--accent);
}

.meta-yuan {
    font-size: 9.5px;
    font-style: normal;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--gold-deep);
    padding: 1px 5px;
    border: 1px solid rgba(176, 138, 62, 0.4);
    border-radius: 3px;
    background: rgba(233, 218, 185, 0.32);
}

.meta-item {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 0 9px;
    border-left: 1px solid var(--line-soft);
    white-space: nowrap;
    font-size: 12px;
    color: var(--ink);
    font-weight: 500;
}

.meta-item:first-of-type {
    border-left: 0;
}

.meta-item i {
    font-style: normal;
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

/* ---------------- 四柱 / 命盘说明 ---------------- */

.calendar-card {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pillars {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--line-soft);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.pillar {
    background: var(--card);
    padding: 7px 0 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.pillar-label {
    font-size: 9px;
    letter-spacing: 0.16em;
    color: var(--ink-faint);
    margin-bottom: 2px;
}

.pillar-gan,
.pillar-zhi {
    font-size: 21px;
    font-weight: 600;
    line-height: 1.18;
    font-variant-numeric: tabular-nums;
}

.wx-wood {
    color: var(--wood);
}

.wx-fire {
    color: var(--fire);
}

.wx-earth {
    color: var(--earth);
}

.wx-metal {
    color: var(--metal);
}

.wx-water {
    color: var(--water);
}

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

.fact {
    display: flex;
    gap: 6px;
    font-size: 11px;
    line-height: 1.55;
    min-width: 0;
}

.fact-label {
    flex: 0 0 auto;
    color: var(--ink-faint);
    letter-spacing: 0.04em;
}

.fact-value {
    flex: 1 1 auto;
    color: var(--ink-soft);
    min-width: 0;
    overflow-wrap: anywhere;
}

.fact-wide {
    grid-column: 1 / -1;
}

.disclaimer {
    padding: 2px 4px 10px;
    text-align: center;
    font-size: 9.5px;
    line-height: 1.7;
    letter-spacing: 0.04em;
    color: var(--ink-faint);
}

/* ---------------- 底部页签 ---------------- */

.tabbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(255, 253, 248, 0.93);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line-soft);
    padding-bottom: var(--safe-bottom);
    position: relative;
    z-index: 6;
}

.tabbar::before {
    content: "";
    position: absolute;
    left: 12%;
    right: 12%;
    top: -1px;
    height: 1px;
    background: linear-gradient(90deg, rgba(176, 138, 62, 0), rgba(176, 138, 62, 0.45), rgba(176, 138, 62, 0));
}

.tab {
    height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--ink-faint);
    transition: color 0.15s ease;
}

.tab-icon {
    width: 21px;
    height: 21px;
}

.tab-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.16em;
}

.tab.active {
    color: var(--accent);
}

.tab.active .tab-label {
    font-weight: 600;
}

.tab.active .tab-icon {
    stroke-width: 1.9;
}

/* ---------------- 启动 / 错误 ---------------- */

.boot {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.boot-seal {
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(160deg, #A93131, #8A2323);
    color: #FFF6E6;
    font-size: 38px;
    font-family: "Kaiti SC", "STKaiti", "KaiTi", var(--font);
    box-shadow: inset 0 0 0 2px rgba(233, 218, 185, 0.5), 0 8px 26px rgba(122, 32, 32, 0.25);
    animation: boot-pulse 1.8s ease-in-out infinite;
}

.boot-text {
    font-size: 11px;
    letter-spacing: 0.28em;
    color: var(--ink-faint);
}

@keyframes boot-pulse {

    0%,
    100% {
        opacity: 0.82;
    }

    50% {
        opacity: 1;
    }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: calc(12px + var(--safe-bottom)) 16px 12px;
    background: #FDF2F0;
    border-top: 1px solid rgba(156, 43, 43, 0.3);
    color: var(--accent);
    font-size: 12px;
    text-align: center;
}

#blazor-error-ui .reload {
    margin-left: 6px;
    color: var(--accent);
}

/* ============================================================
   起局快捷条（无下拉）
   ============================================================ */

.ctl-compact {
    padding: 10px;
    gap: 8px;
}

.ctl-top {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.ctl-time-chip {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 46px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, #FFFDF8, #FBF5EA);
    text-align: left;
}

.ctl-time-chip:active {
    background: var(--paper-mid);
}

.ctl-time-main {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.ctl-time-main b {
    margin-left: 7px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--ink);
}

.ctl-time-gz {
    margin-left: auto;
    font-size: 10px;
    color: var(--ink-faint);
    white-space: nowrap;
}

.ctl-chev {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    color: var(--ink-faint);
}

.ctl-now-btn {
    flex: 0 0 auto;
    width: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card-alt);
    color: var(--ink-soft);
    font-size: 9.5px;
    letter-spacing: 0.08em;
}

.ctl-now-btn:active {
    background: var(--paper-deep);
}

.ctl-now-btn svg {
    width: 17px;
    height: 17px;
}

.ctl-quick-row {
    display: flex;
    gap: 6px;
}

.ctl-quick {
    flex: 1 1 0;
    min-width: 0;
    height: 34px;
    padding: 0 4px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--card);
    color: var(--ink-soft);
    font-size: 11.5px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.ctl-quick:active {
    background: var(--paper-mid);
}

.ctl-quick.on {
    color: var(--gold-deep);
    border-color: rgba(176, 138, 62, 0.5);
    background: rgba(233, 218, 185, 0.28);
    font-weight: 600;
}

/* ---------------- 时间设置弹层 ---------------- */

.ts-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 2px;
}

.ts-row {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.ts-label {
    font-size: 11px;
    color: var(--ink-faint);
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.ts-stepper {
    display: grid;
    grid-template-columns: 32px 32px minmax(0, 1fr) 32px 32px;
    align-items: center;
    gap: 4px;
}

.ts-btn {
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--card);
    color: var(--ink-soft);
    font-size: 18px;
    line-height: 1;
}

.ts-btn:active {
    background: var(--paper-mid);
}

.ts-btn:disabled {
    opacity: 0.3;
}

.ts-btn-big {
    font-size: 12px;
    color: var(--ink-faint);
}

.ts-placeholder {
    border: 0;
    background: transparent;
    pointer-events: none;
}

.ts-value {
    text-align: center;
    font-size: 19px;
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.ts-note {
    margin: 2px 0 0;
    font-size: 10px;
    line-height: 1.65;
    color: var(--ink-faint);
}

.ts-switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0 1px;
}

.ts-switch-row .ts-label {
    letter-spacing: 0.06em;
}

.ts-hint {
    margin-left: auto;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
}

/* ---------------- 年命网格 ---------------- */

.ym-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding-bottom: 2px;
}

.ym-chip {
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--card);
    color: var(--ink);
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.ym-chip:active {
    background: var(--paper-mid);
}

.ym-chip.active {
    border-color: var(--gold);
    background: rgba(233, 218, 185, 0.45);
    font-weight: 600;
}

.ym-none {
    grid-column: 1 / -1;
    font-size: 12.5px;
    color: var(--ink-soft);
}

