/* ------------------------------------------------------------------
   Yiyi's room — UI chrome around the 3D scene.
   The day/night switch in the room drives body[data-time].
------------------------------------------------------------------ */
:root {
  --ink: #2b2635;
  --muted: #6b6480;
  --glass: rgba(255, 251, 247, 0.8);
  --glass-strong: rgba(255, 251, 247, 0.94);
  --line: rgba(60, 40, 90, 0.12);
  --accent: #7c6bc4;
  --accent-ink: #ffffff;
  --chip: rgba(124, 107, 196, 0.12);
  --shadow: 0 10px 30px rgba(60, 40, 90, 0.14), 0 2px 6px rgba(60, 40, 90, 0.08);
  --radius: 22px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: "Caveat", "Comic Sans MS", cursive;
  --pixel: "Press Start 2P", monospace;
  color-scheme: light;
}
body[data-time="night"] {
  --ink: #f1ecff;
  --muted: #b3aacb;
  --glass: rgba(26, 22, 38, 0.78);
  --glass-strong: rgba(26, 22, 38, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #b8a8ff;
  --accent-ink: #1a1626;
  --chip: rgba(184, 168, 255, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
/* The room is an app-like page: the browser's own pinch-zoom is off (the room has its own). */
html, body { touch-action: pan-x pan-y; }
body {
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: #efe6f7;
  -webkit-font-smoothing: antialiased;
  transition: color 0.4s;
}
button { font: inherit; color: inherit; }
a { color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- layers ---------- */
.bg, #css3d, #webgl { position: fixed; inset: 0; }
.bg { z-index: 0; background: radial-gradient(120% 90% at 20% 10%, #fff4ea 0%, #f3e6f6 45%, #ddd3f0 100%); }
.bg::after {
  content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity 0.9s ease;
  background: radial-gradient(120% 90% at 20% 10%, #2e2750 0%, #1d1834 50%, #120f22 100%);
}
body[data-time="night"] .bg::after { opacity: 1; }
#css3d { z-index: 1; overflow: hidden; }
#webgl { z-index: 2; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
body.screen-live #webgl { pointer-events: none; }
.screen3d { background: #120f1a; }
.screen3d iframe { width: 100%; height: 100%; border: 0; display: block; background: #120f1a; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 14px max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  padding: 7px 14px 7px 9px; border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.brand img { image-rendering: pixelated; width: 22px; height: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-text small { font-size: 11.5px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none;
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); transition: transform 0.15s, background 0.3s;
}
.pill:hover { transform: translateY(-1px); }
.pill.ghost { background: var(--glass); color: var(--ink); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.back { display: none; }
body.focused .back { display: inline-flex; animation: pop 0.25s ease; }

.hud-nav {
  display: flex; gap: 2px; margin: 0 auto; padding: 5px;
  border-radius: 999px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: var(--shadow);
}
.hud-nav button {
  border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.hud-nav button:hover { color: var(--ink); background: var(--chip); }
.hud-nav button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
.hud-tools { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: var(--shadow);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn .i-moon { fill: currentColor; stroke: none; }
body[data-time="day"] .i-sun, body[data-time="night"] .i-moon { display: none; }

button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- floating bits ---------- */
.tooltip {
  position: fixed; z-index: 30; left: 0; top: 0; pointer-events: none;
  padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 500;
  background: #2b2635; color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  opacity: 0; transition: opacity 0.15s; white-space: nowrap;
}
.tooltip.show { opacity: 1; }
body[data-time="night"] .tooltip { background: #f1ecff; color: #1a1626; }

.hint {
  position: fixed; z-index: 15; left: 50%; bottom: 28px; margin: 0;
  transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; color: var(--ink);
  background: var(--glass); border: 1px solid var(--line); box-shadow: var(--shadow);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.5s, transform 0.5s;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

.toast {
  position: fixed; z-index: 40; left: 50%; top: 90px; transform: translate(-50%, -12px);
  padding: 10px 18px; border-radius: 999px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.3s, transform 0.3s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.bubble {
  position: fixed; z-index: 25; left: 0; top: 0; pointer-events: none;
  padding: 6px 12px; border-radius: 14px; font-family: var(--hand); font-size: 24px; line-height: 1.1;
  background: #fff; color: #2b2635; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
  opacity: 0; transition: opacity 0.2s;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -7px;
  border: 7px solid transparent; border-bottom: 0; border-top-color: #fff;
}
.bubble.show { opacity: 1; }

/* ---------- now playing ---------- */
.now-playing {
  position: fixed; z-index: 16; left: 18px; bottom: 20px;
  display: flex; align-items: center; gap: 4px; padding: 7px 8px 7px 8px; border-radius: 999px;
  background: var(--glass-strong); border: 1px solid var(--line); box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 0.35s, transform 0.35s;
}
.now-playing { visibility: hidden; }
.now-playing.show { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.np-disc {
  width: 34px; height: 34px; border-radius: 50%; flex: none; margin-right: 6px;
  background: radial-gradient(circle, var(--accent) 0 5px, #1d1b1f 6px 9px, #2c2a30 10px 11px, #1d1b1f 12px 14px, #2c2a30 15px);
  animation: spin 3s linear infinite; animation-play-state: paused;
}
.now-playing.playing .np-disc { animation-play-state: running; }
.np-text { display: flex; flex-direction: column; line-height: 1.15; margin-right: 6px; max-width: 150px; }
.np-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-text small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-text small:empty { display: none; }
.np-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: transparent; color: var(--ink); font-size: 13px; transition: background 0.2s;
}
.np-btn:hover { background: var(--chip); }
#np-play { background: var(--accent); color: var(--accent-ink); }

/* ---------- side panel ---------- */
.panel {
  position: fixed; z-index: 18; right: 18px; top: 76px; bottom: 18px;
  width: min(420px, calc(100vw - 36px));
  border-radius: var(--radius); background: var(--glass-strong); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transform: translateX(calc(100% + 30px)); display: flex; flex-direction: column;
  /* hidden with visibility, not the inert attribute: iOS Safari can leave a once-inert
     scroll area unscrollable by touch */
  visibility: hidden;
  transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.55s;
}
.panel.open { transform: none; visibility: visible; transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
.panel-close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; box-shadow: none; z-index: 1; }
.panel-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 28px 28px 30px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
.panel-body h2 { font-size: 27px; line-height: 1.15; letter-spacing: -0.02em; margin: 2px 40px 14px 0; }
.panel-body h3 { font-size: 16px; margin: 0 0 6px; line-height: 1.3; }
.panel-body p, .panel-body li { font-size: 15px; line-height: 1.6; color: var(--ink); }
.panel-body p { margin: 0 0 14px; }
.eyebrow {
  margin: 0 !important; font-size: 12px !important; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent) !important;
}
.p-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.p-head h2 { margin-bottom: 2px; }
.avatar { width: 88px; height: 88px; object-fit: cover; border-radius: 50%; border: 3px solid var(--glass-strong); box-shadow: var(--shadow); flex: none; }
.role { margin: 0 !important; color: var(--muted) !important; font-size: 14px !important; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.chip-link {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  padding: 8px 13px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--chip); color: var(--ink); transition: background 0.2s, transform 0.15s;
}
.chip-link:hover { background: var(--accent); color: var(--accent-ink); transform: translateY(-1px); }
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 6px;
  padding: 15px 18px; border-radius: 16px; text-decoration: none; font-weight: 700; font-size: 16px;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); word-break: break-all;
}
.aside { color: var(--muted) !important; font-size: 14px !important; margin-top: 18px !important; }
.aside a { color: var(--accent); font-weight: 600; text-decoration: none; }
.aside a:hover { text-decoration: underline; }

.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline > li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--chip); margin-left: 6px; }
.timeline > li::before {
  content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--glass-strong);
}
.timeline > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.when { margin: 0 0 2px !important; font-size: 12.5px !important; font-weight: 600; color: var(--muted) !important; }
.timeline ul { margin: 6px 0 0; padding-left: 18px; }
.timeline ul li { font-size: 14px; line-height: 1.55; margin-bottom: 4px; }

.sub { margin-top: 18px !important; color: var(--muted); font-size: 13px !important; text-transform: uppercase; letter-spacing: 0.1em; }
.plain { margin: 6px 0 10px; padding-left: 18px; }
.plain li { font-size: 14px; line-height: 1.55; }
details { border-top: 1px solid var(--line); padding: 10px 0; }
details:last-of-type { border-bottom: 1px solid var(--line); }
summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; color: var(--accent); transition: transform 0.2s; }
details[open] summary::before { transform: rotate(90deg); }
summary span { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--accent); }

/* ---------- tool bars ---------- */
.toolbar {
  position: fixed; z-index: 18; left: 50%; bottom: 22px;
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px;
  border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transform: translate(-50%, 140%); opacity: 0; visibility: hidden;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s, visibility 0s linear 0.45s;
}
.toolbar.open { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s, visibility 0s; }
.tb-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; background: var(--c);
  border: 3px solid var(--glass-strong); box-shadow: 0 0 0 1px var(--line); transition: transform 0.15s, box-shadow 0.15s;
}
.swatch.on { transform: scale(1.12); box-shadow: 0 0 0 2px var(--accent); }
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; white-space: nowrap;
  padding: 8px 14px; border-radius: 999px; border: 0; font-size: 14px; font-weight: 600;
  background: var(--chip); color: var(--ink); transition: background 0.2s, color 0.2s;
}
.tb-btn:hover, .tb-btn.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- full-screen screen view (touch devices) ---------- */
.modal {
  position: fixed; z-index: 60; inset: 0; display: flex; flex-direction: column;
  background: #120f1a; opacity: 0; pointer-events: none; transform: scale(0.96); visibility: hidden;
  transition: opacity 0.35s, transform 0.35s, visibility 0s linear 0.35s;
}
.modal.open { opacity: 1; pointer-events: auto; transform: none; visibility: visible; transition: opacity 0.35s, transform 0.35s, visibility 0s; }
.modal-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px; color: #f1ecff; font-weight: 600; font-size: 14px;
}
.modal iframe { flex: 1; width: 100%; border: 0; background: #120f1a; }

/* ---------- loader & fallback ---------- */
.loader {
  position: fixed; z-index: 100; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 90% at 20% 10%, #fff4ea 0%, #f3e6f6 45%, #ddd3f0 100%);
  transition: opacity 0.8s ease 0.1s, visibility 0s linear 0.9s;
}
body[data-time="night"] .loader { background: radial-gradient(120% 90% at 20% 10%, #2e2750 0%, #1d1834 50%, #120f22 100%); }
body.ready .loader { opacity: 0; visibility: hidden; }
.loader-card { display: grid; justify-items: center; gap: 14px; }
.loader-sprite { image-rendering: pixelated; animation: hop 0.7s ease-in-out infinite alternate; }
.loader-title { margin: 0; font-family: var(--pixel); font-size: 12px; letter-spacing: 0.05em; color: var(--muted); }
.loader-track { width: 180px; height: 8px; border-radius: 99px; background: var(--chip); overflow: hidden; }
#loader-bar { height: 100%; background: var(--accent); transform: scaleX(0.08); transform-origin: left; transition: transform 0.4s; }
.loader-slow { display: none; margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.loader-slow a { color: var(--accent); font-weight: 600; }
.loader.slow .loader-slow { display: block; }

.fallback {
  position: fixed; z-index: 110; inset: 0; display: none; place-items: center; align-content: center; gap: 16px;
  padding: 24px; text-align: center; background: #efe6f7; color: #2b2635;
}
body.no-webgl .fallback, .fallback.show { display: grid; }

@keyframes hop { to { transform: translateY(-10px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .brand-text small { display: none; }
  .hud-nav button { padding: 8px 11px; font-size: 13.5px; }
}
@media (max-width: 900px) {
  .classic { display: none; }
}
@media (max-width: 760px) {
  .hud { padding-top: max(10px, env(safe-area-inset-top)); gap: 8px; }
  .brand { padding: 6px 12px 6px 8px; }
  .hud-tools { margin-left: auto; }
  .classic { display: inline-flex; padding: 9px 13px; font-size: 13px; }
  .hud-nav {
    position: fixed; left: 10px; right: 10px; bottom: max(12px, env(safe-area-inset-bottom));
    margin: 0; overflow-x: auto; scrollbar-width: none; justify-content: flex-start;
  }
  .hud-nav::-webkit-scrollbar { display: none; }
  body.focused .hud-nav { display: none; }
  body.focused .brand { display: none; }
  .panel {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; height: 58vh; height: 58dvh;
    border-radius: var(--radius) var(--radius) 0 0; transform: translateY(105%);
  }
  .panel-body { padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
  .panel-body h2 { font-size: 23px; }
  .hint { bottom: 86px; font-size: 13px; white-space: nowrap; }
  .toolbar { bottom: max(16px, env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); gap: 6px; padding: 7px 8px; }
  .tb-label { display: none; }
  #wb-tools .tb-text { display: none; }
  #wb-tools .tb-btn { padding: 8px 11px; }
  .swatch { width: 28px; height: 28px; }
  .now-playing { left: 10px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 66px); }
  body.focused .now-playing { display: none; }
}

/* Phones and tablets (html.touch, set in index.html): no frosted-glass blur. It's expensive over a 3D scene and
   can break scrolling in iPhone Safari; slightly more opaque panels instead. */
html.touch *, html.touch *::before, html.touch *::after { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
html.touch body[data-time="day"] { --glass: rgba(255, 251, 247, 0.94); --glass-strong: rgba(255, 251, 247, 0.98); }
html.touch body[data-time="night"] { --glass: rgba(26, 22, 38, 0.94); --glass-strong: rgba(26, 22, 38, 0.98); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
