:root {
  --bg: #fff6f8;
  --bg2: #ffe9ef;
  --card: #ffffff;
  --ink: #3b2530;
  --muted: #8d6b79;
  --line: #f3d3dd;
  --rose: #e8476f;
  --rose-dark: #c7335a;
  --rose-soft: #ffdbe5;
  --green: #22a06b;
  --green-soft: #d7f3e5;
  --red: #d9434b;
  --red-soft: #fde0e1;
  --amber: #f0a020;
  --shadow: 0 6px 24px rgba(200, 60, 100, .12);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1418; --bg2: #2a1c22; --card: #2b1f25; --ink: #fbeef2; --muted: #c4a3b0; --line: #45303a;
    --rose: #ff5f86; --rose-dark: #ff7d9d; --rose-soft: #4a2633; --green: #3dd598; --green-soft: #1f3b2f;
    --red: #ff6b72; --red-soft: #4a2427; --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Nunito, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg2), var(--bg)) fixed, var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3, .brand { font-family: Fredoka, Nunito, sans-serif; letter-spacing: .2px; }
h2 { font-size: 1.15rem; margin: 26px 4px 10px; color: var(--muted); font-weight: 600; }
a { color: var(--rose); }

.app { max-width: 560px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.boot { font-size: 48px; text-align: center; margin-top: 30vh; animation: beat 1.2s infinite; }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.top .brand { font-size: 1.35rem; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .brand .heart { display: inline-block; animation: beat 2.4s infinite; }
.iconbtn {
  border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; min-width: 42px; height: 42px;
  padding: 0 14px; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; color: var(--ink);
}
.iconbtn .badge { background: var(--rose); color: #fff; border-radius: 999px; font-size: .75rem; padding: 1px 7px; }

/* cards & buttons */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 10px; }
.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 800; cursor: pointer; background: var(--rose); color: #fff;
  box-shadow: 0 4px 0 var(--rose-dark); transition: transform .08s, box-shadow .08s; text-decoration: none; display: inline-block; text-align: center;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--rose-dark); }
.btn.secondary { background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--line), var(--shadow); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; padding: 8px 10px; font-weight: 700; }
.btn.small { padding: 8px 12px; font-size: .9rem; border-radius: 11px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.actions .wide { grid-column: span 2; }

input.field {
  width: 100%; border: 2px solid var(--line); background: var(--bg); border-radius: 14px; padding: 12px 14px; outline: none;
  transition: border-color .15s;
}
input.field:focus { border-color: var(--rose); }
label.lbl { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin: 0 0 6px 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .88rem; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }

/* auth */
.hero { text-align: center; margin: 7vh 0 22px; }
.hero h1 { font-size: 2.3rem; margin: 10px 0 4px; line-height: 1.1; }
.hero p { color: var(--muted); margin: 0; }
.hero .logo { width: 92px; height: 92px; border-radius: 26px; box-shadow: var(--shadow); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; padding: 10px; border-radius: 11px; font-weight: 800; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* game list */
.glist { display: grid; gap: 10px; }
.gitem { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; padding: 12px 14px; }
.gitem.myturn { outline: 2.5px solid var(--rose); }
.gitem .info { flex: 1; min-width: 0; }
.gitem .name { font-weight: 800; }
.gitem .last { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .score { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 1.1rem; text-align: right; }
.gitem .score small { display: block; font-family: Nunito, sans-serif; font-size: .75rem; color: var(--muted); font-weight: 600; }
.avatar {
  position: relative; width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--rose-soft); color: var(--rose-dark);
  display: grid; place-items: center; font-weight: 800; font-family: Fredoka, sans-serif; font-size: 1.15rem;
}
.avatar.sm { width: 34px; height: 34px; font-size: .95rem; }
.dot { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid var(--card); background: #bbb; }
.dot.on { background: var(--green); }
.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: .78rem; font-weight: 800; background: var(--rose-soft); color: var(--rose-dark); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.gray { background: var(--bg2); color: var(--muted); }

/* friends */
.flist { display: grid; gap: 8px; }
.fitem { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.fitem .info { flex: 1; min-width: 0; }
.fitem .uname { color: var(--muted); font-size: .85rem; }
.choice { cursor: pointer; border: 2.5px solid transparent; }
.choice.on { border-color: var(--rose); }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg button { border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 0; font-weight: 800; cursor: pointer; }
.seg button.on { border-color: var(--rose); background: var(--rose-soft); color: var(--rose-dark); }

.lenrow { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px; justify-content: center; }
.lenrow button {
  flex: none; min-width: 38px; height: 36px; padding: 0 10px; border: 2px solid var(--line); background: var(--card); border-radius: 11px;
  font-family: Fredoka, sans-serif; font-weight: 700; cursor: pointer;
}
.lenrow button.on { border-color: var(--rose); background: var(--rose-soft); color: var(--rose-dark); }

/* game */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 12px 14px; }
.player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player.right { flex-direction: row-reverse; text-align: right; }
.player .pname { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.player .pts { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 1.4rem; line-height: 1; }
.player.turn .avatar { box-shadow: 0 0 0 3px var(--rose); }
.vs { text-align: center; color: var(--muted); font-size: .8rem; font-weight: 700; }
.status { text-align: center; font-weight: 800; font-size: 1.1rem; margin: 16px 0 4px; font-family: Fredoka, sans-serif; }
.status.me { color: var(--rose); }
.hint { text-align: center; color: var(--muted); margin-bottom: 4px; }
.hint b { color: var(--ink); }

.stage { display: grid; place-items: center; margin: 4px 0; }
.gallows { width: min(250px, 66vw); height: auto; overflow: visible; }
.gallows .part { fill: none; stroke: var(--ink); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; opacity: 0; }
.gallows .part.on { stroke-dashoffset: 0; opacity: 1; }
.gallows .part.new { animation: draw .7s ease-out both; }
.gallows .wood { stroke: var(--muted); }
.gallows .heart { fill: var(--rose); opacity: 0; transition: opacity .4s; }
.gallows .heart.on { opacity: 1; }
.gallows.dead .part.body { stroke: var(--red); }
.lives { text-align: center; color: var(--muted); font-size: .9rem; font-weight: 700; }

.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 14px 0 6px; }
.word .w { display: flex; gap: 5px; }
.tile {
  width: 34px; height: 44px; border-radius: 9px; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center;
  font-family: Fredoka, sans-serif; font-weight: 700; font-size: 1.45rem; border-bottom: 3px solid var(--line);
}
.tile.sym { background: transparent; box-shadow: none; border: 0; width: 14px; }
.tile.ghost { color: var(--muted); opacity: .45; }
.tile.missed { color: var(--red); }
.tile.pop { animation: pop .45s ease-out; }
.word.long .tile { width: 26px; height: 36px; font-size: 1.15rem; }
.word.xlong .tile { width: 21px; height: 30px; font-size: .98rem; border-radius: 7px; }

.kbd { display: grid; gap: 6px; margin-top: 16px; user-select: none; }
.kbd .krow { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1; max-width: 44px; height: 50px; border: 0; border-radius: 10px; background: var(--card); box-shadow: 0 3px 0 var(--line);
  font-family: Fredoka, sans-serif; font-weight: 700; font-size: 1.15rem; cursor: pointer; padding: 0; touch-action: manipulation;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.key.hit { background: var(--green-soft); color: var(--green); box-shadow: none; }
.key.miss { background: var(--red-soft); color: var(--red); box-shadow: none; opacity: .7; }
.key:disabled { cursor: default; }
.kbd.locked .key:not(.hit):not(.miss) { opacity: .45; }

.banner { text-align: center; padding: 18px 14px; }
.banner .big { font-size: 2.2rem; }
.banner h3 { margin: 6px 0 4px; font-size: 1.35rem; }
.prev { display: flex; gap: 10px; align-items: center; font-size: .92rem; padding: 10px 14px; margin-top: 12px; }
.prev .res { font-size: 1.3rem; }
.wait { text-align: center; padding: 26px 14px; }
.wait .hearts span { display: inline-block; animation: float 1.6s infinite ease-in-out; font-size: 1.6rem; }
.wait .hearts span:nth-child(2) { animation-delay: .2s; }
.wait .hearts span:nth-child(3) { animation-delay: .4s; }

.rounds { display: grid; gap: 6px; }
.rround { display: flex; align-items: center; gap: 10px; padding: 9px 12px; font-size: .9rem; }
.rround .rw { font-family: Fredoka, sans-serif; font-weight: 600; letter-spacing: .5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat */
.chat .msgs { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 2px; margin-bottom: 10px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 16px; background: var(--bg2); align-self: flex-start; word-wrap: break-word; }
.msg.mine { align-self: flex-end; background: var(--rose); color: #fff; }
.msg time { display: block; font-size: .7rem; opacity: .7; margin-top: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%); background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 14px; font-weight: 700; max-width: calc(100% - 32px); transition: transform .25s, visibility .25s; z-index: 10; text-align: center;
  visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti span { position: absolute; top: -40px; animation: fall linear forwards; }

@keyframes draw { from { stroke-dashoffset: 1; opacity: 1; } to { stroke-dashoffset: 0; opacity: 1; } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.12); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } .gallows .part.new { stroke-dashoffset: 0; opacity: 1; } }
@media (max-width: 380px) { .key { height: 44px; font-size: 1rem; } .kbd .krow { gap: 4px; } }
