/* Worry Untangler ~ base styles and themes */

:root {
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --radius: 22px;
  --ease: cubic-bezier(.22, .8, .32, 1);

  /* Thread palette (shared by both themes, glow strength changes per theme) */
  --thread-1: #E86F8C; /* rose */
  --thread-2: #F2A541; /* amber */
  --thread-3: #4FB5A5; /* sea teal */
  --thread-4: #6C8CE8; /* cornflower */
  --thread-5: #A66CD6; /* lilac */
  --thread-6: #7CC46A; /* fern */

  --plum: #5E2B74;
  --gold: #E8B64C;
}

/* Light: warm cream, soft pastels, daytime */
:root[data-theme="light"] {
  --bg: #FBF4E8;
  --bg-2: #F4E7D3;
  --surface: #FFFDF8;
  --surface-line: #EADCC6;
  --text: #2E2440;
  --text-soft: #6B5F7A;
  --accent: #7A3E96;
  --accent-text: #FFFFFF;
  --accent-soft: #EEDFF5;
  --thread-glow: 0;
  --sky: radial-gradient(120% 80% at 50% -10%, #FFF6DD 0%, #FBF4E8 45%, #F4E7D3 100%);
  color-scheme: light;
}

/* Dark: deep night plum, threads glow like jewels */
:root[data-theme="dark"] {
  --bg: #1A1530;
  --bg-2: #120E24;
  --surface: #251E40;
  --surface-line: #3A3060;
  --text: #F3ECFF;
  --text-soft: #B9ACD6;
  --accent: #C79BE0;
  --accent-text: #1A1530;
  --accent-soft: #34295A;
  --thread-glow: 1;
  --sky: radial-gradient(120% 80% at 50% -10%, #33275C 0%, #1A1530 50%, #120E24 100%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--sky);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background-color .6s var(--ease), color .6s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 12px; top: -60px;
  background: var(--accent); color: var(--accent-text);
  padding: 8px 14px; border-radius: 12px; z-index: 10;
}
.skip:focus { top: 12px; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  gap: 12px;
  position: relative; z-index: 2; /* sits over Mira's thread */
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.brand img { display: block; }
.controls { display: flex; gap: 8px; align-items: center; }

.icon-btn, .chip {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--surface-line);
  border-radius: 999px;
  height: 40px; min-width: 40px;
  display: inline-grid; place-items: center;
  cursor: pointer;
  transition: transform .2s var(--ease), background-color .3s;
}
.chip { padding: 0 14px; font-weight: 700; font-size: 14px; letter-spacing: .06em; }
.icon-btn:active, .chip:active { transform: scale(.94); }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico .fill { fill: currentColor; stroke: none; }
.ico-dark { fill: currentColor; stroke: none; }

#theme-toggle .ico { display: none; }
#theme-toggle[data-pref="auto"] .ico-auto,
#theme-toggle[data-pref="light"] .ico-light,
#theme-toggle[data-pref="dark"] .ico-dark { display: block; }

#sound-toggle .ico-sound-off { display: none; }
#sound-toggle[aria-pressed="false"] .ico-sound-on { display: none; }
#sound-toggle[aria-pressed="false"] .ico-sound-off { display: block; }
#sound-toggle[aria-pressed="false"] { color: var(--text-soft); }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 16px;
  width: 100%; max-width: 640px; margin: 0 auto;
}

/* Mira's artboard is 400x460 with her thread running from the top edge down
   to her body (which starts a little under halfway). .mira-thread carries that
   thread on up past the top of the screen so she always hangs from somewhere. */
.mira-stage {
  --mira-h: clamp(190px, 33vh, 290px);
  --mira-w: calc(var(--mira-h) * 400 / 460);
  position: relative;
  width: var(--mira-w); height: var(--mira-h);
  margin-top: -6px;
  flex: none;
}
.mira-wrap {
  position: absolute; inset: 0;
  visibility: hidden; /* shown by dropIn() */
  will-change: transform;
}
.mira-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  overflow: visible; /* waving legs can reach past the artboard edge */
}
.mira-thread {
  position: absolute; left: 50%; bottom: calc(100% - 1px);
  width: max(1.5px, calc(var(--mira-w) * 3 / 400));
  height: 100vh;
  transform: translateX(-50%);
  background: #E8EAF2;
}
/* Her thread is near-white, so on cream it gets a soft plum edge. */
:root[data-theme="light"] .mira-wrap {
  filter: drop-shadow(0 0 1px rgba(94, 43, 116, .35)) drop-shadow(0 10px 14px rgba(94, 43, 116, .16));
}
:root[data-theme="dark"] .mira-wrap {
  filter: drop-shadow(0 0 16px rgba(199, 155, 224, .22));
}

.bubble {
  position: relative;
  max-width: 440px; width: 100%;
  min-height: 3.2em;
  background: var(--surface);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius);
  padding: 14px 18px;
  text-align: center;
  font-size: 18px;
  box-shadow: 0 10px 30px -18px rgba(46, 36, 64, .45);
  margin: 14px 0 20px;
}
.bubble::before {
  content: ""; position: absolute; top: -9px; left: 50%;
  width: 16px; height: 16px; transform: translateX(-50%) rotate(45deg);
  background: var(--surface);
  border-left: 1px solid var(--surface-line); border-top: 1px solid var(--surface-line);
}
.bubble:empty { visibility: hidden; }
.bubble-rest { visibility: hidden; }

.panel {
  width: 100%; max-width: 440px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
  animation: rise .6s var(--ease) both;
}
.panel h1 { margin: 0; font-size: clamp(26px, 7vw, 34px); line-height: 1.15; letter-spacing: -.01em; }
.lede { margin: 0; color: var(--text-soft); }
.fineprint { margin: 4px 0 0; font-size: 13px; color: var(--text-soft); }

/* Home-screen tip: phones and tablets only, and not once it's already installed. */
.install-tip { display: none; }
@media (pointer: coarse) { .install-tip { display: block; } }
@media (display-mode: standalone) { .install-tip { display: none; } }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Buttons and form ---------- */
.btn {
  font: inherit; font-weight: 700;
  border: 0; border-radius: 999px;
  padding: 14px 26px; min-height: 52px;
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s, background-color .3s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 10px 24px -12px var(--accent);
}
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--surface-line);
}

.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-soft {
  background: var(--accent-soft); color: var(--text);
}
.btn-big { width: 100%; min-height: 58px; font-size: 18px; }
.btn-link {
  font: inherit; font-weight: 600; font-size: 15px;
  background: none; border: 0; color: var(--text-soft);
  text-decoration: underline; text-underline-offset: 3px;
  padding: 8px 12px; cursor: pointer;
}

.choice { display: grid; gap: 10px; width: 100%; }

/* Clear my garden: a quiet link on the home screen, and its confirm step. */
.clear-link { margin-top: 18px; font-size: 13px; font-weight: 500; opacity: .8; }
.clear-link:hover, .clear-link:focus-visible { opacity: 1; }
.clear-question { margin: 0 0 6px; font-size: 17px; line-height: 1.45; }

/* How many breaths: a small segmented choice. */
.breath-choice { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; justify-items: center; }
.breath-choice legend { padding: 0; margin: 0 auto 8px; font-size: 14px; color: var(--text-soft); }
.bseg { display: inline-flex; background: var(--accent-soft); border-radius: 999px; padding: 4px; gap: 2px; }
.bseg label { position: relative; cursor: pointer; }
.bseg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.bseg span {
  display: inline-grid; place-items: center; min-width: 52px; min-height: 40px; padding: 0 12px;
  border-radius: 999px; font-weight: 700; color: var(--text-soft);
  transition: background .2s var(--ease), color .2s var(--ease);
}
.bseg input:checked + span { background: var(--accent); color: var(--bg); }
.bseg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
#breath-more[hidden] { display: none; }

/* End of session extras: a link card (free page or membership) or the install card. */
.link-card {
  position: relative; display: grid; gap: 2px; width: 100%;
  padding: 14px 48px 14px 18px; text-align: left; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--surface-line); border-radius: var(--radius);
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.link-card:hover { border-color: var(--accent); }
.link-card:active { transform: scale(.98); }
.link-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.link-kicker { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.link-title { font-weight: 700; }
.link-arrow {
  position: absolute; right: 16px; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.link-card[hidden], .install-card[hidden] { display: none; }

.install-card {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px 12px; align-items: center; width: 100%;
  padding: 14px 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--surface-line); border-radius: var(--radius);
}
.install-card img { border-radius: 10px; }
.install-copy p { margin: 0; }
.install-title { font-weight: 700; }
.install-text { font-size: 14px; color: var(--text-soft); }
.install-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
/* !important because the panel's rise-in animation otherwise holds opacity at 1. */
.panel.is-busy { opacity: .35 !important; pointer-events: none; transition: opacity .3s var(--ease); }

.worry-quote {
  margin: 0; max-width: 100%;
  font-weight: 700; font-size: 18px;
  overflow-wrap: anywhere;
}
.worry-quote::before { content: '"'; }
.worry-quote::after { content: '"'; }

.inline-form { display: flex; gap: 8px; width: 100%; }
.inline-form input {
  flex: 1; min-width: 0;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--surface-line);
  border-radius: 999px;
  padding: 0 18px; min-height: 52px;
}
.inline-form input::placeholder { color: var(--text-soft); }
.inline-form input:focus { border-color: var(--accent); outline: none; }

/* ---------- Pond: where the knots drift ---------- */
.pond {
  --k: clamp(68px, 19vw, 92px);
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 210px;
  max-height: 360px;
  margin-bottom: 12px;
}

.knot {
  position: absolute;
  left: calc((100% - var(--k)) * var(--fx));
  top: calc((100% - var(--k) - 24px) * var(--fy)); /* 24px = label height + gap, matches LABEL_H in threads.js */
  width: var(--k);
  padding: 0; border: 0; background: none; color: var(--text);
  font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.knot:focus-visible { outline: none; }
.knot:focus-visible .knot-pose { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 50%; }
.knot-drift, .knot-pose { display: block; width: var(--k); height: var(--k); }
.knot-pose { transition: transform .45s var(--ease), opacity .45s var(--ease), filter .45s var(--ease); }
.knot-svg { width: 100%; height: 100%; display: block; overflow: visible; }

.knot-thread { fill: none; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.knot-shine { fill: none; stroke: #fff; stroke-opacity: .45; stroke-width: 1.1; stroke-linecap: round; stroke-linejoin: round; }

:root[data-theme="light"] .knot-pose { filter: drop-shadow(0 6px 8px rgba(46, 36, 64, .14)); }
/* At night the threads glow like jewels. */
:root[data-theme="dark"] .knot-pose { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c) 70%, transparent)) drop-shadow(0 0 16px color-mix(in srgb, var(--c) 35%, transparent)); }

.knot-label {
  max-width: calc(var(--k) + 16px);
  margin-top: -4px;
  font-size: 12.5px; line-height: 1.25; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: opacity .45s var(--ease);
}

.pond.has-selection .knot:not(.is-selected) .knot-pose { opacity: .35; transform: scale(.88); }
.pond.has-selection .knot:not(.is-selected) .knot-label { opacity: .3; }
.knot.is-selected .knot-pose { transform: scale(1.18); }
.knot.is-selected .knot-label { color: var(--text); font-weight: 700; }
.knot.is-leaving { pointer-events: none; }

/* Scissors that appear beside an out-of-your-hands knot */
.scissors {
  position: absolute; z-index: 3;
  width: 52px; height: 52px; padding: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--surface-line);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 20px -10px rgba(46, 36, 64, .5);
  cursor: pointer;
}
.scissors svg { width: 100%; height: 100%; display: block; overflow: visible; }
.scissors path { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }
.scissors circle { fill: none; stroke: var(--accent); stroke-width: 3; }
.scissors .pivot { fill: var(--gold); stroke: none; }

/* During a session Mira shrinks a little to give the knots room. */
.mira-stage { transition: height .6s var(--ease), width .6s var(--ease); }
/* Tightened so the garden and tapestry strips stay on screen on a phone. */
body.in-session .mira-stage { --mira-h: clamp(140px, 20vh, 220px); }
body.in-session .bubble { margin: 10px 0 8px; }
body.in-session .panel { gap: 10px; }
body.in-session .pond { margin-bottom: 4px; }
body.in-session .btn-big { min-height: 52px; }
body.in-session .strip { min-height: 38px; }
body.in-session .keepsakes { gap: 6px; }

/* ---------- Keepsakes: garden + tapestry ---------- */
.keepsakes {
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  display: grid; gap: 8px;
}
.strip {
  position: relative;
  min-height: 44px;
  border-radius: 16px;
  border: 1px dashed var(--surface-line);
  display: flex; align-items: center;
  overflow: hidden;
}
/* The label sits over the start of the row and fades out into it. */
.strip-label {
  position: absolute; left: 0; top: 0; bottom: 0; z-index: 1;
  display: flex; align-items: center;
  padding: 0 28px 0 14px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-soft);
  background: linear-gradient(to right, var(--strip-bg) 70%, transparent);
  pointer-events: none;
}
.garden { --strip-bg: var(--bg); background: var(--strip-bg); }
.tapestry { --strip-bg: color-mix(in srgb, var(--surface) 70%, var(--bg)); background: var(--strip-bg); }

.bed, .band {
  flex: 1; align-self: stretch;
  display: flex; gap: 2px;
  padding: 0 12px 0 100px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.bed::-webkit-scrollbar, .band::-webkit-scrollbar { display: none; }

/* Garden: plants stand on a soft soil line. */
.bed {
  align-items: flex-end; gap: 4px;
  background: linear-gradient(to top, color-mix(in srgb, #8A6A4A 28%, transparent) 0 5px, transparent 5px);
}
.plant { flex: none; width: 24px; height: 32px; display: flex; align-items: flex-end; justify-content: center; }
.plant svg { display: block; }
.plant .seed-svg { width: 30px; height: 30px; margin: 0 -3px -4px; }
.plant .flower-svg { width: 22px; height: 33px; }
.plant.is-pending { visibility: hidden; }
/* While blooming, seed and flower overlap in the same spot. */
.plant { position: relative; }
.plant.is-blooming .seed-svg { position: absolute; bottom: -4px; left: -3px; }
.plant .flower-svg { overflow: visible; }
.plant.just-planted { animation: settle .5s var(--ease); }
@keyframes settle { 0% { transform: translateY(-3px); } 60% { transform: translateY(1px); } 100% { transform: none; } }
:root[data-theme="dark"] .plant svg { filter: drop-shadow(0 0 4px color-mix(in srgb, #fff 18%, transparent)); }

/* Tapestry: pale warp threads run across the band; each worry adds woven weft. */
.band {
  align-items: center; gap: 0;
  background-image: repeating-linear-gradient(to right, transparent 0 3px, color-mix(in srgb, var(--text-soft) 22%, transparent) 3px 4.5px);
  background-size: 7px 28px; background-repeat: repeat-x; background-position: 0 center;
}
.seg {
  flex: none; width: 21px; height: 28px; /* 3 warp spaces of 7px */
  padding: 0; border: 0; background: none; display: block;
}
.seg svg { width: 100%; height: 100%; display: block; overflow: visible; }
button.seg { cursor: pointer; }
button.seg:hover svg, button.seg:focus-visible svg { filter: brightness(1.15); }
.seg.is-pending { visibility: hidden; }
:root[data-theme="dark"] .seg svg { filter: drop-shadow(0 0 3px color-mix(in srgb, var(--c) 60%, transparent)); }

/* Effects overlay: the travelling thread and the falling seed. */
.fx-layer { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.fx-svg { position: absolute; inset: 0; overflow: visible; }
.fx-thread { fill: none; stroke-width: 3.2; stroke-linecap: round; }
.fx-thread-shine { fill: none; stroke: #fff; stroke-opacity: .45; stroke-width: 1; stroke-linecap: round; }
:root[data-theme="dark"] .fx-thread { filter: drop-shadow(0 0 4px currentColor); }
.fx-knot { position: absolute; overflow: visible; }

/* ---------- Closing breath ---------- */
.breath {
  flex: 1 1 auto;
  min-height: 210px; max-height: 360px;
  width: 100%;
  display: grid; place-items: center;
}
.breath-circle {
  --size: min(56vw, 220px);
  width: var(--size); height: var(--size);
  border-radius: 50%;
  display: grid; place-items: center;
  transform: scale(.55);
  background: radial-gradient(circle at 50% 45%,
    color-mix(in srgb, var(--accent) 38%, transparent) 0%,
    color-mix(in srgb, var(--accent) 18%, transparent) 55%,
    color-mix(in srgb, var(--accent) 4%, transparent) 72%,
    transparent 74%);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 35%, transparent) inset;
}
:root[data-theme="dark"] .breath-circle {
  filter: drop-shadow(0 0 24px color-mix(in srgb, var(--accent) 45%, transparent));
}
.breath-word {
  font-weight: 700; font-size: 22px; letter-spacing: .02em;
  color: var(--text);
}

/* "Keep my steps" */
.check {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text-soft); cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .4);
  z-index: 20;
  animation: rise .4s var(--ease) both;
}

/* ---------- Gentle mode ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 380px) {
  body { font-size: 16px; }
  .brand span { font-size: 15px; }
}
