/* ============================================================
   common.css —— 全站设计系统（浅色编辑风）
   ------------------------------------------------------------
   设计语言：纸感底 + 墨褐字 + 细线分隔 + 克制的朱砂/赭金/青碧点缀。
   取色参考 horosa.app 与项目内 .private/pages/skill.html。

   兼容策略：**保留原有变量名、只替换取值**，让已引用这些 token 的
   子应用（bazi / mingli / ganzhi / jinkoujue / lifecurve / fengshui）
   自动继承新外观；同时新增 --paper / --ink / --vermilion / --ochre /
   --jade / --hairline / --wx-* 供新代码使用。
   ============================================================ */

:root {
    /* ===== 纸面底色 ===== */
    --bg-deep: #f6f0e4;
    --bg-gradient-start: #fffaf0;
    --bg-gradient-mid: #f9f4e8;
    --bg-gradient-end: #f3ead7;

    --paper: #fffaf0;
    --paper-2: #f6f0e4;
    --paper-3: #efe5d2;
    --paper-4: #f3ead7;

    /* ===== 面板（取代玻璃拟态）=====
       原为半透明白 + backdrop-filter 模糊；编辑风改为实心纸面 + 细线，
       既更清晰，也省掉低端安卓 WebView 上的模糊渲染开销 */
    --glass-bg: #fffdf8;
    --glass-border: rgba(42, 36, 29, 0.14);
    --glass-shadow: 0 1px 2px rgba(42, 36, 29, 0.04);
    --glass-blur: 0px;

    /* ===== 点缀色 =====
       赭金：索引编号 / 图标 / 次级强调（与外壳的暖金形成一条线索）
       朱砂：主行动按钮 / hover 强调
       青碧：次要 / 成功 */
    --primary-gold: #b48a3c;
    --primary-gold-dim: #8f6d2c;
    --primary-gold-light: #cfa855;
    --ochre: #b48a3c;
    --vermilion: #a33a2a;
    --vermilion-dark: #872f24;
    --jade: #2f6f62;
    --accent-red: #a33a2a;
    --accent-blue: #3f5f86;
    --accent-green: #2f6f62;

    /* ===== 墨字 ===== */
    --ink: #17120d;
    --ink-body: #2a241d;
    --text-main: #2a241d;
    /* 次要文字：0.72 在纸底 #fffaf0 上约 5.4:1，达标 AA */
    --text-muted: rgba(42, 36, 29, 0.72);
    --text-dark: #17120d;
    /* 标题专用色：深墨褐，在纸底上约 15:1 */
    --text-heading: #17120d;
    /* 金色/朱砂实底上的文字：浅纸白，在 #b48a3c 上约 4.6:1、在 #a33a2a 上约 6.4:1 */
    --text-on-gold: #fffaf0;
    /* 错误/警示文字 */
    --text-danger: #8a2b2b;

    --paper-bg: #fffdf8;
    --paper-border: rgba(42, 36, 29, 0.14);

    /* ===== 细线 ===== */
    --hairline: rgba(42, 36, 29, 0.14);
    --hairline-strong: rgba(42, 36, 29, 0.28);

    /* ===== 五行（八字 / 金口诀等共用，取代各自的高饱和色）===== */
    --wx-jin: #a8823c;
    --wx-mu: #2f6f62;
    --wx-shui: #3f5f86;
    --wx-huo: #a33a2a;
    --wx-tu: #b08a5a;

    /* ===== 字体 ===== */
    --serif-cn: 'Noto Serif SC', 'Source Han Serif SC', 'Noto Serif CJK SC', 'Songti SC', serif;
    --sans: 'Montserrat', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;

    /* ===== 间距 / 圆角 / 缓动 ===== */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 999px;

    --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
    --duration-fast: 0.2s;
    --duration-normal: 0.3s;
}

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

body {
    font-family: var(--serif-cn);
    /* 编辑风：去掉金色渐变，改纯净纸底 */
    background: var(--paper);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* 原为两团金色径向光晕，编辑风下移除（保留选择器，便于子页面覆盖） */
body::before {
    display: none;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--serif-cn);
    font-weight: 700;
    /* 编辑风：由 2px 收到 .01em，大标题不再松散 */
    letter-spacing: 0.01em;
    color: var(--text-heading);
}

a {
    text-decoration: none;
    color: inherit;
}

/* ===== 纸面卡片 ===== */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
}

.content-container {
    flex: 1;
    position: relative;
    overflow: auto;
    padding-bottom: 70px;
    z-index: 1;
    -webkit-overflow-scrolling: touch;
}

.main-screen {
    width: 100%;
    height: 100%;
    display: block;
    opacity: 1;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.main-screen:not(.active) {
    display: none;
    opacity: 0;
}

.main-iframe {
    width: 100%;
    height: 100%;
    border: none;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.app-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* 用 animation 而非 transition：display 由 none 切到 block 时，
   transition 不会触发（元素本就在无过渡状态下首次渲染），此处原先
   的 opacity 过渡实际从未生效，属于无效代码 */
.app-iframe.active {
    display: block;
    animation: iframeFadeIn var(--duration-normal) var(--ease-out);
}

@keyframes iframeFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.tarot-iframe {
    height: 100% !important;
}

.bottom-nav {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: 65px;
    background: var(--paper);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    box-shadow: 0 8px 25px rgba(23, 18, 13, 0.08);
    padding: 0 var(--space-xs);
    transition: all 0.3s ease;
}

.bottom-nav-sub {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: 65px;
    background: var(--paper);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    box-shadow: 0 8px 25px rgba(23, 18, 13, 0.08);
    padding: 0 var(--space-xs);
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: all 0.3s ease;
}

.bottom-nav-sub.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#bottom-nav-sub .nav-btn {
    display: none;
}

#bottom-nav-sub .nav-btn.visible {
    display: flex;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 11px;
    transition: all var(--duration-normal) var(--ease-out);
    flex: 1;
    height: 100%;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.nav-btn i {
    font-size: 19px;
    margin-bottom: 4px;
    transition: transform var(--duration-normal) var(--ease-out);
}

.nav-btn.active {
    color: var(--text-heading);
}

.nav-btn.active i {
    transform: translateY(-2px);
}

.nav-btn.active::after {
    content: '';
    position: absolute;
    bottom: 5px;
    width: 4px;
    height: 4px;
    background: var(--vermilion);
    border-radius: 50%;
}

.more-interface {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--paper);
    display: none;
    flex-direction: column;
    z-index: 99;
    opacity: 0;
    transition: opacity var(--duration-normal);
}

.more-interface.active {
    display: flex;
    opacity: 1;
}

.more-content-wrapper {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.header-text {
    text-align: left;
    color: var(--text-main);
    margin-bottom: var(--space-xl);
    line-height: 1.9;
    font-size: 0.95rem;
    font-family: var(--serif-cn);
    border-bottom: 1px solid var(--hairline);
    padding-bottom: var(--space-md);
}

.buttons-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.more-btn {
    display: flex;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--glass-bg);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    color: var(--text-main);
    transition: all var(--duration-fast);
    position: relative;
    overflow: hidden;
}

.more-btn:hover {
    border-color: var(--hairline-strong);
    transform: translateY(-2px);
}

.more-btn i {
    font-size: 17px;
    margin-right: var(--space-md);
    color: var(--ochre);
    width: 24px;
    text-align: center;
}

.more-btn span {
    flex-grow: 1;
    font-weight: 500;
    letter-spacing: 1px;
}

.more-btn .fa-chevron-right {
    font-size: 13px;
    color: var(--text-muted);
    width: auto;
}

.footer-text {
    margin-top: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: var(--space-lg) 0;
}

/* ===== 子应用顶栏 =====
   原先 bazi / jinkoujue 各写一份完整规则，ganzhi / fengshui 直接把同样内容
   写成内联样式，四处重复且已出现不一致（bazi 的返回箭头被渲染两次）。
   这里收敛为唯一实现，子应用只保留结构。 */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 10px;
    position: relative;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--hairline);
}

.top-bar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: 0.06em;
}

/* 悬浮式顶栏：内容从下方滚过，用于需要标题常驻的页面（风水） */
.top-bar.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    margin-bottom: 0;
    background: var(--paper);
    z-index: 20;
    border-bottom: 1px solid var(--hairline);
}

.back-btn {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color var(--duration-fast), border-color var(--duration-fast);
}

.back-btn:hover {
    color: var(--vermilion);
    border-color: var(--vermilion);
}

/* 箭头统一由这里提供，子应用里不要再手写 ◀，否则会渲染成双箭头 */
.back-btn::before {
    content: '◀';
    font-size: 9px;
}

.back-btn:active {
    transform: translateY(-50%) scale(0.96);
}

/* ===== 按钮 ===== */
.button {
    padding: 10px 20px;
    border: 1px solid var(--hairline-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: transparent;
    color: var(--text-main);
    font-family: var(--serif-cn);
    letter-spacing: 1px;
}

.button:active {
    transform: scale(0.98);
}

.button:disabled {
    border-color: var(--hairline);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* 主行动：朱砂实底 */
.button.primary {
    background: var(--vermilion);
    color: var(--text-on-gold);
    border: none;
    box-shadow: 0 2px 8px rgba(163, 58, 42, 0.18);
}

.button.primary:hover {
    background: var(--vermilion-dark);
}

/* 次要行动：原 common.css 缺失此类，tarot 的 #redrawButton 因此只有基础样式；
   这里补齐，供全站复用 */
.button.secondary {
    background: var(--paper-3);
    color: var(--text-main);
    border: 1px solid var(--hairline);
}

.button.secondary:hover {
    border-color: var(--hairline-strong);
}

input, select, textarea {
    padding: 12px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--glass-bg);
    color: var(--text-main);
    outline: none;
    width: 100%;
    transition: border-color 0.3s;
    font-family: var(--serif-cn);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--ochre);
}

/* ===== 消息气泡（旧版命名，供未迁移的页面使用）===== */
.message {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    line-height: 1.7;
    max-width: 85%;
    margin-bottom: 16px;
    position: relative;
}

.message.user-message {
    background: var(--ink-body);
    color: var(--text-on-gold);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.message.assistant-message {
    background: var(--glass-bg);
    border: 1px solid var(--hairline);
    color: var(--text-main);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message.system-message {
    background: var(--paper-3);
    color: var(--text-muted);
    border: 1px solid var(--hairline);
    align-self: center;
    font-size: 0.9em;
    text-align: center;
}

/* ===== 弹窗 ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(23, 18, 13, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--paper);
    border: 1px solid var(--hairline);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 85%;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(23, 18, 13, 0.18);
    text-align: center;
    color: var(--text-main);
}

.modal-content h3 {
    color: var(--text-heading);
    margin-bottom: 12px;
}

.modal-close {
    margin-top: 16px;
    padding: 8px 20px;
    background: transparent;
    border: 1px solid var(--hairline-strong);
    color: var(--text-muted);
    border-radius: var(--radius-full);
    cursor: pointer;
}

.modal-image {
    width: 100%;
    max-width: 280px;
    height: auto;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
}

.modal-text {
    font-size: 1.2rem;
    color: var(--text-heading);
    margin-bottom: var(--space-lg);
    font-weight: 600;
}

.modal-close-btn {
    padding: 10px 30px;
    background: var(--vermilion);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-on-gold);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.modal-close-btn:hover {
    background: var(--vermilion-dark);
}

/* ============================================================
   模型切换条（modelbar.js 自注入）
   ------------------------------------------------------------
   一行放两件事：左侧「模型」下拉，右侧「今日剩余 N 次」。
   做成细长条而不是卡片：它出现在每个应用页的最上方，体量一大就把
   真正的功能挤下去了；用户大部分时间不会看它，需要时才扫一眼。
   ============================================================ */
.modelbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--paper-2);
    border-bottom: 1px solid var(--hairline);
    font-family: 'Noto Sans SC', var(--serif-cn), sans-serif;
    font-size: 12.5px;
    color: var(--text-muted);
    /* 铺满整行：它注入在 .top-bar 之后 / body 最前，两个位置的父容器宽度不同，
       统一 width:100% + box-sizing 才不会在某种布局下多出 12px 横向滚动条 */
    width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
}

.modelbar[hidden] { display: none; }

.modelbar__label {
    color: var(--text-muted);
    flex: none;
    letter-spacing: 0.04em;
}

.modelbar__select {
    /* flex-basis 必须是 0，不能是 auto —— 这是本行「会不会换行」的关键。
       换行判定用的是 flex-basis（auto = 最长那个 option 的文字宽度，实测 232px），
       「模型 + 下拉 + 倍数标 + 剩余次数」在 430px 屏上合计 389px > 可用 374px，
       于是剩余次数被挤到第二行，整条变成 73px 高。
       改成 basis:0 后基准宽度是 0，四项能排进一行，下拉自己去分剩下的空间；
       再给 min-width 一个下限，保证它不会缩到看不见。 */
    flex: 1 1 0;
    min-width: 96px;
    max-width: 62%;
    padding: 3px 6px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--text-main);
    background: var(--glass-bg);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
}

.modelbar__select:disabled {
    opacity: 0.6;
    cursor: default;
}

/* 倍数小标：只在 >1 时出现，用赭金呼应全站的点缀色 */
.modelbar__mult {
    flex: none;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-on-gold);
    background: var(--ochre);
    border-radius: var(--radius-full, 20px);
    padding: 1px 7px;
}

.modelbar__mult[hidden] { display: none; }

/* 剩余次数靠右：与下拉拉开距离，视线扫过去时不会跟模型名混在一起 */
.modelbar__quota {
    margin-left: auto;
    flex: none;
    white-space: nowrap;
}

.modelbar__quota--empty {
    color: var(--text-danger);
}

/* 无工具提示：只有选了「不支持函数调用」的模型、且当前是命理类应用时才出现。
   单独占一行（flex-basis:100%）—— 这句话 27 个字，跟在四项后面必然把条挤成两行；
   独占一行反而干净，且它是「解释性文字」，不需要跟控件同排。
   颜色走 muted 而不是 danger：这不是错误，是能力差异，吓唬用户没意义。 */
.modelbar__note {
    flex: 1 1 100%;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text-muted);
    opacity: 0.85;
}

.modelbar__note[hidden] { display: none; }

/* ============================================================
   设置按钮 + 侧滑面板（modelbar.js 自注入，全应用统一）
   ------------------------------------------------------------
   每个 AI 应用右上角一个齿轮按钮，点开右侧滑出"设置"面板，
   面板里放「切换模型 + 倍数 + 今日剩余次数」。
   样式从 mingli/style.css 收敛到 common.css：五个应用 + 命理共用同一份，
   不再各页各写一套（改一处就全站生效）。
   ⚠️ 图标不依赖 FontAwesome：个别页面没引 fa6，用纯字符 ⚙ / × 最稳。
   ============================================================ */
.settings-btn {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 17px;
    cursor: pointer;
    z-index: 450;
    color: var(--text-heading);
    transition: transform 0.3s ease;
}
.settings-btn[hidden] { display: none; }
.settings-btn:active { transform: rotate(90deg); }

.settings-panel {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100%;
    background: var(--paper);
    border-left: 1px solid var(--glass-border);
    box-shadow: -10px 0 30px rgba(180, 138, 60, 0.18);
    z-index: 500;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}
.settings-panel.active { right: 0; }
.settings-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}
.settings-header h3 { margin: 0; color: var(--text-heading); font-family: 'Cinzel', serif; letter-spacing: 0.05em; }
.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    min-width: 36px;
    min-height: 36px;
}
.close-btn:active { color: var(--text-heading); }
.settings-content { padding: 20px; flex: 1; }

/* 设置面板内的「切换模型」分组 */
.settings-group {
    padding: 14px 0;
    border-bottom: 1px solid var(--glass-border);
}
.settings-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}
/* 放进面板后，模型条改为纵向排布：下拉整行 + 倍数 + 剩余次数 依次向下 */
.settings-group .modelbar {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    background: none;
    border: none;
    padding: 0;
}
.settings-group .modelbar__select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: var(--glass-bg);
    color: var(--text-main);
    font-size: 14px;
}
.settings-group .modelbar__mult,
.settings-group .modelbar__quota,
.settings-group .modelbar__note {
    font-size: 12px;
    color: var(--text-muted);
}
.settings-group .modelbar__quota { margin-left: 0; }

/* ============================================================
   全站体验优化层（2026-09-21）
   仅作用于交互元素、不改布局、不依赖 JS —— 对 13 个 app 同时生效。
   ============================================================ */

/* 移动端即时响应：去掉双击缩放的 300ms 等待（pan/pinch 仍保留，不伤可达性） */
a, button, input, select, textarea, label, summary,
[role="button"], [role="tab"], .clickable {
    touch-action: manipulation;
}

/* 指针设备上的可点击光标（原生 button 才有，role=button/自定义按钮补上） */
button:not(:disabled),
[role="button"]:not(:disabled),
input[type="submit"]:not(:disabled),
input[type="button"]:not(:disabled),
input[type="checkbox"]:not(:disabled),
input[type="radio"]:not(:disabled),
select:not(:disabled),
.clickable {
    cursor: pointer;
}
button:disabled, [role="button"][aria-disabled="true"] { cursor: not-allowed; }

/* 键盘/指针可达性：只在键盘聚焦时画焦点环，不干扰鼠标点击 */
:focus-visible {
    outline: 3px solid var(--vermilion, #a33a2a);
    outline-offset: 2px;
}

/* 界面 chrome 禁止误选中拖动（输入框、正文仍可选，复制不受影响） */
button, .nav-item, .side-nav, [role="tab"], .brand, .chip {
    -webkit-user-select: none;
    user-select: none;
}

/* 阻止 iframe 内的过度滚动链，避免误触发外层下拉刷新/橡皮筋 */
html, body { overscroll-behavior-y: contain; }

/* 尊重系统「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}
