:root {
  --bg: #fff4ea;
  --card: #ffffff;
  --ink: #3d3553;
  --muted: #8a809c;
  --line: #eadfd6;
  --peach: #ffb4a2;
  --peach-ink: #b34a33;
  --mint: #bfe6d6;
  --mint-ink: #2f7a5f;
  --lilac: #d9c8f0;
  --lilac-ink: #6a4c9c;
  --butter: #ffe39b;
  --sky: #c4e3ff;
  --shadow: 0 6px 0 rgba(61, 53, 83, .08), 0 14px 30px rgba(61, 53, 83, .08);
  --radius: 22px;
  --tile: min(3.1rem, calc((100vw - 7.5rem) / var(--n, 5)));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #221d2e;
    --card: #2e2740;
    --ink: #f4eefc;
    --muted: #ab9fc2;
    --line: #443a5a;
    --peach: #e98d78;
    --peach-ink: #ffd5ca;
    --mint: #3f7d68;
    --mint-ink: #c8f3e2;
    --lilac: #6b56a0;
    --lilac-ink: #ece2ff;
    --butter: #b69540;
    --sky: #3b5e85;
    --shadow: 0 6px 0 rgba(0, 0, 0, .25), 0 14px 30px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--peach) 35%, transparent) 0 18rem, transparent 18rem),
    radial-gradient(circle at 100% 30%, color-mix(in srgb, var(--lilac) 35%, transparent) 0 14rem, transparent 14rem),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .tile, button, .pill { font-family: "Fredoka", "Nunito", sans-serif; }

.top {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.1rem 16px .4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.logo { margin: 0; display: flex; align-items: center; gap: .2rem; font-size: 1.15rem; font-family: "Fredoka", sans-serif; font-weight: 600; text-decoration: none; color: var(--ink); }
.logo .t {
  display: inline-grid; place-items: center;
  width: 1.8rem; height: 1.8rem; border-radius: 9px;
  color: var(--ink); box-shadow: 0 3px 0 rgba(61, 53, 83, .12);
}
.logo .t1 { background: var(--peach); transform: rotate(-6deg); }
.logo .t2 { background: var(--butter); transform: rotate(4deg); }
.logo .t3 { background: var(--mint); transform: rotate(-3deg); }
.logo .t4 { background: var(--lilac); transform: rotate(5deg); }
.logo-rest { margin-left: .35rem; font-weight: 600; color: var(--muted); }

.icon-btn {
  width: 2.6rem; height: 2.6rem; padding: 0; border-radius: 50%;
  background: var(--card); box-shadow: 0 3px 0 rgba(61, 53, 83, .1); font-size: 1.3rem; line-height: 1;
}
.icon-btn:active { box-shadow: 0 1px 0 rgba(61, 53, 83, .1); }

.group-bar { margin: .25rem 0 .5rem; }
.group-title { margin: 0 0 .5rem; font-size: 1.5rem; font-weight: 600; overflow-wrap: anywhere; }
.score { display: flex; gap: .4rem; flex-wrap: wrap; }
.pill.add { border: 0; cursor: pointer; color: var(--muted); background: transparent; box-shadow: inset 0 0 0 2px var(--line); padding: .3rem .7rem; }
.pill.add:active { transform: none; }

main { max-width: 34rem; margin: 0 auto; padding: .5rem 16px 4rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin: 1rem 0;
}

.card h2 { margin: 0 0 .35rem; font-size: 1.35rem; font-weight: 600; }
.sub { margin: 0 0 1rem; color: var(--muted); }
.loading { text-align: center; color: var(--muted); margin-top: 3rem; }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .3rem .7rem; border-radius: 999px;
  background: var(--card); box-shadow: 0 3px 0 rgba(61, 53, 83, .08);
  font-size: .9rem; font-weight: 500; white-space: nowrap;
}
.pill.me { background: var(--butter); }

/* ---------- buttons & inputs ---------- */

button {
  font: inherit; font-weight: 600; font-size: 1.05rem;
  border: 0; border-radius: 16px; cursor: pointer;
  padding: .8rem 1.2rem; color: var(--ink);
  background: var(--mint);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--mint) 60%, #000 20%);
  transition: transform .08s ease, box-shadow .08s ease;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--mint) 60%, #000 20%); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--peach); box-shadow: 0 4px 0 color-mix(in srgb, var(--peach) 60%, #000 22%); }
button.primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--peach) 60%, #000 22%); }
button.ghost { background: transparent; box-shadow: none; color: var(--muted); font-weight: 500; padding: .6rem .8rem; }
button.ghost:active { transform: none; }
button.wide { width: 100%; }

.who { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 1rem 0; }
.who button { padding: 1.1rem .5rem; font-size: 1.2rem; background: var(--card); border: 3px solid var(--line); box-shadow: none; }
.who button.on { border-color: var(--peach); background: color-mix(in srgb, var(--peach) 25%, var(--card)); }
.who button .emoji { display: block; font-size: 2rem; margin-bottom: .2rem; }

label { display: block; font-weight: 700; margin: .75rem 0 .35rem; }
input.text {
  width: 100%; font: inherit; font-size: 1.15rem; font-weight: 700;
  padding: .75rem 1rem; border-radius: 14px;
  border: 3px solid var(--line); background: var(--bg); color: var(--ink);
  outline: none; text-transform: lowercase; letter-spacing: .08em;
}
input.text:focus { border-color: var(--lilac); }
input.text.plain { text-transform: none; letter-spacing: normal; font-weight: 600; }

/* ---------- home, join, menu ---------- */

.hero { text-align: center; padding: 1rem .25rem .25rem; }
.hero h1 { font-size: 1.75rem; line-height: 1.2; margin: .25rem 0 1rem; font-weight: 600; }
.how { list-style: none; padding: 0; margin: 0 auto; display: grid; gap: .55rem; text-align: left; max-width: 26rem; }
.how li { display: flex; gap: .65rem; align-items: flex-start; }
.how .n {
  flex: none; width: 1.6rem; height: 1.6rem; border-radius: 8px; display: grid; place-items: center;
  font-family: "Fredoka", sans-serif; font-weight: 600; background: var(--butter);
}
.how li:nth-child(2) .n { background: var(--mint); }
.how li:nth-child(3) .n { background: var(--lilac); }

.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem; }
.av {
  aspect-ratio: 1; padding: 0; font-size: 1.6rem; border-radius: 14px;
  background: var(--bg); border: 3px solid transparent; box-shadow: none;
}
.av:active { transform: scale(.94); box-shadow: none; }
.av.on { border-color: var(--peach); background: color-mix(in srgb, var(--peach) 22%, var(--card)); }
.av:disabled { opacity: .25; }

.eyebrow { margin: 0; color: var(--muted); font-weight: 700; font-size: .9rem; }
.faces { display: flex; flex-wrap: wrap; gap: .6rem; margin: .25rem 0 1rem; }
.face { display: grid; justify-items: center; font-size: 1.8rem; line-height: 1.1; }
.face small { font-size: .75rem; color: var(--muted); font-weight: 700; font-family: "Nunito", sans-serif; }

.group-list { display: grid; gap: .4rem; }
.group-row {
  display: flex; justify-content: space-between; gap: .5rem; padding: .8rem 1rem; border-radius: 14px;
  background: var(--bg); color: var(--ink); text-decoration: none; font-weight: 700;
}
.muted { color: var(--muted); font-weight: 600; }
.center { text-align: center; }
a.button {
  display: inline-block; text-decoration: none; font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 1.05rem;
  padding: .8rem 1.2rem; border-radius: 16px; color: var(--ink); background: var(--peach);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--peach) 60%, #000 22%);
}

.invite { background: color-mix(in srgb, var(--butter) 35%, var(--card)); }
.link-box {
  padding: .75rem 1rem; border-radius: 14px; background: var(--card); border: 2px dashed var(--line);
  font-weight: 700; overflow-wrap: anywhere; margin-bottom: .75rem; text-align: center;
}

.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 34rem;
  border-radius: 24px 24px 0 0; background: var(--card); color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(30, 24, 45, .35); }
.sheet-body { padding: 1.25rem 16px calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: .35rem; }
.sheet-body h2 { margin: 0 0 .5rem; font-size: 1.25rem; font-weight: 600; outline: none; }
.menu-item {
  display: flex; gap: .8rem; align-items: center; text-align: left; width: 100%;
  background: var(--bg); box-shadow: none; padding: .8rem 1rem; font-size: 1rem;
}
.menu-item:active { transform: none; box-shadow: none; }
.menu-item small { display: block; color: var(--muted); font-family: "Nunito", sans-serif; font-weight: 600; font-size: .82rem; }
.menu-item > span:first-child { font-size: 1.35rem; }

.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: end; }
.pair .arrow { font-size: 1.5rem; padding-bottom: .7rem; color: var(--muted); }
.hint { font-size: .9rem; color: var(--muted); margin: .5rem 0 1rem; min-height: 1.3em; }
.hint.bad { color: var(--peach-ink); }
.actions { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }
.actions .grow { flex: 1; }

/* ---------- the ladder ---------- */

.challenge-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.status-line { display: flex; gap: .4rem; flex-wrap: wrap; margin: .2rem 0 1rem; }

.board { --n: 5; display: flex; flex-direction: column; align-items: center; gap: 0; }

.row { position: relative; display: flex; align-items: center; gap: .5rem; }
.row .tiles { display: flex; gap: .3rem; position: relative; }
.row .side { width: 2rem; height: 2rem; display: grid; place-items: center; flex: none; }

.tile {
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border-radius: 12px; font-size: calc(var(--tile) * .5); font-weight: 600;
  text-transform: uppercase; background: var(--card);
  border: 2.5px dashed var(--line);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.tile.filled { border-style: solid; border-color: var(--line); animation: pop .18s ease; }
.tile.changed { background: var(--butter); border-color: transparent; }
.tile.cursor { border-color: var(--lilac); border-style: solid; }
.row.start .tile { background: var(--mint); border: 0; color: var(--mint-ink); }
.row.end .tile { background: var(--lilac); border: 0; color: var(--lilac-ink); }
.row.start .tile.changed, .row.end .tile.changed { box-shadow: inset 0 0 0 3px var(--butter); }
.row.bad .tile.filled { border-color: var(--peach); }
.row.shake { animation: shake .45s ease; }
.row.focused .tiles { filter: drop-shadow(0 0 0 transparent); }

.row input.capture {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0; font-size: 16px;
  cursor: text; caret-color: transparent;
}

.remove {
  width: 2rem; height: 2rem; padding: 0; border-radius: 50%;
  background: transparent; box-shadow: none; color: var(--muted); font-size: 1.1rem;
}
.remove:active { transform: none; box-shadow: none; }

.link { height: 1.35rem; display: grid; place-items: center; color: var(--line); font-size: .85rem; line-height: 1; }
.link.ok { color: var(--mint-ink); }
.link.bad { color: var(--peach-ink); }

.tries { text-align: center; color: var(--muted); font-size: .9rem; margin-top: .6rem; }

/* ---------- results & history ---------- */

.result-grid { display: grid; gap: 1rem; }
.mini { display: flex; flex-direction: column; gap: .25rem; }
.mini .word { display: flex; gap: .15rem; }
.mini .word span {
  width: 1.55rem; height: 1.55rem; display: grid; place-items: center;
  border-radius: 7px; background: var(--bg); font-family: "Fredoka", sans-serif;
  font-weight: 600; font-size: .85rem; text-transform: uppercase;
}
.mini .word span.changed { background: var(--butter); }
.mini .word.first span { background: var(--mint); color: var(--mint-ink); }
.mini .word.last span { background: var(--lilac); color: var(--lilac-ink); }
.who-result h3 { margin: 0 0 .4rem; font-size: 1.05rem; font-weight: 600; display: flex; gap: .4rem; align-items: center; }
.who-result .meta { color: var(--muted); font-size: .9rem; margin: 0 0 .5rem; }
.ladders { display: flex; gap: 1.25rem; flex-wrap: wrap; }

.banner {
  text-align: center; padding: 1rem; border-radius: 18px; margin-bottom: 1rem;
  background: var(--butter); font-family: "Fredoka", sans-serif; font-size: 1.25rem; font-weight: 600;
}
.banner.soft { background: var(--sky); }

details.history summary { cursor: pointer; font-family: "Fredoka", sans-serif; font-size: 1.2rem; font-weight: 600; list-style: none; }
details.history summary::-webkit-details-marker { display: none; }
details.history summary::after { content: " ▾"; color: var(--muted); }
details.history[open] summary::after { content: " ▴"; }
.past { border-top: 2px dashed var(--line); padding-top: 1rem; margin-top: 1rem; }
.past-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.past-head .date { color: var(--muted); font-size: .9rem; }
.words-inline { font-family: "Fredoka", sans-serif; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); padding: .75rem 1.1rem; border-radius: 14px;
  font-weight: 700; box-shadow: var(--shadow); z-index: 10; animation: rise .2s ease;
}

.confetti { position: fixed; top: -2rem; pointer-events: none; z-index: 20; font-size: 1.4rem; animation: fall linear forwards; }

@keyframes pop { 0% { transform: scale(.85); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

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