:root {
  --paper: #f3ead6;
  --ink: #2b261f;
  --line: #1a1714;
  --blue: #3a9be8;
  --card: #fff8ea;
  --phone-w: 390px;
  --phone-h: 844px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "ZCOOL XiaoWei", "PingFang SC", "Hiragino Maru Gothic ProN", serif;
  color: var(--ink);
  background: #cbb892;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 6px 0;
}

.phone {
  position: relative;
  width: min(var(--phone-w), 100vw);
  height: auto;
  max-height: 100dvh;
  background:
    radial-gradient(circle at 14% 8%, #fff6e4 0 12%, transparent 13%),
    linear-gradient(#f6edd8, #efe3c6);
  border: 3px solid #3d3428;
  border-radius: 26px;
  box-shadow: 0 14px 34px rgba(40, 30, 10, 0.28);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

/* ---- 背景小装饰 ---- */
.sky {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 0;
}
.star {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #f0c24a;
  opacity: 0.85;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.s1 { top: 10px; left: 13%; }
.s2 { top: 34px; left: 22%; transform: scale(0.65); }
.s3 { top: 12px; right: 24%; transform: scale(0.8); }
.s4 { top: 36px; right: 15%; transform: scale(0.6) rotate(18deg); }
.sprout {
  position: absolute;
  bottom: 5px;
  width: 10px;
  height: 15px;
  background: #7cbc4a;
  border-radius: 10px 10px 2px 2px;
  opacity: 0.6;
}
.p1 { left: 5%; }
.p2 { right: 6%; transform: rotate(-12deg); }

.top, .stage, .panels, .tip { position: relative; z-index: 1; }

/* ---- 顶栏 ---- */
.top {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 2px;
}

.gear {
  width: 30px;
  height: 30px;
  border: 2px solid #c9bba0;
  border-radius: 50%;
  background: #efe6d2;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 0 #d8cbb0;
  padding: 0;
}

.brand { text-align: center; min-width: 0; }
h1 {
  margin: 0;
  font-family: "ZCOOL KuaiLe", "ZCOOL XiaoWei", sans-serif;
  font-size: 23px;
  letter-spacing: 0.03em;
  line-height: 1.1;
  background: linear-gradient(90deg, #3a9be8 0 28%, #6ec8ff 36%, #ff9ec0 72%, #ef7aa8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  position: relative;
  display: inline-block;
}
.drop {
  position: absolute;
  width: 8px;
  height: 11px;
  background: #5eb6ff;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  top: 3px;
}
.d-left { left: -11px; transform: rotate(-20deg); }
.d-right { right: -9px; background: #ff9ec0; transform: rotate(16deg); }

.tag {
  display: inline-block;
  margin: 2px 0 0;
  padding: 1px 8px 2px;
  background: #ead9b3;
  border: 1.5px solid #c9b48a;
  border-radius: 999px;
  font-size: 9.5px;
  color: #6a5b42;
  white-space: nowrap;
}

.top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
.score-pill {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #fff7e4;
  border: 2px solid #e0c48a;
  border-radius: 999px;
  padding: 0 7px 1px;
  font-size: 12.5px;
  font-weight: 700;
}
.star-ico { color: #f0c24a; }
.reset-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 2px solid #d9a21a;
  background: linear-gradient(#ffe27a, #f3c14a);
  color: #6a4a10;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10.5px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 0 #d9a21a;
  white-space: nowrap;
}
.reset-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #d9a21a; }

/* ---- 迷宫 ---- */
.stage {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 10px 0;
}

.maze-inner {
  position: relative;
  width: min(100%, calc(100dvh - 344px));
  aspect-ratio: 1;
  background: #f7eed8;
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 7px 7px 12px;
  box-shadow: 0 5px 0 rgba(40, 30, 10, 0.1);
}

#view {
  display: block;
  width: 100%;
  height: auto;
  background: #fbf6ea;
  border-radius: 3px;
}

.lawn {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 3px;
  height: 7px;
  background: repeating-linear-gradient(90deg, #7cbc4a 0 7px, #6aaa3d 7px 12px);
  clip-path: polygon(0 60%, 8% 0, 16% 70%, 28% 10%, 40% 80%, 55% 0, 70% 75%, 85% 8%, 100% 65%, 100% 100%, 0 100%);
}

/* ---- 仪表条 ---- */
.readout {
  width: 100%;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gauge {
  display: flex;
  align-items: baseline;
  gap: 4px;
  background: #fff7e4;
  border: 2px solid #e0c48a;
  border-radius: 999px;
  padding: 1px 10px 2px 8px;
  font-size: 11px;
  color: #6a5b42;
  white-space: nowrap;
}
.gauge .ico { align-self: center; }
.gauge b {
  font-size: 15px;
  color: #1d4f86;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.gauge-unit { font-size: 10px; color: #8a7a5e; }

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 9px 3px;
  font-size: 10.5px;
  white-space: nowrap;
  border: 1.5px solid #cfc3a8;
  background: #efe6d2;
  color: #7a6f57;
}
.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.chip.flowing {
  border-color: #9fd0f5;
  background: #e8f5ff;
  color: #1d6fbf;
}
.chip.flowing::before { animation: blip 1s ease-in-out infinite; }
.chip.done {
  border-color: #9adcae;
  background: #e6f9ec;
  color: #2c7d47;
}
@keyframes blip { 50% { opacity: 0.25; transform: scale(0.7); } }

#status {
  width: 100%;
  margin: 3px 0 0;
  min-height: 16px;
  color: var(--blue);
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- 控制面板 ---- */
.panels {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px 10px 0;
  align-items: stretch;
}

.panel {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(40, 30, 10, 0.1);
  display: flex;
  flex-direction: column;
}
.panel h2 {
  margin: 0;
  padding: 4px 8px 5px;
  text-align: center;
  font-size: 12.5px;
  color: #fff;
}
.tap-panel h2 { background: #3a9be8; }
.dye-panel h2 { background: #8b5cf0; }
.panel-body {
  flex: 1 1 auto;
  padding: 7px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
}

.tap-btn, .dye-btn {
  cursor: pointer;
  font-family: inherit;
  border-radius: 10px;
}
.tap-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px solid #1d4f86;
  background: #e8f5ff;
  padding: 2px 14px 3px;
  color: #1d4f86;
  font-size: 12px;
}
.tap-btn.on { background: #4aa3f0; color: #fff; }
.slider {
  width: 100%;
  display: grid;
  gap: 0;
  font-size: 10.5px;
  color: #4a5d78;
}
.slider.speed { color: #3d7a4a; }
.slider input {
  width: 100%;
  height: 15px;
  margin: 0;
  accent-color: #3a9be8;
}
.slider.speed input { accent-color: #5dce5a; }
.ico { display: inline-block; width: 8px; height: 10px; margin-left: 3px; vertical-align: -1px; }
.drop-ico { background: #3a9be8; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.clock-ico { width: 10px; height: 10px; border: 2px solid #3d7a4a; border-radius: 50%; }

.bottles {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.bottle {
  width: 18px;
  height: 30px;
  border: 1.5px solid #333;
  border-radius: 3px 3px 6px 6px;
  padding: 0;
  background:
    linear-gradient(#fff 0 6px, transparent 6px),
    linear-gradient(var(--dye), var(--dye));
  background-size: 8px 6px, 100% 100%;
  background-position: center 0, 0 7px;
  background-repeat: no-repeat;
  cursor: pointer;
  box-shadow: inset 0 -10px 0 rgba(0,0,0,0.08);
}
.bottle.on { outline: 2px solid #8b5cf0; outline-offset: 1px; }
.dye-state {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: #6b5a86;
  white-space: nowrap;
}
.dye-state::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid rgba(40, 30, 60, 0.45);
  background: var(--tap, #2f86e6);
}
.dye-btn {
  width: 100%;
  border: 0;
  background: #8b5cf0;
  color: #fff;
  padding: 6px 6px 7px;
  font-size: 11.5px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 0 #6d3fd0;
}
.dye-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #6d3fd0; }
.dye-btn.on {
  background: #efe6ff;
  color: #4c2498;
  box-shadow: 0 2px 0 #b9a3e8, 0 0 0 2px rgba(109, 63, 208, 0.9);
}
.dye-btn.on::after {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(40, 30, 60, 0.55);
  background: var(--tap, #2f86e6);
}

/* ---- 底部提示 ---- */
.tip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 7px 10px 10px;
  padding: 6px 9px 7px;
  background: #fdf3d8;
  border: 1.5px dashed #d9be7e;
  border-radius: 10px;
  font-size: 10.5px;
  line-height: 1.45;
  color: #6f5c33;
}
.tip b { color: #b8791b; font-weight: 700; }
.tip-ico { font-size: 12px; line-height: 1; flex: 0 0 auto; }
.tip.glow {
  border-style: solid;
  border-color: #f0b93c;
  background: #fff2cf;
  animation: tipglow 1.4s ease-in-out infinite;
}
@keyframes tipglow {
  50% { box-shadow: 0 0 0 3px rgba(240, 185, 60, 0.32); }
}

/* ---- 说明弹窗 ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 10, 0.35);
  display: grid;
  place-items: center;
  z-index: 20;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(340px, 86vw);
  max-height: 86dvh;
  overflow-y: auto;
  background: #fff8ea;
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
}
.modal-card h3 { margin: 0 0 8px; }
.modal-card p { margin: 0 0 10px; line-height: 1.6; font-size: 13.5px; }
.modal-card b { color: #1d4f86; }
.modal-card button {
  margin-top: 4px;
  border: 0;
  background: #3a9be8;
  color: #fff;
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
}
