:root {
  --garden-grass: #88915d;
  --garden-grass-dark: #52623f;
  --garden-stone: #8b7553;
  --garden-stone-light: #c7ae80;
  --garden-gravel: #d3ad72;
  --garden-gravel-light: #ead2a2;
  --garden-linen: #f4e4c2;
  --garden-ink: #3a2b1e;
  --garden-gold: #e6b74f;
}

html,
body {
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #d9bd86;
}

body {
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--garden-ink);
}

button,
[role="slider"] {
  -webkit-tap-highlight-color: transparent;
}

.game-page,
#activity-root {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

#activity-root {
  position: relative;
}

.app-error {
  position: fixed;
  inset: 50% auto auto 50%;
  width: min(88vw, 520px);
  margin: 0;
  padding: 20px;
  border: 3px solid #8a552c;
  border-radius: 20px;
  background: #fff8e6;
  color: #3d3226;
  text-align: center;
  transform: translate(-50%, -50%);
  z-index: 100;
}

.app-loading {
  position: fixed;
  inset: 50% auto auto 50%;
  margin: 0;
  padding: 14px 22px;
  border: 2px solid rgba(138, 85, 44, 0.58);
  border-radius: 999px;
  background: #fff8e6;
  color: #3d3226;
  font-weight: 600;
  transform: translate(-50%, -50%);
  z-index: 100;
}

.game-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.garden-board {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(3px, 0.65vmin, 7px);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 2px;
  overflow: hidden;
  isolation: isolate;
}

.garden-goals {
  position: relative;
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: clamp(6px, 1.4vmin, 14px);
  min-width: 0;
}

.garden-goal {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  min-width: 0;
  padding: 3px 11px 3px 4px;
  border: 1px solid rgba(78, 67, 42, 0.48);
  border-radius: 9px 7px 10px 6px;
  background:
    linear-gradient(100deg, rgba(255, 250, 232, 0.96), rgba(235, 216, 176, 0.94));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 3px 0 rgba(85, 55, 30, 0.16);
  color: #433723;
  font-size: clamp(11px, 1.7vmin, 15px);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.garden-goal img {
  display: block;
  width: clamp(26px, 4.2vmin, 36px);
  height: clamp(26px, 4.2vmin, 36px);
  max-width: none;
  max-height: none;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(61, 38, 18, 0.2));
}

.garden-map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 18px 13px 20px 12px;
  background:
    radial-gradient(ellipse at center, transparent 52%, rgba(47, 58, 34, 0.2) 100%),
    linear-gradient(140deg, rgba(158, 163, 103, 0.12), rgba(107, 120, 75, 0.16)),
    url("./assets/garden-ground-v2.webp") center / cover no-repeat,
    url("./assets/garden-ground.webp") center / cover no-repeat;
  box-shadow:
    inset 0 0 0 1px rgba(70, 78, 48, 0.3),
    inset 0 9px 24px rgba(53, 57, 31, 0.13),
    inset 0 -8px 24px rgba(39, 50, 31, 0.1);
}

.garden-map-stage::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 24px 8px rgba(52, 62, 35, 0.12);
  content: "";
  pointer-events: none;
}

.garden-map {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.garden-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.path-grass {
  stroke: #62724b;
  stroke-width: var(--path-grass, 28);
  opacity: 0.34;
  filter: blur(2px);
}

.path-stones {
  stroke: #8b7553;
  stroke-width: var(--path-stones, 22);
  opacity: 0.88;
}

.path-gravel {
  stroke: #d3ad72;
  stroke: url("#garden-gravel-texture");
  stroke-width: var(--path-gravel, 16);
}

.gravel-pattern-base {
  fill: #d3ad72;
}

.gravel-pattern-image {
  opacity: 0.78;
}

.garden-route-trace .route-ribbon {
  fill: none;
  stroke: #f1c65b;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.88;
  filter: drop-shadow(0 0 5px rgba(255, 230, 140, 0.75));
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: garden-route-draw 700ms cubic-bezier(0.22, 0.78, 0.22, 1) forwards;
}

.garden-path.is-frontier.path-grass {
  stroke: #b97731;
}

.garden-path.is-frontier.path-stones {
  stroke: #bd8843;
}

.map-gate {
  transition: opacity 160ms ease-out;
}

.gate-raster {
  filter: drop-shadow(0 4px 3px rgba(42, 27, 17, 0.3));
}

.map-gate.is-closed .gate-raster {
  filter: drop-shadow(0 5px 4px rgba(42, 27, 17, 0.38)) saturate(0.9);
}

.map-gate.is-open .gate-raster {
  transform: scale(0.9);
  transform-box: fill-box;
  transform-origin: center;
}

.map-gate.is-frontier .gate-symbol-disc {
  stroke: #f3b84b;
  stroke-width: 5;
}

.gate-symbol-disc {
  fill: #f4e2b9;
  stroke: var(--pair-color);
  stroke-width: 2.5;
  filter: drop-shadow(0 3px 2px rgba(48, 33, 19, 0.28));
}

.gate-sign-pin {
  fill: #7b5a34;
  stroke: #f2d49a;
  stroke-width: 0.6;
}

.gate-symbol-fill {
  fill: var(--pair-color);
}

.gate-symbol-stroke,
.gate-symbol-badge path:not(.gate-symbol-fill) {
  fill: none;
  stroke: var(--pair-ink);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gate-symbol-badge .gate-symbol-fill + .gate-symbol-stroke {
  stroke: var(--pair-ink);
}

.target-prop {
  filter: drop-shadow(0 7px 4px rgba(48, 33, 19, 0.25));
}

.prop-shadow {
  fill: rgba(42, 54, 31, 0.28);
  filter: blur(4px);
}

.prop-shadow--gubo {
  fill: rgba(42, 54, 31, 0.24);
}

.target-table {
  transform-box: fill-box;
  transform-origin: center;
}

.target-crop {
  transform-box: fill-box;
  transform-origin: center;
}

.garden-gubo {
  filter: drop-shadow(0 8px 7px rgba(48, 33, 19, 0.25));
}

.garden-board.is-success .target-table {
  animation: garden-table-pop 420ms cubic-bezier(0.22, 0.9, 0.3, 1.2) both;
}

.success-sparkle {
  fill: #f6d36f;
  stroke: #fff8e6;
  stroke-width: 2;
  animation: garden-sparkle 620ms ease-out both;
}

.success-sparkle-2 {
  animation-delay: 110ms;
}

.success-sparkle-3 {
  animation-delay: 220ms;
}

.switch-dock {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(var(--switch-count, 2), minmax(96px, 1fr));
  gap: clamp(5px, 1vw, 12px);
  min-width: 0;
}

.switch-dock:has(.switch-pair:nth-child(3)) {
  --switch-count: 3;
}

.switch-pair {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 4px;
  min-width: 0;
  padding: 5px 8px 7px;
  border: 1px solid #4d2e18;
  border-radius: 13px 9px 12px 8px;
  background:
    radial-gradient(circle at 14% 20%, rgba(255, 222, 160, 0.18) 0 2px, transparent 3px),
    repeating-linear-gradient(96deg, rgba(255, 221, 157, 0.06) 0 2px, transparent 2px 17px),
    linear-gradient(162deg, #9d693a 0%, #724624 48%, #5e381f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 228, 173, 0.34),
    inset 0 -3px 0 rgba(55, 31, 14, 0.32),
    0 4px 8px rgba(55, 37, 23, 0.22);
}

.switch-pair::after {
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255, 224, 166, 0.13);
  border-radius: 10px 7px 9px 6px;
  content: "";
  pointer-events: none;
}

.switch-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding-inline: 15px;
  color: #ffefcf;
  font-size: clamp(11px, 1.5vmin, 14px);
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(45, 24, 10, 0.7);
}

.switch-heading .gate-pair-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: #fff4d8;
  border-radius: 50%;
}

.pair-symbol {
  width: clamp(18px, 2.7vmin, 24px);
  height: clamp(18px, 2.7vmin, 24px);
  flex: 0 0 auto;
}

.switch-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.switch-slider {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  min-width: 0;
  min-height: 48px;
  margin-top: 2px;
  overflow: hidden;
  border: 2px solid #442817;
  border-radius: 10px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(236, 194, 121, 0.14), transparent 58%),
    linear-gradient(180deg, #50351f, #2f2116);
  box-shadow:
    inset 0 5px 9px rgba(25, 15, 9, 0.6),
    inset 0 -1px 0 rgba(255, 224, 165, 0.18),
    0 1px 0 rgba(255, 229, 177, 0.18);
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
}

.switch-slider::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 222, 160, 0.12) 0 1px, transparent 1px 12px);
  box-shadow: inset 0 0 0 1px rgba(25, 15, 9, 0.28);
  pointer-events: none;
}

.switch-slider:focus-visible {
  outline: 4px solid #8d6197;
  outline-offset: 3px;
}

.switch-slider[aria-disabled="true"] {
  cursor: default;
  opacity: 0.72;
}

.switch-half {
  position: relative;
  z-index: 2;
  align-self: stretch;
  display: grid;
  place-items: center;
  min-width: 0;
  color: rgba(255, 239, 207, 0.48);
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 1px rgba(30, 17, 8, 0.8);
  pointer-events: none;
}

.switch-half--left {
  padding-right: 34%;
}

.switch-half--right {
  padding-left: 34%;
}

.switch-handle {
  position: absolute;
  inset: 4px auto 4px 4px;
  z-index: 3;
  width: calc(50% - 4px);
  border: 1px solid #563419;
  border-radius: 7px;
  background:
    radial-gradient(circle at 22% 50%, #70441f 0 1.5px, transparent 2px),
    radial-gradient(circle at 78% 50%, #70441f 0 1.5px, transparent 2px),
    radial-gradient(ellipse at 50% 20%, rgba(255, 248, 220, 0.5), transparent 38%),
    linear-gradient(90deg, #b8783e, #e4b36a 43%, #f1ca83 58%, #9b5f31);
  box-shadow:
    0 4px 5px rgba(30, 17, 8, 0.44),
    inset 0 1px 0 rgba(255, 247, 218, 0.58),
    inset 0 -2px 0 rgba(93, 51, 24, 0.28);
  pointer-events: none;
  transition: transform 180ms cubic-bezier(0.22, 0.82, 0.3, 1.08);
}

.switch-handle::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 4px;
  border-radius: 999px;
  background: #72451f;
  box-shadow:
    inset 0 1px 2px rgba(36, 20, 8, 0.7),
    0 1px 0 rgba(255, 239, 195, 0.45);
  content: "";
  transform: translate(-50%, -50%);
}

.switch-slider.is-right .switch-handle {
  transform: translateX(100%);
}

.switch-slider.is-right .switch-half--right,
.switch-slider.is-left .switch-half--left {
  color: #fff8e6;
}

.switch-slider.is-dragging .switch-handle {
  transition: none;
  filter: brightness(1.06);
  transform: translateX(var(--drag-offset, 0px));
}

.garden-ambient {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(ellipse at 8% 15%, rgba(48, 66, 34, 0.1), transparent 19%),
    radial-gradient(ellipse at 92% 85%, rgba(48, 66, 34, 0.08), transparent 22%);
}

.garden-board.is-suspended * {
  animation-play-state: paused !important;
}

.garden-hand {
  position: fixed;
  z-index: 34;
  width: clamp(52px, 8vmin, 74px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 6px 7px rgba(42, 27, 17, 0.3));
  transform: translate(-12%, -50%);
  transition: left 220ms ease-out, top 220ms ease-out, opacity 120ms ease-out;
}

.garden-hand[hidden] {
  display: none !important;
}

@keyframes garden-route-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes garden-table-pop {
  0% { transform: scale(1); }
  54% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes garden-sparkle {
  0% { opacity: 0; transform: scale(0.5); }
  45% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.22); }
}

@media (max-width: 430px) {
  .garden-board {
    gap: 3px;
    padding: 0;
  }

  .garden-goal {
    gap: 3px;
    min-height: 30px;
    padding: 2px 7px 2px 3px;
    border-width: 1px;
    font-size: 11px;
  }

  .garden-goal img {
    width: 25px;
    height: 25px;
  }

  .switch-dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .switch-dock:has(.switch-pair:nth-child(3)) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px;
  }

  .switch-dock:has(.switch-pair:nth-child(3)) .switch-pair {
    padding-inline: 0;
  }

  .switch-pair {
    padding: 3px 4px 5px;
    border-width: 1px;
  }

  .switch-heading {
    font-size: 10px;
  }

  .pair-symbol {
    width: 16px;
    height: 16px;
  }

  .switch-slider {
    min-height: 48px;
  }

  .map-gate.is-open .gate-raster {
    transform: none;
  }
}

@media (max-height: 520px) {
  .garden-board {
    gap: 2px;
  }

  .garden-goals {
    gap: 5px;
  }

  .garden-goal {
    min-height: 28px;
    padding-block: 1px;
    font-size: 10px;
  }

  .garden-goal img {
    width: 23px;
    height: 23px;
  }

  .switch-pair {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 1fr;
    align-items: center;
    padding: 3px 5px;
  }

  .switch-heading {
    justify-content: flex-start;
  }

  .switch-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .switch-slider {
    min-height: 48px;
    margin: 0;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .garden-board {
    grid-template-columns: minmax(0, 1fr) clamp(190px, 28vw, 250px);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .garden-goals {
    grid-row: 1;
    grid-column: 2;
  }

  .garden-map-stage {
    grid-row: 1 / -1;
    grid-column: 1;
  }

  .switch-dock {
    grid-row: 2;
    grid-column: 2;
    grid-template-columns: minmax(0, 1fr);
    align-self: stretch;
    align-content: end;
    gap: 2px;
  }

  .switch-pair {
    min-height: 48px;
    padding-block: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .garden-route-trace .route-ribbon,
  .garden-board.is-success .target-table,
  .success-sparkle {
    animation: none;
  }

  .garden-route-trace .route-ribbon {
    stroke-dashoffset: 0;
  }

  .success-sparkle {
    opacity: 0.8;
  }

  .switch-handle,
  .garden-hand {
    transition: none;
  }
}

@media (forced-colors: active) {
  .switch-slider:focus-visible {
    outline-color: Highlight;
  }

  .map-gate.is-closed {
    forced-color-adjust: none;
  }
}
