@import url("https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600&display=swap");

/* Sand Pendulum: a black lacquered tray on a dark studio table under one warm lamp. The tray, the sand and
   the pendulum are all drawn on one canvas; the DOM carries the chrome and the controls. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --cream: #efe6d2;
  --ink-dim: rgba(239, 230, 210, 0.5);
  --amber: #f0a45a;
  --panel: rgba(20, 20, 22, 0.86);
  --edge: rgba(239, 230, 210, 0.16);
  --inset-t: max(12px, env(safe-area-inset-top));
  --inset-r: max(14px, env(safe-area-inset-right));
  --inset-b: max(14px, env(safe-area-inset-bottom));
  --inset-l: max(14px, env(safe-area-inset-left));
}

*,*::before,*::after { box-sizing: border-box; }
html, body {
  -webkit-tap-highlight-color: transparent; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font); background: #08090b; color: var(--cream); touch-action: none; }

canvas {
  display: block; position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 0;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; outline: none;
}
#view { cursor: grab; }
#view.is-drag { cursor: grabbing; }
#view:focus-visible { outline: 2px dashed rgba(240, 164, 90, 0.8); outline-offset: -4px; }

/* the row of actions under the hint (a column on the right in a short landscape) */
.bar {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  top: calc(var(--inset-t) + 64px);
  display: flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.pill, .bar .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font);
  display: inline-flex; align-items: center; gap: 7px; height: 36px; margin: 0; padding: 0 14px 0 12px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; opacity: 1;
  color: var(--cream); background: var(--panel); border: 1px solid var(--edge);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 6px 16px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.pill svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
.pill:hover, .bar .opt-share.opt-share:hover { background: rgba(40, 38, 36, 0.94); border-color: rgba(239, 230, 210, 0.3); text-decoration: none; }
.pill:active, .bar .opt-share.opt-share:active { transform: scale(0.96); }
.pill[aria-pressed="true"] { background: rgba(240, 164, 90, 0.2); border-color: rgba(240, 164, 90, 0.6); color: #ffd9ae; }
.pill[aria-expanded="true"] { border-color: rgba(239, 230, 210, 0.38); }
.pill:focus-visible, .bar .opt-share.opt-share:focus-visible { outline: 2px dashed rgba(240, 164, 90, 0.85); outline-offset: 2px; }
.pill:disabled { opacity: 0.4; cursor: default; }
.share-host { display: inline-flex; }
.share-host:empty { display: none; }

/* the controls */
.panel {
  position: fixed; z-index: 7; left: var(--inset-l); right: var(--inset-r);
  bottom: calc(var(--inset-b) + 66px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; padding: 12px 14px 12px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  touch-action: manipulation;
}
.panel[hidden] { display: none; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; row-gap: 6px; min-width: 0; }
.row label, .row .lbl { font-size: 0.64rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); }
.row output { font-size: 0.72rem; font-weight: 500; color: var(--cream); font-variant-numeric: tabular-nums; }
.row input[type=range] { grid-column: 1 / -1; }
.row--color { grid-template-columns: 1fr; }
.row--color .lbl { display: flex; justify-content: space-between; }
.row--color .lbl output { text-transform: none; letter-spacing: 0; }
.row--save { grid-column: 1 / -1; display: flex; justify-content: center; }
.pill--wide { width: 100%; justify-content: center; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent;
  touch-action: pan-y; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: rgba(239, 230, 210, 0.22); }
input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(239, 230, 210, 0.22); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin-top: -8.5px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe8c4, #d99a52 70%); border: 1px solid rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe8c4, #d99a52 70%);
  border: 1px solid rgba(0, 0, 0, 0.5); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
input[type=range]:focus-visible { outline: 2px dashed rgba(240, 164, 90, 0.85); outline-offset: 2px; border-radius: 6px; }

.swatches { display: flex; gap: 9px; align-items: center; height: 28px; }
.swatch {
  appearance: none; padding: 0; margin: 0; width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; background-clip: padding-box; touch-action: manipulation;
  box-shadow: 0 0 0 1px rgba(239, 230, 210, 0.2) inset, 0 2px 5px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease;
}
.swatch[aria-checked="true"] { border-color: var(--cream); transform: scale(1.08); }
.swatch:focus-visible { outline: 2px dashed rgba(240, 164, 90, 0.85); outline-offset: 2px; }

.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0;
  top: var(--inset-t); right: max(12px, env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--cream); background: var(--panel); border: 1px solid var(--edge);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.sound-btn:active { transform: scale(0.94); }
.sound-btn[aria-pressed="false"] { opacity: 0.55; }
.sound-btn[aria-pressed="false"] .sound-btn__wave { opacity: 0; }
.sound-btn:focus-visible { outline: 2px dashed rgba(240, 164, 90, 0.85); outline-offset: 3px; }

.frame { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.frame__corner {
  position: absolute; font-size: clamp(0.58rem, 1.2vw, 0.7rem); font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase; color: rgba(239, 230, 210, 0.5);
  white-space: nowrap; font-family: var(--font); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
.frame__corner--tl { top: calc(var(--inset-t) + 13px); left: max(18px, env(safe-area-inset-left)); }
.frame__corner--tr { top: calc(var(--inset-t) + 13px); right: calc(max(12px, env(safe-area-inset-right)) + 54px); }
.frame__corner--bl { bottom: max(18px, env(safe-area-inset-bottom)); left: max(18px, env(safe-area-inset-left)); }
.frame__corner a { color: inherit; text-decoration: none; pointer-events: auto; border-bottom: 1px solid transparent; transition: color .14s, border-color .14s; }
.frame__corner a:hover { color: rgba(255, 210, 160, 0.95); border-bottom-color: rgba(255, 210, 160, 0.5); }

.hint {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--inset-t) + 40px);
  width: min(88vw, 520px); margin: 0; text-align: center; z-index: 9; pointer-events: none;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; line-height: 1.6;
  color: rgba(239, 230, 210, 0.62); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.95); transition: opacity .6s;
}
.hint.is-hidden { opacity: 0; }

/* the shared tip-jar and fullscreen badges sit side by side in the bottom-right corner */
.opt-tipjar.opt-tipjar { top: auto; bottom: var(--inset-b); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: var(--inset-b); right: calc(var(--inset-r) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

/* desktop and tablets: the controls float at the right */
@media (min-width: 900px) and (min-height: 501px) {
  .panel { left: auto; right: max(22px, env(safe-area-inset-right)); bottom: auto; top: calc(var(--inset-t) + 64px); width: 300px; grid-template-columns: 1fr; gap: 6px; padding: 14px 16px; }
  .hint { top: calc(var(--inset-t) + 14px); }
  .bar { top: calc(var(--inset-t) + 56px); }
}
/* a phone on its side: the actions stack at the right, the controls open to their left */
@media (orientation: landscape) and (max-height: 500px) {
  .bar { left: auto; transform: none; right: var(--inset-r); top: calc(var(--inset-t) + 48px); flex-direction: column; align-items: flex-end; gap: 7px; }
  .hint { top: calc(var(--inset-t) + 9px); }
  .bar .opt-share.opt-share span { display: none; }
  .panel { left: auto; right: calc(var(--inset-r) + 146px); bottom: auto; top: calc(var(--inset-t) + 38px); width: 244px; grid-template-columns: 1fr; gap: 2px; padding: 8px 14px 10px; }
  .row { row-gap: 0; }
  input[type=range] { height: 24px; }
  .swatches { height: 24px; }
  .pill { height: 34px; }
}
@media (max-width: 520px) { .bar .opt-share.opt-share span { display: none; } .bar .opt-share.opt-share { padding: 0 11px; } }
@media (max-width: 420px) { .swatches { gap: 5px; } .swatch { width: 24px; height: 24px; } .panel { gap: 8px 14px; } }
@media (max-width: 380px) {
  .pill, .bar .opt-share.opt-share { font-size: 0.72rem; padding: 0 11px 0 10px; gap: 6px; }
  .bar { gap: 6px; }
}
@media (max-width: 345px) { .pill svg { display: none; } }
@media (prefers-reduced-motion: reduce) { .pill, .sound-btn, .hint, .swatch, .bar .opt-share.opt-share { transition: none; } }
