:root {
  --bg: #faf7fc;
  --panel: #ffffff;
  --panel-2: #fcfaff;
  --text: #1f1830;
  --text-2: #443a58;
  --muted: #6a6078;
  --faint: #918aa3;
  --border: #ece3f5;
  --axis: #ded3ec;
  --accent: #7a4bc8;
  --accent-deep: #3f2170;
  --accent-soft: #f6f0fe;
  --chip: #efe4fb;
  --danger: #d9534f;
  --warning: #c9871a;
  --ok: #2e7d5b;
  --shadow: 0 1px 2px rgba(38,22,66,.06), 0 8px 24px rgba(38,22,66,.06);
  --plot-bg: #ffffff;

  /* --solid 是「深底白字」实心按钮的底色；--hdr-* 是顶栏专用层，
     魔法模式顶栏要换成浅粉底深玫字，不能跟着 accent 走。 */
  --solid: #5e33a0;
  --hdr-bg: linear-gradient(135deg,#3f2170 0%,#7a4bc8 56%,#b06bc9 100%);
  --hdr-fg: #ffffff;
  --hdr-btn-fg: rgba(255,255,255,.86);
  --hdr-btn-bg: rgba(255, 255, 255, .12);
  --hdr-btn-bd: rgba(255, 255, 255, .32);
  --hdr-btn-hover: rgba(255, 255, 255, .26);
  --hdr-tab-on-bg: #ffffff;
  --hdr-tab-on-fg: #3f2170;
  --hdr-logo-bd: rgba(255, 255, 255, .5);
  --hdr-shadow: 0 2px 12px rgba(63,33,112,.18);
}

body.dark {
  --bg: #130d1e;
  --panel: #1e1630;
  --panel-2: #191227;
  --text: #efe9f8;
  --text-2: #d2c8e6;
  --muted: #a79dc0;
  --faint: #857ba0;
  --border: #342a4a;
  --axis: #453a5e;
  --accent: #b98cf0;
  --accent-deep: #dcc0ff;
  --accent-soft: #271c3c;
  --chip: #302448;
  --danger: #e57373;
  --warning: #d9a441;
  --ok: #5fbf94;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 28px rgba(0,0,0,.3);
  --plot-bg: #1e1630;
  --hdr-bg: linear-gradient(135deg,#1b0f2e 0%,#3d1f66 58%,#5b2a7d 100%);
  --hdr-tab-on-fg: #2a1450;
}

/* 魔法模式：鹿目圆印象色（淡樱 + 奶油白 + 星金），顶栏浅底深字 */
body.magic {
  --bg: #fff6fa;
  --panel: #ffffff;
  --panel-2: #fffafc;
  --text: #3b1526;
  --text-2: #5f2a42;
  --muted: #8c5c72;
  --faint: #b38d9e;
  --border: #f8dce8;
  --axis: #f1c9d9;
  --accent: #ec6e9c;
  --accent-deep: #a83a64;
  --accent-soft: #ffeff6;
  --chip: #ffdcea;
  --danger: #d9534f;
  --warning: #c9871a;
  --ok: #2e7d5b;
  --shadow: 0 1px 2px rgba(122,28,66,.06), 0 8px 24px rgba(122,28,66,.07);
  --plot-bg: #fffdfe;
  --solid: #a83a64;
  --hdr-bg: linear-gradient(135deg,#ffd9e8 0%,#f7bcd4 52%,#e8a8c6 100%);
  --hdr-fg: #7b2f4d;
  --hdr-btn-fg: #8a4260;
  --hdr-btn-bg: rgba(255, 255, 255, .62);
  --hdr-btn-bd: rgba(214, 120, 155, .36);
  --hdr-btn-hover: rgba(255, 255, 255, .95);
  --hdr-tab-on-bg: #ffffff;
  --hdr-tab-on-fg: #a83a64;
  --hdr-logo-bd: rgba(255, 255, 255, .9);
  --hdr-shadow: 0 1px 3px rgba(122,28,66,.07), inset 0 -2px 0 #e8b84b;
}

body.magic input[type="range"],
body.magic input[type="checkbox"] { accent-color: var(--accent-deep); }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .25s, color .25s;
  font-size: 13px;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ================= 顶栏 ================= */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px; height: 46px;
  background: var(--hdr-bg); color: var(--hdr-fg);
  box-shadow: var(--hdr-shadow); z-index: 5; flex: none;
}
.brand { font-size: 16px; font-weight: 700; letter-spacing: .4px; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.brand .brand-ico {
  width: 1.55em; height: 1.55em; flex: none;
  border-radius: 8px; object-fit: cover;
  border: 1px solid var(--hdr-logo-bd);
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
  background: #ffd7e6;
}
.brand .sig {
  font-size: 10px; font-weight: 500; padding: 2px 7px; border-radius: 20px;
  background: var(--hdr-btn-bg); border: 1px solid var(--hdr-btn-bd); letter-spacing: .3px;
}
nav.tabs { display: flex; gap: 2px; margin-left: 6px; overflow-x: auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button { flex: none; }
nav.tabs button {
  border: 1px solid transparent; background: transparent; color: var(--hdr-btn-fg);
  font-size: 12.5px; padding: 6px 11px; border-radius: 7px; transition: .15s;
}
nav.tabs button:hover { background: var(--hdr-btn-hover); color: var(--hdr-fg); }
nav.tabs button.active { background: var(--hdr-tab-on-bg); color: var(--hdr-tab-on-fg); font-weight: 700; }

.head-actions { margin-left: auto; display: flex; gap: 7px; align-items: center; position: relative; }
.head-btn {
  border: 1px solid var(--hdr-btn-bd); background: var(--hdr-btn-bg);
  color: var(--hdr-btn-fg); font-size: 12px; padding: 6px 11px; border-radius: 7px;
  transition: background .15s; white-space: nowrap;
}
.head-btn:hover { background: var(--hdr-btn-hover); }

.tseg { position: relative; display: flex; align-items: center; }
.tseg-menu { display: flex; align-items: center; gap: 2px; padding: 2px 3px;
             border: 1px solid var(--hdr-btn-bd); background: var(--hdr-btn-bg); border-radius: 8px; }
.tseg-menu button {
  border: 0; background: transparent; color: var(--hdr-btn-fg); font-size: 12px;
  padding: 4px 9px; border-radius: 6px; transition: .15s; white-space: nowrap;
}
.tseg-menu button:hover { background: var(--hdr-btn-hover); }
.tseg-menu button.on { background: var(--hdr-tab-on-bg); color: var(--hdr-tab-on-fg); font-weight: 700; }
.tseg-cur { display: none; }
@media (max-width: 900px) {
  .tseg-menu { display: none; }
  .tseg.open .tseg-menu {
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    position: absolute; right: 0; top: calc(100% + 7px); min-width: 92px; padding: 4px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 26px rgba(34, 26, 48, .18); z-index: 90;
  }
  .tseg.open .tseg-menu button { color: var(--text); padding: 7px 10px; }
  .tseg.open .tseg-menu button.on { background: var(--accent-soft); color: var(--accent-deep); }
  .tseg-cur {
    display: flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 7px;
    border: 1px solid var(--hdr-btn-bd); background: var(--hdr-btn-bg);
    color: var(--hdr-btn-fg); font-size: 11px; white-space: nowrap;
  }
  .tseg-cur::before { content: ""; width: 9px; height: 9px; border-radius: 50%;
                      background: var(--accent); box-shadow: 0 0 0 1.5px var(--hdr-tab-on-bg); }
  .tseg-cur::after { content: "▾"; font-size: 9px; opacity: .8; }
}

/* ================= 参数条 ================= */
.parambar {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 9px 12px; flex: none; z-index: 4; grid-area: bar;
}
.prow { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.prow + .prow { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.ptitle {
  font-size: 10.5px; color: var(--faint); font-weight: 600; letter-spacing: .8px;
  display: flex; align-items: center; gap: 5px;
}
.ptitle::before { content: ""; width: 3px; height: 10px; background: var(--accent); border-radius: 2px; }

.ctrl { display: flex; align-items: center; gap: 7px; }
.ctrl > label { font-size: 11.5px; color: var(--muted); white-space: nowrap; min-width: 26px; text-align: right; }
.ctrl > label.wide { min-width: 56px; text-align: left; }
.ctrl input[type="range"] {
  width: 104px; height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--chip); border-radius: 3px; outline: none;
}
.ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--accent); cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.ctrl input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--accent); cursor: grab;
}
.ctrl input[type="number"], .ctrl select {
  padding: 3px 5px; font-size: 11.5px; border: 1px solid var(--border); border-radius: 5px;
  background: var(--panel-2); color: var(--text); text-align: center; outline: none;
}
.ctrl input[type="number"] { width: 68px; }
.ctrl input[type="number"]:focus, .ctrl select:focus { border-color: var(--accent); }
.ctrl select { width: auto; min-width: 58px; text-align: left; padding-right: 3px; }
.ctrl .unit { font-size: 10.5px; color: var(--faint); min-width: 30px; }

.tag {
  font-size: 10.5px; padding: 2px 8px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent-deep);
  border: 1px solid var(--border); white-space: nowrap;
}
.tag.est { background: transparent; color: var(--warning); border-color: var(--warning); }
.tag.man { background: transparent; color: var(--muted); border-color: var(--axis); }

.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button {
  border: none; background: var(--panel-2); color: var(--muted);
  font-size: 11px; padding: 5px 4px; transition: .15s; white-space: nowrap; flex: 1;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--solid); color: #fff; font-weight: 600; }

.chk { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-2); cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); width: 13px; height: 13px; cursor: pointer; }

/* 常见配合物：常驻的一排可点胶囊 */
.cx-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.cx-chip {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text-2);
  font-size: 11.5px; padding: 3px 10px; border-radius: 20px; transition: .15s; white-space: nowrap;
}
.cx-chip:hover { border-color: var(--accent); color: var(--accent-deep); }
.cx-chip.on { background: var(--solid); border-color: var(--solid); color: #fff; font-weight: 600; }

/* ================= 主区 ================= */
main {
  flex: 1; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: minmax(0, 1fr) 208px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "bar bar"
    "plot set";
  min-height: 0;
}
.plotcard {
  background: var(--plot-bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); position: relative; min-height: 0; overflow: hidden; grid-area: plot;
}
#plot { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#plot.grab { cursor: ns-resize; }
.plot-hint {
  position: absolute; right: 12px; bottom: 8px; font-size: 10.5px; color: var(--faint);
  pointer-events: none;
}
.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-desk { display: none; }
  .hint-touch { display: inline; }
}

.settings {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 11px 11px 13px; overflow-y: auto; min-height: 0; grid-area: set;
}
.settings h4 {
  font-size: 10.5px; color: var(--faint); font-weight: 600; letter-spacing: .8px;
  margin-bottom: 8px; display: flex; align-items: center; gap: 5px;
}
.settings h4::before { content: ""; width: 3px; height: 10px; background: var(--accent); border-radius: 2px; }
.setrow { display: flex; flex-direction: column; gap: 7px; }
.setrow + h4 { margin-top: 14px; }
.setbtn {
  width: 100%; text-align: left; font-size: 11.5px; padding: 5px 9px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); color: var(--text-2);
  transition: .15s; display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.setbtn:hover { border-color: var(--accent); color: var(--accent-deep); }

.judge { font-size: 11px; color: var(--text-2); line-height: 1.65; }
.judge .row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--border); }
.judge .row:last-child { border-bottom: none; }
.judge .row b { color: var(--accent-deep); font-weight: 600; }
.judge .verdict { margin-top: 8px; padding: 6px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }

/* ================= 状态栏与页脚 ================= */
.statusbar {
  flex: none; height: 26px; display: flex; align-items: center; gap: 16px;
  padding: 0 14px; font-size: 10.5px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
  white-space: nowrap; overflow: hidden;
}
.statusbar b { color: var(--accent-deep); font-weight: 600; }
.statusbar .sep { color: var(--axis); }
.sb-right { margin-left: auto; display: flex; gap: 18px; }

.creditbar {
  flex: none; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; padding: 7px 18px;
  font-size: 11.5px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
}
.creditbar .foot-author {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent-deep); font-weight: 600; letter-spacing: .2px;
  padding: 2px 11px; border-radius: 20px;
  background: var(--accent-soft); border: 1px solid var(--border);
}
.creditbar .foot-author::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

/* ================= 阅读页（对照 / 学习 / 习题） ================= */
.reading { display: none; grid-area: plot; overflow-y: auto; min-height: 0; padding-right: 4px; }
body.reading-mode .reading { display: block; }
body.reading-mode .plotcard,
body.reading-mode .settings { display: none; }
body.reading-mode main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "read"; }
body.reading-mode .reading { grid-area: read; }
body.reading-full .parambar { display: none; }
body.reading-full main { grid-template-areas: "read"; grid-template-rows: minmax(0, 1fr); }

/* 畸变 / 谱带两个页签不需要右侧设置栏，画布占满 */
body.wide main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "plot"; }
body.wide .settings { display: none; }

.doc { max-width: 860px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
       box-shadow: var(--shadow); padding: 26px 30px 34px; color: var(--text-2); line-height: 1.85; }
.doc h2 { font-size: 19px; color: var(--text); margin: 0 0 6px; letter-spacing: .02em; }
.doc .lede { font-size: 13px; color: var(--muted); margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 15px; color: var(--accent-deep); margin: 26px 0 8px; display: flex; align-items: center; gap: 8px; }
.doc h3 .n {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--solid);
  width: 19px; height: 19px; border-radius: 6px; display: inline-flex;
  align-items: center; justify-content: center; flex: none;
}
.doc h4 { font-size: 13px; color: var(--text); margin: 16px 0 6px; }
.doc p { margin: 8px 0; }
.doc ul, .doc ol { margin: 8px 0 8px 22px; }
.doc li { margin: 4px 0; }
.doc b { color: var(--text); }
.doc code {
  font-family: ui-monospace, Consolas, monospace; font-size: 11.5px;
  background: var(--chip); color: var(--accent-deep); padding: 1px 5px; border-radius: 4px;
}
.doc .fml {
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 0 7px 7px 0; margin: 12px 0;
  font-family: "Cambria", "Times New Roman", serif; font-size: 14px; color: var(--accent-deep);
  overflow-x: auto; white-space: nowrap;
}
body.dark .doc .fml, body.magic .doc .fml { color: var(--text); }
.doc .note {
  border: 1px dashed var(--axis); border-radius: 8px; padding: 10px 14px; margin: 12px 0;
  font-size: 12.5px; color: var(--muted); background: var(--panel-2);
}
.doc .note b { color: var(--accent-deep); }
.doc table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin: 12px 0; }
.doc table th, .doc table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.doc table th { background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }
.doc table td.num, .doc table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc table tr.cur td { background: var(--accent-soft); font-weight: 600; color: var(--accent-deep); }

/* 光谱化学序列 */
.series { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 4px; }
.lig-chip {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text-2);
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px; transition: .15s; white-space: nowrap;
}
.lig-chip:hover { border-color: var(--accent); color: var(--accent-deep); }
.lig-chip.on { background: var(--solid); border-color: var(--solid); color: #fff; font-weight: 600; }
.series-bar {
  position: relative; height: 9px; border-radius: 5px; margin: 10px 0 4px;
  background: linear-gradient(90deg, #e8b74a, #8cc47f 46%, #5b8fd6);
}
.series-bar .ptr {
  position: absolute; top: -5px; width: 3px; height: 19px; border-radius: 2px;
  background: var(--accent-deep); box-shadow: 0 0 0 2px var(--panel); transform: translateX(-50%);
}
.series-ends { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--faint); }

/* 选择定则判定器 */
.rulebox {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 12px 0;
  background: var(--panel-2); display: grid; gap: 8px;
}
.rrow { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.rrow > label { min-width: 78px; color: var(--muted); flex: none; }
.rrow select {
  flex: 1; max-width: 340px; padding: 5px 8px; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text);
}
.rout {
  margin-top: 4px; padding: 10px 12px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent-deep); font-size: 12.5px; line-height: 1.75;
}
.rout b { font-size: 14.5px; }

/* 习题 */.qz { padding: 14px 0; border-bottom: 1px dashed var(--border); }
.qz:last-child { border-bottom: none; }
.qz .qn { font-size: 11px; color: var(--accent-deep); font-weight: 600; margin-bottom: 6px; letter-spacing: .3px; }
.qz .qt { font-size: 13px; color: var(--text); line-height: 1.8; }
.qz .opt { margin: 6px 0 0; font-size: 12.5px; color: var(--text-2); }
.qz .opt div { margin: 3px 0 3px 8px; }
.qz .qa { display: none; font-size: 12.5px; color: var(--text-2); background: var(--accent-soft);
          padding: 10px 13px; border-radius: 7px; margin-top: 9px; line-height: 1.75; }
.qz.open .qa { display: block; }
.qz .qbtns { display: flex; gap: 8px; margin-top: 8px; }
.mini {
  font-size: 11px; padding: 3px 11px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
}
.mini:hover { border-color: var(--accent); color: var(--accent-deep); }

/* 预设菜单 */
.ex-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 14px 38px rgba(0,0,0,.2);
  width: 316px; max-height: 70vh; overflow-y: auto; padding: 6px; display: none; z-index: 60;
}
.ex-menu.show { display: block; }
.ex-group { font-size: 10px; color: var(--faint); font-weight: 600; letter-spacing: .6px; padding: 8px 8px 4px; }
.ex-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 6px 9px; border-radius: 6px; color: var(--text);
}
.ex-item:hover { background: var(--accent-soft); }
.ex-item .t { font-size: 12px; }
.ex-item .h { font-size: 10.5px; color: var(--faint); margin-top: 1px; }

/* ============================================================
   响应式
   ============================================================ */
html { -webkit-text-size-adjust: 100%; }

@media (max-width: 1080px) {
  main { grid-template-columns: minmax(0, 1fr) 186px; }
  .ctrl input[type="range"] { width: 84px; }
  .ctrl input[type="number"] { width: 62px; }
}

@media (max-width: 900px) {
  body {
    display: block; height: auto; min-height: 100vh; min-height: 100dvh;
    overflow-x: hidden; overflow-y: auto;
  }
  header { flex-wrap: wrap; height: auto; padding: 7px 11px; gap: 6px 9px; }
  .brand { font-size: 14.5px; gap: 6px; }
  .brand .brand-ico { width: 1.5em; height: 1.5em; border-radius: 7px; }
  .brand .sig { display: none; }
  nav.tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button { flex: none; font-size: 12px; padding: 7px 11px; }
  .head-actions { gap: 5px; }
  .head-btn { font-size: 11.5px; padding: 6px 9px; }

  main { display: flex; flex-direction: column; gap: 8px; padding: 8px; min-height: 0; }
  .plotcard { flex: none; height: min(40vh, 400px); min-height: 230px; position: sticky; top: 0; z-index: 6; }
  .parambar { flex: none; padding: 8px 10px; }
  .settings { flex: none; max-height: none; overflow: visible; padding: 9px 10px 11px; }

  .prow { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 7px 10px; }
  .prow > .ptitle { grid-column: 1 / -1; }
  /* 常见配合物在窄屏改成单行横向滚动，避免占掉三行高度 */
  .prow.examples { display: block; }
  .prow.examples .ptitle { margin-bottom: 6px; }
  .cx-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .cx-chips::-webkit-scrollbar { display: none; }
  .cx-chip { min-height: 32px; display: inline-flex; align-items: center; flex: none; font-size: 12px; }
  .ctrl { min-width: 0; gap: 6px; }
  .ctrl > label { font-size: 11px; min-width: 20px; }
  .ctrl > label.wide { min-width: 52px; }
  .ctrl input[type="range"] { flex: 1 1 auto; width: auto; min-width: 44px; height: 5px; }
  .ctrl input[type="range"]::-webkit-slider-thumb { width: 17px; height: 17px; }
  .ctrl input[type="number"], .ctrl select { min-height: 32px; font-size: 12px; }
  .ctrl input[type="number"] { width: 72px; }
  .seg button { min-height: 34px; }
  .chk { min-height: 30px; font-size: 12px; }
  .chk input { width: 17px; height: 17px; }
  .setbtn { min-height: 36px; }
  .ex-menu { width: min(320px, calc(100vw - 20px)); max-height: 62vh; }

  .settings .setrow { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .judge { font-size: 11.5px; }

  .plot-hint { font-size: 9.5px; right: 8px; bottom: 3px; }
  .statusbar { height: auto; min-height: 28px; flex-wrap: wrap; padding: 5px 11px; gap: 4px 10px; white-space: normal; font-size: 10px; }
  .creditbar { padding: 6px 11px; font-size: 10.5px; gap: 6px; }

  .reading { overflow: visible; }
  .doc { padding: 18px 16px 24px; border-radius: 10px; }
  .doc h2 { font-size: 17px; }
  .doc .fml { white-space: normal; font-size: 13px; }
  .doc table { font-size: 11px; }
  .doc table th, .doc table td { padding: 5px 6px; }
}

@media (max-width: 430px) {
  .prow { grid-template-columns: 1fr; }
  .plotcard { height: 34vh; min-height: 210px; }
  .plot-hint { display: none; }
  .brand { font-size: 13.5px; }
  .head-btn { font-size: 11px; padding: 6px 8px; }
  .creditbar { flex-direction: column; align-items: flex-start; }
}

@media (max-height: 500px) and (orientation: landscape) {
  header { flex-wrap: nowrap; padding: 4px 10px; }
  nav.tabs { order: 0; width: auto; margin-left: 6px; overflow: visible; }
  .brand .sig { display: inline; }
  .plotcard { position: static; height: 54vh; min-height: 180px; }
}

@media print {
  header, .parambar, .settings, .statusbar, .creditbar { display: none; }
  body { overflow: visible; height: auto; }
  main { display: block; padding: 0; }
  .reading { overflow: visible; }
  .doc { border: none; box-shadow: none; max-width: none; }
}
