:root {
  --sky: #aed9ff;
  --hud-bg: rgba(14, 24, 32, 0.72);
  --hud-bg-strong: rgba(12, 20, 28, 0.88);
  --hud-border: rgba(255, 255, 255, 0.2);
  --hud-text: #f4f7fb;
  --hud-muted: #c8d4e4;
  --accent: #89d9a2;
  --accent-strong: #6dc78a;
  --warn: #ffd26f;
  --danger: #cf4c5a;
  --panel-shadow: 0 10px 24px rgba(3, 10, 16, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  background: var(--sky);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  color: var(--hud-text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.25px;
  z-index: 2;
}

#debug {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  color: var(--hud-text);
  font-size: 12px;
  z-index: 2;
}

#wallet {
  position: absolute;
  top: 52px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  color: var(--hud-text);
  font-size: 12px;
  font-weight: 700;
  z-index: 2;
}

#walletMsg {
  position: absolute;
  top: 124px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(145, 28, 38, 0.92);
  border: 1px solid rgba(255, 210, 210, 0.4);
  color: #ffe8ec;
  font-size: 12px;
  font-weight: 800;
  z-index: 4;
  display: none;
  text-align: center;
  max-width: min(90vw, 480px);
  pointer-events: none;
}

#walletMsg.msg-pop {
  animation: msgPop 220ms ease-out;
}

#visitorBadge {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 210, 111, 0.95);
  border: 1px solid rgba(60, 45, 0, 0.25);
  box-shadow: 0 8px 18px rgba(95, 66, 0, 0.28);
  color: #2b1b00;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
  display: none;
  z-index: 3;
  text-align: center;
  cursor: pointer;
}

#visitorBadge.badge-ready {
  animation: badgePulse 1.3s ease-in-out infinite;
}
#resetBtn {
  position: absolute;
  top: 52px;
  left: 12px;
  right: auto;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-bg);
  color: var(--hud-text);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  font-size: 12px;
  z-index: 2;
}

#placeHouseBtn {
  position: absolute;
  top: 116px;
  left: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--accent);
  color: #1b2430;
  border: 1px solid var(--accent-strong);
  box-shadow: var(--panel-shadow);
  font-size: 12px;
  z-index: 3;
  display: none;
}

#placeHouseBtn:hover {
  background: var(--accent-strong);
}

#placeHouseBtn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

#utilityMenu {
  position: absolute;
  top: 84px;
  left: 12px;
  z-index: 3;
}

#utilityMenuBtn {
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-bg);
  color: var(--hud-text);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  font-size: 12px;
  font-weight: 700;
}

#utilityMenuBtn:hover {
  background: rgba(255,255,255,0.18);
}

#utilityMenuPanel {
  display: none;
  margin-top: 6px;
  min-width: 130px;
  padding: 6px;
  border-radius: 12px;
  background: var(--hud-bg-strong);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(6px);
  gap: 6px;
}

#utilityMenu.open #utilityMenuPanel {
  display: grid;
}

.utility-item {
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12);
  color: var(--hud-text);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.utility-item:hover {
  background: rgba(255,255,255,0.18);
}

#audioMuteBtn.muted {
  background: rgba(207, 76, 90, 0.28);
  border-color: rgba(238, 150, 160, 0.45);
}

.help-body {
  display: grid;
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
  overflow-y: auto;
  padding-right: 6px;
  max-height: 60vh;
}

.help-topic {
  font-weight: 800;
  font-size: 14px;
  display: block;
  letter-spacing: 0.2px;
  margin-bottom: 2px;
}

.help-item {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.help-item:nth-child(even) {
  background: rgba(123, 211, 137, 0.12);
}

.help-text {
  display: block;
  font-size: 12px;
  color: #e2e7ef;
}

#helpModal {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 10, 14, 0.5);
  z-index: 4;
}

#quickStartModal {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 10, 14, 0.72);
  z-index: 8;
}

.quickstart-card {
  width: min(620px, 94vw);
  max-height: 85vh;
}

.quickstart-body {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  max-height: 66vh;
  padding-right: 6px;
}

.quick-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
  line-height: 1.45;
}

.quick-item:nth-child(even) {
  background: rgba(123, 211, 137, 0.16);
}

.quick-topic {
  font-weight: 900;
  font-size: 15px;
  color: #fff2b8;
}
#resetBtn:hover {
  background: rgba(255,255,255,0.15);
}

#tierStatus {
  position: absolute;
  top: 86px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(4px);
  color: var(--hud-text);
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-line;
  width: fit-content;
  z-index: 2;
  max-width: min(60vw, 220px);
}

#tierStatus::first-line {
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.2px;
}

#worldOverlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.garden-ring {
  position: absolute;
  width: 40px;
  height: 40px;
}

.garden-ring svg {
  width: 40px;
  height: 40px;
}

.garden-ring .ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.25);
  stroke-width: 3;
}

.garden-ring .ring-fill {
  fill: none;
  stroke: #7bd389;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 97;
  stroke-dashoffset: 97;
  transition: stroke-dashoffset 0.15s linear;
}

.stable-care-icon {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 210, 111, 0.95);
  color: #2b1b00;
  font-size: 14px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.horse-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

#selectorPanel {
  position: absolute;
  left: 50%;
  bottom: 68px;
  transform: translateX(-50%);
  background: var(--hud-bg-strong);
  color: var(--hud-text);
  border-radius: 16px;
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(6px);
  padding: 10px;
  display: none;
  z-index: 2;
  min-width: 260px;
  touch-action: pan-y;
}

.panel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.panel-row:last-child {
  margin-bottom: 0;
}

.panel-btn {
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.12);
  color: var(--hud-text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.panel-btn.active {
  background: var(--warn);
  color: #1b2430;
  border-color: var(--warn);
}

.panel-btn.danger {
  background: rgba(255, 90, 90, 0.2);
  border-color: rgba(255, 90, 90, 0.6);
}

.panel-btn.sell-btn {
  background: rgba(102, 201, 128, 0.22);
  border-color: rgba(102, 201, 128, 0.65);
}

.panel-btn.sell-btn.active {
  background: rgba(121, 224, 146, 0.35);
  border-color: rgba(121, 224, 146, 0.95);
  color: #eef9f1;
}

.panel-btn.disabled {
  opacity: 0.5;
}

.build-row .panel-btn.build-g1:not(.active):not(.danger) {
  background: rgba(176, 139, 98, 0.2);
  border-color: rgba(219, 189, 156, 0.38);
}

.build-row .panel-btn.build-g2:not(.active):not(.danger) {
  background: rgba(205, 176, 72, 0.24);
  border-color: rgba(244, 222, 138, 0.5);
}

.build-row .panel-btn.build-g3:not(.active):not(.danger) {
  background: rgba(107, 167, 104, 0.2);
  border-color: rgba(166, 219, 154, 0.4);
}

.build-row .panel-btn.build-g4:not(.active):not(.danger) {
  background: rgba(186, 167, 95, 0.22);
  border-color: rgba(231, 216, 150, 0.46);
}

.build-row .panel-btn.build-g5:not(.active):not(.danger) {
  background: rgba(124, 137, 152, 0.2);
  border-color: rgba(181, 191, 206, 0.4);
}

.market-row .panel-btn.market-g1:not(.active):not(.sell-btn) {
  background: rgba(150, 102, 65, 0.26);
  border-color: rgba(212, 165, 128, 0.5);
}

.market-row .panel-btn.market-g2:not(.active):not(.sell-btn) {
  background: rgba(209, 127, 60, 0.25);
  border-color: rgba(245, 176, 110, 0.5);
}

.market-row .panel-btn.market-g3:not(.active):not(.sell-btn) {
  background: rgba(117, 141, 160, 0.22);
  border-color: rgba(174, 197, 218, 0.42);
}

.decor-row .panel-btn.deco-g1:not(.active) {
  background: rgba(176, 139, 98, 0.2);
  border-color: rgba(219, 189, 156, 0.38);
}

.decor-row .panel-btn.deco-g2:not(.active) {
  background: rgba(114, 174, 222, 0.2);
  border-color: rgba(174, 216, 248, 0.42);
}

.decor-row .panel-btn.deco-g3:not(.active) {
  background: rgba(107, 167, 104, 0.2);
  border-color: rgba(166, 219, 154, 0.4);
}

.decor-row .panel-btn.deco-g4:not(.active) {
  background: rgba(180, 156, 124, 0.2);
  border-color: rgba(220, 198, 166, 0.4);
}

.decor-row .panel-btn.deco-g5:not(.active) {
  background: rgba(124, 137, 152, 0.2);
  border-color: rgba(181, 191, 206, 0.4);
}

.decor-row .panel-btn[data-market="buyBow"]:not(.active),
.decor-row .panel-btn[data-market="buySticker"]:not(.active) {
  background: rgba(209, 127, 60, 0.25);
  border-color: rgba(245, 176, 110, 0.5);
}

.panel-label {
  padding: 10px 6px;
  font-size: 12px;
}

.panel-label.market-stats {
  width: 100%;
  padding: 8px 6px 2px;
  white-space: nowrap;
  font-weight: 700;
  font-size: 12px;
  opacity: 0.95;
}

#bottomBar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 8px;
  background: var(--hud-bg-strong);
  border-radius: 16px;
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(6px);
  z-index: 2;
  width: min(96vw, 760px);
  max-width: min(96vw, 760px);
}

.mode-btn {
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.12);
  color: var(--hud-text);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  min-height: 40px;
  min-width: 102px;
  text-align: center;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--accent);
  color: #1b2430;
  border-color: var(--accent-strong);
}

.mode-btn:disabled,
.mode-btn.disabled {
  opacity: 0.5;
}

.undo-btn {
  background: rgba(255, 210, 111, 0.4);
  border-color: rgba(255, 210, 111, 0.9);
}

.undo-btn:disabled {
  opacity: 0.45;
}

.lock-btn.lock-on {
  background: #2a9459;
  border-color: #2a9459;
  color: #e9fff2;
}

.lock-btn.lock-off {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff2f2;
}

#horseMenu {
  position: absolute;
  right: 12px;
  bottom: 76px;
  width: 190px;
  padding: 10px;
  background: var(--hud-bg-strong);
  color: var(--hud-text);
  border-radius: 14px;
  border: 1px solid var(--hud-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(6px);
  display: none;
  z-index: 3;
}

#horseMenuName {
  font-weight: 800;
}

#horseMenuHeart {
  font-size: 14px;
  color: #ff6b6b;
}

#horseMenu button {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.14);
  color: var(--hud-text);
  font-weight: 700;
}

#horseMenu button.secondary {
  background: rgba(255,255,255,0.02);
}

#horseMenuNote {
  margin-top: 6px;
  font-size: 11px;
  color: #cbd7e6;
}

#horseMenuCarrots {
  margin-top: 6px;
  font-size: 11px;
  color: #d7e3f1;
}

#horseMenuBar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
  overflow: hidden;
}

#horseMenuBarFill {
  height: 100%;
  width: 0%;
  background: #ffd26f;
}

.horse-float {
  position: absolute;
  width: 72px;
  height: 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.44);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.35);
  display: grid;
  place-items: center;
}

.horse-float-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  position: absolute;
  left: 0;
  top: 0;
}

.horse-float-label {
  position: relative;
  z-index: 1;
  font-size: 10px;
  color: #f5f7fb;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

#horseBuyModal,
#bowBuyModal,
#stickerBuyModal {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 10, 14, 0.5);
  z-index: 4;
}

.warning-icon {
  position: absolute;
  top: -14px;
  right: -10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffd26f;
  color: #3b2a00;
  font-weight: 900;
  font-size: 12px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  animation: warnPulse 1.1s ease-in-out infinite;
}

#criticalModal {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 10, 14, 0.6);
  z-index: 5;
}

#criticalBody {
  font-size: 12px;
  line-height: 1.4;
  margin-bottom: 10px;
}

#criticalNote {
  margin-top: 8px;
  font-size: 11px;
  color: #cbd7e6;
}

#centerMsg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(20, 30, 40, 0.9);
  color: #f4f7fb;
  font-size: 16px;
  font-weight: 800;
  display: none;
  z-index: 6;
  text-align: center;
}
.modal-card {
  width: min(320px, 90vw);
  background: var(--hud-bg-strong);
  color: #f4f7fb;
  border: 1px solid var(--hud-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  padding: 14px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-title {
  font-weight: 800;
  margin-bottom: 10px;
}

.modal-label {
  font-size: 12px;
  margin-top: 8px;
}

#horseNameInput {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #f4f7fb;
}

.color-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.color-btn {
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #f4f7fb;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
}

.color-btn.active {
  background: #7bd389;
  color: #1b2430;
  border-color: #7bd389;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.modal-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.12);
  color: #f4f7fb;
  font-weight: 700;
}

.modal-actions button.secondary {
  background: rgba(255,255,255,0.03);
}

#horseBuyNote,
#bowBuyNote,
#stickerBuyNote {
  margin-top: 8px;
  font-size: 11px;
  color: #cbd7e6;
}

@keyframes msgPop {
  0% { transform: translateX(-50%) translateY(6px) scale(0.96); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

@keyframes badgePulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.04); }
}

@keyframes warnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@media (max-width: 1024px) {
  #selectorPanel {
    bottom: 138px;
    max-width: 94vw;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  #bottomBar {
    width: calc(100vw - 12px);
    max-width: calc(100vw - 12px);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
  }
  .mode-btn {
    min-width: 0;
    width: 100%;
    padding: 8px 6px;
    font-size: 11px;
    min-height: 34px;
  }
}

@media (max-width: 480px) {
  #hud { font-size: 15px; }
  #debug { font-size: 11px; }
  #selectorPanel {
    min-width: 220px;
    bottom: 148px;
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .panel-btn { padding: 9px 10px; font-size: 11px; }
  .panel-label.market-stats { font-size: 11px; }
  .mode-btn { padding: 8px 5px; font-size: 10px; }
  #horseMenu { width: 170px; bottom: 68px; }
  #utilityMenu { top: 84px; }
  #utilityMenuPanel { min-width: 120px; }
  .utility-item { font-size: 11px; }
}
