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

/* Paper Snowflake: a cutting mat under a desk lamp, then a frosty window. Everything visual is drawn on
   one canvas (#scene); the DOM carries the controls and the chrome. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --ink: #dde7f2;
  --ink-dim: rgba(221, 231, 242, 0.52);
  --frost: #d4e8ff;
  --panel: rgba(13, 19, 29, 0.84);
  --line: rgba(190, 215, 240, 0.17);
  --ring: rgba(170, 214, 255, 0.9);
  --safe-t: max(12px, env(safe-area-inset-top));
  --safe-b: max(14px, env(safe-area-inset-bottom));
}

*,*::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: #070a10; color: var(--ink); touch-action: none; }

canvas#scene {
  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;
}
body.m-cut canvas#scene { cursor: crosshair; }
body.m-done canvas#scene { cursor: pointer; }

/* ---- top row: this session's snowflakes, then the fold count and settings ---- */
.topbar {
  position: fixed; z-index: 8; left: 0; right: 0; top: calc(var(--safe-t) + 34px);
  display: flex; align-items: center; justify-content: center; gap: 10px; pointer-events: none;
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  transition: opacity .3s ease;
}
.topbar > * { pointer-events: auto; }
body.m-fold .topbar, body.m-unfold .topbar { opacity: 0; pointer-events: none; }
body.m-fold .topbar > *, body.m-unfold .topbar > * { pointer-events: none; }
body.m-done .ctl { display: none; }
.ctl { display: flex; align-items: center; gap: 8px; }
.session { display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 12px; border-radius: 999px; background: rgba(13, 19, 29, 0.6); border: 1px solid var(--line); }
.session__lbl { font-size: 0.56rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-dim); margin-right: 4px; white-space: nowrap; }
.session:empty { display: none; }
.thumb {
  appearance: none; padding: 0; margin: 0; cursor: pointer; flex: none; position: relative;
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, rgba(60, 84, 112, 0.7), rgba(12, 18, 28, 0.9) 78%);
  border: 1px solid var(--line); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform .14s ease, border-color .15s ease; touch-action: manipulation;
}
.thumb canvas { width: 26px; height: 26px; display: block; pointer-events: none; }
.thumb:hover { border-color: rgba(212, 232, 255, 0.5); }
.thumb:active { transform: scale(0.94); }
.thumb[aria-current="true"] { border-color: var(--frost); box-shadow: 0 0 0 1px rgba(212, 232, 255, 0.35), 0 4px 12px rgba(0, 0, 0, 0.45); }
.thumb:focus-visible { outline: 2px dashed var(--ring); outline-offset: 2px; }

.seg {
  display: inline-flex; align-items: stretch; padding: 3px; gap: 2px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 6px 16px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.seg button {
  appearance: none; margin: 0; cursor: pointer; font-family: var(--font); font-size: 0.78rem; font-weight: 600;
  min-width: 34px; height: 32px; padding: 0 12px; border: 0; border-radius: 999px; color: var(--ink-dim);
  background: transparent; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .15s ease, color .15s ease; touch-action: manipulation;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: rgba(212, 232, 255, 0.16); color: #fff; box-shadow: 0 0 0 1px rgba(212, 232, 255, 0.28) inset; }
.seg button:focus-visible { outline: 2px dashed var(--ring); outline-offset: 1px; }
.seg svg { flex: none; }

.icobtn, .pill, .dock .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font); margin: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; opacity: 1; white-space: nowrap;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 6px 16px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform .12s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
  touch-action: manipulation; text-decoration: none;
}
.icobtn { width: 38px; padding: 0; }
.icobtn[aria-expanded="true"] { background: rgba(212, 232, 255, 0.16); border-color: rgba(212, 232, 255, 0.4); }
.pill:hover, .icobtn:hover, .dock .opt-share.opt-share:hover { background: rgba(26, 38, 54, 0.94); border-color: rgba(212, 232, 255, 0.34); text-decoration: none; }
.pill:active, .icobtn:active, .dock .opt-share.opt-share:active { transform: scale(0.96); }
.pill:focus-visible, .icobtn:focus-visible, .dock .opt-share.opt-share:focus-visible { outline: 2px dashed var(--ring); outline-offset: 2px; }
.pill[disabled] { opacity: 0.4; cursor: default; pointer-events: none; }
.pill svg, .dock .opt-share.opt-share svg { width: 17px; height: 17px; flex: none; }
.pill--go {
  background: linear-gradient(180deg, #e6f2ff, #bcd6f2); color: #0b1522; border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 8px 20px rgba(60, 120, 190, 0.28);
}
.pill--go:hover { background: linear-gradient(180deg, #f2f9ff, #cde1f6); border-color: #fff; }
.pill--go[disabled] { opacity: 0.35; }
.peek { width: 26px; height: 26px; display: block; margin-left: -4px; border-radius: 50%; background: rgba(11, 21, 34, 0.12); }
.share-host { display: inline-flex; }
.share-host:empty { display: none; }
.dock .opt-share.opt-share { margin: 0; padding: 0 14px 0 12px; font-size: 0.78rem; }

/* ---- the settings sheet ---- */
.sheet {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 78px);
  width: min(320px, calc(100vw - 24px)); padding: 14px 16px 6px; border-radius: 16px;
  background: rgba(10, 15, 24, 0.94); border: 1px solid var(--line); box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.sheet[hidden] { display: none; }
.sheet__row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 0 0 12px; }
.sheet__label { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-dim); }
.swatches { display: flex; gap: 9px; }
.swatches button {
  appearance: none; width: 26px; height: 26px; padding: 0; margin: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.25); touch-action: manipulation;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 3px 8px rgba(0, 0, 0, 0.5);
}
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 2px #0a0f18, 0 0 0 3.5px var(--frost); }
.swatches button:focus-visible { outline: 2px dashed var(--ring); outline-offset: 3px; }
.sheet input[type="range"] { width: 150px; accent-color: #bcd6f2; margin: 0; height: 28px; }
.sheet input[type="range"]:focus-visible { outline: 2px dashed var(--ring); outline-offset: 2px; }

/* ---- the bottom dock ---- */
.dock {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 66px); width: max-content; max-width: calc(100vw - 20px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: opacity .3s ease;
}
.dock__grp { display: none; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
body.m-cut .dock__cut, body.m-done .dock__done { display: flex; }
body.m-fold .dock, body.m-unfold .dock { opacity: 0; pointer-events: none; }
body.m-fold .dock *, body.m-unfold .dock * { pointer-events: none; }
body:not(.m-done) .share-host { display: none; }

.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0;
  top: var(--safe-t); right: max(12px, env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  -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 var(--ring); 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(221, 231, 242, 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(--safe-t) + 13px); left: max(18px, env(safe-area-inset-left)); }
.frame__corner--tr { top: calc(var(--safe-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(212, 232, 255, 0.95); border-bottom-color: rgba(212, 232, 255, 0.5); }

.hint {
  position: static; width: auto; max-width: min(90vw, 560px); margin: 0; text-align: center; pointer-events: none; min-height: 1.6em;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; line-height: 1.6;
  color: rgba(221, 231, 242, 0.78); text-shadow: 0 0 10px rgba(0, 0, 0, 1), 0 0 3px rgba(0, 0, 0, 0.9), 0 1px 14px 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 (doubled classes
   out-specify the components' injected styles) */
.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); right: calc(max(14px, env(safe-area-inset-right)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

@media (max-width: 560px) {
  .pill .lbl { display: none; }
  .pill#pngBtn, .pill#cardBtn, .pill#undoBtn { width: 38px; padding: 0; }
  .seg--tools button { padding: 0 11px; }
  .seg--tools button span { display: none; }
  .seg--tools button { min-width: 38px; }
  .dock .opt-share.opt-share { padding: 0 12px 0 10px; }
}
@media (max-width: 400px) {
  .thumb { width: 28px; height: 28px; }
  .thumb canvas { width: 23px; height: 23px; }
  .session { gap: 4px; }
  .topbar { gap: 6px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .topbar { justify-content: flex-start; top: calc(var(--safe-t) + 30px); }
}
@media (max-height: 460px) {
  .dock { bottom: calc(var(--safe-b) + 40px); gap: 5px; }
  .thumb { width: 26px; height: 26px; }
  .thumb canvas { width: 21px; height: 21px; }
  .session { padding: 2px 8px 2px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .pill, .icobtn, .seg button, .thumb, .sound-btn, .hint, .topbar, .dock { transition: none; }
}

/* off-screen measuring of the dock groups (used by the script to size the paper) */
.dock.mz-cut .dock__cut, .dock.mz-done .dock__done { display: flex !important; visibility: hidden; }
.dock.mz-done .share-host { display: inline-flex !important; }
