:root {
  --paper: #ece7dc;
  --ink: #1c1a1e;
  --dim: #8a857a;
  --card: rgba(250, 248, 242, 0.88);
  --line: rgba(28, 26, 30, 0.14);
  --drawer: 312px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--paper);
  background-image: radial-gradient(ellipse at 50% 40%, #f3efe6 0%, var(--paper) 60%, #e2dccf 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "Noto Sans JP", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; letter-spacing: 0.04em; }
.dim { color: var(--dim); font-size: 10px; text-transform: uppercase; }
button, input { font: inherit; color: inherit; }

.pill {
  border: 1.5px solid var(--ink); background: #fbfaf6; border-radius: 999px;
  padding: 3px 12px; font-size: 12px; cursor: pointer; line-height: 1.5; white-space: nowrap;
}
.pill:hover { background: #fff; }
.pill.dark { background: var(--ink); color: #fbfaf6; }
.pill.on { background: var(--ink); color: #fbfaf6; }
.pill.check { display: inline-flex; gap: 4px; align-items: center; }
select.pill { appearance: none; -webkit-appearance: none; padding-right: 24px; font-weight: 700;
  background: #fbfaf6 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%231c1a1e'/%3E%3C/svg%3E") no-repeat right 9px center; }
body.hub .single-only, body:not(.hub) .hub-only { display: none !important; }
.pill.check input { margin: 0; accent-color: var(--ink); }

#hud-l { position: fixed; top: 18px; left: 22px; z-index: 3; max-width: min(440px, calc(100vw - 150px)); transition: left .25s; pointer-events: none; }
#hud-l > * { pointer-events: auto; }
body.drawer #hud-l { left: calc(var(--drawer) + 22px); }
#fig { font-weight: 700; font-size: 12px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
#card { margin-top: 12px; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 10px 12px; backdrop-filter: blur(4px); }
#card { cursor: pointer; }
#title { font-size: 17px; }
#title::after { content: " ▴"; font-size: 11px; color: var(--dim); }
#card.mini #title::after { content: " ▾ 介紹"; }
#card.mini #meta, #card.mini #desc { display: none; }
#card.mini { padding: 4px 10px; }
#card.mini #title { font-size: 13px; }
#title b { font-weight: 900; }
#meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: #4a463f; margin-top: 4px; align-items: center; }
.chip { background: var(--c); color: #fff; border-radius: 4px; padding: 0 6px; font-weight: 700; }
#desc { margin: 6px 0 0; font-size: 12.5px; line-height: 1.6; color: #3a3630; }

#hud-r { position: fixed; top: 18px; right: 24px; z-index: 3; text-align: right; }
#hud-r .big { font-size: 26px; font-weight: 700; line-height: 1.05; margin-bottom: 6px; }

#drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--drawer); z-index: 4;
  background: rgba(247, 244, 236, 0.94); border-right: 1.5px solid var(--ink);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .25s;
  backdrop-filter: blur(6px);
}
body.drawer #drawer { transform: none; }
.dh { display: flex; align-items: baseline; gap: 8px; padding: 16px 14px 8px; }
.dh b { font-size: 15px; font-weight: 900; }
#search { margin: 0 14px 8px; padding: 6px 10px; border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; font-size: 13px; }
#tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 14px 8px; border-bottom: 1px solid var(--line); }
#tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; cursor: pointer; }
#tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
#list { overflow-y: auto; flex: 1; padding: 6px 8px 90px; }
.grp h4 { margin: 10px 6px 4px; font-size: 12px; display: flex; gap: 6px; align-items: baseline; }
.grp h4::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c); align-self: center; }
.grp h4 small { color: var(--dim); font-weight: 400; font-family: "JetBrains Mono", monospace; font-size: 10px; }
.item { display: grid; grid-template-columns: 14px auto 1fr auto; gap: 8px; align-items: center; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.item:hover { background: rgba(28, 26, 30, 0.06); }
.item.on { background: var(--ink); color: #fbfaf6; }
.item i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--ink); }
.item.on i { border-color: #fbfaf6; }
.item span { color: inherit; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item em { font-style: normal; font-size: 10px; opacity: .6; }
.empty { padding: 20px; color: var(--dim); font-size: 13px; }

#bar {
  position: fixed; left: 22px; right: 22px; bottom: 16px; z-index: 3; display: flex; gap: 22px; align-items: flex-end; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding-top: 10px; transition: left .25s;
}
body.drawer #bar { left: calc(var(--drawer) + 22px); }
.ctl { display: flex; flex-direction: column; gap: 4px; flex: 1 1 220px; }
.ctl.small { flex: 0 1 140px; }
.ctl.btns { flex: 0 0 auto; flex-direction: row; gap: 6px; }
.ctl label { display: block; }
input[type=range] { width: 100%; accent-color: #2f9e74; }
#swatches { display: flex; gap: 6px; }
#swatches button { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--ink); cursor: pointer; padding: 0; font-size: 10px; background: #fbfaf6; }
#swatches button.on { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink); }

@media (max-width: 720px) {
  :root { --drawer: 100vw; }
  body.drawer #hud-l, body.drawer #bar { left: 22px; }
  #hud-l { left: 14px; top: 12px; max-width: calc(100vw - 110px); }
  #hud-r { right: 14px; top: 12px; }
  #hud-r .big { font-size: 20px; }
  #card { padding: 8px 10px; }
  #bar { left: 14px; right: 14px; bottom: 10px; gap: 8px 14px; }
  .ctl { flex: 1 1 40%; }
  .ctl.btns { flex: 1 1 100%; }
  #drawer { top: 0; padding-top: env(safe-area-inset-top); }
  body.drawer #drawer { z-index: 6; }
  .dh { padding-top: 14px; }
}

/* landscape phones: short viewport, keep the HUD out of the scene */
@media (max-height: 500px) {
  :root { --drawer: min(312px, 50vw); }
  body.drawer #hud-l, body.drawer #bar { left: 14px; }
  body.drawer #drawer { z-index: 6; }
  #hud-l { top: 8px; left: 12px; max-width: 46vw; }
  #hud-l > .dim { display: none; }
  #fig { font-size: 10px; }
  .row { margin-top: 4px; gap: 4px; }
  .pill { padding: 1px 9px; font-size: 11px; }
  #card { margin-top: 6px; padding: 6px 10px; max-height: calc(100vh - 120px); overflow-y: auto; }
  #title { font-size: 14px; }
  #desc { font-size: 11.5px; line-height: 1.5; }
  #hud-r { top: 8px; right: 12px; display: grid; grid-template-columns: auto auto; gap: 0 8px; align-items: baseline; }
  #hud-r .big { font-size: 16px; margin: 0; }
  #bar { left: 12px; right: 12px; bottom: 6px; padding-top: 4px; gap: 4px 12px; flex-wrap: nowrap; }
  .ctl { flex: 1 1 0; min-width: 0; gap: 0; }
  .ctl.small { flex: 0 1 110px; }
  .ctl label { font-size: 9px; }
  #swatches { gap: 4px; }
  #swatches button { width: 16px; height: 16px; }
  .ctl.btns { flex: 0 0 auto; }
  .ctl.btns .pill { font-size: 10px; }
}
