@font-face {
  font-family: "TangutWeb";
  src: local("Noto Serif Tangut"), local("NotoSerifTangut-Regular"),
       url("fonts/NotoSerifTangut-subset.woff2?v=3") format("woff2");
  unicode-range: U+16FE0-16FFF, U+17000-187FF, U+18800-18AFF, U+18D00-18D8F;
  font-display: swap;
}
:root {
  --cjk: "Noto Serif TC", "Noto Serif CJK TC", "Source Han Serif TC", "Songti TC", "PMingLiU", "MingLiU", serif;
  --tg: "TangutWeb", "Tangut Yinchuan", "Noto Serif Tangut", var(--cjk);
  --cell: 42px;
  --row: 50px;
  /* soft, paper-like palette */
  --bg: #ece7de;
  --side: #e4ded3;
  --paper: #faf7f1;
  --ink: #3a342e;
  --ink-soft: #6f665c;
  --rule: #8a8075;
  --rule-strong: #6d645a;
  --circle: #c9c1b5;
  --roundel: #4a433c;
  --sel: #eadfc6;
  --sel-edge: #c2a467;
  --hover: #f2ece0;
  --mark: #c0574b;
  --card: #fffdf9;
  --card-edge: #e3dccf;
  --card-head: #f4efe6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--cjk); color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
.tg { font-family: var(--tg); }
.muted { color: var(--ink-soft); font-size: 12px; }

#app { --sidew: 230px; --panelw: 410px; display: grid; height: 100vh;
  grid-template-columns: var(--sidew) minmax(0, 1fr) var(--panelw); transition: grid-template-columns .2s; }
#app.side-folded { --sidew: 30px; }
#app.panel-folded { --panelw: 30px; }
#side, #panel { position: relative; }
.fold { position: absolute; top: 8px; z-index: 5; width: 22px; height: 30px; padding: 0;
  border: 1px solid #cfc7ba; border-radius: 6px; background: var(--paper); color: var(--ink-soft);
  font-size: 16px; line-height: 1; cursor: pointer; }
.fold:hover { background: #fff; color: var(--ink); }
#foldSide { right: 4px; }
#foldPanel { left: 4px; }
#app.side-folded #side { padding: 0; overflow: hidden; }
#app.side-folded .side-in { display: none; }
#app.panel-folded #panel { padding: 0; overflow: hidden; }
#app.panel-folded #panelBody { display: none; }
#panelBody { padding-left: 18px; }
#side { background: var(--side); padding: 20px 18px; overflow-y: auto; font-size: 15px;
  border-right: 1px solid #d8d1c4; }
#main { overflow: auto; padding: 18px; }
#panel { overflow-y: auto; background: #f5f1ea; border-left: 1px solid #d8d1c4; padding: 16px 18px; }

h1 { font-size: 29px; margin: 0 0 6px; line-height: 1.2; font-weight: 600; color: #3f3831; }
h1 .sub { font-size: 23px; font-weight: 500; }
.tagline { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 18px; line-height: 1.45; font-family: Georgia, serif; }
.ctl { margin: 16px 0; }
.ctl > label { display: block; font-weight: 600; margin-bottom: 5px; color: #4a433c; }
select, input[type=search] {
  width: 100%; font: inherit; font-size: 14px; padding: 6px 11px; color: var(--ink);
  border: 1px solid #c8c0b3; border-radius: 16px; background: var(--paper); outline: none;
}
select:focus, input[type=search]:focus { border-color: var(--sel-edge); box-shadow: 0 0 0 3px rgba(194,164,103,.18); }
input[type=search] { font-family: var(--tg); }
.hint { font-size: 11px; color: var(--ink-soft); margin-top: 5px; font-family: Georgia, serif; line-height: 1.4; }
.opts { border: 1px solid #d0c8bb; border-radius: 8px; padding: 6px 12px 8px; margin: 16px 0; font-size: 14px; }
.opts legend { font-weight: 600; padding: 0 4px; color: #4a433c; }
.opts label { display: block; margin: 3px 0; }
.opts input { accent-color: #8c7650; }
#results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
#results li { padding: 5px 6px; border-bottom: 1px solid #d8d1c4; cursor: pointer; font-size: 13px; border-radius: 4px; }
#results li:hover { background: var(--paper); }
#results .tg { font-size: 20px; margin-right: 6px; vertical-align: middle; }
#results .meta { color: var(--ink-soft); font-family: Georgia, serif; font-size: 12px; }
.legend { font-size: 12.5px; margin: 18px 0; line-height: 2.1; color: #4a433c; }
.legend .rn { width: 24px; height: 24px; font-size: 15px; vertical-align: middle; margin-right: 4px; cursor: default; }
.mark-demo { display: inline-block; position: relative; width: 22px; height: 22px; margin: 0 6px 0 2px;
  vertical-align: middle; background: var(--paper); border: 1px solid #d8d1c4; }
.mark-demo::after { content: ""; position: absolute; top: 0; right: 0;
  border-top: 7px solid var(--mark); border-left: 7px solid transparent; }
.about { font-size: 12.5px; line-height: 1.55; font-family: Georgia, var(--cjk); color: #4a433c; }
.about summary { cursor: pointer; font-weight: 600; }

/* ------------------------------------------------------------- chart ---- */
#chartWrap { display: inline-block; width: max-content; background: var(--paper); border: 4px double var(--rule-strong);
  padding: 3px; box-shadow: 0 1px 6px rgba(80, 65, 45, .10); }
#chart { border-collapse: collapse; color: var(--ink); }
#chart td, #chart th { padding: 0; text-align: center; vertical-align: middle; }
#chart th { font-weight: normal; color: #4a433c; }
.navbtn { width: 38px; height: 28px; border: 1px solid #c8c0b3; border-radius: 7px; background: #f3eee5;
  color: var(--ink); font-size: 15px; cursor: pointer; }
.navbtn:hover { background: #e9e2d5; }
.corner { font-size: 19px; color: #4a433c; }
.grp { height: 48px; font-family: var(--tg); font-size: 21px; padding: 0 6px !important; cursor: help; }
.grp .spread { display: flex; justify-content: space-between; }
.grp.single { font-size: 14px; line-height: 1.05; }
.grp.single .v { writing-mode: vertical-rl; display: inline-block; }
.qz { height: 56px; font-size: 15px; color: var(--ink-soft) !important; }
.qz span { writing-mode: vertical-rl; display: inline-block; line-height: 1; letter-spacing: -1px; }
.sep { border-left: 1.5px solid var(--rule); }
thead tr:last-child th { border-bottom: 1.5px solid var(--rule); }
tr.secend td { border-bottom: 1px solid var(--rule); }
.deng { width: 24px; font-size: 13px; color: var(--ink-soft); }
.rowname { width: 52px; line-height: 1; }
.rowname .rf { display: block; font-family: Georgia, serif; font-size: 9.5px; color: var(--ink-soft); margin-top: 1px; }
.seclab { width: 34px; min-width: 34px; font-size: 20px; color: #4a433c; }
.title { width: 40px; min-width: 40px; font-size: 21px; vertical-align: top !important;
  padding-top: 24px !important; border-left: 1.5px solid var(--rule); color: #4a433c; }
.vt { writing-mode: vertical-rl; display: inline-block; letter-spacing: 4px; white-space: nowrap; }
.title .vt { letter-spacing: 3px; }
.deng { min-width: 24px; } .rowname { min-width: 52px; }
td.c { width: var(--cell); min-width: var(--cell); height: var(--row); position: relative; cursor: default; transition: background .12s; }
td.c.has { cursor: pointer; }
td.c.has:hover:not(.sel) { background: var(--hover); }
td.c.sel { background: var(--sel); box-shadow: inset 0 0 0 1.5px var(--sel-edge); }
td.c .ch { font-family: var(--tg); font-size: 24px; line-height: 1.05; display: block; color: #2f2a25; }
td.c .fq { font-family: var(--tg); font-size: 11px; display: block; line-height: 1.1; color: var(--ink-soft); }
td.c .rd { font-family: Georgia, serif; font-size: 9.5px; display: block; line-height: 1.15; color: var(--ink-soft); }
td.c .o { display: inline-block; width: 19px; height: 19px; border: 1px solid var(--circle); border-radius: 50%; }
td.c .mark { position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-top: 7px solid var(--mark); border-left: 7px solid transparent; opacity: .85; }
.rn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 50%; border: 1.2px solid var(--roundel); font-family: var(--tg); font-size: 19px; background: var(--paper);
  color: var(--roundel); cursor: pointer; }
.rn.trad { background: var(--roundel); color: var(--paper); }
.rn.sel { box-shadow: 0 0 0 3px var(--sel), 0 0 0 4.5px var(--sel-edge); }

/* ------------------------------------------------------------- panel ---- */
.placeholder { color: var(--ink-soft); font-size: 14px; line-height: 1.7; }
.slot-h { font-size: 18px; font-weight: 600; margin: 0 0 4px; color: #3f3831; }
.slot-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; font-family: Georgia, var(--cjk); line-height: 1.5; }
.slot-sub .tg { font-size: 15px; }
.card { background: var(--card); border: 1px solid var(--card-edge); border-radius: 8px; margin: 12px 0;
  overflow: hidden; box-shadow: 0 1px 3px rgba(80, 65, 45, .06); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 9px 12px; background: var(--card-head);
  border-bottom: 1px solid var(--card-edge); }
.card-h .big { font-family: var(--tg); font-size: 38px; line-height: 1; color: #2f2a25; }
.card-h .info { font-size: 13px; line-height: 1.5; font-family: Georgia, var(--cjk); color: #4a433c; }
.card-h .tag { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 8px;
  background: #6d645a; color: #faf7f1; margin-left: 4px; }
.card-h .tag.hid { background: #b5ab9e; }
dl.kv { display: grid; grid-template-columns: 92px 1fr; margin: 0; padding: 9px 12px; gap: 5px 8px;
  font-size: 13.5px; font-family: Georgia, var(--cjk); }
dl.kv dt { color: var(--ink-soft); }
dl.kv dd { margin: 0; }
dl.kv .tg { font-size: 21px; vertical-align: middle; }
.fqpart { display: inline-block; text-align: center; margin-right: 7px; }
.fqpart .tg { display: block; font-size: 23px; }
.fqpart small { display: block; font-size: 10.5px; color: var(--ink-soft); }
table.mem { width: 100%; border-collapse: collapse; font-size: 13px; font-family: Georgia, var(--cjk); }
table.mem th { background: #f6f2ea; font-weight: normal; color: var(--ink-soft); text-align: left;
  padding: 4px 6px; border-top: 1px solid var(--card-edge); border-bottom: 1px solid var(--card-edge); }
table.mem td { padding: 3px 6px; border-bottom: 1px solid #f0ebe1; vertical-align: middle; }
table.mem td.n { color: #a59b8e; font-size: 11px; width: 18px; }
table.mem td.tg { font-size: 23px; width: 34px; color: #2f2a25; }
table.mem tr.warn td { background: #fbf4e6; }
table.mem td.gl { line-height: 1.35; }
table.mem td.lfw { font-size: 11.5px; white-space: nowrap; width: 64px; line-height: 1.3; }
table.mem .rdiff { display: block; font-size: 10.5px; color: #9a6a2c; }
.card-h .hgl { color: var(--ink-soft); font-size: 12.5px; }
.opts.lang label { display: inline-block; margin-right: 12px; }
.about a { color: #6b5532; }
.flag { font-size: 12px; color: #9a6a2c; padding: 5px 12px 9px; font-family: Georgia, serif; }
.rhyme-big { font-size: 44px; width: 62px; height: 62px; cursor: default; }

@media (max-width: 1100px) {
  #app, #app.side-folded, #app.panel-folded { grid-template-columns: 1fr; height: auto; }
  #app.side-folded #side, #app.panel-folded #panel { min-height: 44px; }
  #side, #panel { border: none; }
  #main { order: 2; }
  #panel { order: 3; }
}

/* ------------------------------------------------------- font switch ---- */
.fontsel label { display: block; margin: 3px 0; }
.font-status { font: 11.5px/1.45 Georgia, var(--cjk); color: var(--ink-soft); margin-top: 6px; }
.font-status .ok { color: #4e6b3a; }
.font-status .bad { color: #a0472f; }
.font-status a { color: #6b5532; }
.grp.single .v { white-space: nowrap; font-size: 13px; line-height: 1; }

/* ---- Wenhai page viewer ---- */
a.wpos { color: inherit; text-decoration: underline dotted; text-underline-offset: 2px; cursor: zoom-in; }
a.wpos:hover { color: var(--mark); text-decoration-style: solid; }
#pageView { position: fixed; inset: 0; z-index: 50; background: rgba(40, 35, 30, .55); display: flex; padding: 2.5vh 2.5vw; }
#pageView[hidden] { display: none; }
body.pv-open { overflow: hidden; }
.pv-box { flex: 1; display: flex; flex-direction: column; background: var(--paper); border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,.35); overflow: hidden; min-width: 0; }
.pv-bar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--side);
  border-bottom: 1px solid var(--circle); font: 13px/1.4 Georgia, var(--cjk); color: var(--ink); }
#pvCap { flex: 1; text-align: center; min-width: 0; }
.pv-where { color: var(--ink-soft); }
.pv-bar button { font: inherit; font-size: 12.5px; padding: 3px 10px; border: 1px solid var(--circle);
  background: var(--card); color: var(--ink); border-radius: 4px; cursor: pointer; }
.pv-bar button:hover:not(:disabled) { background: var(--hover); }
.pv-bar button:disabled { opacity: .35; cursor: default; }
.pv-bar button.on, .pv-bar button.on:hover { background: var(--sel); border-color: var(--rule); }
.pv-fit { display: inline-flex; gap: 3px; }
#pvStage { flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none; background: #f4f1ea; }
#pvStage.drag { cursor: grabbing; }
#pvImg { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; max-width: none; }
#pvLoad { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font: 14px Georgia, serif; pointer-events: none; }
#pvLoad[hidden] { display: none; }
.pv-hint { padding: 4px 10px; font-size: 11.5px; color: var(--ink-soft); text-align: center; border-top: 1px solid var(--circle); }
@media (max-width: 700px) { #pageView { padding: 0; } .pv-box { border-radius: 0; } .pv-hint { display: none; } }
.corner .cfin { font: 12px Georgia, serif; color: var(--ink-soft); white-space: nowrap; }

.navlink { display: block; margin: -8px 0 16px; padding: 6px 10px; border: 1px solid #d0c8bb; border-radius: 8px;
  background: var(--paper); color: #6b5532; font-size: 13.5px; text-decoration: none; }
.navlink:hover { background: #fff; color: var(--ink); }

/* ------------------------------------------- non-Wenhai characters, row layouts ---- */
td.c.nwc .ch { color: #8a7f72; }
.rn.nwr { border-style: dashed; color: #7d7368; }
.card-h .tag.nwt { background: #c9b48a; color: #3f3831; }
.deng.sm { font-size: 11px; white-space: nowrap; padding: 0 2px !important; min-width: 30px; }
.opts.lay label { display: inline-block; margin-right: 12px; }
