:root {
  --bg0: #0b1220;
  --bg1: #16233a;
  --panel: rgba(17, 25, 41, 0.82);
  --panel-solid: #111929;
  --line: rgba(148, 170, 205, 0.18);
  --text: #e8eef8;
  --muted: #9aabc4;
  --accent: #ff9a3d;
  --accent-ink: #1b1206;
  --chip: rgba(255, 255, 255, 0.06);
  --chip-on: rgba(255, 154, 61, 0.16);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(ellipse at 50% 38%, var(--bg1) 0%, var(--bg0) 70%);
  -webkit-font-smoothing: antialiased;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* loading */
#loading { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: radial-gradient(ellipse at 50% 38%, var(--bg1) 0%, var(--bg0) 70%); transition: opacity .4s; }
#loading.done { opacity: 0; pointer-events: none; }
.lbox { width: min(360px, 80vw); text-align: center; }
.ltitle { font-size: 15px; color: var(--muted); margin-bottom: 14px; }
.bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,.08); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.lpct { margin-top: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* panel */
#panel {
  position: fixed; top: 16px; left: 16px; width: 288px; max-height: calc(100% - 32px);
  display: flex; flex-direction: column; background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 10;
}
#panel header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 16px; }
#panel h1 { font-size: 17px; margin: 0; flex: 1; letter-spacing: -0.01em; }
#panel .body { overflow-y: auto; padding: 0 16px 14px; }
#panel.collapsed .body { display: none; }
#panel.collapsed { width: auto; }
#panel.collapsed #collapse { transform: rotate(180deg); }
#panel section { border-top: 1px solid var(--line); padding: 12px 0 4px; }
#panel h2 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 8px; letter-spacing: .02em; }
.pill { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; }
.icon { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 8px; font-size: 16px; color: var(--muted); }
.icon:hover { background: var(--chip); color: var(--text); }
.muted { color: var(--muted); font-size: 12.5px; margin: 8px 0 6px; line-height: 1.45; }

.search { position: relative; margin-bottom: 12px; }
#q {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0,0,0,.25); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
#q:focus { border-color: rgba(255,154,61,.6); }
#results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: 50vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 20; padding: 4px;
}
.res { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; }
.res:hover { background: var(--chip); }
.res .rn { flex: 1; min-width: 0; cursor: pointer; }
.res .rn b { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res .rn span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res .rs { display: flex; gap: 4px; }
.res .rs button { border: 1px solid var(--line); background: var(--chip); border-radius: 6px; padding: 3px 7px; font-size: 11.5px; }
.res .rs button:hover { border-color: var(--accent); }
.noresult { padding: 10px; color: var(--muted); font-size: 13px; }

#groups { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grp {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--chip); font-size: 13px; text-align: left; min-width: 0;
}
.grp i { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.3); }
.grp span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp.off { opacity: .45; }
.grp.off i { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--muted); }

#layerbar { display: flex; gap: 3px; margin-bottom: 10px; }
#layerbar button {
  flex: 1; height: 26px; border: 0; border-radius: 5px; background: #b3473b; font-size: 11px; color: rgba(255,255,255,.85);
  padding: 0; transition: opacity .2s, background .2s;
}
#layerbar button.gone { background: rgba(255,255,255,.08); color: var(--muted); }
#layerbar button:hover { outline: 1.5px solid var(--accent); }
.row { display: flex; gap: 8px; }
.row button, .foot button, .cact button {
  flex: 1; border: 1px solid var(--line); background: var(--chip); border-radius: 9px; padding: 8px 10px; font-size: 13px;
}
.row button:hover, .foot button:hover, .cact button:hover { border-color: rgba(255,255,255,.35); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button:disabled { opacity: .4; cursor: default; }
.foot { padding-top: 12px !important; }
.foot button { width: 100%; }
button.ghost { background: transparent; color: var(--muted); }

/* view buttons */
#views {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; gap: 4px; padding: 5px;
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 12px; z-index: 10; box-shadow: var(--shadow);
}
#views button { border: 0; background: transparent; border-radius: 8px; padding: 7px 13px; font-size: 13px; color: var(--muted); white-space: nowrap; }
#views button:hover { background: var(--chip); color: var(--text); }

#hiddenchip {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 10; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(14px); border-radius: 999px; padding: 7px 14px; font-size: 13px; box-shadow: var(--shadow);
}
#hiddenchip:hover { border-color: var(--accent); }

/* info card */
#card {
  position: fixed; top: 16px; right: 16px; width: 340px; max-height: calc(100% - 100px); overflow-y: auto;
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px 16px; z-index: 10;
}
.chead { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--chip-on); color: var(--accent); }
.side { font-size: 12px; color: var(--muted); flex: 1; }
#card h3 { margin: 10px 0 2px; font-size: 22px; line-height: 1.25; letter-spacing: -0.01em; }
#card .sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
#cbody { margin: 0; }
#cbody dt { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 10px; }
#cbody dd { margin: 3px 0 0; font-size: 14.5px; line-height: 1.55; }
#cbody dd.issue { color: #ffd3a8; }
.cact { display: flex; gap: 8px; margin-top: 16px; }
.cmore { width: 100%; margin-top: 8px; border: 1px solid rgba(255, 154, 61, .45); background: var(--chip-on); color: var(--accent); font-weight: 600; }
.cmore:hover { border-color: var(--accent); }

/* details sheet (textbook-level facts), docked left of the info card */
#detail {
  position: fixed; top: 16px; right: 372px; width: 400px; max-height: calc(100% - 100px); overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 18px 16px; z-index: 11;
}
.dhead { display: flex; align-items: flex-start; gap: 8px; }
.dhead > div { flex: 1; }
#detail h3 { margin: 2px 0 2px; font-size: 19px; }
#detail .sub { margin: 0 0 6px; color: var(--muted); font-size: 12.5px; }
#dbody { margin: 0; }
#dbody dt { font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 12px; letter-spacing: .02em; }
#dbody dd { margin: 3px 0 0; font-size: 14px; line-height: 1.6; }
.dsrc { margin: 14px 0 0; font-size: 11px; color: var(--muted); line-height: 1.45; border-top: 1px solid var(--line); padding-top: 8px; }

#tip {
  position: fixed; z-index: 30; pointer-events: none; background: rgba(8, 12, 22, .92); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 9px; font-size: 13px; white-space: nowrap; transform: translate(14px, 14px);
}
#tip small { color: var(--muted); margin-left: 6px; }
.small { font-size: 11.5px; line-height: 1.5; margin: 10px 0 0; }
#credits { position: fixed; right: 18px; bottom: 18px; font-size: 11px; color: rgba(154,171,196,.7); z-index: 5; pointer-events: none; }

button.wide { width: 100%; padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.res.scene .rn b::before { content: '▶ '; color: var(--accent); font-size: 11px; }

/* disease scene: story bar */
#story {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(780px, calc(100% - 32px));
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 16px 12px 18px; z-index: 12;
}
.shead { display: flex; align-items: center; gap: 10px; }
.shead h3 { margin: 0; font-size: 16.5px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shead .side { flex: none; font-variant-numeric: tabular-nums; }
#stext { margin: 9px 0 8px; font-size: 16.5px; line-height: 1.6; min-height: 3.2em; }
#slegend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--muted); }
#slegend:empty { display: none; }
.lg { display: inline-flex; align-items: center; gap: 7px; }
.lg i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.lg-focus i { background: #ff8a1f; }
.lg-hot i { background: #ff3a1c; box-shadow: 0 0 8px #ff3a1c; animation: lgpulse 1.5s ease-in-out infinite; }
.lg-pain i, .lg-signal i { width: 22px; height: 5px; border-radius: 3px; background-size: 12px 5px; animation: lgflow .7s linear infinite; }
.lg-pain i { background-image: linear-gradient(90deg, #ff3b1f 0 5px, #f2c84b 5px 12px); }
.lg-signal i { background-image: linear-gradient(90deg, #46a6ff 0 5px, #f2c84b 5px 12px); }
.lg-weak i { background: #8f9aac; }
.lg-cyst i { background: #ffe9a8; box-shadow: 0 0 6px rgba(255, 191, 71, .7); }
.lg-calcium i { background: #f8f4e8; border-radius: 3px; }
@keyframes lgpulse { 50% { opacity: .45; } }
@keyframes lgflow { to { background-position: 12px 0; } }
#scare { margin: 10px 0 0; font-size: 14px; line-height: 1.55; padding: 8px 11px; border-radius: 9px; background: rgba(120, 205, 145, .08); border: 1px solid rgba(120, 205, 145, .25); }
#scare b { color: #9be3b0; margin-right: 8px; }
.sfoot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
#sdots { flex: 1; display: flex; gap: 6px; }
#sdots button { width: 24px; height: 7px; border-radius: 4px; border: 0; padding: 0; background: rgba(255, 255, 255, .14); }
#sdots button.done { background: rgba(255, 154, 61, .45); }
#sdots button.on { background: var(--accent); }
.sfoot > button { border: 1px solid var(--line); background: var(--chip); border-radius: 9px; padding: 8px 15px; font-size: 13.5px; }
.sfoot > button:hover { border-color: rgba(255, 255, 255, .35); }
.sfoot > button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
body.storymode #views { display: none; }
body.storymode #detail { max-height: calc(100% - var(--story-h, 220px) - 32px); }
body.storymode #card { max-height: calc(100% - var(--story-h, 220px) - 32px); }

/* disease scene: picker */
#picker { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(5, 9, 18, .55); backdrop-filter: blur(3px); }
.pbox {
  width: min(880px, calc(100% - 32px)); max-height: calc(100% - 48px); overflow-y: auto; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 16px 20px 20px;
}
.pbox header { display: flex; align-items: center; gap: 8px; }
.pbox header h2 { flex: 1; margin: 0; font-size: 19px; }
.preg h3 { font-size: 12.5px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; letter-spacing: .02em; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 8px; }
.pitem { text-align: left; border: 1px solid var(--line); background: var(--chip); border-radius: 11px; padding: 10px 12px; }
.pitem:hover, .pitem:focus-visible { border-color: var(--accent); background: var(--chip-on); outline: none; }
.pitem b { display: block; font-size: 14.5px; }
.pitem span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

.pitem b em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--chip-on); border-radius: 999px; padding: 1px 7px; margin-left: 6px; vertical-align: 2px; }
.slink { flex: none; border: 1px solid rgba(255, 154, 61, .45); background: var(--chip-on); color: var(--accent); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.slink:hover { border-color: var(--accent); }

/* disc mechanics animation (discanim.js): full-screen, over the 3D view */
#danim { position: fixed; inset: 0; z-index: 45; background: radial-gradient(ellipse at 50% 38%, var(--bg1) 0%, var(--bg0) 70%); }
#dacv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.datop { position: absolute; top: 14px; left: 16px; right: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; pointer-events: none; }
.datop > * { pointer-events: auto; }
.dachap { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.dachap button { border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(10px); border-radius: 999px; padding: 6px 13px; font-size: 13px; color: var(--muted); }
.dachap button:hover { color: var(--text); border-color: rgba(255, 255, 255, .35); }
.dachap button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.dareg { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); backdrop-filter: blur(10px); }
.dareg button { border: 0; background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.dareg button:hover { color: var(--text); }
.dareg button.on { background: var(--chip-on); color: var(--accent); font-weight: 600; }
#daclose { width: 34px; height: 34px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; }
.dabar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(840px, calc(100% - 32px));
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 16px 12px 18px;
}
#datext { margin: 8px 0 4px; font-size: 15.5px; line-height: 1.55; }
.dactl { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; }
.dactl .icon { flex: none; width: 34px; height: 34px; border: 1px solid var(--line); background: var(--chip); color: var(--text); font-size: 13px; }
.dactl .icon:hover { border-color: var(--accent); }
.darange { flex: 1; min-width: 0; }
#daslider { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }
.daticks { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.danote { margin: 5px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.danote:empty { display: none; }
.dacare { margin: 10px 0 0; font-size: 14px; line-height: 1.55; padding: 8px 11px; border-radius: 9px; background: rgba(120, 205, 145, .08); border: 1px solid rgba(120, 205, 145, .25); }
.dacare b { color: #9be3b0; margin-right: 8px; }
#dadots { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; }
#dadots button { width: 24px; height: 7px; border-radius: 4px; border: 0; padding: 0; background: rgba(255, 255, 255, .14); }
#dadots button.gap { margin-left: 8px; }
#dadots button.done { background: rgba(255, 154, 61, .45); }
#dadots button.on { background: var(--accent); }

@media (max-width: 760px) {
  .dabar { bottom: 10px; padding: 10px 12px; }
  #datext { font-size: 15px; }
  .dachap button { padding: 5px 10px; font-size: 12px; }
  #story { bottom: 10px; padding: 10px 12px; }
  #stext { font-size: 15px; }
  #panel { width: calc(100% - 32px); max-height: 46vh; }
  #card { top: auto; bottom: 74px; right: 16px; left: 16px; width: auto; max-height: 42vh; }
  #detail { top: 16px; right: 16px; left: 16px; width: auto; max-height: calc(58vh - 110px); }
  #credits { bottom: 64px; right: 16px; }
  #views { bottom: 14px; }
  #views button { padding: 7px 9px; }
}

/* language list (app/i18n): a globe, the language's own name, a small arrow */
select.lang {
  appearance: none; -webkit-appearance: none; color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer;
  max-width: 132px; padding: 4px 24px 4px 27px; text-overflow: ellipsis; white-space: nowrap; color-scheme: dark;
  background-color: var(--chip);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%239aabc4' stroke-width='1.3'%3E%3Ccircle cx='8' cy='8' r='6.3'/%3E%3Cpath d='M1.7 8h12.6M8 1.7c1.9 1.8 2.9 3.9 2.9 6.3S9.9 12.5 8 14.3M8 1.7C6.1 3.5 5.1 5.6 5.1 8s1 4.5 2.9 6.3'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%239aabc4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 3.8l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 8px 50%, right 8px top 50%; background-size: 14px 14px, 10px 10px;
}
select.lang:hover, select.lang:focus-visible { border-color: rgba(255, 154, 61, .6); outline: none; }
select.lang option { background: var(--panel-solid); color: var(--text); }
/* a longer name of the viewer (some languages) wraps onto a second line instead of being cut */
#panel h1 { min-width: 0; line-height: 1.2; overflow-wrap: anywhere; }

/* each script in a font made for it (Chinese and Japanese would otherwise borrow the Korean font's Hanja and kana);
   the Korean names shown under other languages keep the Korean font */
:root:lang(ja) { font-family: "Segoe UI", "Yu Gothic UI", "Yu Gothic", Meiryo, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
:root:lang(zh-Hans) { font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
:root:lang(zh-Hant) { font-family: "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
:root:lang(th) { font-family: "Segoe UI", "Leelawadee UI", Leelawadee, Tahoma, Thonburi, "Noto Sans Thai", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
:root:lang(hi) { font-family: "Segoe UI", "Nirmala UI", "Kohinoor Devanagari", "Noto Sans Devanagari", Mangal, "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
:root:lang(ar) { font-family: "Segoe UI", Tahoma, "Geeza Pro", "Noto Sans Arabic", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }

/* right to left (Arabic): text runs from the right; the panels keep their places on screen */
[dir=rtl] select.lang { padding: 4px 27px 4px 24px; background-position: right 8px top 50%, 8px 50%; }
[dir=rtl] #panel header { padding: 14px 16px 10px 14px; }
[dir=rtl] #story { padding: 12px 18px 12px 16px; }
[dir=rtl] .grp, [dir=rtl] .pitem { text-align: right; }
[dir=rtl] #tip small { margin-left: 0; margin-right: 6px; }
[dir=rtl] .pitem b em { margin-left: 0; margin-right: 6px; }
[dir=rtl] #scare b, [dir=rtl] .dacare b { margin-right: 0; margin-left: 8px; }
[dir=rtl] #dadots button.gap { margin-left: 0; margin-right: 8px; }
/* group names wrap onto a second line instead of being cut short ("Ligaments, discs, cartilage", longer languages) */
.grp span { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.22; overflow-wrap: anywhere; hyphens: auto; }
:root:lang(ko) .grp span { word-break: keep-all; }
/* in the scene list, long words (German compounds) and the animation tag wrap instead of running out of their card */
.pitem b { overflow-wrap: anywhere; hyphens: auto; }
.pitem b em { display: inline-block; }
