/*! Bone Explorer | Copyright (c) 2026 Nicolas Nowinski | MIT License */
:root {
  --bg: #fff6e6;
  --ink: #26283f;
  --muted: #646a85;
  --card: #ffffff;
  --line: #f0e2c8;
  --accent: #ff7a59;
  --accent-dark: #e85a37;
  --sky: #4cc9f0;
  --good: #22b573;
  --bad: #ef476f;
  --sun: #ffd166;
  --stage-1: #2c3d82;
  --stage-2: #141c42;
  --bone: #efe4ca;
  --bone-far: #cdbf9f;
  --bone-deep: #a89878;
  --bone-edge: #8c7853;
  --rc: #4cc9f0;
  --panel-w: 390px;
  --peek: 84px;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(20, 28, 66, .18);
  --font-head: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); flex: none; }
.logo {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #ffb347); font-size: 26px;
  box-shadow: 0 4px 0 var(--accent-dark); transform: rotate(-8deg);
}
.brand-text { font-family: var(--font-head); font-weight: 800; font-size: 26px; letter-spacing: .2px; line-height: 1; }

.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%; height: 46px; border-radius: 999px; border: 3px solid var(--line);
  padding: 0 16px 0 44px; font: inherit; font-weight: 700; background: #fff; color: var(--ink);
}
.search input:focus { border-color: var(--sky); outline: none; }
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 18px; pointer-events: none; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: #fff; border-radius: 18px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto; z-index: 50;
}
.search-results li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; cursor: pointer;
}
.search-results li[aria-selected="true"], .search-results li:hover { background: #fff1d9; }
.search-results .em { font-size: 22px; flex: none; }
.search-results .nm { font-weight: 800; }
.search-results .sc { color: var(--muted); font-size: 14px; }
.search-results .none { color: var(--muted); cursor: default; }

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--line); background: #fff; font-size: 20px;
  display: grid; place-items: center;
}
.icon-btn[aria-pressed="true"] { background: #e5f8ff; border-color: var(--sky); }
.pill {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 800; background: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.12);
  transition: transform .1s;
}
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.12); }
.quiz-btn { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); font-size: 18px; height: 46px; }
.only-mobile { display: none; }

/* ---------- region chips ---------- */
.regions {
  display: flex; gap: 8px; padding: 2px 16px 12px; overflow-x: auto; scrollbar-width: none;
}
.regions::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: 7px 14px 7px 10px; font-weight: 800; background: #fff; box-shadow: inset 0 0 0 3px var(--c, #ddd);
  white-space: nowrap;
}
.chip .n { font-size: 12px; font-weight: 800; color: #fff; background: var(--c); border-radius: 999px; padding: 1px 7px; }
.chip.active { background: var(--c); color: #fff; }
.chip.active .n { background: rgba(255,255,255,.3); }

/* ---------- stage ---------- */
.stage {
  display: grid; grid-template-columns: 1fr var(--panel-w); gap: 14px;
  padding: 0 16px 16px; min-height: 0;
}
.canvas-wrap {
  position: relative; min-height: 0; border-radius: var(--radius); overflow: hidden;
  background:
    radial-gradient(circle at 50% 25%, rgba(120, 160, 255, .25), transparent 55%),
    radial-gradient(circle at 50% 40%, var(--stage-1), var(--stage-2) 75%);
  box-shadow: var(--shadow);
}
.canvas-wrap::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background-image: radial-gradient(rgba(255,255,255,.18) 1px, transparent 1.4px);
  background-size: 22px 22px;
}
#skeleton { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; display: block; }
#skeleton.dragging { cursor: grabbing; }
#skeleton.flip { animation: flip .5s ease-in-out; }
@keyframes flip { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.02); } 100% { transform: scaleX(1); } }

/* ---------- bones ---------- */
.bone { cursor: pointer; }
.bone .o { fill: var(--bone-edge); stroke: var(--bone-edge); stroke-linejoin: round; fill-rule: evenodd; transition: fill .15s, stroke .15s; }
.bone .f { fill: var(--bone); fill-rule: evenodd; transition: fill .15s; }
.bone.far .f { fill: var(--bone-far); }
.bone.deep .f { fill: var(--bone-deep); }
.bone .s, .decor .s { fill: #fff; opacity: .5; pointer-events: none; }
.bone.far .s { opacity: .25; }
.bone .dl { fill: none; stroke: var(--bone-edge); stroke-linecap: round; opacity: .55; pointer-events: none; }
.decor { pointer-events: none; }
.decor.hole .f { fill: #0b1026; }
.decor.cart .o { fill: #7f9fb0; stroke: #7f9fb0; stroke-linejoin: round; }
.decor.cart .f { fill: #cde4ee; }
.decor.cart .s { opacity: .35; }
.decor.tooth .o { fill: #a59f95; stroke: #a59f95; stroke-linejoin: round; }
.decor.tooth .f { fill: #fffdf7; }
.decor.soft .f { fill: #3b4c88; opacity: .8; }
.decor.drum .f { fill: #f2a7a7; }
.spiral { fill: none; stroke: #9fb3ea; stroke-width: 3.5; stroke-linecap: round; pointer-events: none; }
.note { fill: #fff; font-family: var(--font-head); font-weight: 700; font-size: 14px; pointer-events: none; }
.note.small { font-size: 11px; fill: #c8d3ff; }
.note.big { font-size: 18px; }
.side-label { fill: rgba(255,255,255,.3); font-family: var(--font-head); font-weight: 800; font-size: 34px; letter-spacing: 2px; text-transform: uppercase; pointer-events: none; }

.bone.rhl .f { fill: color-mix(in srgb, var(--rc) 28%, var(--bone)); }
.bone.rhl.far .f { fill: color-mix(in srgb, var(--rc) 28%, var(--bone-far)); }
.bone.rhl .o { fill: color-mix(in srgb, var(--rc) 60%, var(--bone-edge)); stroke: color-mix(in srgb, var(--rc) 60%, var(--bone-edge)); }
.bone.hover .f { fill: #ffe7a3; }
.bone.hover .o { fill: #d29a2c; stroke: #d29a2c; }
.bone.sel { filter: url(#glow); }
.bone.sel .f { fill: #ffb347; }
.bone.sel .o { fill: #b8560b; stroke: #b8560b; }
.bone.good .f { fill: #7ee2a8 !important; }
.bone.good .o { fill: #1d8a55 !important; stroke: #1d8a55 !important; }
.bone.bad .f { fill: #ff9fb3 !important; }
.bone.bad .o { fill: #c0284b !important; stroke: #c0284b !important; }
.bone.found-pulse { animation: pulse 1s ease-in-out 2; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- floating controls on the canvas ---------- */
.scene-tabs {
  position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.scene-tabs button {
  pointer-events: auto; border: 0; border-radius: 999px; padding: 6px 13px; font-weight: 800; font-size: 15px;
  background: rgba(255,255,255,.12); color: #e7ecff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.scene-tabs button[aria-selected="true"] { background: #fff; color: var(--ink); }
.head-chips {
  position: absolute; left: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.head-chips button {
  border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 800; background: var(--sun); color: var(--ink);
  box-shadow: 0 3px 0 #d8a73a; animation: pop .35s ease-out;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.zoom-ctrls { position: absolute; right: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.round {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: #fff; font-size: 22px; font-weight: 800;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); display: grid; place-items: center; line-height: 1;
}
.round:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
#btn-turn { background: var(--sky); color: #fff; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5; background: #fff; color: var(--ink); border-radius: 12px;
  padding: 5px 11px; font-weight: 800; font-size: 15px; box-shadow: var(--shadow); white-space: nowrap;
  transform: translate(-50%, calc(-100% - 16px));
}
.tooltip small { display: block; font-weight: 700; color: var(--muted); font-size: 12px; }
.sel-tag {
  position: absolute; pointer-events: none; z-index: 4; background: var(--accent); color: #fff; border-radius: 999px;
  padding: 4px 12px; font-family: var(--font-head); font-weight: 800; font-size: 16px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); box-shadow: 0 3px 0 var(--accent-dark);
}
.sel-tag::after {
  content: ''; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0;
  border-top-color: var(--accent);
}
.toast {
  position: absolute; left: 50%; top: 58px; transform: translate(-50%, -12px); opacity: 0; transition: .25s;
  background: #fff; color: var(--ink); padding: 8px 16px; border-radius: 999px; font-weight: 800; box-shadow: var(--shadow);
  pointer-events: none; z-index: 6; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- quiz bar ---------- */
.quizbar {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%); width: min(440px, calc(100% - 24px));
  background: #fff; border-radius: 20px; padding: 12px 14px; box-shadow: var(--shadow); z-index: 7;
  border: 4px solid var(--sun);
}
.quiz-top { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--muted); font-size: 14px; }
.quiz-score { color: #c58a00; }
.quiz-x { margin-left: auto; border: 0; background: #f3f0ea; width: 30px; height: 30px; border-radius: 50%; font-weight: 800; }
.quiz-q { font-family: var(--font-head); font-weight: 800; font-size: 22px; line-height: 1.15; margin: 4px 0 2px; }
.quiz-q small { display: block; font-family: var(--font-body); font-size: 14px; color: var(--muted); font-weight: 700; }
.quiz-msg { min-height: 1.4em; font-weight: 800; font-size: 15px; }
.quiz-msg.good { color: var(--good); }
.quiz-msg.bad { color: var(--bad); }
.quiz-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pill.soft { background: #f6f1e6; box-shadow: none; padding: 7px 13px; }
.pill.go { background: var(--good); color: #fff; box-shadow: 0 3px 0 #178a56; margin-left: auto; }

/* ---------- side panel / bottom sheet ---------- */
.panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-body { overflow-y: auto; padding: 20px 22px 24px; flex: 1; overscroll-behavior: contain; }
.grab { display: none; }

.card-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 11px; font-weight: 800; font-size: 13px;
  background: var(--c, #eee); color: #fff; border: 0;
}
.tag.side { background: #eef1ff; color: #3c4cad; }
.close-x { margin-left: auto; border: 0; background: #f3f0ea; width: 34px; height: 34px; border-radius: 50%; font-weight: 800; flex: none; }
.bone-title { font-family: var(--font-head); font-size: 34px; line-height: 1.05; margin: 6px 0 4px; font-weight: 800; }
.sci { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-weight: 700; margin-bottom: 14px; }
.sci b { color: var(--ink); }
.say { background: #fff1d9; border-radius: 8px; padding: 0 7px; font-size: 14px; color: #8a5a00; }
.speak-btn {
  border: 0; background: var(--sky); color: #fff; border-radius: 999px; padding: 8px 16px; font-weight: 800;
  box-shadow: 0 3px 0 #2a9cc4; display: inline-flex; align-items: center; gap: 6px;
}
.speak-btn.speaking { background: #2a9cc4; }
.box { border-radius: 18px; padding: 13px 15px; margin: 12px 0; }
.box h3 { margin: 0 0 4px; font-family: var(--font-head); font-size: 19px; line-height: 1.2; }
.box p { margin: 0; }
.box.what { background: #f2f7ff; }
.box.fact { background: #fff4d6; }
.box.try { background: #e9fbef; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.goto-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.goto { border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 800; background: var(--sun); box-shadow: 0 3px 0 #d8a73a; }
.nav-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; border-top: 2px dashed var(--line); padding-top: 14px; }
.nav-row .where { flex: 1; text-align: center; font-weight: 800; color: var(--muted); font-size: 14px; }
.nav-row button { border: 0; background: #f3f0ea; border-radius: 999px; padding: 8px 14px; font-weight: 800; }

.welcome h2, .region-card h2 { font-family: var(--font-head); font-size: 30px; line-height: 1.1; margin: 4px 0 8px; }
.welcome .hello { font-size: 52px; line-height: 1; }
.steps { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.steps li { display: flex; gap: 12px; align-items: center; background: #f8f4ec; border-radius: 16px; padding: 10px 12px; font-weight: 700; }
.steps .i { font-size: 26px; flex: none; width: 34px; text-align: center; }
.progress { margin: 16px 0; }
.progress .lbl { display: flex; justify-content: space-between; font-weight: 800; font-size: 15px; margin-bottom: 6px; }
.bar { height: 16px; border-radius: 999px; background: #f0e8d8; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--good), #9be15d); transition: width .5s; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.big-btn {
  border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 800; font-size: 17px; color: #fff; background: var(--sky);
  box-shadow: 0 4px 0 #2a9cc4;
}
.big-btn.orange { background: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.copyright { margin: 22px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.more-fact { border: 0; background: none; color: #a46b00; font-weight: 800; padding: 6px 0 0; }

.region-card .side-switch { display: inline-flex; background: #f3f0ea; border-radius: 999px; padding: 4px; margin: 4px 0 10px; }
.region-card .side-switch button { border: 0; background: none; border-radius: 999px; padding: 6px 14px; font-weight: 800; }
.region-card .side-switch button[aria-pressed="true"] { background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.bone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.bone-grid button {
  text-align: left; border: 0; border-radius: 14px; padding: 8px 11px; background: #f8f4ec; font-weight: 800; font-size: 14px; line-height: 1.2;
  display: flex; gap: 8px; align-items: center;
}
.bone-grid button small { display: block; font-weight: 700; color: var(--muted); font-size: 12px; }
.bone-grid button .ck { flex: none; width: 20px; height: 20px; border-radius: 50%; background: #e6dfd0; display: grid; place-items: center; font-size: 12px; color: #fff; }
.bone-grid button.found .ck { background: var(--good); }
.bone-grid button:hover { background: #fff1d9; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(20, 28, 66, .55); display: grid; place-items: center; padding: 16px;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-card {
  background: #fff; border-radius: 28px; padding: 26px 24px; width: min(460px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  text-align: center; box-shadow: var(--shadow); animation: pop .3s ease-out;
}
.modal-card h2 { font-family: var(--font-head); font-size: 32px; margin: 4px 0 6px; line-height: 1.1; }
.modal-card .em { font-size: 56px; line-height: 1; }
.levels { display: grid; gap: 10px; margin: 18px 0 8px; }
.levels button {
  border: 0; border-radius: 18px; padding: 12px 16px; text-align: left; display: flex; gap: 12px; align-items: center;
  background: #f8f4ec; box-shadow: inset 0 0 0 3px transparent; font-weight: 700;
}
.levels button:hover { box-shadow: inset 0 0 0 3px var(--sun); }
.levels .e { font-size: 34px; }
.levels b { display: block; font-family: var(--font-head); font-size: 21px; line-height: 1.1; }
.levels small { color: var(--muted); font-weight: 700; }
.stars { font-size: 46px; letter-spacing: 6px; margin: 8px 0; }
.link-btn { border: 0; background: none; color: var(--muted); font-weight: 800; margin-top: 8px; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 120; overflow: hidden; }
.confetti i { position: absolute; width: 10px; height: 14px; border-radius: 2px; top: -20px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* ---------- phones and small tablets ---------- */
@media (max-width: 820px) {
  body { font-size: 16px; }
  .topbar { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .logo { width: 38px; height: 38px; font-size: 22px; border-radius: 12px; }
  .brand-text { font-size: 22px; }
  .only-mobile { display: grid; }
  .search { display: none; position: absolute; left: 10px; right: 10px; top: calc(100% - 4px); max-width: none; margin: 0; }
  body.searching .search { display: block; }
  .icon-btn { width: 42px; height: 42px; font-size: 18px; }
  .quiz-btn { height: 42px; padding: 8px 14px; font-size: 16px; }
  .regions { padding: 0 12px 8px; }
  .chip { padding: 6px 12px 6px 9px; font-size: 15px; }
  .stage { display: block; position: relative; padding: 0; }
  .canvas-wrap { position: absolute; inset: 0; border-radius: 0; }
  .zoom-ctrls { bottom: calc(var(--sheet-h, var(--peek)) + 10px); right: 10px; gap: 7px; flex-direction: row; transition: bottom .3s cubic-bezier(.3, .8, .3, 1); }
  .round { width: 44px; height: 44px; font-size: 20px; }
  .head-chips { bottom: calc(var(--sheet-h, var(--peek)) + 64px); left: 10px; transition: bottom .3s cubic-bezier(.3, .8, .3, 1); }
  .head-chips button { font-size: 14px; padding: 7px 12px; }
  .scene-tabs { top: 8px; left: 8px; right: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .scene-tabs::-webkit-scrollbar { display: none; }
  .scene-tabs button { flex: none; font-size: 14px; padding: 6px 11px; }
  .quizbar { top: 48px; padding: 8px 12px; border-width: 3px; }
  .quiz-q { font-size: 19px; }
  .quiz-q small { font-size: 13px; }
  .quiz-msg { font-size: 14px; }
  .quiz-actions { margin-top: 2px; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; max-height: 54%;
    border-radius: 24px 24px 0 0; box-shadow: 0 -8px 30px rgba(20, 28, 66, .3);
    transform: translateY(calc(100% - var(--peek))); transition: transform .3s cubic-bezier(.3, .8, .3, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(0); }
  .grab {
    display: block; border: 0; background: none; padding: 10px 0 2px; width: 100%; flex: none; cursor: pointer;
  }
  .grab span { display: block; width: 46px; height: 6px; border-radius: 99px; background: #ddd3c0; margin: 0 auto; }
  .panel-body { padding: 4px 18px 20px; }
  .panel:not(.open) .panel-body { overflow: hidden; }
  .bone-title { font-size: 28px; }
  .welcome h2, .region-card h2 { font-size: 25px; }
  .welcome .hello { font-size: 40px; }
  .side-label { font-size: 40px; }
}
@media (max-width: 440px) {
  .logo { width: 34px; height: 34px; font-size: 20px; }
  .brand-text { font-size: 20px; }
  .icon-btn { width: 40px; height: 40px; }
  .quiz-btn { width: 44px; padding: 0; justify-content: center; display: grid; place-items: center; }
  .quiz-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
