@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/montserrat-latin.woff2') format('woff2');
}

/* Design tokens (Figma "Colormood" UI Kit) */
:root {
  --black: #363853;
  --grey-dark: #7c7c9f;
  --grey-light: #e3e9f8;
  --divider: #e6eaf0;
  --white: #ffffff;
  --font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-pad: max(var(--safe-bottom), 10px);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--white);
  font-family: var(--font);
  color: var(--black);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--white);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* On desktop/tablet browsers, present the app in a phone-sized frame. */
@media (min-width: 640px) and (min-height: 600px) {
  body { background: var(--grey-light); }
  .app {
    inset: auto;
    top: 50%;
    left: 50%;
    width: 390px;
    height: min(844px, calc(100vh - 48px));
    transform: translate(-50%, -50%);
    border-radius: 32px;
    box-shadow: 0 0 0 10px var(--white), 0 24px 60px rgba(54, 56, 83, 0.18);
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  animation: screen-in 0.45s var(--ease);
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 1. Get started ---------- */

.start {
  background: var(--black);
  color: var(--white);
  padding-top: var(--safe-top);
}

.start__strip {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 20px;
  display: flex;
  flex-direction: column;
}

.start__strip span {
  flex: 1;
  transition: background-color 0.9s ease;
}

.start__art {
  flex: none;
  display: flex;
  justify-content: center;
  padding-left: 20px;
  margin-top: clamp(16px, 4vh, 31px);
}

.orbit {
  position: relative;
  width: 291px;
  height: 291px;
  flex: none;
}

.orbit__bg {
  display: block;
  width: 291px;
  height: 291px;
}

.orbit__emoji {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  transition: transform 0.6s var(--ease);
}

.orbit__emoji img {
  position: absolute;
  inset: 0;
  width: 40px;
  height: 40px;
  transition: opacity 0.6s ease;
}

.orbit__emoji .on { opacity: 0; }
.orbit__emoji.is-on .on { opacity: 1; }
.orbit__emoji.is-on .dark { opacity: 0; }
.orbit__emoji.is-on { transform: translate(var(--x), var(--y)) scale(1.08); }
.orbit__emoji { transform: translate(var(--x), var(--y)); }

.start__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px 0 calc(46px + var(--safe-bottom)) 20px;
  align-items: center;
}

.start__txt {
  width: 276px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: clamp(32px, 10vh, 80px);
}

.start__eyebrow {
  margin: 0;
  font-size: 26px;
  line-height: 32px;
  font-weight: 400;
  color: var(--grey-dark);
}

.start__title {
  margin: 0;
  font-size: 44px;
  line-height: 60px;
  font-weight: 700;
}

.start__lead {
  margin: 0;
  font-size: 18px;
  line-height: 24px;
}

.pill-btn {
  width: 276px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 32px;
  border-radius: 52px;
  background: var(--white);
  color: var(--black);
  font-size: 18px;
  line-height: 24px;
  transition: transform 0.15s ease;
}

.pill-btn img {
  width: 24.5px;
  height: 11.5px;
  margin: -0.75px;
  transition: transform 0.3s var(--ease);
}

.pill-btn:active { transform: scale(0.97); }
.pill-btn:hover img { transform: translateX(4px); }

/* ---------- 2. Palette ---------- */

.main {
  background: var(--white);
  padding-top: var(--safe-top);
}

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  border-top: 1px solid var(--divider);
}

.swatches {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
}

.swatches li {
  flex: 1 0 0;
  min-height: 0;
  display: flex;
}

.swatch {
  position: relative;
  flex: 1;
  color: var(--white);
  transition: background-color 0.2s ease;
}

.swatch.is-light { color: var(--black); }

.swatch__hex {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-size: 16px;
  line-height: 20px;
  white-space: nowrap;
  letter-spacing: 0;
}

.swatch__icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
}

.swatch__icon img {
  position: absolute;
  inset: 0;
  width: 24px;
  height: 24px;
}

.swatch__icon .dark { display: none; opacity: 0.8; }
.swatch.is-light .swatch__icon .dark { display: block; }
.swatch.is-light .swatch__icon .light { display: none; }

.swatch.is-spinning .swatch__icon { animation: spin 0.5s var(--ease); }

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

/* ---------- 3. Mood settings drawer ---------- */

.drawer {
  --closed: calc(100% - 12px);
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: calc(100% - 64px);
  background: var(--white);
  transform: translateX(var(--closed));
  transition: transform 0.4s var(--ease);
  z-index: 2;
  touch-action: pan-y;
}

.drawer.is-open { transform: translateX(0); }
.drawer.is-dragging { transition: none; }

.drawer__handle-img {
  position: absolute;
  left: -15px;
  top: 50%;
  width: 34px;
  height: 812px;
  margin-top: -406px;
  pointer-events: none;
  z-index: 1;
}

.drawer__handle {
  position: absolute;
  left: -26px;
  top: 50%;
  width: 52px;
  height: 96px;
  margin-top: -48px;
  z-index: 2;
  touch-action: none;
}

.drawer__scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 32px 32px 32px 32px;
}

.drawer__list {
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.group {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.group__title {
  margin: 0;
  max-width: 248px;
  font-size: 26px;
  line-height: 32px;
  font-weight: 400;
}

.moods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
}

.mood {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 4px 12px;
  background-color: var(--grey-light);
  /* white "nodes" where the grid lines cross */
  background-image:
    radial-gradient(circle at 0.5px 0.5px, var(--white) 4.5px, transparent 5px),
    radial-gradient(circle at calc(100% - 0.5px) 0.5px, var(--white) 4.5px, transparent 5px),
    radial-gradient(circle at 0.5px calc(100% - 0.5px), var(--white) 4.5px, transparent 5px),
    radial-gradient(circle at calc(100% - 0.5px) calc(100% - 0.5px), var(--white) 4.5px, transparent 5px);
  font-size: 12px;
  line-height: 16px;
  transition: transform 0.15s ease;
}

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

.mood__emoji {
  position: relative;
  width: 40px;
  height: 40px;
}

.mood__emoji img {
  position: absolute;
  inset: 0;
  width: 40px;
  height: 40px;
  transition: opacity 0.25s ease, transform 0.35s var(--ease);
}

.mood__emoji .on { opacity: 0; }
.mood[aria-checked='true'] .mood__emoji .on { opacity: 1; transform: scale(1.06); }
.mood[aria-checked='true'] .mood__emoji .light { opacity: 0; }

.tone {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 248px;
}

.tone__slider {
  position: relative;
  height: 16px;
}

.tone__track {
  position: absolute;
  inset: 0;
  border: 4px solid var(--grey-light);
  border-radius: 32px;
  overflow: hidden;
}

.tone__track img {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.tone__range {
  position: absolute;
  left: 0;
  right: 0;
  top: -4px;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: none;
}

.tone__range::-webkit-slider-runnable-track { height: 24px; background: transparent; }
.tone__range::-moz-range-track { height: 24px; background: transparent; }

.tone__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--thumb, #fad601) 0 4px, var(--white) 4.5px 8px, var(--grey-light) 8.5px 11.3px, var(--divider) 11.5px 12px);
}

.tone__range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--thumb, #fad601) 0 4px, var(--white) 4.5px 8px, var(--grey-light) 8.5px 11.3px, var(--divider) 11.5px 12px);
}

.tone__range:focus-visible { outline-offset: 4px; border-radius: 12px; }

.tone__hint {
  margin: 0;
  font-size: 12px;
  line-height: 16px;
}

/* ---------- Toolbar ---------- */

.toolbar {
  position: relative;
  z-index: 3;
  flex: none;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 60px;
  height: calc(44px + var(--bar-pad));
  padding-bottom: var(--bar-pad);
  background: var(--white);
  border-top: 1px solid var(--divider);
}

.toolbar__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  line-height: 24px;
  padding: 8px 4px 0;
  transition: opacity 0.15s ease;
}

.toolbar__btn img { width: 24px; height: 24px; }
.toolbar__btn:active { opacity: 0.6; }
.toolbar__btn.is-spinning img { animation: spin 0.5s var(--ease); }

/* ---------- 4. Export action sheet ---------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgba(54, 56, 83, 0.32);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 24px 32px calc(var(--bar-pad) + 14px);
  background: var(--white);
  border-radius: 40px 40px 0 0;
  transform: translateY(100%);
  transition: transform 0.35s var(--ease);
}

.is-sheet-open .sheet { transform: translateY(0); }
.is-sheet-open .sheet-backdrop { opacity: 1; }

.sheet__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 20px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 16px;
  line-height: 20px;
  text-align: left;
}

.sheet__item img { width: 24px; height: 24px; flex: none; }
.sheet__item span { flex: 1; }
.sheet__item:active span { opacity: 0.6; }
.sheet__item--cancel { border-bottom: 0; text-align: center; }

/* ---------- Toast ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(44px + var(--bar-pad) + 20px);
  z-index: 20;
  max-width: calc(100% - 48px);
  padding: 10px 18px;
  border-radius: 20px;
  background: var(--black);
  color: var(--white);
  font-size: 14px;
  line-height: 20px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
  pointer-events: none;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
