/**
 * 交互内容模块 —— 前台样式
 *
 * 全部使用 ti- 前缀作命名空间，避免与主题既有样式互相污染。
 * 颜色一律走主题 CSS 变量，因此自动跟随 [data-theme="dark"] 暗色模式。
 *
 * @package PurpleDream
 * @since 1.1.0
 */

/* ========== 局部变量：把主题变量映射为模块变量 ========== */
.ti-grid,
.ti-section {
    --ti-card-bg: var(--bg-color, #fff);
    --ti-card-border: var(--border-color, #eee);
    --ti-fg: var(--text-color, #333);
    --ti-muted: var(--text-secondary, #6b6b6b);
    --ti-accent: var(--primary-color, #54a4f3);
    --ti-soft: rgba(84, 164, 243, .1);
    --ti-stage-bg: var(--secondary-bg, #f7f9fc);
    --ti-radius: 14px;
}

/* ========== 分区标题 ========== */
.ti-section {
    margin: 34px 0;
}

.ti-section-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--ti-fg);
    margin-bottom: 8px;
    padding-left: 12px;
    border-left: 4px solid var(--ti-accent);
    line-height: 1.4;
}

.ti-section-hint {
    font-size: .85rem;
    font-weight: 400;
    color: var(--ti-muted);
}

.ti-section-sub {
    color: var(--ti-muted);
    font-size: .95rem;
    margin: 0 0 22px;
    line-height: 1.7;
}

/* ========== 卡片栅格 ========== */
.ti-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 24px 0;
}

.ti-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ti-stage-head {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
    color: var(--ti-fg);
}

/* ========== 卡片本体 ========== */
.ti-card {
    background: var(--ti-card-bg);
    border: 1px solid var(--ti-card-border);
    border-radius: var(--ti-radius);
    padding: 22px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 26px;
    align-items: start;
    transition: box-shadow .25s ease, border-color .25s ease;
}

.ti-card:hover {
    box-shadow: 0 10px 30px rgba(0, 0, 0, .07);
    border-color: rgba(84, 164, 243, .35);
}

.ti-card.ti-layout-stage,
.ti-card.ti-layout-bare {
    grid-template-columns: 1fr;
}

.ti-card.ti-layout-bare {
    padding: 0;
    border: none;
    background: transparent;
}

.ti-card.ti-layout-bare:hover {
    box-shadow: none;
}

/* ========== 左侧信息面板 ========== */
.ti-info {
    border-right: 1px solid var(--ti-card-border);
    padding-right: 24px;
    min-width: 0;
}

.ti-info-head {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    margin-bottom: 3px;
}

.ti-num {
    color: var(--ti-accent);
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
}

.ti-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ti-fg);
}

.ti-tag {
    margin-left: auto;
    font-size: .7rem;
    font-weight: 500;
    background: var(--ti-soft);
    color: var(--ti-accent);
    padding: 3px 11px;
    border-radius: 40px;
    letter-spacing: .3px;
    white-space: nowrap;
}

.ti-stage-head .ti-tag {
    margin-left: 0;
}

.ti-en {
    font-size: .75rem;
    color: var(--ti-accent);
    letter-spacing: .5px;
    text-transform: uppercase;
    margin-bottom: 16px;
    opacity: .85;
}

.ti-field {
    margin-bottom: 12px;
}

.ti-label {
    font-size: .7rem;
    font-weight: 600;
    color: var(--ti-accent);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 3px;
}

.ti-value {
    font-size: .9rem;
    line-height: 1.65;
    color: var(--ti-fg);
    word-break: break-word;
}

.ti-value p {
    margin: 0 0 6px;
}

.ti-prompt {
    margin-top: 15px;
    background: var(--ti-soft);
    border-radius: 12px;
    padding: 12px 13px;
}

.ti-prompt .ti-value {
    font-size: .82rem;
    background: var(--ti-card-bg);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 5px;
    line-height: 1.6;
}

/* ========== 右侧预览区 ========== */
.ti-preview {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.ti-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.ti-caption {
    font-size: .7rem;
    font-weight: 600;
    color: var(--ti-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.ti-tabs {
    display: inline-flex;
    background: var(--ti-stage-bg);
    border: 1px solid var(--ti-card-border);
    border-radius: 30px;
    padding: 3px;
    gap: 2px;
}

.ti-tab {
    border: none;
    background: transparent;
    color: var(--ti-muted);
    font-size: .78rem;
    font-weight: 500;
    padding: 5px 15px;
    border-radius: 30px;
    cursor: pointer;
    transition: background .2s, color .2s;
    font-family: inherit;
    line-height: 1.5;
}

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

.ti-tab.is-active {
    background: var(--ti-accent);
    color: #fff;
}

.ti-actions {
    display: inline-flex;
    gap: 6px;
}

.ti-act {
    width: 30px;
    height: 30px;
    border: 1px solid var(--ti-card-border);
    background: var(--ti-card-bg);
    color: var(--ti-muted);
    border-radius: 9px;
    cursor: pointer;
    font-size: .78rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color .2s, border-color .2s, background .2s;
    padding: 0;
}

.ti-act:hover {
    color: var(--ti-accent);
    border-color: var(--ti-accent);
    background: var(--ti-soft);
}

/* ========== 舞台 / iframe ========== */
.ti-pane {
    display: none;
}

.ti-pane.is-active {
    display: block;
}

.ti-stage {
    position: relative;
    background: var(--ti-stage-bg);
    border: 1px dashed var(--ti-card-border);
    border-radius: var(--ti-radius);
    overflow: hidden;
    min-height: 120px;
}

.ti-frame {
    display: block;
    width: 100%;
    height: 150px;
    border: 0;
    background: transparent;
    transition: height .22s ease;
}

.ti-stage.is-fixed .ti-frame {
    transition: none;
}

.ti-stage.is-ready {
    border-style: solid;
}

/* 载入指示 */
.ti-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ti-stage-bg);
    transition: opacity .25s ease;
}

.ti-stage.is-ready .ti-loading {
    opacity: 0;
    pointer-events: none;
}

.ti-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--ti-card-border);
    border-top-color: var(--ti-accent);
    border-radius: 50%;
    animation: ti-spin .7s linear infinite;
}

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

/* 全屏 */
.ti-preview:fullscreen {
    background: var(--ti-card-bg);
    padding: 24px;
    overflow: auto;
}

.ti-preview:fullscreen .ti-stage {
    height: calc(100vh - 110px);
}

.ti-preview:fullscreen .ti-frame {
    height: 100% !important;
}

/* ========== 源码面板 ========== */
.ti-pane-code {
    border: 1px solid var(--ti-card-border);
    border-radius: var(--ti-radius);
    overflow: hidden;
}

.ti-code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 9px;
    background: var(--ti-stage-bg);
    border-bottom: 1px solid var(--ti-card-border);
}

.ti-code-tabs {
    display: inline-flex;
    gap: 3px;
}

.ti-code-tab {
    border: none;
    background: transparent;
    color: var(--ti-muted);
    font-size: .74rem;
    font-weight: 600;
    padding: 4px 11px;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: .4px;
    transition: background .2s, color .2s;
}

.ti-code-tab:hover {
    color: var(--ti-accent);
}

.ti-code-tab.is-active {
    background: var(--ti-soft);
    color: var(--ti-accent);
}

.ti-copy {
    border: 1px solid var(--ti-card-border);
    background: var(--ti-card-bg);
    color: var(--ti-muted);
    font-size: .74rem;
    padding: 4px 11px;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color .2s, border-color .2s;
}

.ti-copy:hover {
    color: var(--ti-accent);
    border-color: var(--ti-accent);
}

.ti-copy.is-done {
    color: #2e9e5b;
    border-color: #2e9e5b;
}

.ti-code-block {
    display: none;
}

.ti-code-block.is-active {
    display: block;
}

/* 覆盖 prism 默认外边距，贴合卡片 */
.ti-code-block pre {
    margin: 0 !important;
    border-radius: 0 !important;
    max-height: 380px;
    overflow: auto;
    font-size: .82rem;
}

.ti-code-block pre code {
    font-size: .82rem;
}

/* ========== 报错提示 ========== */
.ti-error {
    background: rgba(224, 82, 82, .1);
    border: 1px solid rgba(224, 82, 82, .35);
    color: #d9534f;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: .8rem;
    line-height: 1.6;
    word-break: break-word;
}

.ti-notice {
    background: var(--ti-soft, rgba(84, 164, 243, .1));
    border: 1px dashed var(--primary-color, #54a4f3);
    color: var(--text-color, #333);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: .88rem;
    line-height: 1.6;
    margin: 16px 0;
}

/* ========== 响应式 ========== */
@media (max-width: 900px) {
    .ti-card {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 18px;
    }

    .ti-info {
        border-right: none;
        border-bottom: 1px solid var(--ti-card-border);
        padding-right: 0;
        padding-bottom: 16px;
    }

    .ti-section-title {
        font-size: 1.2rem;
    }
}

@media (max-width: 600px) {
    .ti-bar {
        gap: 8px;
    }

    .ti-tab {
        padding: 5px 12px;
        font-size: .74rem;
    }

    .ti-code-block pre {
        max-height: 280px;
    }
}

/* 尊重用户的减少动效偏好 */
@media (prefers-reduced-motion: reduce) {

    .ti-frame,
    .ti-loading,
    .ti-card {
        transition: none;
    }

    .ti-spinner {
        animation-duration: 2s;
    }
}
