:root {
  font-family: ui-rounded, "Avenir Next", system-ui, sans-serif;
  color: #172f2a;
  background: #e9f2eb;
  --dark: #173c36;
  --line: #cdded4;
  --c0: #e34c68;
  --c1: #327de1;
  --c2: #eeb23b;
  --c3: #1aa87c;
}
* { box-sizing: border-box }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 10% 10%, #f8fbf5, transparent 62%) }
button, input, select { font: inherit }
button, select, summary { cursor: pointer }
button:focus-visible, select:focus-visible, summary:focus-visible, input:focus-visible { outline: 3px solid #205ac3; outline-offset: 3px }
.top { max-width: 1180px; margin: auto; padding: 16px clamp(14px, 4vw, 42px); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line) }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.45rem; letter-spacing: -.05em }
.brand img { border-radius: 12px }
.layout { max-width: 1180px; margin: auto; padding: clamp(18px, 4vw, 42px); display: grid; grid-template-columns: minmax(0, 1.52fr) minmax(0, 1fr); gap: clamp(14px, 3vw, 34px); align-items: start }
.title { margin-bottom: 16px }
h1, h2, p { margin: 0 }
h1 { font-size: clamp(1.8rem, 4.1vw, 3.5rem); line-height: 1.03; letter-spacing: -.065em }
#subtitle { margin-top: 8px; color: #466158 }
h2 { font-size: 1.55rem; letter-spacing: -.045em; line-height: 1.15 }
.board { width: 100%; aspect-ratio: 1; display: grid; grid-template: repeat(11, 1fr) / repeat(11, 1fr); position: relative; isolation: isolate; background: #f9faf4; border: 2px solid #b8d1bf; border-radius: 7%; box-shadow: 0 7px 0 #b8d1bf, 0 18px 38px #143a2618; padding: 2.5% }
.square { align-self: center; justify-self: center; width: 83%; aspect-ratio: 1; border-radius: 50%; background: #fff; border: 1px solid #b6cbbd }
.square.home, .square.start { background: color-mix(in srgb, var(--seat) 57%, white); border-color: var(--seat) }
.square.start::after { content: "◆"; display: grid; height: 100%; place-items: center; font-size: clamp(8px, 1.5vw, 16px); color: #172f2a }
.yard { margin: 3%; border-radius: 22%; background: color-mix(in srgb, var(--seat) 19%, white); border: 1px solid color-mix(in srgb, var(--seat) 50%, white) }
.yard.active { outline: 4px solid var(--seat); outline-offset: -2px }
.reserve { background: #ffffff85; border-color: #172f2a25; width: 90% }
.center { grid-area: 5 / 5 / 8 / 8; pointer-events: none; z-index: -1; margin: 14%; border-radius: 24%; background: #dcebe0 }
.piece { align-self: center; justify-self: center; position: relative; z-index: 2; width: 81%; aspect-ratio: 1; border-radius: 50%; border: 2px solid #172f2a53; background: var(--seat); padding: 0; box-shadow: inset 0 4px 0 #ffffff47, 0 2px 0 #122b2870; color: #102722; line-height: 1; font-size: clamp(.62rem, 1.3vw, .9rem); font-weight: 850; display: grid; place-items: center }
button.piece { outline: 2px solid #172f2a; outline-offset: 2px; animation: bounce .75s ease-in-out alternate infinite }
button.piece:focus-visible { outline: 3px solid #205ac3 }
@keyframes bounce { to { transform: translateY(-3px) } }
.panel { padding: clamp(14px, 2.6vw, 28px); border-radius: 24px; background: white; border: 1px solid var(--line); box-shadow: 0 12px 32px #173c360c }
.stack { display: grid; gap: 12px }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap }
.between { justify-content: space-between }
.mode { width: 100%; text-align: left; display: grid; gap: 3px }
.mode small { font-size: .86rem; font-weight: 500; opacity: .84 }
button, select, input { border: 1px solid #b8cdc0; border-radius: 11px; min-height: 44px; padding: 8px 12px; background: #f5faf6; color: inherit }
input { width: 100%; background: white }
button { font-weight: 700 }
button:hover:not(:disabled):not(.piece) { filter: brightness(.95) }
button:disabled { opacity: .53; cursor: default }
.primary, .mode:first-of-type { background: var(--dark); color: white; border-color: var(--dark) }
label { display: grid; gap: 4px; font-weight: 650 }
details { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 13px }
summary { font-weight: 750 }
details ul { padding-left: 20px; color: #466158; margin-bottom: 0 }
details li + li { margin-top: 6px }
.notice:not(:empty) { margin-top: 12px; color: #8b3426 }
.seat { padding: 6px 8px; border: 1px solid #dbe8df; border-radius: 10px; min-height: 44px }
.seat.active { background: color-mix(in srgb, var(--seat) 18%, white); border-color: var(--seat) }
.dot { width: 13px; height: 13px; border-radius: 50%; background: var(--seat); display: inline-block; border: 1px solid #172f2a50; flex: none }
.seat-name { overflow-wrap: anywhere }
.code { font: 800 1.65rem ui-monospace, monospace; letter-spacing: .12em }
.play-head { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 12px; align-items: center; min-height: 64px }
.die { aspect-ratio: 1; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); border-radius: 13px; box-shadow: 0 3px 0 #bdd0c2; background: #edf5ee; padding: 8px; border: 1px solid #b8cdc0 }
.die i { width: 7px; height: 7px; place-self: center; border-radius: 50%; background: var(--dark) }
.die.rolling { animation: tumble .70s ease both }
@keyframes tumble { 20% { transform: translateY(-8px) rotate(-23deg) } 55% { transform: translateY(-5px) rotate(26deg) } 80% { transform: rotate(-8deg) } }
@media (max-width: 730px) { .layout { grid-template-columns: 1fr; max-width: 610px } .board { box-shadow: 0 5px 0 #b8d1bf } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important } }
.piece { min-height: 0 }
.mobile-moves { display: none }
@media (max-width: 730px) {
  .mobile-moves:not(:empty) { display: flex }
}
.invite-box { padding: 12px; border: 1px solid #93bba2; border-radius: 13px; background: #e9f6eb }
#video-chat { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 13px }
#video-chat[hidden], #video-feeds[hidden] { display: none }
#video-feeds { display: grid; grid-template-columns: 1fr 1fr; gap: 6px }
#video-feeds video { display: block; width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; background: var(--dark); object-fit: cover }
#board-grid { display: contents }
.piece-motion { z-index: 4; pointer-events: none }
.players-entry { border-color: #8fb29a; background: #e9f6eb }
.players-summary { font-weight: 750 }
.video-info { border-top: 1px solid var(--line); padding-top: 12px }
.video-info p { color: #466158 }
#sound { min-height: 40px }

.turn-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 10px; padding: 8px 13px; margin-bottom: 12px; border: 2px solid var(--seat); border-radius: 13px; background: color-mix(in srgb, var(--seat) 14%, white); }
.turn-banner[hidden] { display: none }
.turn-banner .dot { width: 18px; height: 18px }
.turn-caption { font-weight: 700 }
.turn-name { font-size: 1.15rem; overflow-wrap: anywhere }

.turn-banner.winner { padding: 12px 15px; border-width: 3px; background: color-mix(in srgb, var(--seat) 23%, white); }
.turn-banner.winner .turn-name { font-size: clamp(1.3rem, 3vw, 1.85rem) }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 6; container-type: size; border-radius: inherit }
.confetti i { position: absolute; left: var(--x); bottom: -12px; width: 9px; height: 14px; background: var(--confetti-color); border-radius: 2px; animation: confetti-burst var(--flight) var(--delay) both }
.confetti i:nth-child(3n) { width: 8px; height: 8px; border-radius: 50% }
@keyframes confetti-burst {
  0% { transform: translate(0, 0); animation-timing-function: cubic-bezier(.16, .72, .38, 1) }
  35% { transform: translate(var(--peak-x), var(--peak-y)) rotate(var(--spin)); animation-timing-function: cubic-bezier(.35, 0, .79, .63) }
  85% { opacity: 1 }
  100% { transform: translate(var(--landing-x), 12px) rotate(calc(var(--spin) * 2)); opacity: 0 }
}

.piece-avatar { font-size: clamp(10px, 3.5vw, 26px); line-height: 1; pointer-events: none }
.piece-number { position: absolute; right: -3px; bottom: -3px; min-width: 1.05em; padding: 1px; border-radius: 50%; background: #fff; color: #173c36; font-size: clamp(8px, 1.3vw, 12px); line-height: 1; border: 1px solid #173c3660; pointer-events: none }
.seat-avatar, .turn-avatar { line-height: 1; font-size: 1.3rem }
#device-check { margin-top: 16px; border: 1px solid #93bba2; border-radius: 13px; padding: 12px; background: #f4faf5 }
#device-check[hidden], #device-level[hidden], #device-preview[hidden], #device-audio[hidden] { display: none }
#device-preview { width: 100%; max-height: 230px; object-fit: contain; border-radius: 10px; background: var(--dark) }
#device-meter, #device-audio { width: 100% }

#video-feeds video[hidden] { display: none }
#video-feeds:not(.has-remotes) { grid-template-columns: minmax(0, 1fr) }
#video-remotes { display: contents }
.video-tile { display: grid; gap: 4px; min-width: 0 }
.video-tile strong { overflow-wrap: anywhere }

body.is-playing {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}
.is-playing .top { flex: none; width: 100%; padding-block: 8px }
.is-playing .layout {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
  padding-block: 10px 14px;
  align-items: stretch;
  grid-template-columns: minmax(0, 1.52fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.is-playing .table { min-width: 0; min-height: 0; display: flex; flex-direction: column }
.is-playing .title { display: none }
.is-playing .turn-banner { flex: none; margin-bottom: 8px }
.is-playing .board-slot {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
  margin-bottom: 7px;
}
.is-playing .board {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  padding: min(2.5cqw, 2.5cqh);
}
.is-playing .panel {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
@media (max-width: 730px) and (orientation: portrait), (max-width: 500px) {
  .is-playing .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 3fr) minmax(0, 2fr);
    gap: 8px;
    padding: 8px 12px 10px;
  }
  .is-playing .board-slot { margin-bottom: 5px }
  .is-playing .panel { padding: 12px }
}
@media (max-height: 500px) {
  .is-playing .top { padding-block: 3px }
  .is-playing .brand img { width: 34px; height: 34px }
  .is-playing .layout { padding-block: 5px 8px }
  .is-playing .turn-banner { padding-block: 3px; margin-bottom: 4px }
}

.table-seat[hidden], #table-actions[hidden] { display: none }
body.is-shared-table .layout {
  max-width: 900px;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  padding: 6px clamp(8px, 3vw, 30px) 10px;
}
.is-shared-table .panel { display: none }
.is-shared-table .turn-banner { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap }
.is-shared-table .board-slot { margin: 6px 0 9px }
.table-seat {
  flex: none;
  align-self: center;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  width: min(100%, 470px);
  min-height: 46px;
  padding: 3px 8px;
  border: 2px solid #d0e0d5;
  border-radius: 14px;
  background: white;
}
.table-seat-far { transform: rotate(180deg) }
.table-seat.active { border-color: var(--seat); background: color-mix(in srgb, var(--seat) 15%, white) }
.table-seat .die { width: 34px; height: 34px; padding: 4px; border-radius: 8px }
.table-seat .die i { width: 4px; height: 4px }
.table-seat button { min-height: 40px; padding: 5px 8px; font-size: .9rem }
.table-seat-text { display: grid; min-width: 0; overflow-wrap: anywhere; line-height: 1.1 }
.table-seat-text small { font-size: .78rem }
#table-actions button { min-height: 40px; padding: 5px 8px; font-size: .9rem }
.is-shared-table .brand img { width: 34px; height: 34px }
@media (max-width: 410px) { .is-shared-table .brand strong { display: none } }

.piece-far .piece-avatar, .piece-far .piece-number { transform: rotate(180deg) }
.piece-far .piece-number { inset: -3px auto auto -3px }

#departure-notice { padding: 6px 10px; margin-bottom: 6px; background: #fff3de; border: 1px solid #e5c487; border-radius: 9px; font-weight: 650 }
#departure-notice[hidden] { display: none }

#friends-dialog { width: min(480px, calc(100% - 24px)); max-height: 85dvh; border: 1px solid #9cbaac; border-radius: 18px; padding: 16px; color: inherit; background: #fff; overscroll-behavior: contain }
#friends-dialog::backdrop { background: #163b3480 }
#friends-button[hidden] { display: none }

.friend-status {
  border-radius: 999px;
  padding: .45em .75em;
  background: #dcf4e2;
  color: #175b30;
  font-weight: 700;
}

.friend-request {
  flex: 1 0 100%;
}

/* Warm, large-touch layouts for the game's entry and invitations. */
:root {
  background: #fff6e6;
  --ink: #113e43;
  --orange: #ad4206;
  --blue: #07638c;
}
body {
  color: var(--ink);
  background: radial-gradient(ellipse at 10% 5%, #fffdf9, transparent 68%), #fff6e6;
}
.top { border-color: #e8dac1 }
.panel { background: #fffdf8; border-color: #eadbc1; border-radius: 26px }
.primary { background: var(--orange); border-color: var(--orange); color: white }
.secondary { background: var(--blue); border-color: var(--blue); color: white }
.welcome-art { display: none }
.is-entry .table { display: none }
.is-entry .layout {
  max-width: 670px;
  grid-template-columns: minmax(0, 1fr);
}
.is-entry .panel { padding: clamp(18px, 4vw, 34px) }
.is-entry:not(.is-welcome) .panel > details { display: none }
.is-entry .top button, .is-entry .top select { background: #fffdf8 }
.is-welcome .layout {
  max-width: 1080px;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  align-items: center;
}
.is-welcome .welcome-art {
  display: block;
  aspect-ratio: 3 / 2;
  background: #fff6e6 url('/welcome.webp') center / cover no-repeat;
  border-radius: 28px;
}
.welcome-title {
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 900;
  text-align: center;
  margin: 0 0 8px;
}
.mode.mode-online, .mode.mode-solo, .mode.mode-local {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 62px;
  padding: 13px clamp(13px, 3vw, 23px);
  border: 1px solid transparent;
  border-radius: 20px;
  font-size: clamp(1.05rem, 2.7vw, 1.35rem);
}
.mode.mode-online { color: white; background: var(--orange); box-shadow: 0 3px 0 #80300a }
.mode.mode-solo { color: white; background: var(--blue); box-shadow: 0 3px 0 #05435f }
.mode.mode-local { background: #fff4dc; border-color: #dfccab }
.mode-icon { font-size: 1.45em; line-height: 1 }
.setup-title { font-size: clamp(1.7rem, 5vw, 2.5rem) }
.entry-back { justify-self: start; background: #fff8ed; border-color: #e6d4b7 }
.visible-online { color: #255d43; font-weight: 650 }
.visible-online::before { content: '●'; color: #278552; margin-right: .55em }
.lobby-player { border: 1px solid #e6d9c2; background: #fff8ed; padding: 13px; border-radius: 18px }
.lobby-identity { gap: 12px; flex-wrap: nowrap }
.lobby-identity strong, .lobby-identity small { display: block }
.lobby-identity strong { font-size: 1.25rem }
.lobby-identity small { color: #255d43 }
.lobby-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 56px;
  aspect-ratio: 1;
  background: #cdeaf4;
  border-radius: 50%;
  font-size: 1.8rem;
}
.group-toggle { display: flex; align-items: center; gap: 8px; font-weight: 550 }
.group-toggle input { width: 20px; margin: 0; accent-color: var(--blue) }
.play-invitation { text-align: center; overflow-wrap: anywhere }
.play-invitation .lobby-avatar { width: 88px; font-size: 3rem; justify-self: center }
.play-invitation h2 { font-size: clamp(1.6rem, 5vw, 2.5rem) }
.play-invitation button, .lobby-player button, .is-playing #controls .primary {
  min-height: 54px;
  border-radius: 16px;
  font-size: clamp(1rem, 2vw, 1.22rem);
}
.is-invited .panel { background: #fffaf1 }
.appearance > label, .appearance > fieldset { margin-top: 10px }
.is-playing .board { background: #fffbef; border-color: #d7c9ad; box-shadow: 0 6px 0 #d7c9ad }
@media (max-width: 680px) {
  .is-welcome .layout { grid-template-columns: minmax(0, 1fr); max-width: 480px }
  .is-welcome .welcome-art { order: 1; max-height: 175px; background-position: center }
  .is-entry .top { gap: 8px; flex-wrap: wrap }
  .is-entry .top .row { gap: 4px }
}

/* The zoo sits under the existing grid so every playable square stays tappable. */
.board, .is-playing .board {
  background: radial-gradient(ellipse at 22% 14%, #fff0cb, transparent 60%), #e8c38b;
  border: 2px solid #bd965f;
  box-shadow: 0 7px 0 #917044, 0 12px 20px #613d322c, inset 0 2px 3px #fff8d7;
}
.board .square {
  background: radial-gradient(ellipse at 35% 19%, #fff7e5, #f8e2bd 75%);
  border-color: #c6a473;
  box-shadow: 0 2px 0 #aa8355, inset 0 2px 1px #fffbf4;
}
.board .square.home, .board .square.start {
  background: linear-gradient(146deg, color-mix(in srgb, var(--seat) 40%, white), var(--seat));
  border-color: color-mix(in srgb, var(--seat) 80%, #3b2e20);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--seat) 64%, #3b2e20), inset 0 1px 1px #fff9;
}
.board .square.reserve {
  background: color-mix(in srgb, var(--seat) 16%, #fff6e7);
  border-color: color-mix(in srgb, var(--seat) 60%, #776653);
  box-shadow: inset 0 2px 4px #493a3842, 0 1px 0 #fffc;
}
.board .center {
  display: grid;
  place-items: center;
  color: #70522a;
  background: radial-gradient(ellipse at 35% 23%, #ffefcf, #e4b776);
  border: 1px solid #b58a54;
  box-shadow: 0 3px 0 #a87b48, inset 0 2px 1px #fff7dd;
  font-size: clamp(12px, 4vmin, 34px);
}
.habitat {
  position: relative;
  border: 2px solid var(--seat);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--seat) 75%, #36261d), inset 0 1px 4px #fff9;
  background-image: url('/zoo-habitats.webp');
  background-size: 200% 200%;
}
.habitat-0 { background-position: top left }
.habitat-1 { background-position: top right }
.habitat-2 { background-position: bottom right }
.habitat-3 { background-position: bottom left }
.zoo-animal {
  position: absolute;
  z-index: 2;
  font-size: clamp(11px, 3.2vmin, 29px);
  line-height: 1;
  user-select: none;
  pointer-events: none;
  opacity: 0;
}
.zoo-animal-0 { top: 4%; left: 4% }
.zoo-animal-1 { top: 4%; right: 4% }
.zoo-animal-2 { bottom: 4%; right: 4% }
.zoo-animal-3 { bottom: 4%; left: 4% }
.board .piece {
  background: radial-gradient(ellipse at 35% 21%, color-mix(in srgb, var(--seat) 60%, white), var(--seat) 70%);
  box-shadow: inset 0 3px 1px #fff7, 0 3px 0 color-mix(in srgb, var(--seat) 55%, #191813), 0 5px 6px #29251e55;
}
.board .square.gate-tile { outline: 2px solid #985112; outline-offset: -2px }
.zoo-gate {
  z-index: 4;
  align-self: start;
  justify-self: center;
  margin-top: 1px;
  width: 64%;
  height: 31%;
  pointer-events: none;
  border: 1px solid #78401e;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, #b96c32 0 19%, #87471e 20% 24%);
  box-shadow: inset 0 2px 0 #ffdf9f, 0 2px 0 #603015, 0 3px 4px #3a251e77;
  transform: translateX(22%) rotate(-23deg) scale(.74);
  transform-origin: right center;
}
.zoo-gate.closed {
  background: repeating-linear-gradient(90deg, #e39946 0 19%, #95451e 20% 24%);
  transform: translateY(-15%);
}
.waiting-at-gate { outline: 2px solid #864514; outline-offset: 1px }
.zoo-wait { padding: 8px 12px; background: #fff2d8; border: 1px solid #dfbc79; border-radius: 12px; color: #62370f; font-weight: 700 }
.zoo-home-glow { display: grid; place-items: center; font-size: clamp(8px, 2.4vmin, 18px); animation: zoo-arrival .9s ease both }
@keyframes zoo-arrival {
  15%, 70% { box-shadow: 0 0 11px 4px #ffdf75; filter: brightness(1.18) }
}
