@import url("../tokens/fonts.css");

/* ==========================================================================
   Squiggle: Pop meets 80s Memphis.
   Thick ink outlines, hard offset shadows, flat clashing fills, confetti
   shapes, buttons that click. Every colour/space/radius/shadow comes from
   tokens.css; motion lives here.
   Motion law: transform + opacity only, 100-400ms; entrances use
   animation-fill-mode: backwards (never both/forwards); box-shadow changes
   only on hover/active of one element; no blur, no gradients.
   ========================================================================== */

:root {
  --sq-spring: cubic-bezier(.34, 1.56, .64, 1);   /* release, pop-in, selected tilt: ~10% overshoot */
  --sq-boing: cubic-bezier(.3, 1.9, .5, 1);       /* knob + checkbox pop: bigger overshoot, short travel */
  --sq-snap: cubic-bezier(.2, .9, .3, 1);         /* hover lift, wipes, fades: quick, no overshoot */
  --sq-squash: cubic-bezier(.4, 0, .7, 1);        /* press-in: fast, accelerating */
  --sq-t-press: 90ms;
  --sq-t-snap: 180ms;
  --sq-t-spring: 340ms;
  --sq-t-draw: 380ms;
  --sq-t-confetti: 620ms;
  --sq-graph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M24 0H0V24' fill='none' stroke='%23ece3d2' stroke-width='2'/%3E%3C/svg%3E");
  --sq-zig: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='16'%3E%3Cpath d='M-4 13l8-10 8 10 8-10 8 10 8-10' fill='none' stroke='%23141216' stroke-width='3' stroke-linejoin='miter'/%3E%3C/svg%3E");
  color-scheme: light;
}
[data-theme="dark"] { color-scheme: dark; --sq-graph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M24 0H0V24' fill='none' stroke='%231d1b22' stroke-width='2'/%3E%3C/svg%3E"); --sq-zig: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='16'%3E%3Cpath d='M-4 13l8-10 8 10 8-10 8 10 8-10' fill='none' stroke='%23f7f2e9' stroke-width='3' stroke-linejoin='miter'/%3E%3C/svg%3E"); }

body {
  margin: 0;
  background-color: var(--board);
  background-image: var(--sq-graph);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
*, *::before, *::after { box-sizing: border-box; }
[class*="sq-"][hidden] { display: none !important; }

/* ---------- patterns (static data-URI SVG; use on corners and bands, not everywhere) ---------- */
.sq-pat-graph { background-image: var(--sq-graph); background-size: 24px 24px; }
.sq-pat-confetti { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' stroke='%23141216' stroke-width='2' stroke-linejoin='round' stroke-linecap='round'%3E%3Cpath d='M14 22l9-14 9 14z' fill='%23ffd83d'/%3E%3Ccircle cx='76' cy='16' r='6' fill='%23ff6f5e'/%3E%3Cpath d='M92 48q4-7 8 0t8 0' fill='none' stroke='%232c47f0' stroke-width='4'/%3E%3Crect x='44' y='50' width='10' height='10' rx='2' fill='%2314b8a6' transform='rotate%2820 49 55%29'/%3E%3Cpath d='M10 70a9 9 0 0 1 18 0z' fill='%23c4a8ff'/%3E%3Cpath d='M58 96h12M64 90v12' stroke-width='3'/%3E%3Ccircle cx='104' cy='94' r='5' fill='%237ee2b8'/%3E%3Cpath d='M24 104l6-8 6 8 6-8' fill='none' stroke='%23ff6f5e' stroke-width='4'/%3E%3Ccircle cx='60' cy='30' r='2' fill='%23141216'/%3E%3Ccircle cx='34' cy='86' r='2' fill='%23141216'/%3E%3Ccircle cx='96' cy='72' r='2' fill='%23141216'/%3E%3C/svg%3E"); background-size: 120px 120px; }
.sq-pat-terrazzo { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cpath d='M8 10l10-4 4 9-9 5z' fill='%2314b8a6'/%3E%3Cpath d='M52 6l9 3-3 9-8-4z' fill='%23ff6f5e'/%3E%3Cpath d='M80 20l8 6-7 6-4-8z' fill='%232c47f0'/%3E%3Cpath d='M28 40l7-3 3 8-8 2z' fill='%23ffd83d'/%3E%3Cpath d='M66 46l10-2 1 9-9 1z' fill='%23c4a8ff'/%3E%3Cpath d='M10 66l8 2-2 8-8-3z' fill='%237ee2b8'/%3E%3Cpath d='M44 74l9-4 4 8-9 4z' fill='%2314b8a6'/%3E%3Cpath d='M80 78l7 3-4 7-6-5z' fill='%23ffd83d'/%3E%3Cpath d='M34 18l3 1-1 3-3-1z' fill='%23141216'/%3E%3Cpath d='M58 30l3 1-1 3-3-1z' fill='%23141216'/%3E%3Cpath d='M24 88l3 1-1 3-3-1z' fill='%23141216'/%3E%3Cpath d='M88 56l3 1-1 3-3-1z' fill='%23ff6f5e'/%3E%3C/svg%3E"); background-size: 96px 96px; }
.sq-pat-zigzag { background-image: var(--sq-zig); background-size: 32px 16px; background-repeat: repeat-x; background-position: left center; }

/* ---------- preview + layout helpers ---------- */
.sq-stage { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); padding: var(--space-6); }
.sq-stage--top { align-items: flex-start; }
.sq-col { display: flex; flex-direction: column; gap: var(--space-3); }
.sq-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.sq-spacer { flex: 1; }
.sq-cap { width: 100%; font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.sq-d { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 56px; line-height: 60px; letter-spacing: -.01em; }
.sq-t { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 32px; line-height: 38px; }
.sq-h { margin: 0; font-weight: 800; font-size: 20px; line-height: 26px; letter-spacing: -.015em; }
.sq-p { margin: 0; font-size: 16px; line-height: 24px; }
.sq-sm { margin: 0; font-size: 14px; line-height: 20px; font-weight: 500; }
.sq-soft { color: var(--ink-soft); }
.sq-icon { width: 20px; height: 20px; flex: none; display: block; }
.sq-vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:where(.sq-btn, .sq-ibtn, .sq-seg__opt, .sq-tabs__tab, .sq-day, .sq-slot, .sq-card--interactive, .sq-tag__x):focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* tones: flat fills, ink text (cobalt takes white) */
.sq-tone-teal { --sq-fill: var(--teal); }
.sq-tone-coral { --sq-fill: var(--coral); }
.sq-tone-lemon { --sq-fill: var(--lemon); }
.sq-tone-lilac { --sq-fill: var(--lilac); }
.sq-tone-mint { --sq-fill: var(--mint); }
.sq-tone-cobalt { --sq-fill: var(--cobalt); }
.sq-tone-paper { --sq-fill: var(--paper); }

/* ---------- the label pill: Pop's black pill with yellow text ---------- */
.sq-label { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius-full); background: var(--line); color: var(--lemon); font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.sq-label .sq-icon { width: 14px; height: 14px; }

/* ==========================================================================
   Button: lift on hover, squash flat on press, boing back on release
   ========================================================================== */
.sq-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 44px; padding: 0 20px; border: 3px solid var(--line); border-radius: var(--radius-full);
  background: var(--sq-fill, var(--paper)); color: var(--ink);
  font: 700 16px/1 var(--font-body); letter-spacing: -.005em; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm); cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transform: translate(0, 0);
  transition: transform var(--sq-t-spring) var(--sq-spring), box-shadow var(--sq-t-snap) var(--sq-snap);
}
/* invisible hover-catcher: 5px past the right and bottom so a lifted button never jitters off the cursor */
.sq-btn::after, .sq-ibtn::after, .sq-card--interactive::after, .sq-slot::after, .sq-day::after { content: ""; position: absolute; inset: -3px -8px -8px -3px; z-index: -1; border-radius: inherit; }
.sq-btn--primary { --sq-fill: var(--lemon); color: var(--on-fill); }
.sq-btn--danger { --sq-fill: var(--coral); color: var(--on-fill); }
.sq-btn[class*="sq-tone-"] { color: var(--on-fill); }
.sq-btn.sq-tone-cobalt { color: #ffffff; }
.sq-btn--ghost { background: transparent; border-color: transparent; box-shadow: none; }
.sq-btn--sm { height: 36px; padding: 0 14px; font-size: 14px; }
.sq-btn--lg { height: 54px; padding: 0 26px; font-size: 18px; }
.sq-btn--block { display: flex; width: 100%; }
.sq-btn .sq-icon { width: 18px; height: 18px; }
.sq-btn--lg .sq-icon { width: 20px; height: 20px; }
@media (hover: hover) {
  .sq-btn:not(:disabled):not(.sq-btn--ghost):hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
  .sq-btn--ghost:not(:disabled):hover { background: var(--sunk); }
}
.sq-btn:not(:disabled):not(.sq-btn--ghost):active, .sq-btn.is-pressed {
  transform: translate(3px, 3px) scale(1.03, .9); box-shadow: var(--shadow-press);
  transition-duration: var(--sq-t-press); transition-timing-function: var(--sq-squash);
}
.sq-btn--ghost:not(:disabled):active { transform: translate(1px, 1px) scale(.95); transition-duration: var(--sq-t-press); }
.sq-btn:disabled, .sq-btn[aria-disabled="true"] { background: var(--sunk); color: var(--ink-soft); border-style: dashed; border-color: var(--rim); box-shadow: none; cursor: not-allowed; }
.sq-btn.is-loading { color: transparent; pointer-events: none; }
.sq-btn__dots { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--on-fill); }
.sq-btn:not(.sq-btn--primary):not(.sq-btn--danger) .sq-btn__dots { color: var(--ink); }
.sq-btn__dots i { width: 8px; height: 8px; background: currentColor; animation: sq-hop 600ms var(--sq-snap) infinite alternate; }
.sq-btn__dots i:nth-child(1) { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.sq-btn__dots i:nth-child(2) { border-radius: 50%; animation-delay: 120ms; }
.sq-btn__dots i:nth-child(3) { animation-delay: 240ms; }
@keyframes sq-hop { to { transform: translateY(-5px) rotate(90deg); } }

/* ---------- IconButton ---------- */
.sq-ibtn {
  position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 3px solid var(--line); border-radius: var(--radius-sm); background: var(--sq-fill, var(--paper)); color: var(--ink);
  box-shadow: var(--shadow-sm); cursor: pointer; -webkit-tap-highlight-color: transparent; transform: translate(0, 0);
  transition: transform var(--sq-t-spring) var(--sq-spring), box-shadow var(--sq-t-snap) var(--sq-snap);
}
.sq-ibtn--round { border-radius: var(--radius-full); }
.sq-ibtn--sm { width: 36px; height: 36px; border-radius: 12px; }
.sq-ibtn--lg { width: 54px; height: 54px; }
.sq-ibtn--primary { --sq-fill: var(--lemon); color: var(--on-fill); }
.sq-ibtn--danger { --sq-fill: var(--coral); color: var(--on-fill); }
.sq-ibtn--ghost { background: transparent; border-color: transparent; box-shadow: none; }
.sq-ibtn[aria-pressed="true"] { --sq-fill: var(--coral); color: var(--on-fill); }
.sq-ibtn[aria-pressed="true"] .sq-icon { fill: currentColor; }
.sq-ibtn--sm .sq-icon { width: 18px; height: 18px; }
@media (hover: hover) {
  .sq-ibtn:not(:disabled):not(.sq-ibtn--ghost):hover { transform: translate(-2px, -2px) rotate(-4deg); box-shadow: var(--shadow-md); }
  .sq-ibtn--ghost:not(:disabled):hover { background: var(--sunk); }
}
.sq-ibtn:not(:disabled):not(.sq-ibtn--ghost):active { transform: translate(3px, 3px) scale(.9); box-shadow: var(--shadow-press); transition-duration: var(--sq-t-press); transition-timing-function: var(--sq-squash); }
.sq-ibtn:disabled { background: var(--sunk); color: var(--ink-soft); border-style: dashed; border-color: var(--rim); box-shadow: none; cursor: not-allowed; }
.sq-ibtn.is-popped .sq-icon { animation: sq-pop 340ms var(--sq-boing); }
.sq-ibtn__count { position: absolute; top: -9px; right: -9px; }
@keyframes sq-pop { from { transform: scale(.4) rotate(-20deg); } }

/* ==========================================================================
   Toggle: knob slides, the squiggle in the track straightens when on
   ========================================================================== */
.sq-toggle { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; font-weight: 500; -webkit-tap-highlight-color: transparent; }
.sq-toggle__input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.sq-toggle__track { position: relative; flex: none; width: 62px; height: 34px; border: 3px solid var(--rim); border-radius: var(--radius-full); background: var(--sunk); overflow: hidden; }
.sq-toggle__fill { position: absolute; inset: 0; background: var(--teal); opacity: 0; transition: opacity var(--sq-t-snap) var(--sq-snap); }
.sq-toggle__wave { position: absolute; left: 6px; right: 6px; top: 50%; width: calc(100% - 12px); height: 12px; margin-top: -6px; overflow: visible; transform-origin: 50% 50%; transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-toggle__wave path { fill: none; stroke: var(--ink-soft); stroke-width: 2.5; stroke-linecap: round; }
.sq-toggle__knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border: 3px solid var(--line); border-radius: 50%; background: var(--paper); box-shadow: var(--shadow-xs); transition: transform var(--sq-t-spring) var(--sq-boing); }
.sq-toggle__input:checked + .sq-toggle__track .sq-toggle__fill { opacity: 1; }
.sq-toggle__input:checked + .sq-toggle__track .sq-toggle__wave { transform: scaleY(.06); }
.sq-toggle__input:checked + .sq-toggle__track .sq-toggle__wave path { stroke: var(--on-fill); }
.sq-toggle__input:checked + .sq-toggle__track .sq-toggle__knob { transform: translateX(28px) rotate(180deg); }
.sq-toggle__input:checked + .sq-toggle__track { border-color: var(--line); }
.sq-toggle:active .sq-toggle__knob { transform: scale(1.15, .85); transition-duration: var(--sq-t-press); }
.sq-toggle:active .sq-toggle__input:checked + .sq-toggle__track .sq-toggle__knob { transform: translateX(28px) scale(1.15, .85); }
.sq-toggle__input:focus-visible + .sq-toggle__track { outline: 3px solid var(--focus); outline-offset: 3px; }
.sq-toggle.is-disabled { cursor: not-allowed; color: var(--ink-soft); }
.sq-toggle.is-disabled .sq-toggle__track { border-style: dashed; }

/* ==========================================================================
   Checkbox + Radio: zigzag tick wipes in; checked box tilts
   ========================================================================== */
.sq-check, .sq-radio { display: inline-flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sq-check__input, .sq-radio__input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.sq-check__box { position: relative; flex: none; width: 28px; height: 28px; border: 3px solid var(--rim); border-radius: var(--radius-xs); background: var(--paper); box-shadow: var(--shadow-xs); overflow: hidden; transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-check__fill, .sq-radio__fill { position: absolute; inset: 0; background: var(--sq-fill, var(--lemon)); opacity: 0; transition: opacity var(--sq-t-snap) var(--sq-snap); }
.sq-wipe { position: absolute; overflow: hidden; transform: translateX(-101%); transition: transform var(--sq-t-draw) var(--sq-snap); }
.sq-wipe > * { display: block; transform: translateX(101%); transition: transform var(--sq-t-draw) var(--sq-snap); }
.sq-check__box .sq-wipe { inset: 0; }
.sq-check__tick { width: 100%; height: 100%; }
.sq-check__tick path { fill: none; stroke: var(--on-fill); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.sq-check__input:checked + .sq-check__box { transform: rotate(-6deg); border-color: var(--line); }
.sq-check__input:checked + .sq-check__box .sq-check__fill { opacity: 1; }
.sq-check__input:checked + .sq-check__box .sq-wipe, .sq-check__input:checked + .sq-check__box .sq-wipe > * { transform: none; }
.sq-check__input:focus-visible + .sq-check__box, .sq-radio__input:focus-visible + .sq-radio__dot { outline: 3px solid var(--focus); outline-offset: 3px; }
.sq-check__text, .sq-radio__text { display: flex; flex-direction: column; padding-top: 2px; font-weight: 500; }
.sq-check__hint, .sq-radio__hint { font-size: 14px; line-height: 20px; color: var(--ink-soft); font-weight: 400; }
.sq-check.is-disabled, .sq-radio.is-disabled { cursor: not-allowed; color: var(--ink-soft); }
.sq-check.is-disabled .sq-check__box, .sq-radio.is-disabled .sq-radio__dot { border-style: dashed; box-shadow: none; background: var(--sunk); }
.sq-check:active .sq-check__box { transform: scale(.88); transition-duration: var(--sq-t-press); }

.sq-radio__dot { position: relative; flex: none; width: 28px; height: 28px; border: 3px solid var(--rim); border-radius: 50%; background: var(--paper); box-shadow: var(--shadow-xs); overflow: hidden; }
.sq-radio__pip { position: absolute; inset: 6px; border-radius: 50%; background: var(--on-fill); transform: scale(0); transition: transform var(--sq-t-spring) var(--sq-boing); }
.sq-radio__input:checked + .sq-radio__dot { border-color: var(--line); }
.sq-radio__input:checked + .sq-radio__dot .sq-radio__fill { opacity: 1; }
.sq-radio__input:checked + .sq-radio__dot .sq-radio__pip { transform: scale(1); }
.sq-radio:active .sq-radio__pip { transform: scale(.5); }
.sq-radiogroup { display: flex; flex-direction: column; gap: var(--space-3); border: 0; margin: 0; padding: 0; min-width: 0; }
.sq-radiogroup--row { flex-direction: row; flex-wrap: wrap; gap: var(--space-4); }
.sq-radiogroup legend { padding: 0; margin-bottom: var(--space-2); font-weight: 800; }

/* ==========================================================================
   TextField: lifts on focus, wobbles on error
   ========================================================================== */
.sq-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sq-field__label { font-size: 14px; line-height: 20px; font-weight: 700; }
.sq-field__box { position: relative; display: flex; align-items: center; gap: var(--space-2); height: 48px; padding: 0 var(--space-4); border: 3px solid var(--rim); border-radius: var(--radius-sm); background: var(--paper); box-shadow: var(--shadow-xs); transform: translate(0, 0); transition: transform var(--sq-t-snap) var(--sq-snap), box-shadow var(--sq-t-snap) var(--sq-snap); }
.sq-field__box .sq-icon { color: var(--ink-soft); }
.sq-field__input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font: 500 16px/24px var(--font-body); }
.sq-field__input::placeholder { color: var(--ink-soft); opacity: 1; }
textarea.sq-field__input { padding: 10px 0; resize: vertical; }
.sq-field--multi .sq-field__box { height: auto; align-items: flex-start; }
.sq-field__box:focus-within { transform: translate(-2px, -2px); box-shadow: var(--shadow-sm); border-color: var(--line); outline: 3px solid var(--focus); outline-offset: 3px; }
.sq-field__hint { font-size: 14px; line-height: 20px; color: var(--ink-soft); }
.sq-field.is-error .sq-field__box { border-color: var(--coral); box-shadow: 4px 4px 0 var(--coral); }
.sq-field.is-error .sq-field__box.is-shaking { animation: sq-shake 380ms var(--sq-snap); }
.sq-field__error { display: flex; align-items: center; gap: var(--space-2); font-size: 14px; line-height: 20px; font-weight: 600; color: var(--ink); }
.sq-field__error::before { content: "!"; display: inline-grid; place-items: center; width: 20px; height: 20px; flex: none; border: 2px solid var(--line); border-radius: 50%; background: var(--coral); color: var(--on-fill); font-size: 12px; font-weight: 800; }
.sq-field.is-disabled .sq-field__box { background: var(--sunk); border-style: dashed; box-shadow: none; }
@keyframes sq-shake { 20% { transform: translateX(-6px) rotate(-1deg); } 45% { transform: translateX(5px) rotate(1deg); } 70% { transform: translateX(-3px); } 90% { transform: translateX(1px); } }

/* ==========================================================================
   Tabs: the active tab's squiggle draws in under it
   ========================================================================== */
.sq-tabs { display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.sq-tabs::-webkit-scrollbar { display: none; }
.sq-tabs__tab { position: relative; flex: none; padding: 8px 14px 18px; border: 0; background: none; color: var(--ink-soft); font: 700 16px/24px var(--font-body); cursor: pointer; border-radius: 12px; -webkit-tap-highlight-color: transparent; transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-tabs__tab:hover { color: var(--ink); }
.sq-tabs__tab:active { transform: translateY(2px) scale(.96); transition-duration: var(--sq-t-press); }
.sq-tabs__tab[aria-selected="true"] { color: var(--ink); }
.sq-tabs__line { left: 10px; right: 10px; bottom: 2px; height: 12px; }
.sq-tabs__line svg { width: 100%; height: 12px; overflow: visible; }
.sq-tabs__line path { fill: none; stroke: var(--sq-fill, var(--coral)); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.sq-tabs__tab[aria-selected="true"] .sq-wipe, .sq-tabs__tab[aria-selected="true"] .sq-wipe > * { transform: none; }
.sq-tabs__tab:not([aria-selected="true"]) .sq-wipe { transition: opacity var(--sq-t-snap) var(--sq-snap); opacity: 0; transform: none; }
.sq-tabs__tab:not([aria-selected="true"]) .sq-wipe > * { transition: none; }
.sq-tabs__count { margin-left: 6px; }
.sq-tabpanel { padding-top: var(--space-4); }
.sq-tabpanel.is-in { animation: sq-rise 260ms var(--sq-snap) backwards; }
@keyframes sq-rise { from { opacity: 0; transform: translateY(8px); } }

/* ==========================================================================
   SegmentedControl: the picked chip pops in lemon and tilts
   ========================================================================== */
.sq-seg { display: inline-flex; gap: 2px; padding: var(--space-1); border: 3px solid var(--rim); border-radius: var(--radius-full); background: var(--sunk); max-width: 100%; }
.sq-seg__opt { position: relative; flex: 1 1 auto; height: 36px; padding: 0 16px; border: 3px solid transparent; border-radius: var(--radius-full); background: transparent; color: var(--ink-soft); font: 700 15px/1 var(--font-body); cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-seg__opt:hover { color: var(--ink); }
.sq-seg__opt:active { transform: scale(.94); transition-duration: var(--sq-t-press); }
.sq-seg__opt[aria-checked="true"] { background: var(--sq-fill, var(--lemon)); border-color: var(--line); color: var(--on-fill); box-shadow: var(--shadow-xs); transform: rotate(-2deg); }
.sq-seg__opt.is-popped { animation: sq-chip-pop 340ms var(--sq-spring); }
@keyframes sq-chip-pop { from { transform: scale(.85) rotate(4deg); } }
.sq-seg--sm .sq-seg__opt { height: 30px; padding: 0 12px; font-size: 14px; }

/* ==========================================================================
   Card: flat fill, ink outline, hard shadow; corner shapes jiggle on hover
   ========================================================================== */
.sq-card { position: relative; isolation: isolate; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; padding: var(--space-6); border: 3px solid var(--line); border-radius: var(--radius-lg); background: var(--sq-fill, var(--paper)); color: var(--ink); box-shadow: var(--shadow-md); }
.sq-card[class*="sq-tone-"]:not(.sq-tone-paper) { color: var(--on-fill); }
.sq-card[class*="sq-tone-"]:not(.sq-tone-paper) .sq-soft { color: var(--on-fill); opacity: .8; }
.sq-card[class*="sq-tone-"]:not(.sq-tone-paper) .sq-stat__foot { color: var(--on-fill); }
.sq-card.sq-tone-cobalt, .sq-card.sq-tone-cobalt .sq-soft { color: #ffffff; }
.sq-card--flat { box-shadow: none; }
.sq-card[class*="sq-tone-"]:not(.sq-tone-paper) :is(.sq-btn--ghost, .sq-ibtn--ghost, .sq-tabs__tab) { color: var(--on-fill); }
.sq-card[class*="sq-tone-"]:not(.sq-tone-paper) :is(.sq-btn--ghost, .sq-ibtn--ghost):hover { background: rgb(20 18 22 / .12); }

.sq-card--sm { padding: var(--space-4); border-radius: 18px; box-shadow: var(--shadow-sm); }
.sq-card--interactive { cursor: pointer; transform: translate(0, 0); transition: transform var(--sq-t-snap) var(--sq-snap), box-shadow var(--sq-t-snap) var(--sq-snap); text-align: left; font: inherit; }
@media (hover: hover) { .sq-card--interactive:hover { transform: translate(-3px, -3px); box-shadow: var(--shadow-lg); } }
.sq-card--interactive:active { transform: translate(2px, 2px); box-shadow: var(--shadow-xs); transition-duration: var(--sq-t-press); }
.sq-card.is-selected { transform: rotate(-1.5deg); }
@media (hover: hover) { .sq-card--interactive.is-selected:hover { transform: translate(-3px, -3px) rotate(-1.5deg); } }
.sq-card__head { display: flex; align-items: center; gap: var(--space-3); }
.sq-card__title { margin: 0; font-weight: 800; font-size: 20px; line-height: 26px; letter-spacing: -.015em; }
.sq-card__corner { position: absolute; top: 0; right: 0; z-index: -1; width: 28%; max-width: 112px; height: 80px; border-top-right-radius: 21px; background-position: right top; pointer-events: none; }
.sq-card__corner.sq-pat-zigzag { height: 16px; width: 100%; max-width: none; top: auto; bottom: 18px; border-radius: 0; opacity: .9; }
.sq-card__deco { position: absolute; top: -18px; right: -12px; display: flex; align-items: flex-end; pointer-events: none; }
.sq-card__deco .sq-shape { margin-left: -10px; }
@media (hover: hover) {
  .sq-card:hover .sq-card__deco .sq-shape, .sq-jiggle-host:hover .sq-shape { animation: sq-jiggle 520ms var(--sq-spring); }
  .sq-card:hover .sq-card__deco .sq-shape:nth-child(2) { animation-delay: 50ms; }
  .sq-card:hover .sq-card__deco .sq-shape:nth-child(3) { animation-delay: 100ms; }
}
.sq-card.is-jiggling .sq-card__deco .sq-shape { animation: sq-jiggle 520ms var(--sq-spring); }
@keyframes sq-jiggle { 0% { transform: var(--sq-rot, rotate(0)); } 25% { transform: var(--sq-rot, rotate(0)) rotate(-14deg) scale(1.12); } 55% { transform: var(--sq-rot, rotate(0)) rotate(9deg) translateY(-3px); } 80% { transform: var(--sq-rot, rotate(0)) rotate(-4deg); } 100% { transform: var(--sq-rot, rotate(0)); } }

/* entrance: one-shot pop, staggered by --sq-i. backwards fill only, so hover lifts never fight it */
.sq-enter { animation: sq-enter 380ms var(--sq-spring) backwards; animation-delay: calc(var(--sq-i, 0) * 60ms); }
@keyframes sq-enter { from { opacity: 0; transform: translateY(14px) scale(.94) rotate(-1deg); } }

/* ==========================================================================
   Shape: decorative Memphis bits
   ========================================================================== */
.sq-shape { display: inline-block; flex: none; width: var(--sq-size, 48px); height: var(--sq-size, 48px); transform: var(--sq-rot, rotate(0)); transform-origin: 50% 60%; }
.sq-shape svg { display: block; width: 100%; height: 100%; overflow: visible; }
.sq-shape .k { fill: none; stroke: var(--line); stroke-linecap: round; stroke-linejoin: round; }
.sq-shape .f { fill: var(--sq-fill, var(--coral)); stroke: var(--line); stroke-width: 3; stroke-linejoin: round; }
.sq-shape .s { fill: none; stroke: var(--sq-fill, var(--coral)); stroke-linecap: round; stroke-linejoin: round; }
.sq-shape .i { fill: var(--ink); }
.sq-shape .g { fill: none; stroke: var(--ink-soft); stroke-width: 1.5; }
.sq-shape--bare .k { stroke: transparent; }
.sq-shape--wiggle { animation: sq-wiggle 2.6s ease-in-out infinite; }
@keyframes sq-wiggle { 0%, 100% { transform: var(--sq-rot, rotate(0)) rotate(-5deg); } 50% { transform: var(--sq-rot, rotate(0)) rotate(5deg) translateY(-2px); } }

/* ==========================================================================
   Confetti: 8-14 shapes, transform + opacity, ~600ms, then removed (JS)
   ========================================================================== */
.sq-confetti { position: fixed; z-index: 9999; width: 0; height: 0; pointer-events: none; }
.sq-confetti > span { position: absolute; left: 0; top: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; will-change: transform, opacity; }
.sq-confetti svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ==========================================================================
   Badge + Tag
   ========================================================================== */
.sq-badge { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px; border: 2px solid var(--line); border-radius: var(--radius-full); background: var(--sq-fill, var(--paper)); color: var(--on-fill); font-size: 13px; line-height: 1; font-weight: 700; white-space: nowrap; }
.sq-badge.sq-tone-paper { color: var(--ink); }
.sq-badge.sq-tone-cobalt { color: #ffffff; }
.sq-badge .sq-icon { width: 14px; height: 14px; }
.sq-badge--count { min-width: 24px; height: 24px; padding: 0 6px; justify-content: center; --sq-fill: var(--coral); font-size: 12px; font-weight: 800; }
.sq-badge--dot { width: 14px; height: 14px; min-width: 0; padding: 0; --sq-fill: var(--mint); }
.sq-badge.is-bumped { animation: sq-pop 340ms var(--sq-boing); }
.sq-tag { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px 0 12px; border: 2px solid var(--line); border-radius: var(--radius-full); background: var(--sq-fill, var(--paper)); color: var(--on-fill); font-size: 14px; font-weight: 700; box-shadow: var(--shadow-xs); transition: transform 200ms var(--sq-snap), opacity 200ms var(--sq-snap); }
.sq-tag.sq-tone-paper { color: var(--ink); }
.sq-tag:not(:has(.sq-tag__x)) { padding-right: 12px; }
.sq-tag__x { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 2px solid currentColor; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-tag__x .sq-icon { width: 12px; height: 12px; }
.sq-tag__x:hover { transform: rotate(90deg); }
.sq-tag.is-leaving { transform: scale(.6) rotate(-12deg); opacity: 0; }

/* ==========================================================================
   Avatar
   ========================================================================== */
.sq-avatar { position: relative; display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; border: 3px solid var(--line); border-radius: 50%; background: var(--sq-fill, var(--lilac)); color: var(--on-fill); font: 800 16px/1 var(--font-body); letter-spacing: -.02em; box-shadow: var(--shadow-xs); transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-avatar.sq-tone-cobalt { color: #ffffff; }
.sq-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.sq-avatar--sm { width: 32px; height: 32px; font-size: 12px; border-width: 2px; }
.sq-avatar--lg { width: 64px; height: 64px; font-size: 22px; }
.sq-avatar__status { position: absolute; right: -4px; bottom: -4px; width: 16px; height: 16px; border: 3px solid var(--line); border-radius: 50%; background: var(--mint); }
.sq-avatar--sm .sq-avatar__status { width: 12px; height: 12px; border-width: 2px; }
.sq-avatar__status--away { background: var(--lemon); }
.sq-avatar__status--busy { background: var(--coral); }
.sq-avatar__status--off { background: var(--sunk); }
.sq-avstack { display: inline-flex; align-items: center; }
.sq-avstack > * + * { margin-left: -12px; }
.sq-avstack--sm > * + * { margin-left: -6px; }
@media (hover: hover) { .sq-avstack .sq-avatar:hover, .sq-avatar--hop:hover { transform: translateY(-5px) rotate(-8deg); z-index: 1; } }
.sq-avstack__more { --sq-fill: var(--paper); color: var(--ink); }

/* ==========================================================================
   Tooltip: Pop label pill: line fill, lemon text
   ========================================================================== */
.sq-tipwrap { position: relative; display: inline-flex; }
.sq-tip { position: absolute; left: 50%; bottom: calc(100% + 12px); z-index: 50; width: max-content; max-width: 240px; padding: 6px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--line); color: var(--lemon); font-size: 13px; line-height: 18px; font-weight: 700; box-shadow: var(--shadow-xs); pointer-events: none; opacity: 0; transform: translateX(-50%) translateY(6px) scale(.7) rotate(-4deg); transform-origin: 50% 100%; transition: opacity 120ms var(--sq-snap), transform 120ms var(--sq-snap); }
.sq-tip::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -7px; border: 7px solid transparent; border-top-color: var(--line); border-bottom: 0; }
.sq-tip--below { bottom: auto; top: calc(100% + 12px); transform-origin: 50% 0; }
.sq-tip--below::after { top: auto; bottom: 100%; border-top: 0; border-bottom: 7px solid var(--line); }
.sq-tipwrap:hover .sq-tip, .sq-tipwrap:focus-within .sq-tip, .sq-tip.is-open { opacity: 1; transform: translateX(-50%) rotate(-2deg); transition: opacity 160ms var(--sq-snap) 250ms, transform var(--sq-t-spring) var(--sq-spring) 250ms; }

/* ==========================================================================
   Toast
   ========================================================================== */
.sq-toasts { position: fixed; left: 50%; bottom: var(--space-6); z-index: 9000; display: flex; flex-direction: column-reverse; align-items: center; gap: var(--space-3); width: min(420px, calc(100vw - 32px)); transform: translateX(-50%); pointer-events: none; }
.sq-toast { position: relative; display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3); border: 3px solid var(--line); border-radius: 18px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-md); pointer-events: auto; }
.sq-toasts .sq-toast { animation: sq-toast-in 380ms var(--sq-spring) backwards; transition: opacity 200ms var(--sq-snap), transform 200ms var(--sq-snap); }
.sq-toast.is-leaving { opacity: 0; transform: translateY(16px) scale(.92); }
.sq-toast__icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 3px solid var(--line); border-radius: 50%; background: var(--sq-fill, var(--mint)); color: var(--on-fill); }
.sq-toast__icon.sq-tone-cobalt { color: #ffffff; }
.sq-toast__body { flex: 1; min-width: 0; }
.sq-toast__title { margin: 0; font-weight: 800; font-size: 16px; line-height: 22px; }
.sq-toast__msg { margin: 0; font-size: 14px; line-height: 20px; color: var(--ink-soft); }
@keyframes sq-toast-in { from { opacity: 0; transform: translateY(28px) scale(.9) rotate(2deg); } }

/* ==========================================================================
   Modal
   ========================================================================== */
.sq-modal { position: fixed; inset: 0; z-index: 8000; display: grid; place-items: center; padding: var(--space-4); }
.sq-modal__scrim { position: absolute; inset: 0; background: rgb(20 18 22 / .55); animation: sq-fade 200ms var(--sq-snap) backwards; }
[data-theme="dark"] .sq-modal__scrim { background: rgb(0 0 0 / .72); }
.sq-modal__panel { position: relative; isolation: isolate; width: min(480px, 100%); max-height: calc(100% - 16px); overflow: visible; display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-8) var(--space-6) var(--space-6); border: 3px solid var(--line); border-radius: 26px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); animation: sq-modal-in 380ms var(--sq-spring) backwards; }
.sq-modal__deco { position: absolute; top: -22px; left: 18px; display: flex; align-items: flex-end; gap: 0; pointer-events: none; }
.sq-modal__deco .sq-shape { animation: sq-jiggle 600ms var(--sq-spring) 220ms; }
.sq-modal__close { position: absolute; top: 14px; right: 14px; }
.sq-modal__close:hover { transform: rotate(90deg) !important; }
.sq-modal__title { margin: 0; padding-right: 48px; font-family: var(--font-display); font-weight: 400; font-size: 32px; line-height: 38px; }
.sq-modal__body { margin: 0; color: var(--ink); }
.sq-modal__actions { display: flex; justify-content: flex-end; gap: var(--space-3); flex-wrap: wrap; padding-top: var(--space-2); }
.sq-modal.is-leaving .sq-modal__scrim { opacity: 0; transition: opacity 160ms var(--sq-snap); }
.sq-modal.is-leaving .sq-modal__panel { opacity: 0; transform: scale(.94) translateY(8px); transition: opacity 160ms var(--sq-snap), transform 160ms var(--sq-snap); }
@keyframes sq-fade { from { opacity: 0; } }
@keyframes sq-modal-in { from { opacity: 0; transform: translateY(24px) scale(.9) rotate(-2deg); } }

/* ==========================================================================
   Progress: a zigzag (or squiggle) line that fills
   ========================================================================== */
.sq-progress { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sq-progress__top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); font-size: 14px; line-height: 20px; font-weight: 700; }
.sq-progress__val { font-weight: 800; font-variant-numeric: tabular-nums; }
.sq-progress__track { position: relative; height: 28px; border: 3px solid var(--rim); border-radius: var(--radius-full); background: var(--sunk); overflow: hidden; }
.sq-progress__ghost, .sq-progress__line { position: absolute; left: 0; top: 50%; width: 100%; height: 12px; margin-top: -6px; }
.sq-progress__ghost path { fill: none; stroke: var(--ink-soft); stroke-width: 2; opacity: .45; }
.sq-progress__line path { fill: none; stroke: var(--on-fill); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.sq-progress .sq-wipe { inset: 0; transform: translateX(var(--sq-off, -100%)); transition: transform 400ms var(--sq-spring); }
.sq-progress .sq-wipe > * { position: absolute; inset: 0; transform: translateX(calc(var(--sq-off, -100%) * -1)); transition: transform 400ms var(--sq-spring); background: var(--sq-fill, var(--teal)); }
.sq-progress .sq-wipe { border-radius: 0; }
.sq-progress--sm .sq-progress__track { height: 20px; border-width: 2px; }
.sq-progress--sm .sq-progress__ghost, .sq-progress--sm .sq-progress__line { height: 8px; margin-top: -4px; }

/* ==========================================================================
   Widgets
   ========================================================================== */
.sq-stat__num { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.sq-stat__value { margin: 0; font-family: var(--font-display); font-size: 44px; line-height: 50px; font-weight: 400; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.sq-stat__value.is-bumped { animation: sq-num 380ms var(--sq-spring); }
@keyframes sq-num { from { transform: translateY(10px) rotate(-3deg); opacity: .2; } }
.sq-stat__spark { width: 100%; height: 56px; overflow: visible; }
.sq-stat__spark .u { fill: none; stroke: var(--line); stroke-width: 7; stroke-linejoin: miter; stroke-linecap: square; vector-effect: non-scaling-stroke; }
.sq-stat__spark .o { fill: none; stroke: var(--sq-line, var(--cobalt)); stroke-width: 3.5; stroke-linejoin: miter; stroke-linecap: square; vector-effect: non-scaling-stroke; }
[data-theme="dark"] .sq-stat__spark .u { stroke: var(--drop); }
.sq-stat__foot { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: 14px; line-height: 20px; color: var(--ink-soft); }

.sq-sched__days { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-2); }
.sq-day { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 0 8px; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink); font: inherit; cursor: pointer; box-shadow: var(--shadow-xs); transform: translate(0, 0); transition: transform var(--sq-t-spring) var(--sq-spring), box-shadow var(--sq-t-snap) var(--sq-snap); }
.sq-day span { font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.sq-day strong { font-size: 20px; line-height: 24px; font-weight: 800; letter-spacing: -.03em; }
@media (hover: hover) { .sq-day:hover { transform: translate(-1px, -1px); box-shadow: var(--shadow-sm); } }
.sq-day[aria-pressed="true"], .sq-day[aria-pressed="true"]:hover { background: var(--line); color: var(--lemon); box-shadow: 3px 3px 0 var(--coral); transform: rotate(-3deg); }
[data-theme="dark"] .sq-day[aria-pressed="true"] { background: var(--lemon); color: var(--on-fill); box-shadow: 3px 3px 0 var(--coral); }
.sq-day[aria-pressed="true"] span { color: inherit; }
.sq-sched__slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--space-3); }
.sq-slot { position: relative; height: 44px; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink); font: 800 16px/1 var(--font-body); letter-spacing: -.02em; cursor: pointer; box-shadow: 3px 3px 0 var(--drop); transform: translate(0, 0); transition: transform var(--sq-t-snap) var(--sq-snap), box-shadow var(--sq-t-snap) var(--sq-snap); }
@media (hover: hover) { .sq-slot:not(:disabled):hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--drop); } }
.sq-slot:not(:disabled):active { transform: translate(2px, 2px); box-shadow: var(--shadow-press); transition-duration: var(--sq-t-press); }
.sq-slot[aria-checked="true"], .sq-slot[aria-checked="true"]:hover { background: var(--lemon); color: var(--on-fill); transform: translate(-2px, -2px) rotate(-2deg); box-shadow: 5px 5px 0 var(--drop); transition-timing-function: var(--sq-spring); transition-duration: var(--sq-t-spring); }
.sq-slot:disabled { background: transparent; color: var(--ink-soft); border-style: dashed; border-color: var(--rim); box-shadow: none; text-decoration: line-through; cursor: not-allowed; }

.sq-goal__count { margin: 0; font-family: var(--font-display); font-size: 32px; line-height: 38px; }
.sq-goal__count small { font-family: var(--font-body); font-size: 16px; font-weight: 700; }
.sq-goal.is-done { transform: rotate(-1.5deg); transition: transform var(--sq-t-spring) var(--sq-spring); }
.sq-goal__done { display: none; }
.sq-goal.is-done .sq-goal__done { display: inline-flex; animation: sq-pop 340ms var(--sq-boing) backwards; }

/* ==========================================================================
   Reduced motion: drop the movement, keep every state
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  [class*="sq-"], [class*="sq-"]::before, [class*="sq-"]::after, [class*="sq-"] * { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }
  .sq-btn:hover, .sq-btn:active, .sq-btn.is-pressed, .sq-ibtn:hover, .sq-ibtn:active, .sq-card--interactive:hover, .sq-card--interactive:active, .sq-slot:hover, .sq-slot:active, .sq-day:hover, .sq-field__box:focus-within, .sq-avstack .sq-avatar:hover { transform: none !important; }
}
