/* dm-refine.css — DuMingStudio 全站精致化层 v20261116a
   目标：缩放/平板/手机自适应、焦点与弹窗可达、低对比修正、简约精致的统一质感。
   原则：只加令牌与低特异性增强，不推翻现有暖金主题与首页糖果卡定稿；
        不恢复任何已永久删除的元素；不写死版本号当缓存键（由 nginx 注入处带 ?v=）。 */

:root{
  --dm-r-focus:#ffc65c;
  --dm-r-hair:rgba(255,255,255,.10);
  --dm-r-gold:#ffc65c;
  --dm-r-radius:14px;
  --dm-r-radius-sm:9px;
  --dm-r-ease:cubic-bezier(.2,.8,.2,1);
}
html[data-dm-theme="light"]{
  --dm-r-focus:#a85b08;
  --dm-r-hair:rgba(90,55,10,.16);
}

/* ---------- 1 基础润物 ---------- */
html{
  -webkit-text-size-adjust:100%; text-size-adjust:100%;
  /* 不在这里写 overflow-x:clip：它会让 body 的百分比高度塌陷，
     导致 /programming/ 这类 height:100% 布局变成空白页。 */
}
/* 编程中心这类整屏工作台：显式高度，避免受任何根元素溢出规则影响 */
body:has(> .shell) > .shell{height:100dvh}
body{min-width:0}
img,video{max-width:100%}
::selection{background:rgba(255,198,92,.34);color:#fff}

*{scrollbar-width:thin;scrollbar-color:rgba(255,198,92,.55) transparent}
*::-webkit-scrollbar{width:9px;height:9px}
*::-webkit-scrollbar-track{background:transparent}
*::-webkit-scrollbar-thumb{
  background:linear-gradient(180deg,rgba(255,198,92,.62),rgba(168,91,8,.62));
  border:2px solid transparent; border-radius:99px; background-clip:padding-box;
}

:where(p,li,td,th,dd,dt,label,figcaption){line-height:1.65}
:where(h1,h2,h3,h4){line-height:1.25;letter-spacing:-.015em}
:where(h1,h2,h3){text-wrap:balance}

/* 卡片圆角与悬浮：用 :where() 保持低特异性，站点自定义规则优先 */
:where(.card,.entry,.hub-card,.course-card,.lv-card,.panel,.box,.tile){
  border-radius:var(--dm-r-radius);
  transition:transform .24s var(--dm-r-ease),box-shadow .24s var(--dm-r-ease),border-color .24s var(--dm-r-ease);
}
@media (hover:hover) and (prefers-reduced-motion:no-preference){
  :where(.card,.entry,.hub-card,.course-card,.lv-card):hover{
    transform:translateY(-3px);
    box-shadow:0 14px 34px rgba(0,0,0,.20);
  }
}

:where(button,.btn,[role="button"],summary){
  cursor:pointer; -webkit-tap-highlight-color:transparent;
  transition:transform .18s var(--dm-r-ease),filter .18s ease,border-color .18s ease,box-shadow .18s ease;
}
@media (hover:hover){:where(button,.btn,[role="button"]):not(:disabled):hover{filter:brightness(1.07)}}
:where(button,.btn):not(:disabled):active{transform:translateY(1px) scale(.986)}
:where(button,.btn):disabled{cursor:not-allowed;opacity:.55}

:where(a){text-underline-offset:.22em;text-decoration-thickness:1px}
:where(main a,.content a,article a):hover{text-decoration-color:var(--dm-r-gold)}
:where(table){border-collapse:collapse}
:where(th){font-weight:650}
:where(tbody tr:hover){background:rgba(255,198,92,.045)}
:where(input,textarea,select){font:inherit}

/* ---------- 2 焦点可见（WCAG 2.4.7） ---------- */
:where(a[href],button,input,textarea,select,summary,[role="button"],[tabindex]):focus-visible{
  outline:3px solid var(--dm-r-focus) !important;
  outline-offset:2px !important;
}
/* 站点里 outline:none!important 的输入框由上面覆盖；同时保留自身边框提示 */

/* 触屏目标 ≥44px（只作用于可点控件，不影响行内文字链接） */
@media (pointer:coarse){
  :where(nav a,button,.btn,[role="button"],summary,.tab,.tabs a,.picker-options button){
    min-height:44px;
  }
  :where(nav a,.tab,.tabs a,button,.btn){
    display:inline-flex; align-items:center; justify-content:center;
  }
  :where(input[type="checkbox"],input[type="radio"]){min-height:0}
}

/* ---------- 3 表格横向滚动（由 dm-refine.js 包装） ---------- */
.dm-r-table-wrap{max-width:100%;overflow-x:auto;overscroll-behavior-x:contain}
.dm-r-table-wrap:focus-visible{outline:3px solid var(--dm-r-focus);outline-offset:2px}

/* ---------- 4 弹窗质感（由 dm-refine.js 打标） ---------- */
.dm-refine-dialog:not([hidden]){backdrop-filter:blur(6px)}
.dm-refine-dialog-card{
  border-radius:18px !important;
  box-shadow:0 24px 70px rgba(0,0,0,.55) !important;
  animation:dm-r-pop .24s var(--dm-r-ease) both;
}
@keyframes dm-r-pop{from{opacity:0;transform:translateY(9px) scale(.985)}to{opacity:1;transform:none}}

/* ---------- 5 缩放 / 窄屏 / 矮屏 ---------- */
@media (max-width:1024px){
  :where(.container,.wrap,.page,.shell,.content){
    padding-left:clamp(16px,3vw,28px); padding-right:clamp(16px,3vw,28px);
  }
}
@media (max-width:768px){
  :where(.grid,.cards,.row,[class*="-grid"]>*,[class*="-list"]>*){min-width:0}
  :where(.grid,.cards){gap:12px}
  :where(.hero,.banner,.jumbotron){gap:14px}
}
@media (max-width:560px){
  :where(.grid,.cards):not(.dm-r-keep-grid){
    grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));
  }
  :where(.toolbar,.actions,.btn-row){flex-wrap:wrap;gap:8px}
  :where(.toolbar button,.actions button,.btn-row button){flex:0 1 auto}
}
/* 浏览器缩放等于缩小 CSS 视口；矮屏时任何「锁死一屏」都让位给可滚动 */
@media (max-height:620px){
  :where(html,body){overflow-y:auto}
}

/* ---------- 6 动效与高对比偏好 ---------- */
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.01ms !important; animation-iteration-count:1 !important;
    transition-duration:.01ms !important; scroll-behavior:auto !important;
  }
}
@media (prefers-contrast:more){
  :where(.hint,.muted,.meta,.tip,small){opacity:1 !important}
  :where(.card,.entry,.panel,.box){border-color:var(--dm-r-hair) !important}
}

/* ---------- 7 门户首页：解除强制单屏（保留视觉，不恢复已删元素） ----------
   文档级 html 规则必须用 :has(body#dmHome) 锁定「仅首页」。
   若写成裸 html，会把 height:auto !important 泄漏到全站，
   摧毁 star / programming 等依赖 html,body{height:100%} 的整屏布局，
   让 body 塌成 84px、3D 舞台与成绩瀑布流变 0 高（2026-11-17 事故根因）。 */
html:has(body#dmHome), html body#dmHome{height:auto !important;min-height:100dvh;overflow-x:clip;overflow-y:auto !important}
html body#dmHome{min-height:100dvh}
#homeMain{padding-top:clamp(16px,3vh,34px);padding-bottom:clamp(16px,3vh,30px)}
#dmHome .hero .lede{max-width:52ch}
#dmHome .start-picker-trigger{min-height:46px;padding:0 22px}
@media (max-width:480px){
  #dmHome .hero .lede{font-size:12.5px}
  #dmHome .start-picker-trigger{width:100%;max-width:260px}
}

/* ---------- 8 竞赛成绩页：深色小字对比 + 窄屏可滚 ---------- */
html[data-dm-theme="dark"] .camera .tbtn,
html[data-dm-theme="dark"] .camera .wf-total,
html[data-dm-theme="dark"] .camera .focus-badge .sb,
html[data-dm-theme="dark"] .camera .stage .tourbar{
  color:rgba(231,235,240,.78) !important;   /* ≈9:1，原 .48 仅 4.3:1 */
}
.camera .tbtn,.camera .wf-total,.camera .focus-badge .sb,.camera .stage .tourbar{
  font-size:max(11px,1em) !important;
}
@media (max-width:760px),(max-height:620px){
  html:has(body > .camera),body:has(> .camera){
    height:auto !important; min-height:100dvh; overflow-y:auto !important;
  }
  body > .camera{min-height:100dvh;height:auto}
}

/* ---------- 9 AI 课程中心：缩放/窄屏不裁切，小字抬到可读 ---------- */
@media (max-width:900px),(max-height:620px){
  html:has(body > #app),body:has(> #app){overflow-y:auto !important;height:auto !important;min-height:100dvh}
  body > #app{height:auto;min-height:100dvh}
}
html .dm-nav .dm-links a .dm-link-sub{font-size:11px !important;opacity:.9 !important}
html #app .side-sub,html #app .prog-txt span,html #app .t-sub,
html #app .l-state,html #app .tt-count,html #app .nav-caption span,
html #app .t-chev{font-size:12px}
html #app .hl-meta{color:var(--muted-fg,#e8d6b4);opacity:.92}
html #app .dm-ai-msg .dm-ai-who{opacity:.85}

/* 各主题内 9–11px 说明文字统一抬到 11px 以上（保持原配色与布局） */
html #app .hl-hint,html #app .hl-help,html #app .task-card small,
html #app .live-hud,html #app .st-legend,html #app .node-quest,
html #app .chip-sub,html #app .npc-tag,html #app .scene-tip{font-size:11px}

/* ---------- 10 横滚导航/工具栏：保留可发现的细滚动条 ---------- */
.dm-nav .dm-links,.ed-bar{scrollbar-width:thin !important}
.dm-nav .dm-links::-webkit-scrollbar,.ed-bar::-webkit-scrollbar{display:block !important;height:5px}
.dm-nav .dm-links::-webkit-scrollbar-thumb,.ed-bar::-webkit-scrollbar-thumb{
  background:rgba(255,198,92,.45);border-radius:99px;border:1px solid transparent;background-clip:padding-box;
}

/* ---------- 11 编程四站 / OJ / Blockly：窄屏与缩放不裁切 ---------- */
@media (max-width:980px){
  html.wxapp .wrap{min-width:0 !important;width:100%}
  html.wxapp .compare-pane{min-width:0}
}
@media (max-width:900px),(max-height:620px){
  body.dm-star #app{height:auto;min-height:100dvh}
  body.dm-star .view{overflow:visible}
  .ed-body .CodeMirror{min-height:220px;height:300px}
}
@media (max-width:820px),(max-height:620px){
  html:has(.app.mode-problem),body:has(.app.mode-problem){
    height:auto !important;min-height:100dvh;overflow-y:auto !important;
  }
  .app.mode-problem{height:auto;min-height:100dvh}
  .ws-code{height:44%;min-height:208px}
}
/* Blockly 三栏在窄屏已有降级；这里只防止内容被外力挤出横向滚动 */
html:has(.board) .board,html:has(.board) .main{max-width:100%}
/* 判题/运行区域的细滚动条替代完全隐藏 */
.ed-bar::-webkit-scrollbar{width:5px;height:5px}

/* ---------- 12 三个入口页：统一版式与卡片语言 ---------- */
:where(body[data-page="course"],body:has(> .shell),html:has(#app[data-tk="home"])){
  --hub-ink:#fdf4e3; --hub-sub:rgba(253,244,227,.66);
  --hub-line:rgba(255,198,92,.16); --hub-surface:rgba(255,255,255,.045);
  --hub-accent:#ffc65c;
}
html[data-dm-theme="light"] :where(body[data-page="course"],body:has(> .shell),html:has(#app[data-tk="home"])){
  --hub-ink:#2f2417; --hub-sub:rgba(47,36,23,.66);
  --hub-line:rgba(122,80,30,.16); --hub-surface:rgba(255,255,255,.7);
  --hub-accent:#a85b08;
}
body[data-page="course"] .hub-grid,
body:has(> .shell) .hub-grid{
  display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr));
  gap:14px; max-width:1180px; margin-inline:auto;
}
#app[data-tk="home"] .course-grid{
  display:grid; grid-template-columns:repeat(4,minmax(0,1fr));
  gap:14px; max-width:1120px; margin-inline:auto;
}
#app[data-tk="home"] .cc-head{flex-wrap:nowrap;gap:8px;min-width:0}
#app[data-tk="home"] .cc-name{
  min-width:0; flex:1 1 auto; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
#app[data-tk="home"] .cc-name small{
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
#app[data-tk="home"] .cc-count{flex:none}
#app[data-tk="home"] .cc-caret{flex:none;opacity:.6}
body[data-page="course"] .tcard,
body:has(> .shell) .hub-card,
#app[data-tk="home"] .course-card{
  min-height:168px; padding:16px; border-radius:16px;
  border:1px solid var(--hub-line);
  background:linear-gradient(160deg,var(--hub-surface),rgba(0,0,0,.05));
  box-shadow:0 6px 18px rgba(0,0,0,.16);
  display:flex; flex-direction:column; gap:10px;
  color:var(--hub-ink); text-align:left;
  transition:transform .24s var(--dm-r-ease),box-shadow .24s ease,border-color .24s ease;
}
@media (hover:hover){
  body[data-page="course"] .tcard:hover,
  body:has(> .shell) .hub-card:hover,
  #app[data-tk="home"] .course-card:hover{
    transform:translateY(-3px); border-color:rgba(255,198,92,.42);
    box-shadow:0 14px 30px rgba(0,0,0,.28);
  }
}
body[data-page="course"] .tc-name,
body:has(> .shell) .hc-name,
#app[data-tk="home"] .cc-name{
  font-size:15px; font-weight:800; line-height:1.25; color:var(--hub-ink);
}
body[data-page="course"] .tc-name small,
#app[data-tk="home"] .cc-name small{
  display:block; font-size:10px; font-weight:600; letter-spacing:.12em;
  color:var(--hub-sub); margin-top:2px;
}
body[data-page="course"] .tc-count,
body:has(> .shell) .hc-count,
#app[data-tk="home"] .cc-count{
  font-size:11px; font-weight:750; color:var(--hub-accent);
  background:rgba(255,198,92,.10); border:1px solid var(--hub-line);
  padding:3px 8px; border-radius:999px; white-space:nowrap;
}
body[data-page="course"] .tc-desc,
body:has(> .shell) .hc-desc,
#app[data-tk="home"] .cc-desc{
  font-size:12px; line-height:1.6; color:var(--hub-sub); margin:0;
  display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden;
}
body[data-page="course"] .tc-tags span,
#app[data-tk="home"] .cc-tags span{
  font-size:10px; padding:2px 8px; border-radius:999px;
  background:rgba(255,198,92,.09); border:1px solid var(--hub-line); color:var(--hub-sub);
}
body[data-page="course"] .tc-bar,
body:has(> .shell) .hc-bar,
#app[data-tk="home"] .cc-bar{
  height:4px; border-radius:99px; background:rgba(127,127,127,.18);
  margin-top:auto; overflow:hidden; flex:none;
}
body[data-page="course"] .tc-foot,
body:has(> .shell) .hc-cta,
#app[data-tk="home"] .cc-cta{
  font-size:11px; font-weight:750; color:var(--hub-accent);
  display:inline-flex; align-items:center; gap:6px; text-decoration:none;
}
body[data-page="course"] .hub-head h1,
body:has(> .shell) .hub-head h1,
#app[data-tk="home"] .home-head h1{
  font-size:clamp(24px,2.6vw,34px); font-weight:850; letter-spacing:-.02em;
  color:var(--hub-ink); text-align:center;
}
body[data-page="course"] .hub-head p,
body:has(> .shell) .hub-head p,
#app[data-tk="home"] .home-stat{
  font-size:12px; color:var(--hub-sub); text-align:center;
}
