:root {
            /* 墨色基底 */
            --ink-darkest: #0a0604;
            --ink-dark: #14100a;
            --ink-medium: #1f1810;

            /* 紙金 */
            --paper-cream: #f5ead0;
            --paper-warm:  #eddfbf;
            --paper-shadow:#d8c69a;
            --paper-deep:  #c2ad7c;

            /* 古銅金 */
            --gold-bright: #f0d28a;
            --gold-primary:#c9a65a;
            --gold-deep:   #8a6a26;
            --gold-shadow: #5e4818;

            /* 朱砂 / 印泥紅 */
            --vermilion:        #9c2826;
            --vermilion-deep:   #6b1818;
            --vermilion-bright: #b53a36;

            /* 墨綠 / 竹綠 */
            --moss:  #4a6b3e;

            /* 玄紫 */
            --purple-mystic: #6b2d7d;

            /* 文字色 */
            --text-ink:    #2a1f12;
            --text-muted:  #5b4a30;
            --text-on-dark:#e6d4a8;
        }

        * { box-sizing: border-box; }

        html, body {
            margin: 0;
            padding: 0;
        }

        body {
            min-height: 100vh;
            font-family: "Noto Serif TC", "Source Han Serif TC", "PingFang TC", serif;
            color: var(--text-on-dark);
            background-color: var(--ink-darkest);
            background-image:
                radial-gradient(ellipse 80% 60% at 50% 35%, rgba(201, 166, 90, 0.12) 0%, transparent 65%),
                radial-gradient(ellipse 60% 50% at 50% 100%, rgba(156, 40, 38, 0.06) 0%, transparent 55%),
                linear-gradient(180deg, var(--ink-darkest) 0%, var(--ink-dark) 50%, var(--ink-darkest) 100%);
            background-attachment: fixed;
            position: relative;
            overflow-x: hidden;
        }

        /* 紙紋噪點覆蓋 */
        body::before {
            content: "";
            position: fixed;
            inset: 0;
            pointer-events: none;
            opacity: 0.06;
            mix-blend-mode: overlay;
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.5 0'/></filter><rect width='200' height='200' filter='url(%23n)'/></svg>");
            z-index: 1;
        }

        main {
            position: relative;
            z-index: 2;
            max-width: 1320px;
            margin: 0 auto;
            padding: 60px 28px 80px;
        }

        /* ====== 頁面標題 ====== */
        .site-header {
            text-align: center;
            margin-bottom: 56px;
            position: relative;
        }

        .site-header::before,
        .site-header::after {
            content: "";
            position: absolute;
            top: 50%;
            width: clamp(40px, 14vw, 160px);
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--gold-primary), transparent);
        }
        .site-header::before { left: max(0px, calc(50% - 320px)); }
        .site-header::after  { right: max(0px, calc(50% - 320px)); }

        .site-title {
            font-family: "Noto Serif TC", serif;
            font-weight: 900;
            font-size: clamp(34px, 5vw, 52px);
            margin: 0;
            letter-spacing: 0.3em;
            color: var(--paper-cream);
            text-indent: 0.3em;
            background: linear-gradient(180deg, var(--gold-bright) 0%, var(--paper-cream) 35%, var(--gold-primary) 100%);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            position: relative;
            display: inline-block;
        }

        /* 印章式紅章 */
        .subtitle {
            font-family: "Cinzel", "Noto Serif TC", serif;
            font-style: italic;
            font-size: 14px;
            color: var(--text-on-dark);
            opacity: 0.7;
            margin-top: 12px;
            letter-spacing: 0.18em;
        }
        .subtitle .subtitle-en {
            opacity: 0.7;
        }
        .designer-name {
            font-family: "Noto Serif TC", serif;
            font-style: normal;
            font-weight: 500;
            color: var(--gold-primary);
            text-decoration: none;
            border-bottom: 1px dotted var(--gold-primary);
            padding-bottom: 1px;
            margin-left: 8px;
            letter-spacing: 0.1em;
            transition: color 0.2s, border-color 0.2s;
        }
        .designer-name:hover {
            color: var(--gold-bright);
            border-bottom-color: var(--gold-bright);
            border-bottom-style: solid;
        }

        /* ====== App 主容器 ====== */
        .app-container {
            display: grid;
            grid-template-columns: minmax(320px, 420px) 1fr;
            gap: 56px;
            align-items: start;
        }

        /* ====== 左側控制面板（宣紙感卡片） ====== */
        .control-panel {
            background:
                linear-gradient(180deg, var(--paper-cream) 0%, var(--paper-warm) 100%);
            border-radius: 6px;
            padding: 36px 36px 32px;
            position: relative;
            box-shadow:
                0 30px 60px -20px rgba(0, 0, 0, 0.6),
                0 0 0 1px rgba(201, 166, 90, 0.4),
                inset 0 0 0 1px rgba(255, 255, 255, 0.4);
        }

        /* 卡片紙紋 */
        .control-panel::before {
            content: "";
            position: absolute;
            inset: 0;
            border-radius: 6px;
            opacity: 0.4;
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.4  0 0 0 0 0.2  0 0 0 0.4 0'/></filter><rect width='300' height='300' filter='url(%23n)'/></svg>");
            mix-blend-mode: multiply;
            pointer-events: none;
        }

        /* 雙線邊框 */
        .control-panel::after {
            content: "";
            position: absolute;
            inset: 10px;
            border: 1px solid var(--gold-deep);
            border-radius: 3px;
            pointer-events: none;
            opacity: 0.35;
        }

        .panel-content {
            position: relative;
            z-index: 1;
        }

        .panel-title {
            font-family: "Noto Serif TC", serif;
            font-weight: 700;
            font-size: 22px;
            color: var(--text-ink);
            text-align: center;
            letter-spacing: 0.4em;
            text-indent: 0.4em;
            margin: 0 0 28px;
        }

        .divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--gold-deep), transparent);
            margin: 22px 0;
            opacity: 0.45;
        }

        .field-label {
            display: block;
            font-family: "Noto Serif TC", serif;
            font-size: 13px;
            font-weight: 500;
            color: var(--text-muted);
            letter-spacing: 0.3em;
            text-indent: 0.3em;
            margin-bottom: 10px;
            text-align: center;
        }

        .input-row {
            display: flex;
            align-items: baseline;
            justify-content: center;
            gap: 10px;
            margin-bottom: 16px;
        }

        input[type="number"] {
            width: 130px;
            padding: 8px 10px;
            font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
            font-size: 26px;
            font-weight: 700;
            text-align: center;
            color: var(--text-ink);
            background: rgba(255, 250, 235, 0.6);
            border: none;
            border-bottom: 1.5px solid var(--gold-deep);
            outline: none;
            transition: border-color 0.2s;
        }
        input[type="number"]:focus {
            border-bottom-color: var(--vermilion);
        }
        input[type="number"]::-webkit-outer-spin-button,
        input[type="number"]::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }
        input[type="number"] { -moz-appearance: textfield; }

        .deg-symbol {
            font-family: "Noto Sans TC", sans-serif;
            font-size: 20px;
            color: var(--text-muted);
            font-weight: 500;
        }

        /* 客製化 range slider */
        input[type="range"] {
            -webkit-appearance: none;
            appearance: none;
            width: 100%;
            background: transparent;
            margin: 12px 0 4px;
            cursor: pointer;
        }
        input[type="range"]::-webkit-slider-runnable-track {
            height: 2px;
            background: linear-gradient(90deg, var(--gold-deep), var(--gold-primary), var(--gold-deep));
            border-radius: 1px;
        }
        input[type="range"]::-moz-range-track {
            height: 2px;
            background: var(--gold-deep);
            border-radius: 1px;
        }
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: radial-gradient(circle at 35% 30%, var(--gold-bright), var(--gold-primary) 60%, var(--gold-deep));
            border: 1px solid var(--gold-shadow);
            margin-top: -8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
            cursor: pointer;
            transition: transform 0.15s;
        }
        input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
        input[type="range"]::-moz-range-thumb {
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: var(--gold-primary);
            border: 1px solid var(--gold-shadow);
            cursor: pointer;
        }

        /* 局位顯示 */
        .ju-display {
            text-align: center;
            font-family: "Noto Serif TC", serif;
            font-weight: 700;
            font-size: 22px;
            letter-spacing: 0.18em;
            color: var(--text-ink);
            padding: 18px 0 16px;
            transition: color 0.3s ease;
        }
        .ju-display .deg-num {
            font-family: "Noto Sans TC", "PingFang TC", sans-serif;
            font-weight: 700;
            font-size: 24px;
            color: inherit;
            margin: 0 4px;
        }
        .ju-display.is-warning  { color: var(--vermilion); }
        .ju-display.is-bian     { color: #b85525; }

        /* 資訊區（古文書） */
        .info-display {
            background: linear-gradient(180deg, rgba(255, 250, 235, 0.55), rgba(245, 234, 208, 0.55));
            border-left: 3px solid var(--vermilion);
            border-right: 1px solid rgba(201, 166, 90, 0.3);
            padding: 18px 20px;
            min-height: 90px;
            position: relative;
        }
        .info-display p {
            margin: 8px 0;
            font-family: "Noto Serif TC", serif;
            font-size: 16px;
            line-height: 1.7;
            color: var(--text-ink);
            letter-spacing: 0.06em;
        }
        .info-display p:first-child { margin-top: 0; }
        .info-display p:last-child  { margin-bottom: 0; }

        .info-display .highlight-xt,
        .info-display .highlight-ht {
            color: var(--purple-mystic);
            font-weight: 700;
            border-bottom: 1px dotted var(--purple-mystic);
            padding-bottom: 1px;
        }

        .kongwang-msg {
            color: var(--vermilion-deep) !important;
            font-size: 18px !important;
            font-weight: 700 !important;
            text-align: center;
            line-height: 1.7;
        }

        /* 開關 */
        .toggle-row {
            margin-top: 22px;
            padding-top: 22px;
            border-top: 1px dashed var(--paper-deep);
            display: flex;
            justify-content: center;
        }
        .toggle-row + .toggle-row {
            margin-top: 14px;
            padding-top: 0;
            border-top: none;
        }

        /* 下載按鈕 */
        .action-row {
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px dashed var(--paper-deep);
            display: flex;
            justify-content: center;
        }
        .ornate-btn {
            font-family: "Noto Serif TC", serif;
            font-weight: 700;
            font-size: 15px;
            color: var(--text-ink);
            background: linear-gradient(180deg, #f4e6c2 0%, #e0cb95 100%);
            border: 1px solid var(--gold-deep);
            border-radius: 3px;
            padding: 11px 28px;
            letter-spacing: 0.32em;
            text-indent: 0.32em;
            cursor: pointer;
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.6),
                0 2px 6px rgba(94, 72, 24, 0.25);
            transition: all 0.18s ease;
            position: relative;
        }
        .ornate-btn:hover {
            background: linear-gradient(180deg, #f0d28a 0%, #c9a65a 100%);
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.7),
                0 4px 12px rgba(94, 72, 24, 0.35);
            transform: translateY(-1px);
        }
        .ornate-btn:active {
            transform: translateY(0);
            box-shadow:
                inset 0 1px 2px rgba(94, 72, 24, 0.4),
                0 1px 2px rgba(94, 72, 24, 0.2);
        }
        .ornate-btn.is-loading {
            opacity: 0.6;
            cursor: wait;
            pointer-events: none;
        }

        .toggle-label {
            display: inline-flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            user-select: none;
            font-family: "Noto Serif TC", serif;
            font-size: 15px;
            font-weight: 500;
            color: var(--gold-deep);
            letter-spacing: 0.18em;
            transition: color 0.2s;
        }
        .toggle-label:hover { color: var(--vermilion); }

        .toggle-label input[type="checkbox"] {
            -webkit-appearance: none;
            appearance: none;
            width: 18px;
            height: 18px;
            border: 1.5px solid var(--gold-deep);
            background: rgba(255, 250, 235, 0.5);
            border-radius: 2px;
            cursor: pointer;
            position: relative;
            margin: 0;
            transition: all 0.2s;
        }
        .toggle-label input[type="checkbox"]:checked {
            background: var(--vermilion);
            border-color: var(--vermilion);
        }
        .toggle-label input[type="checkbox"]:checked::after {
            content: "";
            position: absolute;
            left: 4px;
            top: 0px;
            width: 6px;
            height: 11px;
            border: solid var(--paper-cream);
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }

        /* ====== 右側羅盤 ====== */
        .compass-stage {
            position: relative;
            width: 100%;
            max-width: 720px;
            margin: 0 auto;
            aspect-ratio: 1;
        }

        /* 羅盤底盤光暈 */
        .compass-stage::before {
            content: "";
            position: absolute;
            inset: -4%;
            border-radius: 50%;
            background: radial-gradient(circle at 50% 45%, rgba(240, 210, 138, 0.25) 0%, transparent 70%);
            filter: blur(20px);
            z-index: 0;
        }

        .compass-frame {
            position: relative;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background:
                radial-gradient(circle at 30% 25%, var(--paper-cream) 0%, var(--paper-warm) 60%, var(--paper-shadow) 100%);
            box-shadow:
                0 30px 80px -20px rgba(0, 0, 0, 0.7),
                0 0 0 4px var(--gold-deep),
                0 0 0 5px rgba(0, 0, 0, 0.4),
                0 0 0 12px var(--ink-medium),
                0 0 0 14px var(--gold-primary),
                inset 0 0 60px rgba(138, 106, 38, 0.18);
            overflow: hidden;
            z-index: 1;
        }

        /* 羅盤紙紋 */
        .compass-frame::before {
            content: "";
            position: absolute;
            inset: 0;
            border-radius: 50%;
            opacity: 0.35;
            mix-blend-mode: multiply;
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.55' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.4  0 0 0 0 0.3  0 0 0 0 0.15  0 0 0 0.5 0'/></filter><rect width='400' height='400' filter='url(%23n)'/></svg>");
            pointer-events: none;
            z-index: 2;
        }

        /* 中央天池外環光 */
        .compass-frame::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 19%;
            height: 19%;
            border-radius: 50%;
            background: radial-gradient(circle, transparent 55%, rgba(138, 106, 38, 0.25) 75%, transparent 85%);
            pointer-events: none;
            z-index: 4;
        }

        svg.luopan {
            width: 100%;
            height: 100%;
            display: block;
            position: relative;
            z-index: 3;
        }

        /* 白底套圖模式：勾選後羅盤本體變成乾淨白底，方便擷取套圖 */
        body.is-clean .compass-stage::before { display: none; }
        body.is-clean .compass-frame {
            background: #ffffff;
            box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
        }
        body.is-clean .compass-frame::before,
        body.is-clean .compass-frame::after { display: none; }
        body.is-clean .plate-bg { fill: #ffffff; }
        body.is-clean .taiji-paper { fill: #ffffff; }

        /* ====== 頁尾 ====== */
        .site-footer {
            margin-top: 60px;
            text-align: center;
            font-family: "Cinzel", "Noto Serif TC", serif;
            font-size: 12px;
            color: var(--text-on-dark);
            opacity: 0.45;
            letter-spacing: 0.22em;
        }
        .site-footer .dot {
            display: inline-block;
            margin: 0 12px;
            color: var(--gold-primary);
            opacity: 0.6;
        }

        /* ====== 響應式 ====== */
        @media (max-width: 980px) {
            main { padding: 40px 18px 60px; }
            .app-container {
                grid-template-columns: 1fr;
                gap: 40px;
            }
            .control-panel {
                max-width: 480px;
                margin: 0 auto;
            }
            .compass-stage { max-width: 560px; }
            .site-header::before,
            .site-header::after { display: none; }
        }

        @media (max-width: 520px) {
            .site-title { letter-spacing: 0.18em; }
            .control-panel { padding: 28px 22px 24px; }
            .panel-title { font-size: 19px; }
            input[type="number"] { width: 105px; font-size: 24px; }
            .ju-display { font-size: 19px; }
            .info-display p { font-size: 15px; }
        }

        /* 入場動畫 */
        @keyframes fadeUp {
            from { opacity: 0; transform: translateY(12px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to   { opacity: 1; }
        }
        .site-header { animation: fadeUp 0.8s ease-out both; }
        .control-panel { animation: fadeUp 0.8s 0.2s ease-out both; }
        .compass-stage { animation: fadeIn 1.2s 0.3s ease-out both; }
        .site-footer { animation: fadeIn 1.5s 0.7s ease-out both; }

        /* 二十四山字顏色過渡（被標為曜煞時平滑變色） */
        #dizhi-group text {
            transition: fill 0.25s ease;
        }
        /* 曜煞標記淡入 */
        #yao-sha-marks > g,
        #shui-kou-marks > g {
            animation: fadeIn 0.35s ease both;
        }
