/* Page frame, shared components and motion. Colours come from tokens.css. */

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* Scrollbars: thin, soft accent thumb on a transparent track; follows the light and dark theme */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent) 55%, transparent) transparent;
}

/* older WebKit browsers ignore scrollbar-color; they use these instead */
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--accent) 55%, transparent);
    border: 2px solid transparent;
    background-clip: content-box;
    border-radius: 999px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
    background-clip: content-box;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.75rem, 1.3rem + 2vw, 2.5rem);
}

h2 {
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.6rem);
}

h3 {
  font-size: 1.1rem;
}

p {
  margin: 0;
}

a {
  color: var(--accent-strong);
}

img,
svg {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.muted {
  color: var(--muted);
}

/* ---------- living background ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.backdrop span {
  position: absolute;
  width: 62vmax;
  height: 62vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: var(--glow-opacity);
  will-change: transform;
  animation: drift 26s ease-in-out infinite alternate;
}

.backdrop span:nth-child(1) {
  top: -26vmax;
  left: -22vmax;
  background: var(--glow-1);
}

.backdrop span:nth-child(2) {
  top: -28vmax;
  right: -24vmax;
  background: var(--glow-2);
  animation-duration: 32s;
  animation-delay: -8s;
}

.backdrop span:nth-child(3) {
  right: -24vmax;
  bottom: -30vmax;
  background: var(--glow-3);
  animation-duration: 29s;
  animation-delay: -15s;
}

.backdrop span:nth-child(4) {
  bottom: -30vmax;
  left: -24vmax;
  background: var(--glow-4);
  animation-duration: 36s;
  animation-delay: -4s;
}

/* ---------- page frame ---------- */

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  background: var(--surface-solid);
  color: var(--ink);
  font-weight: 600;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.topbar-wrap {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px 12px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 10px 8px 16px;
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-bar);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  text-decoration: none;
}

.logo {
  position: relative;
  flex: none;
  width: 32px;
  height: 32px;
}

.logo::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--grad-logo);
  animation: spin-slow 14s linear infinite;
}

.logo svg {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

.mainnav {
  display: none;
  gap: 2px;
  font-size: 15px;
  font-weight: 500;
}

.navlink {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.2s;
}

.navlink:hover {
  background: var(--well);
  color: var(--ink);
}

.navlink:active {
  transform: scale(0.96);
}

.navlink[aria-current="page"] {
  background: var(--grad-primary);
  color: var(--on-accent);
  font-weight: 600;
}

.icon {
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.langswitch {
  display: flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--well);
  font-size: 13px;
  font-weight: 600;
}

.langswitch a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 38px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
}

.langswitch a[aria-current="true"] {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: 0 2px 6px rgb(37 35 74 / 0.12);
}

.iconbtn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--well);
  color: var(--ink-soft);
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.2s;
}

.iconbtn:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.iconbtn:active {
  transform: scale(0.94);
}

.iconbtn[aria-current="page"] {
  background: var(--grad-primary);
  color: var(--on-accent);
}

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: var(--surface-solid);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* the theme button shows the icon of the theme it switches to */
.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}

/* menus built on <details>, so they open without any script */
.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--surface-edge);
  border-radius: 22px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-lift);
  animation: drop 0.2s ease-out backwards;
}

.menu-panel .navlink {
  white-space: normal;
}

.menu-panel form {
  margin: 0;
}

.menu-panel button.navlink {
  width: 100%;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}

.menu-panel button.navlink:hover {
  background: var(--well);
}

.tabbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--surface-edge);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-bar);
  backdrop-filter: blur(16px);
}

.tab {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  padding: 0 4px;
  border-radius: 20px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.tab .icon {
  width: 22px;
  height: 22px;
}

.tab span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab[aria-current="page"] {
  background: var(--grad-primary);
  color: var(--on-accent);
}

.tabbar .menu {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
}

.tabbar .menu > summary {
  flex: 1;
}

.tabbar .menu-panel {
  top: auto;
  bottom: calc(100% + 14px);
  animation-name: rise;
}

.page {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 16px;
  scroll-margin-top: 112px;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

.page-head {
  margin-bottom: 24px;
}

.page-head p {
  margin-top: 8px;
  color: var(--muted);
}

.footer {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 16px 112px;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.footer-top {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.footer .brand {
  min-height: 0;
  font-size: 18px;
}

.footer .logo {
  width: 26px;
  height: 26px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  font-weight: 500;
}

.footer-links a {
  color: var(--ink-soft);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent-strong);
}

.footer small {
  color: var(--muted);
  font-size: 12px;
}

/* a signed-in phone bar has three round buttons, so the name gives way to them */
@media (max-width: 479px) {
  .topbar {
    gap: 8px;
    padding-left: 10px;
  }

  .topbar-user .brand-name {
    display: none;
  }

  .tools {
    gap: 6px;
  }
}

@media (min-width: 640px) {
  .topbar-wrap {
    padding: 24px 32px 0;
  }

  .page {
    padding: 40px 32px;
  }

  .footer {
    padding-left: 32px;
    padding-right: 32px;
  }

  .footer-top {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

@media (min-width: 1100px) {
  .mainnav {
    display: flex;
  }

  .tabbar {
    display: none;
  }

  .footer {
    padding-bottom: 32px;
  }
}

/* ---------- components ---------- */

.card {
  padding: 20px;
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

@media (min-width: 640px) {
  .card {
    padding: 26px;
  }
}

.card-highlight {
  border: 0;
  background: var(--grad-highlight);
}

.card-reflection {
  border: 0;
  background: var(--grad-reflection);
  box-shadow: none;
}

.grid {
  display: grid;
  gap: 16px;
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--grad-primary);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 8px 20px rgb(91 85 214 / 0.28);
  transition:
    transform 0.2s,
    box-shadow 0.2s,
    opacity 0.2s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgb(91 85 214 / 0.34);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  border-color: var(--line);
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: none;
}

.btn-ghost {
  background: none;
  color: var(--accent-strong);
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--accent-soft);
  box-shadow: none;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.btn-mint {
  background: var(--grad-mint);
  color: var(--ink);
  box-shadow: none;
}

.btn-small {
  min-height: 40px;
  padding: 0 16px;
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  background: var(--surface-solid);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

textarea.input {
  min-height: 160px;
  resize: vertical;
}

.input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.field-error {
  font-size: 13px;
  font-weight: 500;
  color: var(--danger);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

/* set --emo on the element (see emotions.js) to tint a chip or a tile */
.chip-emotion {
  background: color-mix(in srgb, var(--emo, var(--accent)) 30%, var(--surface-solid));
}

button.chip {
  cursor: pointer;
}

button.chip[aria-pressed="true"] {
  background: var(--grad-primary);
  color: var(--on-accent);
}

/* states: loading, empty, error */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 20px;
  text-align: center;
}

.state p {
  max-width: 44ch;
  color: var(--muted);
}

.state-error {
  border-radius: var(--radius-card);
  background: var(--danger-soft);
}

.state-error h3,
.state-error p {
  color: var(--danger);
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--grad-logo);
  animation: pulse 3.2s ease-in-out infinite;
}

.skeleton {
  min-height: 16px;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--well) 25%, var(--accent-soft) 50%, var(--well) 75%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton-card {
  min-height: 120px;
  border-radius: var(--radius-card);
}

/* toasts */

.toasts {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 92px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  padding: 12px 12px 12px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-lift);
  font-size: 14px;
  font-weight: 500;
  pointer-events: auto;
  animation: rise 0.3s ease-out backwards;
}

.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast-success {
  border-color: var(--success);
}

.toast button {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--well);
  cursor: pointer;
}

@media (min-width: 1100px) {
  .toasts {
    left: auto;
    right: 32px;
    bottom: 32px;
    align-items: flex-end;
  }
}

/* crisis support card */

.crisis {
  border: 0;
  background: var(--grad-highlight);
}

.crisis-lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.crisis-lines a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--surface-solid);
  color: var(--ink);
  text-decoration: none;
}

.crisis-lines strong {
  flex: none;
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--accent-strong);
}

/* ---------- motion ---------- */

@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(9vmax, 6vmax, 0) scale(1.18);
  }
  100% {
    transform: translate3d(-5vmax, 11vmax, 0) scale(0.92);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.82);
  }
  70% {
    transform: scale(1.04);
  }
}

@keyframes bob {
  50% {
    transform: translateY(-3px);
  }
}

@keyframes spin-slow {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(0.85);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes sheen {
  to {
    background-position: -200% 0;
  }
}

.animate-rise {
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

.animate-drop {
  animation: drop 0.35s ease-out backwards;
}

.animate-pop {
  animation: pop 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) backwards;
}

.animate-bob {
  display: inline-block;
  animation: bob 3.6s ease-in-out infinite;
}

.text-sheen {
  color: transparent;
  background: linear-gradient(100deg, var(--ink) 0%, var(--accent) 30%, var(--accent-strong) 50%, var(--ink) 70%, var(--ink) 100%)
    0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: sheen 9s linear infinite;
}

.hover-lift {
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease;
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lift);
}

@supports (animation-timeline: view()) {
  .reveal {
    animation: rise linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 45%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .text-sheen {
    color: var(--ink);
    background: none;
  }
}
