/* ================================================================
   Shared chrome for the full-screen canvas toys (Epicycles, Prism,
   Singularity): a top bar of frosted pills, a bottom
   dock, a hint and a "How it works" sheet. Each project sets
   --bg / --accent / --accent-ink and adds its own few rules.
   ================================================================ */

:root {
  --bg: #0b0c10;
  --accent: #e8541a;
  --accent-ink: #fff;

  --surface: rgba(20, 22, 27, 0.86);
  --surface-strong: rgba(18, 20, 25, 0.97);
  --raised: rgba(255, 255, 255, 0.06);
  --raised-2: rgba(255, 255, 255, 0.11);
  --line: rgba(255, 255, 255, 0.09);
  --text: #ece9e2;
  --muted: #a9a69e;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);

  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "DM Serif Display", Georgia, serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --safe-b: max(16px, env(safe-area-inset-bottom));
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.pill {
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

/* ── Top bar ── */
#topbar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

#backLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 15px 0 11px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.15s;
}
#backLink:hover { color: var(--text); }

#title {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 16px;
  min-width: 0;
}
#title h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
#title .sub {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#infoBtn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 15px;
  font-size: 14px;
  color: var(--muted);
  transition: color 0.15s;
}
#infoBtn:hover, #infoBtn[aria-expanded="true"] { color: var(--text); }

/* ── Dock ── */
#dock {
  position: fixed;
  left: 50%;
  bottom: var(--safe-b);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  max-width: calc(100vw - 16px);
  border-radius: 16px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 10;
}

.dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: none;
  height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.dock-btn:hover { background: var(--raised-2); }
.dock-btn svg { flex: none; }
.dock-btn.primary { background: var(--accent); color: var(--accent-ink); padding: 0 16px; }
.dock-btn.primary:hover { filter: brightness(1.08); }
.dock-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
}
.dock-btn:disabled { opacity: 0.4; cursor: default; }
.dock-btn:disabled:hover { background: none; }

.dock-sep { flex: none; width: 1px; height: 22px; margin: 0 5px; background: var(--line); }

.dock-field {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.dock-field output {
  min-width: 2.4em;
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 28px;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--raised-2); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--raised-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

/* Segmented control */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--raised); }
.seg button {
  height: 34px;
  min-width: 38px;
  padding: 0 11px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.active { color: var(--text); background: color-mix(in srgb, var(--accent) 26%, transparent); }

/* ── Hint ── */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 70px);
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  padding: 8px 15px;
  border-radius: 19px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.7s var(--ease);
}
#hint.hidden { opacity: 0; }

/* ── "How it works" sheet ── */
#info {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 50px);
  right: max(14px, env(safe-area-inset-right));
  width: min(360px, calc(100vw - 28px));
  max-height: calc(100vh - 150px);
  max-height: calc(100dvh - 150px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 22px 22px;
  border-radius: 18px;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 20;
  opacity: 0;
  transform: translateY(-8px);
  visibility: hidden;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), visibility 0s linear 0.2s;
}
#info.open {
  opacity: 1;
  transform: none;
  visibility: visible;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), visibility 0s;
}
#info h2 { font-family: var(--serif); font-weight: 400; font-size: 21px; margin-bottom: 10px; }
#info p { font-size: 14px; line-height: 1.6; color: var(--muted); }
#info p + p { margin-top: 10px; }
#info strong { color: var(--text); font-weight: 500; }
#info .formula {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--raised);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: nowrap;
}

/* ── Small screens ── */
@media (max-width: 640px) {
  #title .sub { display: none; }
  #infoBtn span { display: none; }
  #infoBtn { width: 40px; padding: 0; justify-content: center; }
  .back-text { display: none; }
  #backLink { width: 40px; padding: 0; justify-content: center; }
  .dock-btn .dock-label { display: none; }
  .dock-btn.keep-label .dock-label { display: inline; }
  .dock-btn { padding: 0 10px; }
  .dock-sep { margin: 0 2px; }
  input[type="range"] { width: 104px; }
  .dock-field { padding: 0 6px; gap: 6px; }
}

@media (max-height: 460px) {
  #hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
