/* ============ 共享组件（Layer 2 · components） ============
 * 跨页面可复用的 UI 原子/组件：页头、卡片、按钮、题型卡片、题目卡片(renderCard)、
 * 页面控制器、四线格等。所有视觉原子属性引用 shared/styles/tokens.css 的变量。
 * 依赖：tokens（变量） → base（reset）。
 * 注意：题目卡片(.question-card 家族)由 PluginUtil.renderCard 类化输出，样式统一在此维护，
 *       插件自定义卡片请复用这些类，不要内联重复样式。
 */
@layer components {

/* 年级文字（纯文字，无胶囊/背景，字号与科目一致 2.0rem） */
.page-title .pt-grade {
    font-size: 2.0rem;
    font-weight: 600;
    letter-spacing: 2px;
    opacity: 0.9;
}

/* 二级页面主标题统一标准：logo + 年级 + 科目，左右/上下居中，大小协调。
   用法：<div class="page-header"><div class="page-title">
          <span class="pt-logo"><img src="assets/logo-*.png" alt="科目"></span>
          <span class="pt-grade" id="gradeBadge">一年级</span>
          <h1 class="pt-subject">数学</h1></div>
        <p>副标题（可选）</p></div>
   logo 高度随 --header-title-size 协调缩放；年级与科目均为纯文字、大小递减、三者 flex 垂直居中。 */
.page-header {
    /* --header-title-size 已在 tokens.css（:root）统一定义 */
    display: flex;
    flex-direction: column;
    align-items: center;       /* 左右居中 */
    justify-content: center;   /* 上下居中 */
    gap: 8px;
    text-align: center;
    color: #fff;
    margin-bottom: 20px;
}
.page-title {
    display: flex;
    align-items: center;       /* 上下居中：logo / 年级 / 科目 垂直对齐 */
    justify-content: center;   /* 左右居中 */
    gap: 14px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.page-title .pt-logo {
    display: inline-flex;
    align-items: center;
}
/* logo 高度随标题字号协调缩放（约 1.7 倍），保证图文大小比例一致 */
.page-title .pt-logo img {
    height: calc(var(--header-title-size) * 1.7);
    width: auto;
    object-fit: contain;
    display: block;
}
.page-title .pt-subject {
    margin: 0;
    font-size: var(--header-title-size);
    font-weight: 800;
    letter-spacing: 1px;
    line-height: 1.15;
}
.page-header p { margin: 0; font-size: 1rem; opacity: 0.95; }

/* 卡片：淡蓝透明玻璃效果 */
.card {
    background: rgba(255,255,255,0.35);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1.5px solid rgba(255,255,255,0.6);
    border-radius: 24px;
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18);
}

/* 设置面板 */
.settings-card {
    background: var(--card);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    margin-bottom: 30px;
}
.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    margin-bottom: 18px;
}
.setting-group {
    flex: 1;
    min-width: 180px;
}
.setting-group label {
    display: block;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 10px;
    font-size: 0.95rem;
}

/* 表单控件 */
.number-input, .select-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
    background: var(--card);
}
.number-input:focus, .select-input:focus {
    outline: none;
    border-color: var(--brand);
}

/* 按钮 */
.btn {
    padding: 12px 28px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 8px;
}
.btn-primary {
    background: var(--toolbar-btn-grad);
    color: #fff;
    box-shadow: 0 4px 14px rgba(102,126,234,0.4);
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102,126,234,0.5);
}
.btn-success {
    background: linear-gradient(135deg, #11998e, #38ef7d);
    color: #fff;
    box-shadow: 0 4px 14px rgba(56,239,125,0.4);
}
.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56,239,125,0.5);
}
.btn-warning {
    background: var(--grad-cta);
    color: #fff;
    box-shadow: 0 4px 14px rgba(247,151,30,0.4);
}
.btn-warning:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(247,151,30,0.5);
}
.btn-danger {
    background: linear-gradient(135deg, #eb3349, #f45c43);
    color: #fff;
    box-shadow: 0 4px 14px rgba(235,51,73,0.4);
}
.btn-danger:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(235,51,73,0.5);
}
.btn-info {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    color: #fff;
    box-shadow: 0 4px 14px rgba(79,172,254,0.4);
}
.btn-info:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79,172,254,0.5);
}

/* 辅助提示 */
.helper-note {
    margin-top: 8px;
    color: #7c5cff;
    font-size: 0.86rem;
    font-weight: 600;
}

/* 题型选择卡片 */
.type-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 18px;
}
.type-grid.two-col { grid-template-columns: repeat(2, 1fr); }
.type-grid.three-col { grid-template-columns: repeat(3, 1fr); }
.type-grid.four-col { grid-template-columns: repeat(4, 1fr); }
.type-card {
    display: block;
    width: 100%;
    padding: 26px 14px;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 20px;
    cursor: pointer;
    text-align: center;
    user-select: none;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}
/* 图标 / 标题 / 描述三段式卡片结构（一级、二级页面通用） */
.type-card .t-icon { display: block; font-size: 2rem; line-height: 1.2; margin-bottom: 6px; }
.type-card .t-name, .type-card .t-title { font-size: 1.02rem; font-weight: 800; display: inline-block; vertical-align: middle; max-width: 100%; overflow-wrap: anywhere; }
.type-card .t-desc { display: block; margin-top: 8px; font-size: 0.8rem; color: #5a6b8c; line-height: 1.5; }
/* 键盘可达性：Tab 聚焦时与 hover 同等反馈 */
.type-card:focus-visible {
    outline: 3px solid rgba(91,141,239,.55); outline-offset: 2px;
    transform: translateY(-4px);
}
/* 入场过渡：卡片列表淡入上浮，轻微错峰（prefers-reduced-motion 时关闭） */
@keyframes type-card-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}
.type-grid > .type-card, .type-grid > .type-cell, .type-grid > .section-label {
    animation: type-card-in .32s ease-out both;
}
.type-grid > :nth-child(2)  { animation-delay: .03s; }
.type-grid > :nth-child(3)  { animation-delay: .06s; }
.type-grid > :nth-child(4)  { animation-delay: .09s; }
.type-grid > :nth-child(5)  { animation-delay: .12s; }
.type-grid > :nth-child(6)  { animation-delay: .15s; }
.type-grid > :nth-child(n+7) { animation-delay: .18s; }
@media (prefers-reduced-motion: reduce) {
    .type-grid > .type-card, .type-grid > .type-cell, .type-grid > .section-label { animation: none; }
    .type-card, .type-card:hover, .type-card:focus-visible { transform: none; transition: none; }
}

/* 禁用/占位态统一语义：不可点击、灰色 --muted 视觉 */
.type-card[aria-disabled='true'] { cursor: default; }
.type-card.coming-soon,
.type-card.competition {
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}
.type-card.coming-soon {
    opacity: 0.6;
    border-style: dashed;
}
.type-card.coming-soon:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(255,255,255,0.65);
}
.type-card.coming-soon .t-name { color: var(--muted); }
/* 竞赛等未上线模块：灰底置灰、虚线边框、悬停无位移（点击行为由各页面以占位提示承接） */
.type-card.competition {
    background: linear-gradient(160deg, rgba(230,236,244,.75), rgba(206,215,230,.55));
    border: 1.5px dashed rgba(122,135,156,.55);
    color: var(--muted);
    box-shadow: none;
}
.type-card.competition:hover {
    transform: none;
    background: linear-gradient(160deg, rgba(230,236,244,.9), rgba(206,215,230,.7));
    box-shadow: none;
    border-color: rgba(122,135,156,.8);
}
.type-card.competition .t-name { color: var(--muted); }
.type-card.competition .t-icon { filter: grayscale(.75); opacity: .8; }
.type-card.competition .t-desc { color: var(--muted); }

/* ============ 卡片操作按钮 (P7: 练习 + 打印) ============ */
.type-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    justify-content: center;
}
.type-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 8px;
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
}
.type-btn.practice {
    background: var(--grad-cta);
    color: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(245,166,35,.3);
}
.type-btn.practice:hover {
    filter: brightness(1.05);
}
.type-btn.print {
    background: #fff;
    color: var(--brand);
    border: 2px solid var(--brand);
}
.type-btn.print:hover {
    background: var(--brand);
    color: #fff;
}
.type-card.disabled .type-btn {
    opacity: 0.5;
    pointer-events: none;
}

/* ============ 加载骨架屏（题型卡片占位，避免内容跳动） ============ */
.skel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}
.type-card.skel-card {
    pointer-events: none;
    min-height: 118px;
    position: relative;
    overflow: hidden;
}
.skel-card::after {
    content: '';
    position: absolute; inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
    animation: skel-shimmer 1.4s infinite;
}
@keyframes skel-shimmer { 100% { transform: translateX(100%); } }
.skel-card .skel-line { height: 14px; border-radius: 7px; background: rgba(120,140,170,.22); margin: 9px auto 0; }
.skel-card .skel-line.i { width: 34px; height: 34px; border-radius: 10px; margin-top: 4px; }
.skel-card .skel-line.t { width: 56%; height: 17px; }
.skel-card .skel-line.s { width: 78%; }
@media (prefers-reduced-motion: reduce) {
    .skel-card::after { animation: none; }
}

/* ============ 错误状态组件（无效参数 / 加载失败友好提示） ============ */
.error-state {
    max-width: 520px;
    margin: var(--spacing-lg) auto;
    padding: var(--spacing-lg);
    text-align: center;
    background: rgba(255,255,255,.92);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.error-state .es-icon { font-size: 3rem; line-height: 1; }
.error-state .es-title { font-size: 1.15rem; font-weight: 800; color: var(--ink); margin: 12px 0 6px; }
.error-state .es-desc { font-size: .86rem; color: var(--muted); line-height: 1.7; margin-bottom: var(--spacing-md); word-break: break-all; }
.error-state .es-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.es-btn {
    display: inline-block; cursor: pointer; text-decoration: none;
    border-radius: 12px; padding: 10px 22px; font-size: .9rem; font-weight: 700; transition: .18s;
}
.es-btn.primary { background: var(--grad-cta); color: #fff; box-shadow: 0 4px 14px rgba(245,166,35,.35); }
.es-btn.primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.es-btn.ghost { border: 1.5px solid var(--line-strong); color: var(--brand-d); background: #fff; }
.es-btn.ghost:hover { border-color: var(--brand); background: var(--brand-bg); }

/* 段落标签 */
.section-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 20px;
    padding-left: 12px;
    border-left: 5px solid var(--brand);
}

/* 底部提示 */
.foot-tip {
    text-align: center;
    color: #fff;
    opacity: 0.85;
    margin-top: 25px;
    font-size: 0.9rem;
}

/* ============ 页面控制器 ============ */
.page-controller {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    z-index: 1000;
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
}
.pc-inner {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    padding: 0 6px;
    justify-content: center;
}
.pc-inner::-webkit-scrollbar { display: none; }
.pc-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 10px;
    min-width: 56px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.pc-item .pc-icon { font-size: 1.2rem; line-height: 1; }
.pc-item.active {
    color: var(--brand);
    background: var(--brand-bg);
}
.pc-item:active { transform: scale(0.95); }

/* 平板/桌面端：顶部标签栏 */
@media (min-width: 768px) {
    .page-controller {
        position: static;
        background: transparent;
        box-shadow: none;
        padding: 0;
        margin-bottom: 18px;
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
    }
    .pc-inner {
        justify-content: flex-start;
        padding: 0;
        gap: 8px;
        overflow-x: auto;
    }
    .pc-item {
        flex-direction: row;
        gap: 5px;
        padding: 9px 18px;
        font-size: 0.88rem;
        min-width: auto;
        background: rgba(255,255,255,0.18);
        color: rgba(255,255,255,0.85);
        border-radius: 10px;
        backdrop-filter: blur(10px);
    }
    .pc-item.active {
        background: rgba(255,255,255,0.95);
        color: var(--brand);
        box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    }
    .pc-item:hover:not(.active) {
        background: rgba(255,255,255,0.3);
    }
}

/* 移动端底部栏占位 */
.has-page-controller {
    padding-bottom: 75px;
}
@media (min-width: 768px) {
    .has-page-controller {
        padding-bottom: 0;
    }
}

/* 四线格拼音 */
.pinyin-grid {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--paper-fourline-bg);
    background-image:
        linear-gradient(var(--paper-fourline-rule) 1px, transparent 1px),
        linear-gradient(var(--paper-fourline-rule) 1px, transparent 1px),
        linear-gradient(var(--paper-fourline-rule) 1px, transparent 1px),
        linear-gradient(var(--paper-fourline-rule) 1px, transparent 1px);
    background-size: 100% 9px;
    background-position: 0 0, 0 8px, 0 16px, 0 24px;
    background-repeat: no-repeat;
    height: 32px;
    padding: 0 10px;
    border-radius: 4px;
    font-size: 1.1rem;
    font-family: "Times New Roman", "Georgia", serif;
    color: var(--ink);
    letter-spacing: 1px;
    line-height: 32px;
    border: 1px solid #f0d0d0;
    min-width: 50px;
}

/* ============ 题目卡片（PluginUtil.renderCard 类化输出，勿删——插件渲染依赖） ============
 * renderCard 只输出 class，样式统一在此维护。 */
.question-card {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    gap: var(--q-header-gap) var(--q-grid-gap);
    overflow: hidden;
    /* 保留原有样式属性 */
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: var(--card-padding-screen);
    position: relative;
    text-align: left;
    background: var(--card);
    align-self: start;
    justify-self: start;
}
.question-card .q-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--q-header-gap);
    margin: 2px 0 6px;

}
.question-card .num {
    flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    vertical-align: middle; flex-shrink: 0;
    background: var(--brand-bg); color: var(--brand-d);
    font-weight: 800; font-size: 12px;
}
.question-card .q-text {
    display: inline;
    font-size: 17px;
    font-weight: 800;
    color: var(--ink);
    vertical-align: middle;
}
.question-card .scene-box {
    grid-row: 2;
    max-width: var(--q-scene-max-width);
    max-height: var(--q-scene-max-height);
    margin: 0 auto;
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 8px; background: var(--soft-bg);
    border-radius: 8px;

}
/* 共享 SVG 生成器（svg-core/svg-geometry/svg-calculation/svg-make-ten）输出：
   带 viewBox 的完整 <svg>。窄屏等比收缩、打印按容器宽度缩放。 */
.question-card .scene-box svg {
    max-width: 100%; height: auto;
}
.question-card .q-hint { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.question-card .options {
    grid-row: 4;
    display: flex; flex-wrap: wrap;
    justify-content: flex-start; gap: var(--q-grid-gap);
    margin: 4px 0 0;}

/* 选项（choice 题型）：原生 <button role=radio>，键盘可达 + 可见焦点环 */
.question-card .opt {
    appearance: none; -webkit-appearance: none;
    font: inherit; font-size: var(--q-option-size); font-weight: 600; line-height: 1.2;
    color: var(--ink); background: var(--soft-bg);
    border: 2px solid var(--line-strong); border-radius: 8px;
    padding: 6px 14px; cursor: pointer; margin: 0;
}
.question-card .opt:hover { border-color: var(--brand); }
.question-card .opt:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.question-card .opt.chosen {
    background: var(--brand-bg); border-color: var(--brand); color: var(--brand-d);
    box-shadow: 0 2px 8px rgba(51, 95, 181, .18);
}

.question-card .input-group {
    grid-row: 4;
    display: flex; align-items: center; gap: var(--q-grid-gap);
    margin-top: 4px;
}

.question-card .unit { font-size: 13px; color: var(--muted); font-weight: 600; }

.question-card .qa-row {
    display: flex; align-items: center; justify-content: flex-start;
    gap: 6px; flex-wrap: wrap; margin: 6px 0;
}

.question-card .qa-label { font-size: 12px; font-weight: 700; color: var(--muted); }

.question-card .formula-inp {
    width: 120px; height: 32px;
    border: 2px dashed var(--line-strong); border-radius: 7px;
    font-size: 15px; font-weight: 700; text-align: center;
    color: var(--brand-d); background: var(--soft-bg); outline: none;
}

/* 答案输入框：默认宽 96px；调用方传 opts.inputWidth 时由内联 style 覆盖 */
.answer-inp {
    width: 96px; height: 32px;
    border: 2px dashed var(--line-strong); border-radius: 7px;
    font-size: 15px; font-weight: 700; text-align: center;
    color: var(--brand-d); background: var(--soft-bg); outline: none;
}

.question-card .feedback { font-size: 12px; font-weight: 700; min-height: 16px; margin-top: 6px; }

/* 紧凑模式（P2.3）：仅服务「屏幕」紧凑场景（口算/填空卡片，density=compact 时由 html-renderer 挂类）。
 * 打印试卷排版不经过本类——打印端为无框无底练习单，样式单一来源 shared/presentation/print.js PRINT_QCSS（P1.1/P1.3）。
 * 两侧语义一致（紧凑=省版面），数值各自独立演进；compact 本类不新增卡片框/阴影/底色。 */
.question-card.compact {
  --q-card-padding: 8px 10px;
  --q-text-size: 14px;
  --q-scene-max-width: 120px;
  --q-scene-max-height: 80px;
  --q-grid-gap: 8px;
}

.question-card.compact .q-header {
    grid-template-columns: auto 1fr;
    gap: var(--q-header-gap);
}

.question-card.compact .scene-box {
    max-width: 120px;
    max-height: 80px;
    margin: 0 auto;
}

.question-card.compact .options {
    grid-row: auto;
    flex-direction: row;
    gap: 4px;
}

.question-card.compact .input-group {
    margin-top: 2px;
}

/* 全局提示（任务6：插件 meta.tip，仅显示一次） */
.global-tip {
  background: var(--soft-bg);
  border-left: 4px solid var(--brand-d);
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.global-tip .tip-inner {
  max-width: 100%;
}

/* ============ 新渲染器（html-renderer.js / PluginUtil.layout）题目卡片内层结构 ============
 * 屏幕端此前无样式（仅在 shared/presentation/print.js PRINT_QCSS 内定义），导致屏幕与打印不一致。
 * 此处补齐与打印端等价的屏幕样式，保证题干/选项/图形/答题线一致呈现（P0 排版一致性修复）。 */
.question-stem { font-size: 15px; line-height: 1.5; font-weight: 600; }
.question-stem .num { display: inline-block; min-width: 18px; font-weight: 800; color: #1A1B1C; }
.question-graphic { margin: 6px 0 4px; text-align: center; }
.question-graphic svg { max-width: 100%; height: auto; }
.question-options { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 15px; }
.question-options .option-letter { display: inline-block; min-width: 20px; font-weight: 700; color: #7c5cff; margin-right: 4px; }
.question-answer { margin-top: 6px; min-height: 20px; border-bottom: 1px dashed #b9c6de; }
.question-answer-print { min-height: 20px; }
.feedback { display: none; }
.feedback:not(:empty) { display: block; }
