/* Togetherly: shared tokens, avatars, and phone screens.
   Look: a warm "party at night" palette. Deep plum background, eight candy-bright
   player colors, chunky press-down buttons, and blob characters that blink and wobble. */

:root {
  --night: #160f2e;
  --night-2: #221747;
  --night-3: #2e2160;
  --ink: #fff6ea;
  --ink-dark: #1b1430;
  --muted: #b9addb;
  --line: rgb(255 255 255 / 0.14);
  --panel: rgb(255 255 255 / 0.06);

  --coral: #ff6b5b;
  --sun: #ffc93c;
  --mint: #3ddc97;
  --sky: #4cb4ff;
  --grape: #a77bff;
  --pink: #ff7eb6;
  --tangerine: #ff9f43;
  --lime: #b5e55c;

  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(60rem 40rem at 110% -10%, rgb(255 107 91 / 0.22), transparent 60%),
    radial-gradient(50rem 40rem at -20% 110%, rgb(76 180 255 / 0.18), transparent 60%),
    var(--night);
  background-attachment: fixed;
  color: var(--ink);
  font: 500 1.0625rem/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, .display { font-family: var(--display); font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; margin: 0; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; color: inherit; }
.brand .logo { width: 2.25rem; height: auto; }
.wordmark { font: 800 1.5rem/1 var(--display); letter-spacing: -0.03em; }

/* ---------- Phone shell ---------- */
.phone {
  width: 100%;
  max-width: 30rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  display: flex;
  flex-direction: column;
}
.phone > header { display: flex; align-items: center; justify-content: space-between; padding: 0.25rem 0 1.25rem; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.screen { display: flex; flex-direction: column; gap: 1rem; animation: screen-in 0.45s var(--spring) both; }
.title { font-size: clamp(2.2rem, 10vw, 2.9rem); }
.lede { color: var(--muted); margin: -0.25rem 0 0.25rem; }
.muted { color: var(--muted); }

.card {
  background: linear-gradient(180deg, rgb(255 255 255 / 0.08), rgb(255 255 255 / 0.04));
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field > span { font-weight: 700; font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.input {
  width: 100%;
  font: 600 1.2rem var(--body);
  color: var(--ink);
  background: rgb(0 0 0 / 0.22);
  border: 2px solid var(--line);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.input::placeholder { color: rgb(255 255 255 / 0.32); }
.input:focus { border-color: var(--sun); background: rgb(0 0 0 / 0.3); }
.code-input {
  font: 800 2.6rem/1 var(--display);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.45em;
  padding: 0.9rem 0 0.9rem 0.45em; /* balance the trailing letter-spacing */
}
.code-input::placeholder { letter-spacing: 0.45em; }

.form-error { margin: -0.25rem 0 0; min-height: 1.4em; color: var(--coral); font-weight: 700; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 1.1rem;
  padding: 1.05rem 1.25rem;
  font: 800 1.3rem/1 var(--display);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--sun); color: #2b1b00; box-shadow: 0 6px 0 #c48a00, 0 12px 24px rgb(0 0 0 / 0.3); }
.btn-primary:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 #c48a00, 0 4px 10px rgb(0 0 0 / 0.3); }
.btn-secondary { background: var(--sky); color: #04213a; box-shadow: 0 6px 0 #1f7fc4; }
.btn-secondary:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 #1f7fc4; }
.btn-ghost { background: transparent; color: var(--muted); border: 2px solid var(--line); font-size: 1.05rem; padding: 0.85rem 1rem; }
.btn:disabled { background: #3a3157; color: rgb(255 255 255 / 0.4); box-shadow: 0 6px 0 #251d3d; cursor: not-allowed; }
.btn:focus-visible, .input:focus-visible, a:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }

.link { color: var(--muted); text-align: center; text-decoration: none; padding: 0.75rem; }
.link b { color: var(--ink); text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 4px; }

.banner {
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  background: rgb(255 201 60 / 0.12);
  border: 1px solid rgb(255 201 60 / 0.35);
  font-weight: 600;
}
.status-dot { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.status-dot::before { content: ''; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgb(61 220 151 / 0.2); }
.status-dot.offline::before { background: var(--coral); box-shadow: 0 0 0 4px rgb(255 107 91 / 0.2); animation: pulse 1s infinite alternate; }

/* ---------- Avatars ---------- */
.avatar {
  --size: 3.5rem;
  --c: var(--coral);
  --shape: 52% 48% 46% 54% / 56% 50% 50% 44%;
  --shape-2: 46% 54% 52% 48% / 50% 58% 42% 50%;
  --delay: 0s;
  position: relative;
  flex: none;
  width: var(--size);
  height: var(--size);
  background: radial-gradient(circle at 32% 28%, rgb(255 255 255 / 0.35), transparent 42%), var(--c);
  border-radius: var(--shape);
  box-shadow: inset 0 calc(var(--size) * -0.09) 0 rgb(0 0 0 / 0.16), 0 calc(var(--size) * 0.07) 0 rgb(0 0 0 / 0.28);
  animation: wobble 5.5s ease-in-out var(--delay) infinite alternate;
}
.avatar .face { position: absolute; inset: 0; }
.avatar .eye {
  position: absolute;
  top: 36%;
  width: 15%;
  height: 21%;
  background: var(--ink-dark);
  border-radius: 50%;
  animation: blink 4.8s var(--delay) infinite;
}
.avatar .eye:first-child { left: 30%; }
.avatar .eye:nth-child(2) { right: 30%; }
.avatar .eye::after { content: ''; position: absolute; top: 18%; left: 22%; width: 38%; height: 30%; border-radius: 50%; background: #fff; }
.avatar .mouth {
  position: absolute;
  top: 60%;
  left: 50%;
  width: 24%;
  height: 12%;
  transform: translateX(-50%);
  border-bottom: max(2px, calc(var(--size) * 0.05)) solid var(--ink-dark);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.avatar-sm { --size: 2.4rem; }
.avatar-xl { --size: 8.5rem; }

[data-color='coral'] { --c: var(--coral); --delay: 0s; }
[data-color='sun'] { --c: var(--sun); --delay: -1.3s; --shape: 48% 52% 55% 45% / 52% 46% 54% 48%; --shape-2: 55% 45% 47% 53% / 46% 54% 48% 52%; }
[data-color='mint'] { --c: var(--mint); --delay: -2.1s; --shape: 56% 44% 50% 50% / 48% 56% 44% 52%; --shape-2: 47% 53% 44% 56% / 55% 47% 53% 45%; }
[data-color='sky'] { --c: var(--sky); --delay: -3.4s; --shape: 45% 55% 52% 48% / 58% 44% 56% 42%; --shape-2: 53% 47% 46% 54% / 47% 55% 45% 53%; }
[data-color='grape'] { --c: var(--grape); --delay: -0.7s; --shape: 50% 50% 44% 56% / 54% 48% 52% 46%; --shape-2: 56% 44% 53% 47% / 46% 52% 48% 54%; }
[data-color='pink'] { --c: var(--pink); --delay: -2.8s; --shape: 53% 47% 49% 51% / 45% 55% 45% 55%; --shape-2: 46% 54% 55% 45% / 55% 47% 53% 47%; }
[data-color='tangerine'] { --c: var(--tangerine); --delay: -4.2s; --shape: 47% 53% 56% 44% / 52% 52% 48% 48%; --shape-2: 54% 46% 45% 55% / 48% 56% 44% 52%; }
[data-color='lime'] { --c: var(--lime); --delay: -1.9s; --shape: 55% 45% 47% 53% / 50% 45% 55% 50%; --shape-2: 45% 55% 54% 46% / 56% 50% 50% 44%; }

/* ---------- Roster (phone) ---------- */
.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.roster-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: opacity 0.3s, filter 0.3s;
}
.roster-item.enter { animation: pop-in 0.5s var(--spring) both; }
.roster-item.away { opacity: 0.55; filter: saturate(0.3); }
.roster-item.exit { animation: roster-out 0.35s ease-in both; pointer-events: none; overflow: hidden; }
@keyframes roster-out {
  from { max-height: 4.5rem; }
  to { max-height: 0; opacity: 0; transform: scale(0.92); padding-block: 0; margin-top: -0.5rem; border-width: 0; }
}
.roster-name { font-weight: 700; font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-tags { display: flex; gap: 0.35rem; }
.tag { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; padding: 0.2rem 0.5rem; border-radius: 999px; background: rgb(255 255 255 / 0.1); color: var(--muted); }
.tag-host { background: var(--sun); color: #2b1b00; }
.tag-away { background: rgb(255 107 91 / 0.18); color: var(--coral); }
.section-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0.5rem 0 -0.25rem; }

/* ---------- "You're in" hero ---------- */
.me { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.75rem; padding: 0.5rem 0 0.5rem; }
.me .avatar { animation: wobble 5.5s ease-in-out var(--delay) infinite alternate, bob 2.4s ease-in-out infinite; }
.me h1 { font-size: clamp(2.4rem, 11vw, 3.2rem); overflow-wrap: anywhere; }
.code-chip { font: 800 1.1rem var(--display); letter-spacing: 0.2em; padding: 0.2rem 0.6rem; border-radius: 0.6rem; background: rgb(255 255 255 / 0.1); }

/* Celebration and end screens sit in the middle of the phone */
#starting, #ended { margin-block: auto; align-items: center; text-align: center; }
.party { display: flex; justify-content: center; gap: 0.5rem; flex-wrap: wrap; }
.party .avatar { animation: hop 0.9s ease-in-out infinite alternate; }
.party .avatar:nth-child(2n) { animation-delay: 0.3s; }
.party .avatar:nth-child(3n) { animation-delay: 0.55s; }

/* ---------- Motion ---------- */
@keyframes screen-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.6); } }
@keyframes wobble { to { border-radius: var(--shape-2); } }
@keyframes blink { 0%, 90%, 100% { transform: scaleY(1); } 94% { transform: scaleY(0.1); } }
@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes hop { to { transform: translateY(-14px) rotate(-4deg); } }
@keyframes pulse { to { opacity: 0.4; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.shake { animation: shake 0.4s ease-in-out; }

@media (prefers-reduced-motion: reduce) {
  .phone *, .phone *::before, .phone *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Dialog (confirmDialog in ui.js) ---------- */
.btn-danger { background: var(--coral); color: #2e0703; box-shadow: 0 6px 0 #c43f31, 0 12px 24px rgb(0 0 0 / 0.3); }
.btn-danger:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 #c43f31, 0 4px 10px rgb(0 0 0 / 0.3); }
.dialog {
  width: min(100% - 2rem, 24rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
  animation: dialog-in 0.4s var(--spring) both;
}
.dialog::backdrop { background: rgb(10 6 30 / 0.72); backdrop-filter: blur(4px); animation: backdrop-in 0.25s ease-out both; }
.dialog.closing { animation: dialog-out 0.18s ease-in both; }
.dialog.closing::backdrop { animation: backdrop-out 0.18s ease-in both; }
.dialog-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.6rem 1.25rem 1.25rem;
  text-align: center;
  border-radius: 1.75rem;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--night-3), var(--night-2));
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.5);
}
.dialog-card .avatar { --size: 4rem; margin-top: -3.4rem; margin-bottom: 0.25rem; }
.dialog-title { font-size: 1.85rem; }
.dialog-body { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; flex-direction: column; gap: 0.75rem; align-self: stretch; margin-top: 0.5rem; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(24px) scale(0.9); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(12px) scale(0.95); } }
@keyframes backdrop-in { from { opacity: 0; } }
@keyframes backdrop-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .dialog, .dialog::backdrop, .dialog * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
