@font-face {
  font-family: "Avali";
  src: url("../assets/avali_font.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #000;
  --panel: rgba(10, 14, 22, 0.78);
  --panel-solid: #0b1018;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f5f8;
  --muted: #9aa6b4;
  --accent: #ffa62b;
  --accent-dim: rgba(255, 166, 43, 0.18);
  --on-accent: #1d1206;
  --radius: 10px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-cond: "Barlow Condensed", "Barlow", system-ui, sans-serif;
}

/* Avali script switch: letters, digits and punctuation use the Avali font;
   anything it lacks (°, ä, ⊕ …) falls back to Barlow per character. */
body.avali-font {
  --font: "Avali", "Barlow", system-ui, sans-serif;
  --font-cond: "Avali", "Barlow Condensed", "Barlow", system-ui, sans-serif;
}

/* The switch itself stays readable so it can always be turned back off. */
#toggle-font { font-family: "Barlow", system-ui, sans-serif; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* ---------- Labels ---------- */

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  font-family: var(--font-cond);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 0 4px #000, 0 0 2px #000;
  will-change: transform;
  user-select: none;
}

.label .dot {
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  border-radius: 50%;
  border: 1.5px solid var(--c, #fff);
  flex: none;
  transition: transform 0.15s;
}

.label.big .dot { visibility: hidden; }
.label.minor { font-size: 12px; color: rgba(255, 255, 255, 0.62); }
.label:hover { color: #fff; }
.label:hover .dot { transform: scale(1.35); background: var(--c); }
.label.active { color: var(--accent); }
.label.hidden { display: none; }

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), transparent);
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-cond);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 6px;
  border-radius: 6px;
}

.brand img { width: 28px; height: 28px; display: block; }
.brand:hover { background: rgba(255, 255, 255, 0.06); }

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
}

#breadcrumb button {
  padding: 3px 6px;
  border-radius: 5px;
  color: var(--muted);
  white-space: nowrap;
}

#breadcrumb button:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
#breadcrumb button:last-child { color: var(--text); }
#breadcrumb .sep { opacity: 0.5; }

.tools { display: flex; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.chip svg { width: 16px; height: 16px; }
.chip:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.3); }
.chip.on { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }
.chip.accent { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.chip.accent:hover { filter: brightness(1.1); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text);
  transition: background 0.15s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Panels ---------- */

.panel {
  position: fixed;
  top: 64px;
  max-height: calc(100% - 150px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  transition: opacity 0.25s, transform 0.25s;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.panel.hidden { opacity: 0; pointer-events: none; }

#explore {
  left: 16px;
  top: 64px;
  width: 290px;
  padding: 10px;
}

#explore.hidden { transform: translateX(-12px); }

.panel-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }

#search {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  outline: none;
}

#search:focus { border-color: var(--accent); }

#body-list { list-style: none; margin: 0; padding: 0; }

#body-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
}

#body-list button:hover { background: rgba(255, 255, 255, 0.07); }
#body-list button.active { background: var(--accent-dim); }
#body-list .swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#body-list .name { flex: 1; }
#body-list .type { color: var(--muted); font-size: 12px; text-transform: capitalize; }
#body-list li.hidden { display: none; }

#info {
  right: 16px;
  width: 360px;
  padding: 20px 22px 22px;
}

#info.hidden { transform: translateX(12px); }

#info .close { position: absolute; top: 10px; right: 10px; font-size: 22px; }
.panel-head .close { font-size: 22px; }

.kicker {
  margin: 0 0 2px;
  color: var(--accent);
  font-family: var(--font-cond);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#info h1 {
  margin: 0 0 12px;
  font-family: var(--font-cond);
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
}

#info h2 {
  margin: 20px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.desc { line-height: 1.55; color: #d6dde5; }
.desc p { margin: 0 0 0.8em; }
.desc a { color: var(--accent); }
.desc img { max-width: 100%; border-radius: 6px; }

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  margin: 0;
  font-size: 14px;
}

.facts dt, .facts dd {
  margin: 0;
  padding: 7px 0;
  border-top: 1px solid var(--line);
}

.facts dt { color: var(--muted); padding-right: 14px; }
.facts dd { text-align: right; font-variant-numeric: tabular-nums; }

#info-children { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
#info-children:empty { display: none; }

/* ---------- Time bar ---------- */

.timebar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.timebar .play { background: var(--accent); color: var(--on-accent); width: 42px; height: 42px; }
.timebar .play:hover { background: var(--accent); filter: brightness(1.1); }
.timebar .i-play { display: none; }
.timebar.paused .i-play { display: block; }
.timebar.paused .i-pause { display: none; }

.time {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 190px;
  padding: 0 8px;
  line-height: 1.2;
}

#date-btn {
  font-family: var(--font-cond);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
  border-radius: 5px;
}

#date-btn:hover { background: rgba(255, 255, 255, 0.08); }
#rate-label { font-size: 12px; color: var(--muted); }
.timebar.paused #rate-label { color: #ffb648; }

#date-pop {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#date-pop.hidden { display: none; }
#date-pop label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }

#date-pop input {
  height: 34px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #121924;
  color: var(--text);
  font: inherit;
  color-scheme: dark;
}

#date-pop .row { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; }

/* ---------- About dialog ---------- */

.chip.round { width: 32px; padding: 0; justify-content: center; }
.chip.round svg { width: 18px; height: 18px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}

.modal.hidden { opacity: 0; pointer-events: none; }

.modal-card {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100% - 32px);
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  line-height: 1.55;
  color: #d6dde5;
  transition: transform 0.2s;
}

.modal.hidden .modal-card { transform: translateY(8px); }
.modal-card .close { position: absolute; top: 10px; right: 10px; font-size: 22px; }
.modal-card p { margin: 0 0 12px; }
.modal-card a { color: var(--accent); }
.modal-card h2 { margin: 18px 0 6px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }

.about-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.about-head img {
  width: 88px; height: 88px; flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
  background: #111;
}
.about-head h1 { margin: 0; font-family: var(--font-cond); font-size: 28px; font-weight: 600; line-height: 1.1; color: var(--text); }
.about-head .kicker { margin: 0; }
.about-head .byline { margin: 4px 0 0; color: var(--muted); }
.about-head .byline strong { color: var(--accent); }

.credits dd { text-align: left; }
.credits dt { white-space: nowrap; }

/* ---------- Scale bar ---------- */

#scalebar {
  position: fixed;
  left: 16px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#scalebar .bar {
  display: block;
  height: 6px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-top: 0;
}

#scalebar.hidden { display: none; }

/* ---------- Loading ---------- */

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000;
  color: var(--muted);
  font-family: var(--font-cond);
  font-size: 18px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  transition: opacity 0.6s;
}

#loading.done { opacity: 0; pointer-events: none; }
#loading.error { color: #ff8080; letter-spacing: 0.02em; text-transform: none; padding: 16px; text-align: center; }

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
  #breadcrumb { order: 5; width: 100%; }
  .tools .chip { padding: 0 10px; }
  .brand { font-size: 17px; }

  #explore { left: 16px; right: 16px; width: auto; top: 140px; max-height: calc(100% - 230px); }
  #scalebar { top: 100px; bottom: auto; left: auto; right: 16px; align-items: flex-end; }

  #info {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 84px;
    width: auto;
    max-height: 46%;
  }

  #info.hidden { transform: translateY(12px); }
  #info h1 { font-size: 32px; }

  .timebar { left: 16px; right: 16px; transform: none; justify-content: center; }
  .time { min-width: 0; flex: 1; }
  #date-btn { font-size: 15px; }
  #now-btn { padding: 0 10px; }
  #date-pop { left: 0; transform: none; }
}
