@font-face {
  font-family: DM;
  src: url(assets/dm.woff2) format("woff2");
  font-weight: 100 1000;
  font-display: swap;
}

:root {
  --blush: #f5eeec;
  --ink: #433a49;
  --muted: #65586d;
  --line: #e5dce7;
  --wash: #f3edf5;
  --green: #345e47;
  --surface: #fff;
  --page-gutter: clamp(14px, 4.2vw, 25px);
  --comb: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 72'%3E%3Cpath fill='%23e5c7a5' fill-opacity='.23' stroke='%23a57956' stroke-opacity='.17' stroke-width='1.2' stroke-linejoin='round' d='M24 2 43 13v22L24 46 5 35V13ZM0 38 19 49v22L0 82-19 71V49ZM48 38 67 49v22L48 82 29 71V49ZM0-34 19-23v22L0 10-19-1v-22ZM48-34 67-23v22L48 10 29-1v-22Z'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: #f3ebe7; color: var(--ink); }
body { margin: 0; font-family: DM, system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .62; }
:focus-visible { outline: 3px solid #387681; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
img, video { max-width: 100%; }
button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
input, select {
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #cabdce;
  border-radius: 12px;
  background: white;
  font-size: 16px;
}
input::placeholder { color: #766d7a; }
summary { cursor: pointer; padding-block: 10px; font-weight: 750; }
.micro { font-size: 13px; color: var(--muted); line-height: 1.5; }

.primary, .secondary, .textbutton, .icon, .dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-weight: 800;
}
.primary { background: var(--green); color: white; border-color: #294f3b; box-shadow: 0 2px 0 #214231; }
.secondary { background: #fbf8fc; color: var(--ink); border-color: var(--line); }
.textbutton { background: transparent; color: #62420f; }
.textbutton:hover { text-decoration: underline; }
.primary:active, .secondary:active { transform: translateY(1px); box-shadow: none; }
.icon, .dialog-close { width: 44px; padding: 0; flex: none; border-radius: 50%; font-size: 20px; }
.icon { background: #fff9f3; border-color: #e7d9d4; }
.icon[aria-pressed="false"] { background: #f1e5e2; color: #716371; }

.phone {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  background: var(--blush);
  box-shadow: 0 0 36px #61424b16;
}
.phone::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: 240px;
  pointer-events: none;
  background-image: var(--comb);
  background-size: 60px 90px;
  mask-image: linear-gradient(#000 6%, transparent 94%);
}
.phone:has(#welcome[hidden])::before { display: none; }
.app-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) var(--page-gutter) 4px;
}
.app-header .brand { text-align: center; font-weight: 850; }
.phone:not(.join-scene):has(#welcome:not([hidden])) .app-header :is(#home, .brand) { visibility: hidden; }
#welcome { flex: 1; padding: 0 var(--page-gutter) 16px; }
.home-hero { display: grid; justify-items: center; gap: 4px; text-align: center; }
.home-wordmark { display: block; width: min(100%, 320px); height: auto; margin: auto; }
.home-wave { display: block; height: clamp(160px, 52vw, 229px); width: auto; object-fit: contain; }
.welcome-content { width: min(100%, 365px); margin: auto; }
.welcome-content label { display: block; width: min(100%, 252px); margin: 0 auto 5px; font-size: 13px; font-weight: 800; }
#name { display: block; width: min(100%, 252px); margin: 0 auto 11px; }
.home-actions { display: grid; justify-items: center; gap: 3px; }
.home-actions .garden-play {
  display: flex;
  justify-content: space-between;
  width: min(100%, 252px);
  min-height: 54px;
  padding: 7px 12px 7px 17px;
  border: 1px solid #bd772f;
  border-radius: 18px;
  background: linear-gradient(#ffe29b, #ffc366);
  box-shadow: 0 3px 0 #bb742e, inset 0 2px 0 #fff1be;
  color: #4b2d11;
  font-size: 18px;
}
.home-actions .garden-play:active { box-shadow: 0 1px 0 #bb742e; }
.home-actions .garden-play small { padding: 4px 8px; border-radius: 12px; background: #fff2c6; color: #684012; }
.level-welcome, #join-decoration { display: none; }
.levels { margin: 9px auto 0; }
.levels summary { text-align: center; color: #62420f; font-size: 14px; }
.levels .micro { margin-bottom: 9px; text-align: center; }
#levelgrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 4px;
}
#levelgrid button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 1px;
  min-height: 44px;
  aspect-ratio: 1;
  border: 1px solid #d3c5de;
  border-radius: 12px;
  background: #eee6f5;
  color: #65497d;
  font-weight: 850;
}
#levelgrid button.level-locked { background: #f3eff2; opacity: 1; color: #776d7e; }
#levelgrid button.level-current { background: #d4ebdc; border: 2px solid #8db49a; color: #386849; }
#levelgrid button small { font-size: 10px; }
#levelgrid button svg { width: 13px; height: 13px; }
.dock {
  position: sticky;
  z-index: 3;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-top: auto;
  padding: 6px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.dock button {
  display: grid;
  gap: 4px;
  justify-items: center;
  align-content: center;
  min-height: 49px;
  padding: 4px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.dock button:hover { background: var(--wash); }
.dock button[aria-current="page"] { background: #fff3d8; color: #62420f; }
.dock svg { width: 18px; height: 18px; }

.phone.join-scene::before { display: none; }
.join-scene { background: #e8efe5; }
.join-scene #welcome { display: grid; align-items: start; padding-block: 22px; }
.join-scene :is(.home-hero, #play-level, #rejoin, .dock, .levels) { display: none; }
.join-scene .welcome-content {
  width: min(100%, 390px);
  margin: 0 auto;
  padding: 20px 14px 24px;
  border: 1px solid #cddcce;
  border-radius: 22px;
  background: #fff;
  text-align: center;
}
.join-scene .level-welcome { display: grid; justify-items: center; gap: 10px; margin-bottom: 16px; }
.level-welcome img { display: block; width: auto; height: 150px; object-fit: contain; }
.level-welcome h2 { font-size: 25px; font-weight: 850; }
.level-welcome p { margin-top: 5px; color: var(--muted); font-size: 14px; }
.join-scene #name, .join-scene label { text-align: left; }
.join-scene .home-actions .garden-play { justify-content: center; }
#join-pitch { margin: 0 auto 9px; font-size: 14px; color: var(--green); }

@media (prefers-reduced-motion: no-preference) {
  .phone::before { animation: comb-drift 28s linear infinite; }
  #play-level { animation: play-jiggle 5.5s ease-in-out 1s 3; }
  #play-level:is(:hover, :focus-visible, :active) { animation: none; }
}
@keyframes comb-drift { to { background-position: 60px -90px; } }
@keyframes play-jiggle {
  0%, 16%, 100% { transform: translateY(0) rotate(0); }
  3% { transform: translateY(-2px) rotate(-2deg); }
  6% { transform: translateY(-2px) rotate(2deg); }
  9% { transform: translateY(-1px) rotate(-1deg); }
  12% { transform: translateY(-1px) rotate(1deg); }
}

#game { width: min(100%, 485px); margin: 0 auto; padding: 5px var(--page-gutter) 20px; }
.level-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-inline: 5px; }
#chapter { color: #735a7e; font-size: 11px; font-weight: 850; letter-spacing: .11em; }
#leveltitle { margin-top: 3px; font-size: 27px; line-height: 1.14; font-weight: 850; letter-spacing: -.025em; }
.hearts { padding: 4px 9px 3px; border-radius: 999px; background: white; color: #ad4665; font-size: 21px; white-space: nowrap; }
#battle-panel { margin: 13px 0 10px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 15px; background: white; }
.mode-switch button {
  min-height: 39px;
  padding: 6px 4px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: #605665;
  font-size: 14px;
  font-weight: 800;
}
.mode-switch button[aria-pressed="true"] { border-color: #e5dbea; color: #6d527e; box-shadow: 0 1px 3px #62477919; }
#battle-start { width: 100%; margin-top: 9px; }
#battle-scoring { font-size: 13px; color: var(--muted); }
#battle-scoring p { line-height: 1.5; }
#team-totals, .result-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 9px 0; }
#team-totals > div, .result-teams > div { padding: 10px; text-align: center; border-radius: 13px; }
.rose { background: #f3dbe6; color: #78475f; }
.sky { background: #dcecf7; color: #36627d; }
#team-totals span, .result-teams span { font-size: 14px; font-weight: 850; }
#team-totals strong, .result-teams strong { display: block; font-size: 23px; }
#team-totals small, .result-teams small { font-size: 12px; }
.progressline { display: flex; gap: 10px; align-items: center; margin: 12px 4px 11px; font-size: 13px; }
.track { flex: 1; overflow: hidden; height: 7px; border-radius: 10px; background: #e8e1ec; }
#progress { display: block; width: 0; height: 100%; border-radius: inherit; background: #86b494; }
.rulechips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-bottom: 10px; padding: 4px; border-radius: 12px; background: white; }
.rule-example { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 8px; background: #f8efeb; color: #574854; font-size: clamp(10px, 2.7vw, 12px); font-weight: 780; line-height: 1.2; }
.rule-grid { display: grid; flex: none; width: clamp(23px, 7.4vw, 34px); aspect-ratio: 1; grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); gap: 1px; }
.rule-grid > span { display: grid; place-items: center; border-radius: 2px; overflow: hidden; color: white; background: #eef2f5; font-size: 10px; line-height: 1; }
.rule-grid svg { display: block; width: 100%; height: 100%; }
.rule-grid .bee-piece { width: 100%; height: 100%; animation: none; }
.rule-grid .bee-blink { display: none; }
.board-tray { max-width: 400px; margin: 0 auto; padding: 5px; border-radius: 15px; background: white; }
.board-tray:has(#board[hidden]) { display: none; }
.bee-reference { display: flex; justify-content: center; align-items: center; gap: clamp(3px, 1vw, 6px); min-height: 36px; padding: 1px 5px 5px; }
.bee-target { position: relative; height: 34px; flex: 0 1 34px; color: var(--bee-color); min-width: 0; }
.bee-target > svg { display: block; width: 100%; height: 100%; fill: currentColor; }
.found-tick { position: absolute; right: -2px; bottom: 0; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; border: 1px solid #b7cdbb; background: white; color: #426b4b; font-size: 12px; font-weight: 900; }
#board { display: grid; gap: clamp(3px, .95vw, 5px); touch-action: none; user-select: none; -webkit-user-select: none; }
.cell {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: var(--tile);
  touch-action: none;
}
.cell:focus-visible { outline-offset: -3px; }
.cell > svg, .cell > .bee-piece { position: relative; z-index: 2; width: 94%; height: 94%; pointer-events: none; }
.cell .cross { width: 69%; height: 69%; color: white; }
.cross path { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; }
.cross.drawing path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw-x .09s ease-out forwards; }
.cross.drawing path + path { animation-delay: .065s; }
.cell .cross.erasing { animation: erase-x .13s ease-out forwards; }
.cell.hinted { outline: 3px solid #76510f; outline-offset: -3px; }
.cell.wrong { animation: wrong .36s ease; }
.cell.bloom .bee-piece { animation: bloom .6s ease-out; }
.bee-piece { display: block; position: relative; pointer-events: none; }
.bee-piece svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; overflow: hidden; }
.bee-piece .bee-open { animation: eyes-open 4.7s steps(1) infinite; animation-delay: var(--phase); }
.bee-piece .bee-blink { animation: eyes-blink 4.7s steps(1) infinite; animation-delay: var(--phase); }
.rule-grid .bee-open { animation: none; }
.rule-grid .bee-blink { display: none; }
.cell .credit { position: absolute; z-index: 1; top: 2px; left: 2px; width: 23%; max-width: 20px; aspect-ratio: 1; border-radius: 50%; background: var(--player-color); color: white; opacity: .5; font-size: 10px; font-weight: 850; pointer-events: none; }
@keyframes draw-x { to { stroke-dashoffset: 0; } }
@keyframes erase-x { to { transform: scale(.45); opacity: 0; } }
@keyframes bloom { 25% { transform: scale(.7); } 65% { transform: scale(1.15); } }
@keyframes wrong { 25%, 75% { transform: translateX(2px); } 50% { transform: translateX(-2px); } }
@keyframes eyes-open { 0%, 94%, 100% { opacity: 1; } 92% { opacity: 0; } }
@keyframes eyes-blink { 0%, 94%, 100% { opacity: 0; } 92% { opacity: 1; } }
.motion-paused * { animation-play-state: paused !important; }
.instruction { margin: 7px 0 0; text-align: center; font-size: 13px; line-height: 1.4; color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 7px 12px; margin: 8px 0 12px; }
.tool { display: grid; justify-items: center; gap: 3px; min-width: 46px; padding: 3px; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 800; }
.tool-circle { position: relative; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #e3d9e8; border-radius: 50%; background: white; color: #73568c; }
#board-clue { margin: 0 0 12px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: white; font-size: 14px; }
#board-clue .secondary { margin-top: 8px; }

.team { padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.teamhead { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }
.teamhead h3 { font-size: 17px; }
#room-capacity { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 650; }
#voice-status { margin-top: 8px; }
#players .player, #finishscores .player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 49px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.player > b { white-space: nowrap; }
.player > b > small { margin-left: 2px; font-size: 11px; }
.player-name { flex: 1 1 75px; min-width: 0; overflow-wrap: anywhere; font-weight: 750; }
.player-name > small { display: block; color: var(--muted); font-size: 12px; }
.player-photo { display: grid; place-items: center; overflow: hidden; }
.player-photo img { width: 100%; height: 100%; object-fit: cover; }
.player .avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--player-color); color: white; font-weight: 850; }
.voice-controls { display: grid; justify-items: center; gap: 3px; }
.voice-button, .voice-flag, .play-request, .cancel-request { min-height: 44px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 12px; background: #f6f2f8; color: #65536f; font-size: 12px; font-weight: 800; }
.voice-button, .voice-flag { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.voice-button svg { width: 15px; height: 17px; }
.voice-button.mic-live { background: #e0f0e0; border-color: #8eb18c; color: #365e36; }
.voice-button.locally-muted { background: #f6e4e2; color: #92544e; }
.voice-state { font-size: 10px; color: var(--muted); }
.voice-flag { width: 44px; }
.team-choice { min-height: 38px; padding: 5px; border: 0; border-radius: 9px; font-size: 12px; font-weight: 800; }
.team-choice:disabled { opacity: 1; }

dialog {
  position: fixed;
  width: min(calc(100% - 26px), 465px);
  max-height: min(88vh, 88dvh);
  overflow: auto;
  margin: auto;
  padding: 19px clamp(12px, 4vw, 24px);
  border: 1px solid #ded0df;
  border-radius: 20px;
  background: #fffaf8;
  color: var(--ink);
  box-shadow: 0 12px 45px #402a4b30;
}
dialog::backdrop { background: #302439a3; }
dialog h2 { margin-right: 46px; font-size: 24px; line-height: 1.25; }
dialog p { margin: 11px 0; line-height: 1.5; }
dialog :is(.primary, .secondary) + p { margin-bottom: 0; }
.dialog-close { position: absolute; right: 11px; top: 9px; background: #f4ecef; }
.friends-invite-art, .ranking-banner {
  display: flex;
  align-items: center;
  aspect-ratio: 960 / 412;
  margin: 13px 0;
  padding: 11px 13px;
  overflow: hidden;
  border: 1px solid #e6d9dc;
  border-radius: 15px;
  background: #eadce9 url(assets/approved/friends-garden.webp) center / cover;
}
.ranking-banner { background: #f5e7d4 url(assets/approved/ranking-garden.webp) center / cover; }
.friends-invite-art h3, .ranking-banner h3 {
  width: 44%;
  color: #442e47;
  font-size: clamp(17px, 5vw, 23px);
  font-weight: 850;
  line-height: 1.08;
  text-wrap: balance;
}
.ranking-banner h3 { color: #51332a; }
#friends-dialog .primary, #inviteDialog input, #inviteDialog :is(.primary, .secondary) { width: 100%; margin-top: 7px; }
.rank-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.rank-row > span { flex: 1; overflow-wrap: anywhere; }
.rank-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.rank-row strong { color: #5f4675; }
.voice-safety-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#voice-safety-dialog label { display: block; margin-bottom: 5px; }
#voice-blocked-list > div { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0; overflow-wrap: anywhere; }
#failureDialog { background: #f7f0ee; text-align: center; }
#failureDialog h2 { margin: 0; }
.empty-hearts { margin-bottom: 4px; color: #a64a68; font-size: 22px; }
.retry-scene { position: relative; width: min(100%, 235px); margin: 7px auto 0; border-radius: 14px; overflow: hidden; }
.retry-scene img { display: block; width: 100%; height: auto; }
.retry-scene video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #f7f0ee; }
#failure-retry { width: 100%; }
#finish { position: fixed; z-index: 6; inset: 0; overflow-y: auto; background: #e3f1f5; color: #163e50; }
.finish-content { position: relative; width: min(100%, 470px); margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom)); text-align: center; }
.finish-content > small { font-weight: 850; letter-spacing: .1em; }
.finish-content h2 { margin: 5px 0 8px; font-size: clamp(25px, 7vw, 36px); }
.finish-content p { margin: 10px 0; }
.bee-stage img { display: block; width: auto; max-height: min(34vh, 235px); margin: auto; object-fit: contain; }
#finishscores { margin: 10px 0; }
#finishscores .player { justify-content: space-between; padding-inline: 5px; }
#next { width: 100%; margin-top: 11px; }
.mvp { padding: 9px; border-radius: 12px; background: white; color: #5c4776; }
.mvp strong { display: block; margin: 3px 0; font-size: 20px; }
.round-breakdown p { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.round-breakdown p span { text-align: right; }
.rank-total { display: block; color: #536c7a; font-size: 11px; }
.confetti { position: absolute; z-index: 1; top: -13px; width: 7px; height: 10px; pointer-events: none; animation: confetti-fall 3s ease-in forwards; }
@keyframes confetti-fall { to { transform: translateY(94vh) rotate(450deg); opacity: .2; } }
#toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(77px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 10px 16px;
  transform: translate(-50%, 5px);
  opacity: 0;
  pointer-events: none;
  border-radius: 16px;
  background: #413344;
  color: white;
  text-align: center;
  font-size: 14px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 350px) {
  .rule-example { gap: 3px; padding-inline: 3px; }
  .voice-button { padding-inline: 4px; }
}
@media (max-height: 720px) and (orientation: portrait) {
  .home-wave { height: clamp(140px, 30vh, 190px); }
  .home-wordmark { width: min(100%, 280px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
  .bee-piece .bee-blink, .retry-scene video { display: none; }
  .cross.drawing path { stroke-dashoffset: 0; }
}
