:root {
  --bg: #070509;
  --text: #f1e9dc;
  --muted: #9a8f7e;
  --accent: #ffc24d;      /* candle / crystal gold */
  --accent-dim: #7a5410;
  --danger: #ff5a4d;
  --panel: rgba(10, 7, 12, 0.95);
  --grid: #2a2320;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}

.wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.wrap:fullscreen, .wrap:-webkit-full-screen { width: 100vw; height: 100vh; }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 8px;
}
.bar h1 { font-size: 16px; font-weight: 800; letter-spacing: 0.2px; }
.scores { display: flex; align-items: center; gap: 12px; }
.score { font-size: 14px; color: var(--muted); }
.score strong { color: var(--text); margin-left: 2px; }
#hearts { font-size: 14px; letter-spacing: 1px; }

.icon {
  background: transparent;
  border: 1px solid var(--grid);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  width: 34px;
  height: 30px;
  cursor: pointer;
}
.icon:active { background: var(--grid); }
.icon.home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.stage {
  flex: 0 0 auto;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 6px;
}
.stage strong { color: var(--accent); }

.board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 8px 6px;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--grid);
  background: #050307;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* Cart countdown ------------------------------------------------------------ */
.cart-timer {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(28, 12, 6, 0.85);
  border: 2px solid var(--accent);
  box-shadow: 0 0 24px rgba(255, 194, 77, 0.45);
  pointer-events: none;
  animation: cartpulse 0.9s ease-in-out infinite;
}
.cart-timer.hidden { display: none; }
.cart-label { font-size: 12px; font-weight: 800; color: #ffe3a6; letter-spacing: 0.5px; }
.cart-count {
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.cart-count.urgent { color: var(--danger); }
@keyframes cartpulse {
  0%, 100% { box-shadow: 0 0 18px rgba(255, 194, 77, 0.4); }
  50% { box-shadow: 0 0 30px rgba(255, 120, 60, 0.75); }
}

/* Overlays ------------------------------------------------------------------ */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 12px;
  padding: 18px;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  z-index: 5;
}
.overlay.hidden { display: none; }
#select-title, #overlay-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(255, 194, 77, 0.4);
}
#select-sub, #overlay-sub { font-size: 14px; color: var(--muted); max-width: 420px; line-height: 1.4; }

/* Character select ---------------------------------------------------------- */
.heroes { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid var(--grid);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
  transition: transform .08s, border-color .12s, background .12s;
}
.hero:hover, .hero:active { transform: translateY(-2px); border-color: var(--accent); background: rgba(255, 194, 77, 0.14); }
.hero-canvas { image-rendering: pixelated; }
.char-name { font-size: 15px; font-weight: 800; }
.char-blurb { font-size: 11px; color: var(--muted); }
.pick-hint { font-size: 13px; color: var(--accent); font-weight: 700; }

.nick-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.nick-input {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--grid);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 8px 14px;
  width: min(260px, 80vw);
  outline: none;
  text-align: center;
}
.nick-input:focus { border-color: var(--accent); background: rgba(255, 194, 77, 0.09); }

.play {
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #2a1a00;
  font-size: 17px;
  font-weight: 800;
  padding: 12px 34px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dim);
  transition: transform .08s;
}
.play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dim); }

/* Touch controls: D-pad bottom-left, friend-summon bottom-right ------------- */
.touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
.touch.hidden { display: none; }
.dpad {
  position: absolute;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(4px, 1vw, 8px);
  width: clamp(150px, 38vmin, 220px);
  height: clamp(150px, 38vmin, 220px);
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(24, 14, 8, 0.5);
  color: #fff;
  font-size: clamp(20px, 5vmin, 32px);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  backdrop-filter: blur(2px);
}
.tbtn:active { background: rgba(255, 194, 77, 0.55); }
.tbtn.up    { grid-column: 2; grid-row: 1; }
.tbtn.left  { grid-column: 1; grid-row: 2; }
.tbtn.right { grid-column: 3; grid-row: 2; }
.tbtn.down  { grid-column: 2; grid-row: 3; }
.tbtn.friend {
  position: absolute;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  width: clamp(74px, 17vmin, 110px);
  height: clamp(74px, 17vmin, 110px);
  border-radius: 50%;
  font-size: clamp(28px, 7vmin, 44px);
  background: rgba(255, 194, 77, 0.32);
}

/* Chat / food / power / attack action stack, above the friend button ------- */
.action-stack {
  position: absolute;
  right: clamp(12px, 3vw, 28px);
  bottom: calc(clamp(12px, 3vh, 28px) + clamp(74px, 17vmin, 110px) + 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}
.tbtn.small {
  position: static;
  width: clamp(42px, 9vmin, 56px);
  height: clamp(42px, 9vmin, 56px);
  border-radius: 50%;
  font-size: clamp(16px, 4vmin, 24px);
  background: rgba(24, 14, 8, 0.6);
}
.tbtn.small:disabled { opacity: 0.35; }
.tbtn.hidden { display: none; }
#chat-add.hidden { display: none; }

/* Contextual "Service" button (gathering-place stalls) ---------------------- */
.service-btn {
  position: absolute;
  left: 50%;
  bottom: clamp(90px, 20vh, 160px);
  transform: translateX(-50%);
  z-index: 7;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  background: rgba(28, 12, 6, 0.9);
  color: #ffe3a6;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(255, 194, 77, 0.4);
  animation: cartpulse 0.9s ease-in-out infinite;
}
.service-btn.hidden { display: none; }

/* Stall / friends / chat panels ---------------------------------------------- */
.item-grid { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 480px; }
.item-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid var(--grid);
  border-radius: 12px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.item-btn:hover, .item-btn:active { border-color: var(--accent); background: rgba(255, 194, 77, 0.14); }
.item-btn.selected { border-color: var(--accent); background: rgba(255, 194, 77, 0.22); }
.item-count { color: var(--accent); margin-left: 4px; }
.panel-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.play.secondary {
  background: transparent;
  border: 2px solid var(--grid);
  color: var(--text);
  box-shadow: none;
  padding: 10px 20px;
  font-size: 14px;
}
.play.secondary:active { transform: translateY(2px); }
.chat-sub { font-size: 12px; color: var(--muted); }

.hint {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px 4px;
}
.foot { flex: 0 0 auto; text-align: center; font-size: 10px; color: var(--muted); padding-bottom: 4px; }
