:root {
  --paper: #f6eddc;
  --ink: #1b1b1f;
  --blue: #4a86f5;
  --purple: #5b1a99;
  --periwinkle: #5457d4;
  --pink: #f5aee6;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "Libertinus Serif", "Linux Libertine", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

#tp-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: grab;
}
#tp-stage.panning { cursor: grabbing; }
#tp-stage.over-shape { cursor: pointer; }
#tp-stage.over-clip { cursor: grab; }
#tp-stage.dragging-clip { cursor: grabbing; }

/* mirrors the camera transform so playhtml can anchor cursors to world coordinates */
#tp-world {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  pointer-events: none;
  z-index: 2;
}

/* ---------- about + signup (lives in world space, under the wordmark) ---------- */
#tp-intro-layer {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  z-index: 1;
  pointer-events: none; /* drags over the text still pan the canvas */
}
#tp-intro-layer[hidden] { display: none; }
#tp-intro {
  position: absolute;
  left: 190px; /* off-centre: starts under the end of the wordmark */
  top: 150px;
  width: 520px;
  font-family: "Alegreya", Georgia, serif;
  font-size: 22px;
  line-height: 1.32;
  color: #1e8b4c;
  -webkit-font-smoothing: antialiased;
}
#tp-intro p { margin: 0 0 0.62em; }
#tp-intro .credit { font-style: italic; }
#tp-intro a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(30, 139, 76, 0.35);
  pointer-events: auto;
}
#tp-intro a:hover { border-bottom-color: currentColor; }
#tp-intro .mini { width: 0.78em; height: 0.78em; vertical-align: -0.06em; margin: 0 1px; overflow: visible; }
#tp-intro .mini path { fill: var(--blue); stroke: var(--ink); stroke-width: 1.1; stroke-linejoin: round; }
#tp-intro .arrow { font-size: 0.8em; }
#tp-intro .deco { position: absolute; left: 0; top: 0; }
#tp-intro .deco .green { fill: none; stroke: #1e8b4c; stroke-width: 2; stroke-linecap: round; }
#tp-intro .divider { display: block; margin: 14px 0 26px; overflow: visible; }
#tp-intro .divider path { fill: none; stroke: var(--periwinkle); stroke-width: 1.6; stroke-linecap: round; }
#tp-intro .signup {
  display: block;
  margin: 0 auto;
  border: 0;
  background: transparent;
  color-scheme: light;
  pointer-events: auto;
}

/* ---------- hud ---------- */
#tp-hud {
  position: fixed;
  left: 18px;
  bottom: 16px;
  z-index: 3;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--purple);
  pointer-events: none;
  line-height: 1.7;
}
#tp-about { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#tp-about .dot {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--ink); display: inline-block;
}
#tp-about .dot.blue { background: var(--blue); }
#tp-about .dot.purple { background: var(--purple); margin-left: 10px; }
#tp-count { text-transform: uppercase; }

#tp-sound {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 3;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fbf6ec;
  color: var(--purple);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease;
}
#tp-sound:hover { transform: scale(1.08); }
#tp-sound .off { display: none; }
#tp-sound[aria-pressed="false"] .on { display: none; }
#tp-sound[aria-pressed="false"] .off { display: inline; }
#tp-sound[aria-pressed="false"] { color: #8a7f9c; }
body.reading #tp-sound { display: none; }

#tp-mini {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fbf6ec;
  cursor: crosshair;
  touch-action: none;
  transition: transform 0.15s ease;
}
#tp-mini[hidden] { display: none; }
#tp-mini:hover { transform: scale(1.02); }
body.reading #tp-mini { display: none; }

#tp-hint {
  position: fixed;
  left: 18px;
  white-space: nowrap;
  top: 18px; /* top-left is the one corner the about text and HUD never use */
  z-index: 3;
  font-size: 12px;
  color: var(--purple);
  opacity: 0.75;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
#tp-hint.gone { opacity: 0; }
body.reading #tp-hint { display: none; }
@media (max-width: 1100px) { #tp-hint { display: none; } }

#tp-loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 4;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--purple);
  background: var(--paper);
  transition: opacity 0.5s ease;
}
#tp-loading.done { opacity: 0; pointer-events: none; }

/* ---------- viewer ---------- */
#tp-viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
}
#tp-viewer[hidden] { display: none; }

#tp-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(1100px, calc(100vw - 80px));
  height: min(820px, calc(100vh - 120px));
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #2b2b30;
  border-radius: 36px;
  overflow: hidden;
  animation: card-in 0.22s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes card-in {
  from { transform: translate(-50%, -48%) scale(0.96); opacity: 0; }
}

#tp-card iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
#tp-card iframe[hidden] { display: none; }

#tp-fade {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 85%);
  pointer-events: none;
}

.round {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--pink);
  border: 4px solid var(--periwinkle);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  font-size: 38px;
  line-height: 1;
  transition: transform 0.15s ease, background 0.15s ease;
  z-index: 2;
}
.round:hover { transform: scale(1.06); }
.round:active { transform: scale(0.96); }
.round span { display: block; transform: translateY(1px); }

#tp-close {
  /* sits on the card's top-right corner */
  left: calc(50% + min(1100px, calc(100vw - 80px)) / 2 - 44px);
  top: calc(50% - min(820px, calc(100vh - 120px)) / 2 - 36px);
}
#tp-scissors {
  left: calc(50% - 40px);
  top: calc(50% + min(820px, calc(100vh - 120px)) / 2 - 44px);
}
#tp-scissors span { transition: transform 0.25s ease; }
#tp-scissors[aria-pressed="true"] { background: var(--periwinkle); }
#tp-scissors[aria-pressed="true"] span { transform: rotate(-90deg); }

/* ---------- cut mode ---------- */
#tp-viewer.cutting #tp-fade { display: none; }

#tp-lasso {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
#tp-lasso[hidden] { display: none; }
#tp-lasso .shade { fill: rgba(27, 27, 31, 0.28); fill-rule: evenodd; transition: fill 0.2s; }
#tp-lasso .shade.busy { fill: rgba(27, 27, 31, 0.45); }
#tp-lasso .preview { fill: rgba(245, 174, 230, 0.11); stroke: none; }
#tp-lasso .ghost {
  fill: none;
  stroke: var(--periwinkle);
  stroke-width: 1.5;
  stroke-dasharray: 2 6;
  stroke-linecap: round;
  opacity: 0.55;
}
#tp-lasso .ghost.near { opacity: 1; stroke-width: 2.5; }
#tp-lasso .start { fill: #fff; stroke: var(--periwinkle); stroke-width: 2; transition: r 0.15s; }
#tp-lasso .start.near { fill: var(--pink); stroke-width: 3; }
#tp-lasso .line {
  fill: none;
  stroke: var(--periwinkle);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 7 6;
  animation: ants 0.6s linear infinite;
}
#tp-lasso .line.closed { fill: rgba(84, 87, 212, 0.06); }
#tp-lasso .pt { fill: #fff; stroke: var(--periwinkle); stroke-width: 2; }
#tp-lasso .pt.first { fill: var(--pink); }
@keyframes ants { to { stroke-dashoffset: -13; } }

/* when a real mouse is over the page, the drawn scissors are the cursor */
body.direct-cut #tp-lasso { cursor: none; }

#tp-shears {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 4;
  will-change: transform;
}
#tp-shears[hidden] { display: none; }
#tp-shears svg { display: block; } /* no inline baseline gap, or the hotspot drifts */
#tp-shears .blade { fill: #fff; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
#tp-shears .shank { stroke: var(--ink); stroke-width: 3.4; stroke-linecap: round; fill: none; }
#tp-shears .loop { fill: var(--pink); stroke: var(--periwinkle); stroke-width: 2.6; }
#tp-shears .pivot { fill: var(--ink); }

.tp-lifted {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  transform-origin: 50% 60%;
}

#tp-cut-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.86);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--purple);
  text-align: center;
  padding: 24px;
}
#tp-cut-status[hidden] { display: none; }

#tp-cutbar {
  position: absolute;
  left: 50%;
  top: calc(50% + min(820px, calc(100vh - 120px)) / 2 - 104px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 16px;
  background: #fff;
  border: 2px solid var(--periwinkle);
  border-radius: 999px;
  font-size: 12px;
  color: var(--purple);
  white-space: nowrap;
  z-index: 3;
}
#tp-cutbar[hidden] { display: none; }

/* desktop: no scissors button; the hint sits where the button was */
body.direct-cut #tp-scissors { display: none; }
body.direct-cut #tp-cutbar {
  top: calc(50% + min(820px, calc(100vh - 120px)) / 2 - 22px);
  padding: 9px 18px;
  font-size: 13px;
  animation: hint-in 0.5s 0.15s both cubic-bezier(.2, .9, .3, 1.3);
}
#tp-undo[hidden] { display: none; }
#tp-cutbar:not(:has(#tp-undo:not([hidden]))) { padding: 8px 16px; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } }
#tp-cut-hint { margin-right: 4px; }

.pill {
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  text-transform: lowercase;
  border: 2px solid var(--periwinkle);
  background: #fff;
  color: var(--periwinkle);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.pill:hover { background: #f1f1ff; }
.pill.primary { background: var(--pink); color: var(--purple); }
.pill:disabled { opacity: 0.4; cursor: default; }

/* ---------- toast ---------- */
#tp-toast {
  position: fixed;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--purple);
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 9px 16px;
  border-radius: 999px;
  pointer-events: none;
  animation: toast-in 0.2s ease;
}
#tp-toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -6px); } }

@media (max-width: 640px) {
  #tp-card {
    width: calc(100vw - 24px);
    height: calc(100vh - 150px);
    border-radius: 26px;
  }
  .round { width: 62px; height: 62px; font-size: 28px; }
  #tp-close {
    left: calc(100vw - 12px - 50px);
    top: calc(50% - (100vh - 150px) / 2 - 26px);
  }
  #tp-scissors {
    left: calc(50% - 31px);
    top: calc(50% + (100vh - 150px) / 2 - 34px);
  }
  #tp-cutbar {
    top: calc(50% + (100vh - 150px) / 2 - 90px);
    font-size: 11px;
  }
  body.direct-cut #tp-cutbar { top: calc(50% + (100vh - 150px) / 2 - 22px); }
  #tp-cut-hint { margin-right: 0; }
  #tp-hint { display: none; }
  body.reading #tp-hud { display: none; }
  #tp-mini { right: 12px; bottom: 12px; border-radius: 10px; }
}
