:root {
  --ink: rgba(255, 250, 252, 0.92);
  --ink-dim: rgba(255, 245, 250, 0.55);
  --glass: rgba(22, 18, 24, 0.38);
  --glass-edge: rgba(255, 255, 255, 0.10);
  --accent: #f3b4c6;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d0b0e; color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
canvas#gl {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; cursor: grab; opacity: 0; transition: opacity 1.4s ease;
}
body.ready canvas#gl { opacity: 1; }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(ellipse at 50% 60%, #1d171d 0%, #0d0b0e 70%);
  transition: opacity .9s ease .2s, visibility 0s linear 1.2s; z-index: 5;
}
body.ready #loader { opacity: 0; visibility: hidden; }
#loader p { margin: 0; font: italic 300 18px/1.2 Fraunces, Georgia, serif; color: var(--ink-dim); letter-spacing: .01em; }
#loader.error p { color: #ffb3c4; max-width: 34ch; text-align: center; font-style: normal; font-family: Inter, sans-serif; font-size: 14px; line-height: 1.5; }
.bean-loader { position: relative; width: 74px; height: 70px; }
.bean-loader i, .bean-loader b {
  position: absolute; background: linear-gradient(160deg, #f6c6d2, #d98ea4); border-radius: 50%;
  box-shadow: inset -2px -3px 6px rgba(120, 40, 70, .35), inset 2px 2px 4px rgba(255, 255, 255, .5);
  animation: squish 1.4s ease-in-out infinite;
}
.bean-loader i { width: 15px; height: 19px; }
.bean-loader i:nth-child(1) { left: 2px; top: 22px; transform: rotate(-28deg); animation-delay: 0s; }
.bean-loader i:nth-child(2) { left: 19px; top: 4px; transform: rotate(-8deg); animation-delay: .12s; }
.bean-loader i:nth-child(3) { left: 40px; top: 4px; transform: rotate(8deg); animation-delay: .24s; }
.bean-loader i:nth-child(4) { left: 57px; top: 22px; transform: rotate(28deg); animation-delay: .36s; }
.bean-loader b { left: 17px; top: 34px; width: 40px; height: 32px; border-radius: 48% 48% 42% 42% / 58% 58% 42% 42%; animation-delay: .5s; }
@keyframes squish { 0%, 100% { scale: 1 1; } 40% { scale: 1.12 .82; } 60% { scale: .94 1.06; } }

/* ---------- chrome ---------- */
.chrome { transition: opacity .5s ease, transform .5s ease; }
body:not(.ready) .chrome { opacity: 0; }
body.clean .chrome { opacity: 0; pointer-events: none; transform: translateY(6px); }

#top {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(18px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left));
  pointer-events: none; z-index: 2;
}
.brand { font: italic 400 26px/1 Fraunces, Georgia, serif; letter-spacing: -.01em; text-shadow: 0 1px 12px rgba(0, 0, 0, .35); }
.brand span { color: var(--accent); }
.counter { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 12px rgba(0, 0, 0, .4); }
.counter span { font: 500 22px/1 Inter, sans-serif; display: inline-block; }
.counter small { font-size: 12px; color: var(--ink-dim); letter-spacing: .06em; text-transform: lowercase; }
.counter.pop span { animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(1.28); color: var(--accent); } 100% { transform: scale(1); } }

#hint {
  position: fixed; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  margin: 0; padding: 9px 16px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-edge);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  font: italic 300 15px/1 Fraunces, Georgia, serif; color: var(--ink); white-space: nowrap; pointer-events: none;
  animation: breathe 3.2s ease-in-out infinite; z-index: 2;
}
body.touched #hint, body.clean #hint { opacity: 0; transform: translate(-50%, 8px); animation: none; }
@keyframes breathe { 0%, 100% { opacity: .9; } 50% { opacity: .55; } }

#dock {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 18px; padding: 10px 12px 10px 18px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--glass-edge);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25); z-index: 2; max-width: calc(100vw - 24px);
}
body.clean #dock { transform: translate(-50%, 10px); }
.group { display: grid; gap: 6px; }
.group label { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-dim); white-space: nowrap; }
.group label em { font: italic 300 12px/1 Fraunces, Georgia, serif; text-transform: none; letter-spacing: 0; color: var(--ink); margin-left: 4px; }
.sws { display: flex; gap: 7px; }
.sw {
  width: 24px; height: 24px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .25), inset 0 2px 3px rgba(255, 255, 255, .25), 0 0 0 1px rgba(255, 255, 255, .14);
  transition: transform .2s cubic-bezier(.2, 1.5, .4, 1), box-shadow .2s;
}
.sw:hover { transform: scale(1.12); }
.sw.on { box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .25), inset 0 2px 3px rgba(255, 255, 255, .25), 0 0 0 2px rgba(13, 11, 14, .6), 0 0 0 3.5px var(--ink); }
.tools { display: flex; gap: 4px; padding-left: 12px; border-left: 1px solid var(--glass-edge); }
.tools button {
  width: 36px; height: 36px; border-radius: 12px; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  display: grid; place-items: center; transition: background .2s;
}
.tools button:hover { background: rgba(255, 255, 255, .1); }
.tools svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#unhide { position: fixed; right: 0; bottom: 0; width: 64px; height: 64px; background: transparent; border: 0; display: none; z-index: 3; cursor: pointer; }
body.clean #unhide { display: block; }

@media (max-width: 640px) {
  #dock { gap: 12px; padding: 10px 10px 10px 14px; flex-wrap: wrap; justify-content: center; border-radius: 20px; width: calc(100vw - 24px); }
  .tools { border-left: 0; padding-left: 0; }
  .sw { width: 22px; height: 22px; }
  .sws { gap: 6px; }
  .brand { font-size: 22px; }
  #hint { bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 14px; }
}
