/*
 * Theme. Every page takes its colours, corners and fonts from these tokens,
 * so the site's look can be changed here in one place. The site's name is in
 * src/site.ts.
 */
:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1c1a2e;
  --muted: #5f5b70;
  --border: #e7e3ee;
  /* The brand colour: buttons, links, focus rings. */
  --accent: #5a3fe0;
  --accent-hover: #4a30cc;
  --accent-ink: #ffffff;
  --accent-soft: #eeeaff;
  /* Party colours, shared with the name wheel's slices. */
  --c1: #ef476f;
  --c2: #f78c6b;
  --c3: #ffd166;
  --c4: #06d6a0;
  --c5: #118ab2;
  --c6: #8e7dff;
  --radius: 16px;
  --radius-small: 10px;
  --shadow: 0 1px 2px #1c1a2e0f, 0 8px 24px #1c1a2e0f;
  --shadow-lift: 0 2px 4px #1c1a2e14, 0 16px 40px #5a3fe024;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --page-width: 1120px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121c;
    --surface: #1f1c2a;
    --text: #f2f0f8;
    --muted: #a9a4ba;
    --border: #343046;
    --accent: #a693ff;
    --accent-hover: #bcadff;
    --accent-ink: #14121c;
    --accent-soft: #2b2545;
    --shadow: 0 1px 2px #0000004d;
    --shadow-lift: 0 12px 32px #00000066;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  font-family: var(--font);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3 {
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

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

main {
  flex: 1;
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* Header and footer, the same on every page */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner,
.site-footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 10px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}

/* A little wheel in the party colours. */
.brand-mark {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--surface) 0 18%, transparent 19%),
    conic-gradient(var(--c1) 0 60deg, var(--c2) 0 120deg, var(--c3) 0 180deg, var(--c4) 0 240deg, var(--c5) 0 300deg, var(--c6) 0);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border);
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

a.brand:hover .brand-mark {
  transform: rotate(120deg);
}

.brand-small {
  font-size: 1rem;
  min-height: 0;
}

.brand-small .brand-mark {
  width: 22px;
  height: 22px;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer-inner {
  padding-top: 20px;
  padding-bottom: 20px;
}

.site-footer p {
  margin: 0;
}

/* Buttons */

.button,
button.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 22px;
  border: 2px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.button-primary,
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.button-primary:hover,
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button:active,
button.primary:active:not(:disabled) {
  transform: scale(0.97);
}

.button-ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-ghost:hover {
  border-color: var(--accent);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Home page */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  margin: 8px 0 8px;
  padding: 28px 20px;
  border-radius: calc(var(--radius) + 8px);
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--c3) 35%, transparent), transparent 45%),
    radial-gradient(circle at 0% 100%, color-mix(in srgb, var(--c1) 18%, transparent), transparent 50%),
    var(--accent-soft);
  overflow: hidden;
}

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 5.5vw, 3.25rem);
}

.eyebrow {
  display: inline-block;
  margin: 0 0 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

.hero-lede {
  max-width: 36rem;
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 1.1rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0;
}

.hero-art {
  position: relative;
  width: min(55vw, 200px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.hero-wheel {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--surface) 0 10%, transparent 10.5%),
    repeating-conic-gradient(from 15deg, var(--c1) 0 45deg, var(--c2) 0 90deg, var(--c3) 0 135deg, var(--c4) 0 180deg);
  box-shadow: 0 0 0 6px var(--surface), var(--shadow-lift);
  animation: hero-spin 24s linear infinite;
}

.hero-pointer {
  position: absolute;
  top: 2%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid var(--text);
}

.dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  transform: rotate(20deg);
}

.dot-1 { top: 6%; left: 2%; background: var(--c5); }
.dot-2 { top: 20%; right: 0; background: var(--c1); transform: rotate(-30deg); }
.dot-3 { bottom: 4%; left: 12%; background: var(--c4); width: 10px; height: 10px; }
.dot-4 { bottom: 12%; right: 4%; background: var(--c6); }
.dot-5 { top: 48%; left: -2%; background: var(--c3); width: 10px; }

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

@media (prefers-reduced-motion: reduce) {
  .hero-wheel {
    animation: none;
  }
}

@media (min-width: 760px) {
  .hero {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 40px;
    padding: 48px;
  }

  .hero-art {
    width: min(100%, 320px);
  }
}

.section {
  margin-top: 40px;
}

.section h2 {
  margin: 0 0 16px;
  font-size: 1.5rem;
}

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

a.card:hover,
a.card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow-lift);
  transform: translateY(-3px);
}

.card-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 6px;
  border-radius: var(--radius-small);
  background: var(--accent-soft);
  font-size: 1.9rem;
}

.tile-1 { background: color-mix(in srgb, var(--c6) 22%, var(--surface)); }
.tile-2 { background: color-mix(in srgb, var(--c4) 22%, var(--surface)); }
.tile-3 { background: color-mix(in srgb, var(--c2) 25%, var(--surface)); }
.tile-4 { background: color-mix(in srgb, var(--c5) 22%, var(--surface)); }
.tile-5 { background: color-mix(in srgb, var(--c3) 35%, var(--surface)); }
.tile-6 { background: color-mix(in srgb, var(--c1) 22%, var(--surface)); }

.card-name {
  font-weight: 700;
  font-size: 1.2rem;
}

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

.card-go {
  margin-top: auto;
  padding-top: 8px;
  color: var(--accent);
  font-weight: 700;
}

.card-soon {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

.card-soon .card-icon {
  background: transparent;
  border: 1px dashed var(--border);
}

.perks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 16px;
}

.perk {
  padding: 4px 0;
}

.perk-icon {
  font-size: 1.6rem;
}

.perk h3 {
  margin: 6px 0 4px;
  font-size: 1.1rem;
}

.perk p {
  margin: 0;
  color: var(--muted);
}

/* Shared bits for tool pages */

.tool-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 320px;
  font-weight: 600;
}

.tool-form input,
.tool-form textarea,
.tool-form button {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.tool-form input:focus,
.tool-form textarea:focus,
.tool-form select:focus {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
  outline-offset: 0;
}

.tool-form button:not(.primary) {
  font-weight: 600;
  border-radius: 999px;
  padding-inline: 16px;
  cursor: pointer;
}

.tool-form button:not(.primary):hover {
  border-color: var(--accent);
}

.result {
  font-size: 1.5rem;
  font-weight: 600;
  min-height: 2.25rem;
}

/* Shared bits for tool pages */

.tool-form select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.tool-form .check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

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

.error {
  color: #c62828;
  font-weight: 600;
}

/* Name wheel */

/* The wheel page can use more of a wide screen than other pages. */
body:has(.wheel-page) {
  --page-width: 1280px;
}

main:has(.wheel-page) h1 {
  margin: 8px 0;
}

.wheel-intro {
  margin-top: 0;
}

.wheel-page {
  --wheel-size: min(100%, max(280px, calc(100svh - 330px)));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  /* Confetti can fly past the sides without making the page scroll sideways. */
  overflow-x: clip;
  overflow-clip-margin: 16px;
}

/* Side by side when there's room across, as on a laptop or a tablet held sideways. */
@media (min-width: 900px) and (orientation: landscape) {
  .wheel-page:not(.wheel-only) {
    --wheel-size: min(100%, max(320px, calc(100svh - 290px)));
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
  }
}

.wheel-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wheel-wrap {
  position: relative;
  width: var(--wheel-size);
  margin: 0 auto;
}

.wheel {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 30px solid var(--text);
  z-index: 1;
}

button.spin-button {
  min-width: min(100%, 240px);
  min-height: 52px;
  font-size: 1.2rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The winner pops up in the middle of the wheel. Tap it to put it away. */
.winner-pop {
  position: absolute;
  /* Centred over the wheel, as wide as the name needs, up to most of the wheel. */
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: fit-content;
  min-width: 45%;
  max-width: 92%;
  height: fit-content;
  margin: auto;
  padding: 14px 26px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: clamp(1rem, 2.5vmin, 1.4rem);
  box-shadow: 0 10px 40px #0000004d;
  cursor: pointer;
}

.winner-pop[hidden] {
  display: none;
}

.winner-name {
  max-width: 100%;
  /* Long names shrink to fit (see client.ts) rather than break mid-word. */
  overflow-wrap: normal;
  font-size: clamp(1.8rem, 6vmin, 3.2rem);
  line-height: 1.1;
  text-align: center;
}

.winner-party {
  font-size: 1.6em;
  line-height: 1;
}

.winner-pop.pop {
  animation: winner-pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.winner-pop.pop .winner-party {
  animation: winner-wiggle 0.9s ease-in-out 0.3s 2;
}

@keyframes winner-pop {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes winner-wiggle {
  25% { transform: rotate(-15deg) scale(1.2); }
  75% { transform: rotate(15deg) scale(1.2); }
}

.confetti {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.confetti span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-burst 1.8s cubic-bezier(0.1, 0.8, 0.3, 1) var(--delay, 0ms) forwards;
}

@keyframes confetti-burst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 80px)) rotate(var(--spin));
  }
}

@media (prefers-reduced-motion: reduce) {
  .winner-pop.pop,
  .winner-pop.pop .winner-party {
    animation: none;
  }
}

.wheel-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.wheel-only .wheel-side {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.wheel-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wheel-controls label {
  max-width: none;
}

.wheel-controls textarea {
  min-height: 12rem;
  resize: vertical;
}

@media (min-width: 700px) {
  .wheel-controls textarea {
    min-height: 18rem;
  }
}

/* Big enough to tap with a finger. */
.wheel-page .tool-form .check {
  min-height: 44px;
}

.wheel-page .tool-form .check input {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

/* "Add You again, Delegate and Spin again", under the Spin button. */
.bonus-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--muted);
  cursor: pointer;
}

.bonus-option input {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.wheel-page .tool-form input,
.wheel-page .tool-form button {
  min-height: 44px;
}

.names-editor summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}

.wheel-only .names-editor summary {
  display: flex;
  width: fit-content;
  margin: 0 auto;
}

.names-editor[open] summary {
  margin-bottom: 12px;
}

.saved-wheels {
  margin-top: 0;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.saved-wheels h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.save-wheel label {
  flex: 1 1 200px;
}

.saved-status {
  min-height: 1.5em;
  margin: 8px 0;
}

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.saved-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.saved-list .saved-title {
  flex: 1 1 160px;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.saved-list .saved-title[aria-current="page"] {
  color: var(--text);
  text-decoration: none;
}

.saved-list .saved-title[aria-current="page"]::after {
  content: " (this one)";
  color: var(--muted);
  font-weight: 400;
}

.saved-wheels h2 + .saved-list,
.saved-wheels h2:not(:first-child) {
  margin-top: 12px;
}

.saved-list .saved-count {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}


.saved-wheels h2 .saved-count {
  color: var(--muted);
  font-weight: 400;
}

.tool-form textarea[readonly] {
  background: transparent;
}

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

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

/* Accounts: header links, sign-in forms and the account page */

.account-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-nav a {
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.button-link {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink) !important;
}

.account-box {
  max-width: 420px;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.account-form label {
  max-width: none;
}

.account-form .primary {
  align-self: flex-start;
}

.hint {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--muted);
}

.notice {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.notice-error {
  border-color: var(--accent);
}

.account-details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
}

.account-details dt {
  font-weight: 600;
}

.account-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}
