:root {
  --bg: #f3ece2;
  --ink: #2c2620;
  --muted: #7b6f62;
  --card: rgba(255, 251, 245, 0.92);
  --line: rgba(60, 45, 30, 0.14);
  --accent: #c8643c;
  --shadow: 0 6px 24px rgba(40, 28, 15, 0.16);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: 'Rubik', system-ui, sans-serif; }
#app { position: fixed; inset: 0; }
#app canvas { display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; direction: ltr; }
#labels > * { left: 0; top: 0; direction: rtl; }

button, select { font: inherit; color: inherit; }

#top {
  position: fixed; top: max(12px, env(safe-area-inset-top)); inset-inline: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; pointer-events: none;
}
#top > * { pointer-events: auto; }
.clock { background: var(--card); border-radius: 16px; padding: 8px 16px; box-shadow: var(--shadow); line-height: 1.1; }
#day { font-size: 13px; color: var(--muted); }
#time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.speed { display: flex; background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.speed button { border: 0; background: none; padding: 7px 11px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.speed button.on { background: var(--ink); color: #fff; }

#panel {
  position: fixed; bottom: max(12px, env(safe-area-inset-bottom)); inset-inline: 16px;
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px; max-width: 980px; margin-inline: auto;
}
.scrub { display: flex; gap: 10px; align-items: center; }
.scrub select { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 8px; }
#timeSlider { flex: 1; accent-color: var(--accent); direction: ltr; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff;
  border-radius: 14px; padding: 6px 12px 6px 10px; cursor: pointer; text-align: start;
}
.chip .dot { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 15px; }
.chip b { display: block; font-size: 14px; }
.chip span { display: block; font-size: 12px; color: var(--muted); }
.chip.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.views { display: flex; gap: 6px; flex-wrap: wrap; }
#rooms {
  position: absolute; bottom: calc(100% + 8px); inset-inline: 0; background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow); padding: 10px; display: none;
}
#panel.rooms-open #rooms { display: flex; }
.views button, .chips.small button {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 13px;
}
.views button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chips.small { gap: 6px; }

.tag {
  transform: translateY(-6px); background: rgba(255, 251, 245, 0.95); border-radius: 12px; padding: 3px 8px 3px 9px;
  font-size: 12px; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.18); display: flex; gap: 5px; align-items: center;
  pointer-events: auto; cursor: pointer;
}
.tag .em { font-size: 14px; }
.room-label {
  font-size: 12px; color: #fff; background: rgba(44, 38, 32, 0.55); padding: 2px 8px; border-radius: 8px;
  pointer-events: auto; cursor: pointer; white-space: nowrap;
}

#loading { position: fixed; inset: 0; display: grid; place-content: center; gap: 12px; background: var(--bg); z-index: 5; text-align: center; transition: opacity .5s; }
#loading .bar { width: 220px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#loading p { margin: 0; color: var(--muted); }

@media (max-width: 640px) {
  #panel { padding: 10px; gap: 8px; }
  #time { font-size: 22px; }
  .speed button { padding: 6px 8px; font-size: 13px; }
  .chip { padding: 5px 9px 5px 8px; }
  .chip span { font-size: 11px; }
  .chip .dot { width: 22px; height: 22px; font-size: 13px; }
  .chips { gap: 6px; }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-skin="xp"]) { --card: rgba(36, 32, 28, 0.92); --ink: #f2ebe2; --muted: #b3a797; --line: rgba(255,255,255,.14); }
  :root:not([data-theme="light"]):not([data-skin="xp"]) .chip, :root:not([data-theme="light"]):not([data-skin="xp"]) .views button,
  :root:not([data-theme="light"]):not([data-skin="xp"]) .chips.small button, :root:not([data-theme="light"]):not([data-skin="xp"]) .scrub select { background: #2c2824; }
  :root:not([data-theme="light"]):not([data-skin="xp"]) .speed button.on, :root:not([data-theme="light"]):not([data-skin="xp"]) .views button.on { background: #f2ebe2; color: #222; }
  :root:not([data-theme="light"]):not([data-skin="xp"]) .tag { background: rgba(36,32,28,.95); color: #f2ebe2; }
}

/* ---------- first-person walk ---------- */
#walkbar, #stick, .xp-title, #xpbar { display: none; }
body.walking #panel { display: none; }
body.walking #walkbar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center;
  position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); inset-inline: 16px; pointer-events: none;
}
#walkbar button { pointer-events: auto; border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 10px 16px; cursor: pointer; }
#walkbar .hint { background: rgba(0,0,0,.45); color: #fff; font-size: 12px; padding: 5px 10px; border-radius: 8px; }
@media (pointer: coarse) {
  #walkbar .hint { display: none; }
  body.walking #walkbar { justify-content: flex-start; }
  body.walking #stick {
    display: block; position: fixed; left: 24px; bottom: calc(90px + env(safe-area-inset-bottom)); width: 120px; height: 120px;
    border-radius: 50%; background: rgba(255,255,255,.25); border: 2px solid rgba(255,255,255,.6); touch-action: none;
  }
  #stick i { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: var(--shadow); }
}
