:root {
  --accent: #ffb347;
  --glow: #ffe9a8;
  --ink: #2b2118;
  --panel: rgba(30, 40, 28, 0.62);
  --quiet: #6ee7a0;
  --warn: #ffd166;
  --loud: #ff6b6b;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: #fff; }
button, select { font: inherit; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ---------- Scene: a 16:9 stage that always covers the screen ---------- */
#viewport { position: fixed; inset: 0; overflow: hidden; }
#stage {
  position: absolute;
  left: 50%; top: 50%;
  width: max(100vw, 177.78vh);
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
}
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* Film grain over the scene, for themes that set grain: true */
#stage.grain::after {
  content: '';
  position: absolute; inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Speech bubbles (a creature's says and chat in theme.js). js/three/stage.js
   pins them above heads with the translate property and sets .show. */
#bubbles3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.bubble {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, -100%) scale(0.6);
  transform-origin: 50% 100%;
  width: max-content; max-width: 22vh;
  padding: 0.7vh 1.2vh;
  border-radius: 1.4vh;
  background: #fff;
  color: var(--ink);
  font-size: 1.9vh; font-weight: 800; line-height: 1.15;
  text-align: center;
  box-shadow: 0 0.4vh 1.2vh rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 2;
}
.bubble::after {
  content: '';
  position: absolute; left: 50%; top: 100%;
  border: 0.8vh solid transparent;
  border-top-color: #fff;
  transform: translateX(-50%);
}
.bubble.show { opacity: 1; transform: translate(-50%, -100%) scale(1); }

@keyframes pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.55; }
  50% { transform: scale(1.08); opacity: 0.9; }
}

/* Red edges when the room is too loud */
#alarm {
  position: fixed; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 18vh 4vh rgba(255, 70, 70, 0.75);
  opacity: 0;
  transition: opacity 0.4s;
  z-index: 6;
}
body.warning #alarm { opacity: 0.3; box-shadow: inset 0 0 14vh 2vh rgba(255, 200, 80, 0.7); }
body.noisy #alarm { opacity: 1; animation: alarm 1s ease-in-out infinite alternate; }
@keyframes alarm { from { opacity: 0.55; } to { opacity: 1; } }

/* ---------- HUD ---------- */
#hud-top, #hud-bottom {
  position: fixed; left: 0; right: 0;
  display: flex; align-items: center; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top { top: 0; align-items: flex-start; }
#hud-bottom { bottom: 0; align-items: flex-end; }
#hud-top > *, #hud-bottom > * { pointer-events: auto; }

#toolbar { display: flex; gap: 0.5vw; transition: opacity 0.5s; }
body.idle #toolbar { opacity: 0; }
#toolbar button {
  width: 5.2vh; height: 5.2vh;
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  backdrop-filter: blur(6px);
  font-size: 2.6vh;
  cursor: pointer;
  color: #fff;
}
#toolbar button:hover { background: rgba(255, 255, 255, 0.25); }

#message {
  margin: 0 auto;
  text-align: center;
  font-size: clamp(22px, 4.6vh, 64px);
  font-weight: 800;
  line-height: 1.15;
  padding: 0.6vh 2.4vw;
  border-radius: 4vh;
  background: var(--panel);
  backdrop-filter: blur(6px);
  text-shadow: 0 0.3vh 0 rgba(0, 0, 0, 0.35), 0 0 3vh rgba(0, 0, 0, 0.45);
  transition: transform 0.3s, color 0.3s;
}
#message:empty { visibility: hidden; }
#message.pop { animation: message-pop 0.5s cubic-bezier(.2, .9, .3, 1.4); }
body.noisy #message { color: #ffd5d5; }
@keyframes message-pop { from { transform: scale(0.85); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

#score {
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-radius: 2vh;
  padding: 1vh 1.6vw;
  text-align: right;
}
#stars { font-size: 5vh; font-weight: 800; line-height: 1; display: flex; align-items: center; gap: 0.6vw; justify-content: flex-end; }
#stars.bump .star { display: inline-block; animation: star-bump 0.9s cubic-bezier(.2, .9, .3, 1.5); }
@keyframes star-bump { 0% { transform: scale(0.4) rotate(-90deg); } 60% { transform: scale(1.6) rotate(15deg); } 100% { transform: scale(1); } }
#streak { font-size: 2.1vh; opacity: 0.9; white-space: nowrap; }

#next {
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-radius: 2.4vh;
  padding: 1.2vh;
  width: 17vh;
  text-align: center;
}
#next-art { position: relative; height: 13vh; display: grid; place-items: center; }
#next-art img { position: absolute; max-height: 100%; max-width: 100%; }
#next-shadow { filter: brightness(0) opacity(0.55); }
#next-fill { transition: clip-path 0.25s linear; }
#next-mystery {
  font-size: 9vh; font-weight: 800;
  color: var(--glow);
  text-shadow: 0 0 2vh var(--accent);
  display: none;
}
#next.mystery #next-mystery { display: block; animation: pulse 1.4s ease-in-out infinite; }
#next.mystery img { display: none; }
#next-label { font-size: 2vh; font-weight: 700; margin-top: 0.4vh; }

#meter-wrap {
  flex: 1;
  display: flex; align-items: center; gap: 1.4vw;
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-radius: 2.4vh;
  padding: 1.6vh 2vw;
  margin-bottom: 0.5vh;
}
#meter-face { font-size: 6vh; line-height: 1; transition: transform 0.2s; }
body.noisy #meter-face { animation: shiver 0.25s linear infinite; }
#meter {
  position: relative;
  flex: 1;
  height: 4.4vh;
  border-radius: 2.2vh;
  background: rgba(0, 0, 0, 0.35);
  overflow: visible;
}
#meter-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0;
  border-radius: 2.2vh;
  background: var(--quiet);
  box-shadow: 0 0 2vh var(--quiet);
  transition: background 0.3s, box-shadow 0.3s;
}
body.warning #meter-fill { background: var(--warn); box-shadow: 0 0 2vh var(--warn); }
body.noisy #meter-fill { background: var(--loud); box-shadow: 0 0 2.4vh var(--loud); }
#meter-line {
  position: absolute; top: -1.2vh; bottom: -1.2vh;
  width: 0.5vh;
  margin-left: -0.25vh;
  background: #fff;
  border-radius: 0.3vh;
  transition: left 0.3s;
}
#meter { cursor: ew-resize; touch-action: none; }
#meter.dragging #meter-line { transition: none; }
#meter-line i {
  position: absolute; left: 50%; top: 50%;
  width: 2.6vh; height: 2.6vh;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0.3vh 1vh rgba(0, 0, 0, 0.4);
}
#meter-line i::before {
  content: '⇔';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-style: normal; font-size: 1.8vh; font-weight: 800;
  color: #333;
}
#sensitivity { display: flex; gap: 0.6vh; }
#sensitivity button {
  width: 5vh; height: 5vh;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 3.4vh; font-weight: 800; line-height: 1;
  cursor: pointer;
}
#sensitivity button:hover { background: rgba(255, 255, 255, 0.32); }
#meter-line span {
  position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 1.8vh; font-weight: 700;
  text-shadow: 0 0 0.6vh #000, 0 0 0.3vh #000;
}

#demo-hint {
  position: absolute; right: 2vw; bottom: 100%;
  font-size: 1.9vh;
  background: var(--panel);
  padding: 0.5vh 1vw;
  border-radius: 1vh;
  display: none;
}
body.demo #demo-hint { display: block; }
body.demo [data-action=recalibrate] { display: none; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #3d7a4a; }

/* ---------- Overlays ---------- */
#celebrate, #paused, #calibrate, #setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
}
[hidden] { display: none !important; }
#celebrate { pointer-events: none; align-items: start; padding-top: 14vh; }
.card {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: 3vh;
  padding: 3vh 4vw;
  text-align: center;
  box-shadow: 0 2vh 6vh rgba(0, 0, 0, 0.35);
}
.card h1 { margin: 0; font-size: 6.5vh; line-height: 1.1; color: var(--glow); }
.card p { margin: 1vh 0 0; font-size: 3vh; }
#celebrate .card { animation: message-pop 0.7s cubic-bezier(.2, .9, .3, 1.4); }
#celebrate .award { margin-top: 1.6vh; font-size: 4vh; font-weight: 800; color: #fff6c9; }
#paused { background: rgba(0, 0, 0, 0.45); }
#calibrate { background: rgba(0, 0, 0, 0.5); }
.cal-bar { margin-top: 2vh; height: 1.6vh; border-radius: 1vh; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
#cal-fill { height: 100%; width: 0; background: var(--quiet); }

#setup {
  background: radial-gradient(ellipse at center, rgba(10, 20, 15, 0.55), rgba(5, 10, 8, 0.85));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(880px, 94vw);
  background: rgba(255, 252, 245, 0.96);
  color: var(--ink);
  border-radius: 28px;
  padding: 28px 36px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo {
  margin: 0;
  font-size: 56px; line-height: 1;
  font-weight: 800;
  color: #3d7a4a;
  letter-spacing: -0.5px;
}
.tagline { margin: 6px 0 18px; font-size: 19px; line-height: 1.35; color: #5b4a3a; }
.panel h2 { margin: 0 0 10px; font-size: 20px; }
#theme-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.theme-card {
  position: relative;
  border: 4px solid transparent;
  border-radius: 18px;
  overflow: hidden;
  padding: 0;
  aspect-ratio: 16 / 9;
  cursor: pointer;
  background: #ccc center / cover;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s, border-color 0.15s;
}
.theme-card:hover { transform: translateY(-3px); }
.theme-card[aria-pressed='true'] { border-color: #3d7a4a; transform: translateY(-3px); }
.theme-card .name {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.row label { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 16px; }
.row select { padding: 8px 10px; border-radius: 12px; border: 2px solid #d9cfbf; background: #fff; font-size: 16px; }
.row input[type='range'] { accent-color: #3d7a4a; height: 28px; margin: 6px 0 0; }
.range-ends { display: flex; justify-content: space-between; font-weight: 500; font-size: 14px; color: #7a6a58; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.buttons button, #reset-stars {
  border: 2px solid #3d7a4a;
  background: #fff;
  color: #3d7a4a;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
}
.buttons button.primary { background: #3d7a4a; color: #fff; font-size: 22px; padding: 12px 30px; box-shadow: 0 6px 0 #2a5634; }
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #2a5634; }
.error { color: #b3261e; font-weight: 700; }
.help { margin-top: 18px; font-size: 15px; color: #5b4a3a; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }
.help kbd { background: #eee5d6; border-color: #cbbda7; color: var(--ink); }
#reset-stars { font-size: 14px; padding: 6px 14px; border-color: #b3261e; color: #b3261e; }
