:root {
  --bg: #0a0612;
  --bg2: #1a1025;
  --coffee: #c87941;
  --gold: #f0c040;
  --neon: #ff6b9d;
  --green: #4ade80;
  --red: #f87171;
  --glass: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f5e6d3;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
}

/* HUD */
.hud {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  padding: 10px 14px 8px;
  z-index: 200;
  background: linear-gradient(180deg, rgba(10, 6, 18, 0.96), transparent);
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.hud-score {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--gold), var(--coffee));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hud-rank {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--border);
}

.hud-combo {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--neon);
  animation: pulse 0.5s infinite alternate;
}

.hud-progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.hud-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--coffee), var(--gold));
  box-shadow: 0 0 8px var(--gold);
  transition: width 0.4s;
}

@keyframes pulse {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

/* Pages */
.page {
  display: none;
  min-height: 100vh;
  padding: 72px 16px 108px;
  animation: slideUp 0.4s ease;
}

.page.active { display: block; }

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

.hero {
  text-align: center;
  padding: 16px 8px 20px;
}

.hero .logo {
  font-size: 3.2rem;
  filter: drop-shadow(0 0 18px var(--coffee));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.hero h1 {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 10px 0 6px;
  background: linear-gradient(135deg, #fff, var(--gold), var(--coffee));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero .sub {
  font-size: 0.82rem;
  opacity: 0.72;
  line-height: 1.65;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.glass h2 {
  font-size: 1.02rem;
  margin-bottom: 10px;
  background: linear-gradient(90deg, var(--gold), var(--coffee));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.glass p, .glass li {
  font-size: 0.85rem;
  line-height: 1.65;
  opacity: 0.88;
}

.tip-box {
  background: rgba(240, 192, 64, 0.08);
  border-left: 3px solid var(--gold);
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.55;
  margin-top: 12px;
  border-radius: 0 10px 10px 0;
}

.progress {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-bottom: 14px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--coffee), var(--gold));
  border-radius: 2px;
  transition: width 0.35s;
  box-shadow: 0 0 10px rgba(240, 192, 64, 0.5);
}

/* Roles */
.roles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.role-card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 10px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.role-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, rgba(240, 192, 64, 0.15), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s;
}

.role-card:active { transform: scale(0.96); }
.role-card:active::after { opacity: 1; }

.role-card .icon { font-size: 2rem; display: block; margin-bottom: 6px; }
.role-card .name { font-weight: 700; font-size: 0.9rem; }
.role-card .tag { font-size: 0.68rem; opacity: 0.6; margin-top: 4px; }
.role-card .pts {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.62rem;
  background: var(--gold);
  color: #1a0a00;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 700;
}

.role-card .line-score {
  font-size: 0.72rem;
  color: var(--gold);
  margin-top: 6px;
}

/* Options */
.opts { display: flex; flex-direction: column; gap: 10px; }

.opt {
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
  transition: all 0.2s;
  width: 100%;
}

.opt:hover, .opt.selected {
  border-color: var(--gold);
  background: rgba(240, 192, 64, 0.1);
  box-shadow: 0 0 16px rgba(240, 192, 64, 0.15);
}

.opt.correct { border-color: var(--green); background: rgba(74, 222, 128, 0.12); animation: pop 0.35s; }
.opt.wrong { border-color: var(--red); background: rgba(248, 113, 113, 0.12); animation: shake 0.35s; }

@keyframes pop {
  50% { transform: scale(1.02); }
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Buttons */
.btn-row {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  padding: 12px 16px 28px;
  display: flex;
  gap: 10px;
  background: linear-gradient(transparent, rgba(10, 6, 18, 0.96));
  z-index: 150;
}

.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--coffee));
  color: #1a0a00;
  box-shadow: 0 4px 20px rgba(240, 192, 64, 0.35);
}

.btn-ghost {
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Timer & score pop */
.timer {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold);
  margin: 8px 0;
}

.timer.urgent { color: var(--red); animation: pulse 0.3s infinite; }

.score-pop {
  position: fixed;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 30px var(--gold);
  pointer-events: none;
  z-index: 300;
  opacity: 0;
  transition: all 0.35s;
}

.score-pop.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.score-pop.hide {
  opacity: 0;
  transform: translate(-50%, -70%) scale(0.6);
}

/* Result */
.result-box { text-align: center; }

.result-score {
  font-size: 2.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), var(--neon), var(--coffee));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.result-rank {
  font-size: 1rem;
  color: var(--gold);
  font-weight: 700;
  margin: 8px 0;
}

.stars { font-size: 1.6rem; letter-spacing: 3px; margin: 10px 0; }
.star-off { opacity: 0.2; }

.breakdown {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.bd-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
  border: 1px solid var(--border);
}

.bd-item .v { font-size: 1rem; font-weight: 700; color: var(--gold); }
.bd-item .l { font-size: 0.65rem; opacity: 0.6; margin-top: 2px; }

/* Game areas */
.grinder-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  min-height: 100px;
}

.bean-pool {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.draggable-bean {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #a67c52, #4a3222);
  border: 2px solid var(--gold);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

.grinder-slot {
  width: 90px;
  height: 90px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  transition: all 0.3s;
}

.grinder-slot.active {
  border-color: var(--gold);
  background: rgba(240, 192, 64, 0.1);
  box-shadow: 0 0 20px rgba(240, 192, 64, 0.3);
}

#latteCanvas {
  width: 100%;
  height: 220px;
  border-radius: 50% 50% 42% 42%;
  background: radial-gradient(ellipse at 50% 35%, #d4a574, #6b3a1f);
  display: block;
  touch-action: none;
  box-shadow: inset 0 -20px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(200, 121, 65, 0.25);
}

.extract-btn {
  width: 100%;
  padding: 20px;
  margin-top: 14px;
  border-radius: 50%;
  width: 120px;
  height: 120px;
  display: block;
  margin-left: auto;
  margin-right: auto;
  border: 3px solid var(--gold);
  background: radial-gradient(circle, var(--coffee), #4a3222);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.extract-gauge {
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  margin: 12px 0;
  overflow: hidden;
}

.extract-gauge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
  transition: width 0.05s linear;
}

.cherry-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.cherry {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--border);
  font-size: 1.5rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  transition: all 0.2s;
}

.cherry.ripe { background: rgba(192, 57, 43, 0.25); border-color: #c0392b; }
.cherry.picked { opacity: 0.25; transform: scale(0.75); pointer-events: none; }
.cherry.bad-pick { animation: shake 0.3s; border-color: var(--red); }

.sort-zone {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.sort-bin {
  min-height: 80px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  font-size: 0.8rem;
}

.sort-bin.over { border-color: var(--gold); background: rgba(240, 192, 64, 0.08); }

.sort-beans {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 12px 0;
}

.sort-bean {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.route-map {
  position: relative;
  height: 180px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  margin: 12px 0;
  border: 1px solid var(--border);
}

.route-node {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--glass);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
}

.route-node.done { border-color: var(--green); box-shadow: 0 0 12px rgba(74, 222, 128, 0.4); }

.customer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.customer .need { font-size: 0.78rem; opacity: 0.8; }
.customer button {
  background: linear-gradient(135deg, var(--coffee), var(--gold));
  color: #000;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.8rem;
}

.customer button:disabled { opacity: 0.35; }

.menu-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.menu-slot {
  min-height: 56px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  text-align: center;
  padding: 4px;
}

.menu-slot.filled { border-style: solid; border-color: var(--gold); background: rgba(240, 192, 64, 0.08); }

.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.match-item {
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
}

.match-item.selected { border-color: var(--neon); background: rgba(255, 107, 157, 0.1); }
.match-item.matched { border-color: var(--green); opacity: 0.6; pointer-events: none; }

.flip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.flip-card {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--coffee), #4a3222);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 4px;
  text-align: center;
}

.flip-card.open { background: rgba(240, 192, 64, 0.15); border-color: var(--gold); }
.flip-card.done { opacity: 0.5; pointer-events: none; }

.cup-preview {
  font-size: 4.5rem;
  margin: 12px 0;
  filter: drop-shadow(0 0 16px var(--coffee));
}

.diy-cup-row, .diy-ing-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 12px 0;
}

.diy-chip {
  padding: 10px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-size: 0.85rem;
}

.diy-chip.selected {
  border-color: var(--gold);
  background: rgba(240, 192, 64, 0.12);
  box-shadow: 0 0 12px rgba(240, 192, 64, 0.2);
}

.poster-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  margin: 10px 0;
}

.opening-seq {
  text-align: center;
  padding: 20px 0;
}

.opening-seq .step {
  font-size: 0.9rem;
  opacity: 0;
  margin: 8px 0;
  animation: fadeStep 0.8s forwards;
}

.opening-seq .step:nth-child(1) { animation-delay: 0.3s; }
.opening-seq .step:nth-child(2) { animation-delay: 1.1s; }
.opening-seq .step:nth-child(3) { animation-delay: 1.9s; }

@keyframes fadeStep {
  to { opacity: 1; }
}

.personality-tag {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(240, 192, 64, 0.2), rgba(200, 121, 65, 0.2));
  border: 1px solid var(--gold);
  font-size: 0.85rem;
  margin: 6px 4px;
}

.hidden { display: none !important; }

input[type="range"] { width: 100%; accent-color: var(--gold); }
.slider-label { font-size: 0.82rem; margin-bottom: 6px; display: block; }

.map-line {
  position: absolute;
  height: 2px;
  background: linear-gradient(90deg, var(--coffee), var(--gold));
  transform-origin: left center;
  opacity: 0.6;
}
