:root {
  --ink: #231f1b; --ink2: rgba(35, 31, 27, .62); --paper: rgba(245, 239, 225, .9); --line: rgba(60, 45, 30, .22);
  --red: #b8372b; --gold: #a5834a; --shadow: 0 6px 24px rgba(0, 0, 0, .28);
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", serif;
  --song: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --e0: #2f7a3e; --e1: #c8321e; --e2: #8a6234; --e3: #a8831c; --e4: #1f5f8b;
}
body[data-night="1"] {
  --ink: #ece5d2; --ink2: rgba(236, 229, 210, .6); --paper: rgba(17, 21, 40, .82); --line: rgba(220, 205, 160, .22);
  --red: #ff8a6a; --gold: #d9bb7a;
  --e0: #7fd98a; --e1: #ffb347; --e2: #d2a56a; --e3: #ffe08a; --e4: #8fd3f0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #141210; color: var(--ink); font-family: var(--song);
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }
[data-e="0"] { color: var(--e0); } [data-e="1"] { color: var(--e1); } [data-e="2"] { color: var(--e2); }
[data-e="3"] { color: var(--e3); } [data-e="4"] { color: var(--e4); }

#wx, #codex, #bar, #probe, #help, .toast, #intro .card, #sceneMenu {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: background .8s, color .8s, border-color .8s;
}

#brand { position: fixed; top: 14px; left: 18px; display: flex; align-items: center; gap: 10px; pointer-events: none; }
#brand b { font: 700 21px/1 var(--kai); color: #f6eddc; background: #b8372b; padding: 6px 7px 5px; border-radius: 4px; letter-spacing: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25) inset, 0 2px 8px rgba(0, 0, 0, .3); }
#brand i { font: normal 13px var(--song); letter-spacing: .5em; color: var(--ink2); text-shadow: 0 0 6px var(--paper); transition: color .8s; }

/* 笔 */
#palette { position: fixed; left: 16px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 9px; align-items: center; }
.pb { position: relative; width: 52px; height: 52px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--line);
  box-shadow: var(--shadow); font: 700 27px/1 var(--kai); transition: transform .15s, background .3s, color .3s, box-shadow .2s; }
.pb:hover { transform: scale(1.08); }
.pb small { position: absolute; left: -3px; top: -3px; width: 17px; height: 17px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line);
  font: 10px/15px var(--song); color: var(--ink2); }
.pb em { position: absolute; right: -6px; bottom: -3px; font: normal 10px/1 var(--song); color: var(--ink2); background: var(--paper); border-radius: 6px; padding: 2px 3px; border: 1px solid var(--line); }
.pb.on { background: currentColor; box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px currentColor, var(--shadow); transform: scale(1.1); }
.pb.on span { color: #fbf6ea; } body[data-night="1"] .pb.on span { color: #141829; }
.pb.tool { width: 42px; height: 42px; font-size: 19px; color: var(--ink); }
#bSize i { display: block; margin: auto; border-radius: 50%; background: currentColor; }

/* 五行图 */
#wx { position: fixed; top: 12px; right: 14px; width: 176px; padding: 8px 8px 9px; text-align: center; }
#wxsvg { width: 150px; height: 150px; display: block; margin: 0 auto; overflow: visible; }
#wxsvg path { fill: none; stroke: var(--ink2); stroke-width: 1.3; stroke-dasharray: 1.5 4; opacity: .45; transition: stroke .5s, opacity .5s; }
#wxsvg path.on { stroke-dasharray: none; opacity: .95; }
#wxsvg path.s.on { stroke: var(--gold); } #wxsvg path.k.on { stroke: var(--red); }
#wxsvg path.hit { animation: wxhit .7s ease-out; }
@keyframes wxhit { 0% { stroke-width: 7; opacity: 1; } 100% { stroke-width: 1.3; } }
#wxsvg circle { fill: var(--paper); stroke: currentColor; stroke-width: 1.6; transition: r .6s; }
#wxsvg text { font: 700 17px var(--kai); fill: currentColor; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#wxsvg marker path { stroke: none; fill: var(--ink2); opacity: 1; stroke-dasharray: none; }
#wxtip { font-size: 11px; color: var(--ink2); min-height: 30px; line-height: 15px; margin: 2px 0 6px; }
.chip { font-size: 12px; padding: 5px 9px; border-radius: 14px; border: 1px solid var(--line); width: 100%; }
.chip:hover, #bar button:hover { background: rgba(128, 110, 80, .16); }
.chip b { color: var(--red); font-family: var(--song); }

/* 字典 */
#codex { position: fixed; top: 12px; right: 200px; width: 336px; max-height: calc(100% - 96px); overflow: auto; padding: 10px 12px 12px; }
#codex header { display: flex; justify-content: space-between; align-items: center; font: 700 17px var(--kai); letter-spacing: .3em; margin-bottom: 6px; }
#codexX { font-size: 20px; width: 26px; height: 26px; border-radius: 50%; }
#codexDetail { display: flex; gap: 12px; align-items: center; min-height: 68px; padding: 6px 4px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
#codexDetail .g { font: 700 50px/1 var(--kai); width: 58px; text-align: center; flex: none; }
#codexDetail p { margin: 0; font-size: 13px; line-height: 1.65; }
#codexDetail p i { display: block; font-style: normal; color: var(--ink2); font-size: 12px; }
#codexGrid h4 { margin: 8px 0 4px; font: normal 11px var(--song); color: var(--ink2); letter-spacing: .4em; }
#codexGrid .row { display: flex; flex-wrap: wrap; gap: 5px; }
.tile { width: 39px; height: 39px; border-radius: 6px; border: 1px solid var(--line); font: 700 23px/37px var(--kai); text-align: center; transition: transform .15s; }
.tile:hover { transform: scale(1.12); }
.tile.no { color: var(--ink2); opacity: .45; font-size: 15px; border-style: dashed; }
.tile.new { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.7); box-shadow: 0 0 0 6px var(--gold); } 100% { transform: scale(1); } }

/* 底栏 */
#bar { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 5px 8px; white-space: nowrap; }
#bar button { padding: 6px 11px; border-radius: 7px; font-size: 14px; }
#bar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 5px; }
#bar .menu { position: relative; }
#sceneMenu { position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; padding: 5px; min-width: 210px; }
#sceneMenu button { text-align: left; font: 700 16px var(--kai); }
#sceneMenu button i { font: normal 11px var(--song); color: var(--ink2); margin-left: 10px; }
#bDemo.on { color: var(--red); }

#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 7px 18px 7px 12px; animation: tin .35s ease-out; max-width: 78vw; }
.toast.out { opacity: 0; transform: translateY(-8px); transition: all .4s; }
.toast .g { font: 700 38px/1 var(--kai); }
.toast .g small { font-size: 22px; opacity: .7; margin: 0 2px; }
.toast p { margin: 0; font-size: 13px; line-height: 1.5; }
.toast p b { display: block; font-size: 11px; font-weight: normal; letter-spacing: .3em; color: var(--ink2); }
@keyframes tin { from { opacity: 0; transform: translateY(-14px) scale(.96); } to { opacity: 1; transform: none; } }

#caption { position: fixed; left: 0; right: 0; bottom: 84px; text-align: center; font: 700 28px var(--kai); letter-spacing: .2em; pointer-events: none;
  color: var(--ink); text-shadow: 0 0 12px var(--paper), 0 0 3px var(--paper); opacity: 0; transition: opacity .6s, color .8s; }
#caption.show { opacity: 1; }
#caption small { display: block; font: normal 13px var(--song); letter-spacing: .25em; color: var(--ink2); margin-top: 4px; }

#probe { position: fixed; left: 16px; bottom: 14px; padding: 5px 11px 5px 8px; font-size: 12px; display: flex; align-items: center; gap: 8px; max-width: 300px; opacity: 0; transition: opacity .3s; pointer-events: none; }
#probe.show { opacity: 1; }
#probe b { font: 700 22px/1 var(--kai); }

#help { position: fixed; bottom: 66px; left: 50%; transform: translateX(-50%); padding: 10px 18px; font-size: 13px; line-height: 1.5; }
#help p { margin: 4px 0; } #help b { color: var(--red); font-weight: 700; }

#intro { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 11vh; pointer-events: none; transition: opacity .9s; }
#intro.gone { opacity: 0; }
#intro .card { pointer-events: auto; padding: 18px 34px 16px; text-align: center; font-size: 15px; line-height: 1.8; }
#intro.gone .card { pointer-events: none; }
#intro .lead { font: 700 23px var(--kai); margin: 0 0 4px; }
#intro .lead span { margin: 0 3px; font-size: 27px; }
#intro p { margin: 0; }
#intro .row { display: flex; gap: 12px; justify-content: center; margin: 14px 0 8px; }
#intro button { font: 700 19px var(--kai); letter-spacing: .4em; padding: 8px 20px 8px 26px; border-radius: 6px; background: #b8372b; color: #f8f0df; box-shadow: 0 2px 10px rgba(184, 55, 43, .4); transition: transform .15s; }
#intro button:hover { transform: translateY(-1px) scale(1.03); }
#intro button.ghost { background: none; color: var(--ink); border: 1px solid var(--line); box-shadow: none; font-size: 16px; letter-spacing: .15em; padding: 8px 18px; }
#intro .hint { font-size: 12px; color: var(--ink2); }
#nogl { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: #e9e2cf; font-size: 18px; }

body.clean #palette, body.clean #wx, body.clean #bar, body.clean #brand, body.clean #probe, body.clean #codex { opacity: 0; pointer-events: none; }
#palette, #wx, #bar, #brand { transition: opacity .6s; }

@media (max-width: 820px) {
  #wx { width: 132px; transform-origin: top right; } #wxsvg { width: 112px; height: 112px; } #wxtip { display: none; }
  #codex { right: 8px; top: 190px; width: min(336px, calc(100% - 16px)); }
  .pb { width: 44px; height: 44px; font-size: 23px; } #palette { left: 8px; gap: 7px; }
  #bar { max-width: calc(100% - 12px); overflow-x: auto; } #bar button { padding: 6px 8px; font-size: 13px; }
  #brand i { display: none; } #caption { font-size: 21px; }
}
