:root {
  --soil-deep: #3d2a16;
  --soil-mid: #8b6914;
  --sand: #d4b483;
  --sand-light: #e8d4a8;
  --ink: #1f160c;
  --tomato: #c62828;
  --tomato-glow: #ef5350;
  --gourd: #2e7d32;
  --gourd-glow: #66bb6a;
  --cream-text: #f3e6c8;
  --panel: rgba(32, 22, 12, 0.72);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Outfit", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--cream-text);
  font-family: var(--font-body);
  background: #2a1c0e;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.soil {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #5c4224 0%, transparent 55%),
    radial-gradient(ellipse 90% 60% at 80% 100%, #1a1208 0%, transparent 50%),
    linear-gradient(165deg, #4a3420 0%, #2a1c0e 45%, #1a1208 100%);
}
.soil::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

#app {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.home-center {
  min-height: min(78dvh, 640px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.75rem;
  animation: rise 0.55s ease both;
}
.home-brand .lede {
  margin-left: auto;
  margin-right: auto;
}
.app-logo {
  display: block;
  width: clamp(88px, 22vw, 112px);
  height: auto;
  margin: 0 auto 1rem;
  border-radius: 22%;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(232, 212, 168, 0.18);
  animation: logoIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.app-logo-sm {
  width: 36px;
  height: 36px;
  margin: 0 0 0.55rem;
  border-radius: 22%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
@keyframes logoIn {
  from {
    opacity: 0;
    transform: scale(0.86) translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.home-menu {
  width: min(100%, 320px);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.btn-menu {
  width: 100%;
  position: relative;
}
.updates-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: var(--tomato-glow);
  box-shadow: 0 0 0 3px rgba(239, 83, 80, 0.25);
  vertical-align: middle;
  animation: pulseDot 1.2s ease-in-out infinite;
}
@keyframes pulseDot {
  50% {
    transform: scale(1.15);
    opacity: 0.75;
  }
}

.btn-back {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--sand);
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 0;
  margin-bottom: 0.75rem;
  cursor: pointer;
}
.sm-head h1 {
  margin: 0.2rem 0 0;
  font-size: 1.35rem;
  font-family: var(--font-display);
  color: var(--sand-light);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.mode-card {
  appearance: none;
  text-align: left;
  cursor: pointer;
  padding: 1.1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid rgba(212, 180, 131, 0.22);
  background: var(--panel);
  color: inherit;
  font: inherit;
  transition: transform 0.15s ease, border-color 0.15s;
}
.mode-card:active {
  transform: scale(0.98);
}
.mode-card strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
  color: var(--sand-light);
}
.mode-card span {
  font-size: 0.88rem;
  color: rgba(243, 230, 200, 0.62);
}

.lang-field {
  border: 1px solid rgba(212, 180, 131, 0.22);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin: 0.75rem 0;
}
.lang-field legend {
  padding: 0 0.35rem;
  color: var(--sand);
  font-size: 0.85rem;
}
.radio-row,
.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.35rem 0;
  font-size: 0.95rem;
}
.field-hint {
  margin: 0.35rem 0 0.85rem;
  font-size: 0.82rem;
  line-height: 1.4;
  color: rgba(243, 230, 200, 0.55);
}

.help-block {
  margin-top: 1rem;
  padding: 1.1rem 1.15rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid rgba(212, 180, 131, 0.15);
}
.help-block h2 {
  margin: 1rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--sand);
}
.help-block h2:first-child {
  margin-top: 0;
}
.help-block ol,
.help-block p {
  margin: 0;
  color: rgba(243, 230, 200, 0.72);
  font-size: 0.92rem;
  line-height: 1.5;
}
.help-block ol {
  padding-left: 1.15rem;
}
.help-block li + li {
  margin-top: 0.3rem;
}

.changelog {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}
.changelog-card h2 {
  font-size: 0.95rem !important;
  font-family: var(--font-body) !important;
  font-weight: 500 !important;
}

.screen {
  display: none;
  animation: rise 0.55s ease both;
}
.screen.active {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.brand-mark {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--sand-light);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.brand-mark.sm {
  font-size: 1.35rem;
  margin-bottom: 0.15rem;
}

.brand h1,
.room-head h1 {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--sand);
}

.lede {
  margin: 0.65rem 0 0;
  max-width: 28ch;
  color: rgba(243, 230, 200, 0.72);
  font-size: 1rem;
  line-height: 1.45;
}

.ver-chip {
  display: inline-block;
  margin: 0.75rem 0 0;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #2a1c0e;
  background: linear-gradient(90deg, #e8d4a8, #c4a574);
}

.upgrade-card {
  margin: 1.25rem 0 0;
  padding: 1.1rem 1.15rem;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(198, 40, 40, 0.18), transparent 45%),
    linear-gradient(225deg, rgba(46, 125, 50, 0.18), transparent 50%),
    var(--panel);
  border: 1px solid rgba(232, 212, 168, 0.28);
  animation: rise 0.65s ease 0.08s both;
}
.upgrade-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}
.upgrade-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--sand-light);
}
.upgrade-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff8f0;
  background: var(--tomato);
}
.upgrade-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.upgrade-list li {
  position: relative;
  padding: 0.4rem 0 0.4rem 1.1rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: rgba(243, 230, 200, 0.78);
  border-top: 1px solid rgba(212, 180, 131, 0.12);
}
.upgrade-list li:first-child {
  border-top: none;
}
.upgrade-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.85rem;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--sand);
}
.upgrade-list strong {
  color: var(--sand-light);
  font-weight: 600;
}

.starter-label {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: rgba(243, 230, 200, 0.5);
}

.score-trays {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 0.75rem 0 0.6rem;
}
.tray {
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(212, 180, 131, 0.14);
  min-height: 3.1rem;
}
.tray-title {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(243, 230, 200, 0.5);
  margin-bottom: 0.35rem;
}
.tray-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  min-height: 1rem;
}
.tray-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  animation: popIn 0.35s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
.tomato-tray .tray-dot {
  background: radial-gradient(circle at 35% 30%, #ff8a80, var(--tomato));
}
.gourd-tray .tray-dot {
  background: radial-gradient(circle at 35% 30%, #a5d6a7, var(--gourd));
}

.eat-banner {
  position: absolute;
  left: 50%;
  top: 12%;
  z-index: 5;
  transform: translateX(-50%);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  pointer-events: none;
  background: rgba(20, 12, 6, 0.88);
  border: 1px solid rgba(232, 212, 168, 0.45);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  animation: eatPop 0.9s ease both;
}
.eat-banner.tomato-eat {
  color: #ffcdd2;
}
.eat-banner.gourd-eat {
  color: #c8e6c9;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes eatPop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.9);
  }
  18% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1.05);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px) scale(0.98);
  }
}

.fx-flyer,
.fx-victim {
  pointer-events: none;
}

.lobby-form {
  margin-top: 2rem;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid rgba(212, 180, 131, 0.18);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.lobby-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--sand);
}

input[type="text"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(212, 180, 131, 0.28);
  border-radius: 10px;
  background: rgba(20, 12, 6, 0.55);
  color: var(--cream-text);
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus {
  border-color: var(--sand);
}
input[type="text"]::placeholder {
  color: rgba(243, 230, 200, 0.35);
}

#join-code {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
  text-align: center;
}

.lobby-actions {
  margin-top: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lobby-sep {
  margin: 0.15rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(243, 230, 200, 0.4);
}

.native-only.hidden {
  display: none !important;
}
body.is-native .native-only.hidden {
  display: flex !important;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--sand);
}
.server-label input {
  margin-top: 0.15rem;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0.8rem 1.2rem;
  border-radius: 10px;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s;
}
.btn:active:not(:disabled) {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, var(--tomato-glow), var(--tomato));
  color: #fff8f0;
  box-shadow: 0 6px 0 #7f1515;
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: linear-gradient(180deg, var(--gourd-glow), var(--gourd));
  color: #f0fff2;
  box-shadow: 0 6px 0 #1b4d1e;
}

.btn-ghost {
  background: transparent;
  color: var(--sand);
  border: 1px solid rgba(212, 180, 131, 0.35);
}

.how {
  margin-top: 1.75rem;
}
.how h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--sand);
}
.how ol {
  margin: 0;
  padding-left: 1.2rem;
  color: rgba(243, 230, 200, 0.7);
  font-size: 0.92rem;
  line-height: 1.55;
}
.how li + li {
  margin-top: 0.35rem;
}

/* Room */
.room-head {
  margin-bottom: 1.5rem;
}
#room-code-display {
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  color: var(--sand-light);
}

.roster {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.seat {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid rgba(212, 180, 131, 0.15);
}
.seat strong {
  display: block;
  font-size: 1.05rem;
}
.seat .pill {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(243, 230, 200, 0.55);
}
.seat .pill.on {
  color: var(--gourd-glow);
}

.seat-piece {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
}
.seat.tomato .seat-piece {
  background: radial-gradient(circle at 35% 30%, #ff8a80, var(--tomato) 55%, #8b0000);
  box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.15);
}
.seat.gourd .seat-piece {
  background: radial-gradient(circle at 35% 30%, #a5d6a7, var(--gourd) 55%, #1b5e20);
  box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.15);
}

.room-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Game */
.game-bar {
  text-align: center;
  margin-bottom: 0.75rem;
}
.turn-label {
  margin: 0.35rem 0 0;
  font-weight: 600;
  font-size: 1.05rem;
}
.you-label {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: rgba(243, 230, 200, 0.55);
}

.board-wrap {
  position: relative;
  margin: 0 auto;
  width: min(100%, 420px);
  aspect-ratio: 1;
  animation: boardIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes boardIn {
  from {
    opacity: 0;
    transform: scale(0.92) rotate(-2deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#board {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.45));
  touch-action: manipulation;
}

.node-hit {
  fill: transparent;
  cursor: pointer;
}
.node-ring {
  fill: none;
  stroke: rgba(61, 42, 22, 0.45);
  stroke-width: 0.6;
  pointer-events: none;
}

.piece {
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform-box: fill-box;
  transform-origin: center;
}
.piece.selected {
  transform: scale(1.18);
}
.piece.tomato-piece circle.skin {
  fill: url(#tomatoFill);
}
.piece.gourd-piece circle.skin {
  fill: url(#gourdFill);
}

.hint-dot {
  fill: rgba(255, 248, 220, 0.55);
  stroke: rgba(255, 248, 220, 0.9);
  stroke-width: 0.4;
  pointer-events: none;
  animation: pulse 1.1s ease-in-out infinite;
}
.hint-capture {
  fill: rgba(239, 83, 80, 0.45);
  stroke: #ffcdd2;
  stroke-width: 0.5;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
    r: 2.2;
  }
  50% {
    opacity: 1;
    r: 2.8;
  }
}

.status-msg {
  text-align: center;
  min-height: 1.4em;
  margin: 0.85rem 0 0;
  font-size: 0.95rem;
  color: var(--sand);
}

.end-panel {
  margin-top: 1rem;
  padding: 1.1rem;
  text-align: center;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid rgba(212, 180, 131, 0.2);
  animation: rise 0.4s ease both;
}
.end-panel p {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
}
.end-panel .btn + .btn {
  margin-top: 0.55rem;
  width: 100%;
}
.end-panel .btn-primary {
  width: 100%;
}
.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.7rem 1.1rem;
  max-width: min(90vw, 360px);
  background: #1a1208;
  border: 1px solid rgba(212, 180, 131, 0.35);
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: rise 0.3s ease both;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(10, 7, 3, 0.65);
  backdrop-filter: blur(2px);
  animation: rise 0.2s ease both;
}
.modal-card {
  width: min(420px, 100%);
  padding: 1.5rem 1.4rem;
  background: #241709;
  border: 1px solid rgba(212, 180, 131, 0.3);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-card h2 {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--sand-light);
}
.modal-card p {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: rgba(243, 230, 200, 0.85);
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.advanced-block {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid rgba(212, 180, 131, 0.2);
  background: rgba(20, 14, 8, 0.35);
  color: rgba(243, 230, 200, 0.75);
}
.advanced-block summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--sand);
  margin-bottom: 0.5rem;
}
.advanced-block[open] summary {
  margin-bottom: 0.75rem;
}

.last-move-from,
.last-move-to {
  animation: flash 0.6s ease;
}
@keyframes flash {
  from {
    stroke: #fff3c4;
    stroke-width: 1.4;
  }
}

@media (max-width: 420px) {
  #app {
    padding: 1.1rem 0.9rem 2.5rem;
  }
  .brand-mark {
    font-size: 2.2rem;
  }
}
