/* ── Reset & Custom Properties ───────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #110d07;
  --surface: #1e1610;
  --surface-2: #2d2318;
  --surface-3: #3d3020;
  --accent: #e8a420;
  --accent-glow: rgba(232, 164, 32, 0.25);
  --buy: #c8841a;
  --buy-hover: #daa030;
  --text: #f0e4cc;
  --text-dim: #8a7858;
  --danger: #b83220;
  --foam: #fff8e0;
  --gold: #ffd700;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 40%, #1e1610 0%, #110d07 70%);
  touch-action: none;
}

/* ── Stats Bar (floating overlay) ───────────────────── */
#stats-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: rgba(17, 13, 7, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(232, 164, 32, 0.1);
}

.stat { text-align: center; }

.stat-label {
  display: block;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 1px;
}

.stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.save-ind {
  position: absolute;
  right: 12px;
  bottom: 3px;
  font-size: 0.55rem;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.3s;
}
.save-ind.show { opacity: 1; }

/* ── Update Banner ──────────────────────────────────── */
#update-banner {
  position: fixed;
  top: max(48px, calc(env(safe-area-inset-top) + 44px));
  right: 12px;
  z-index: 15;
  padding: 6px 14px;
  background: linear-gradient(135deg, #1b3a1b 0%, #244024 100%);
  border: 1px solid rgba(80, 200, 80, 0.4);
  border-radius: 20px;
  color: #7ddf7d;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 8px rgba(80,200,80,0.15);
  animation: update-pulse 2.5s ease-in-out infinite;
  transition: transform 0.15s, background 0.15s;
}
#update-banner:active { transform: scale(0.95); }
#update-banner.hidden { display: none; }
@keyframes update-pulse {
  0%, 100% { box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 8px rgba(80,200,80,0.15); }
  50% { box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 16px rgba(80,200,80,0.35); }
}

/* ── Game Area (full screen, house centered) ─────────── */
#game-area {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

#house-wrap {
  position: relative;
  display: inline-block;
}

#house {
  display: block;
  max-width: min(97vw, 484px);
  max-height: min(68vh, 550px);
  width: auto;
  height: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 8px 28px rgba(0,0,0,0.6));
  transition: transform 0.1s ease, filter 0.4s;
}

@keyframes pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}
#house.pop { animation: pop 0.12s ease; }

/* ── Floating +N Text ────────────────────────────────── */
@keyframes float-up {
  0%   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60px) scale(1.2); }
}
.float-text {
  position: absolute;
  pointer-events: none;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  animation: float-up 0.7s ease-out forwards;
  z-index: 10;
  white-space: nowrap;
}

/* ── SVG Can Pop Animation ────────────────────────────── */
.can-burst {
  position: absolute;
  pointer-events: none;
  z-index: 9;
}

@keyframes can-pop {
  0%   { transform: translate(-50%, -50%) scale(0) rotate(-20deg); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.15) rotate(5deg); opacity: 1; }
  50%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -75%) scale(0.85) rotate(0deg); opacity: 0; }
}
.can-burst svg {
  display: block;
  animation: can-pop 0.6s ease-out forwards;
}

.foam-drop {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--foam);
  opacity: 0;
  top: 0;
  left: 50%;
}
@keyframes fd1 { 0%{opacity:.9;transform:translate(-8px,0) scale(1)}  100%{opacity:0;transform:translate(-14px,-32px) scale(.2)} }
@keyframes fd2 { 0%{opacity:.9;transform:translate(4px,0) scale(1)}   100%{opacity:0;transform:translate(10px,-36px) scale(.25)} }
@keyframes fd3 { 0%{opacity:.8;transform:translate(-2px,0) scale(1)}  100%{opacity:0;transform:translate(-5px,-40px) scale(.3)} }
@keyframes fd4 { 0%{opacity:.7;transform:translate(6px,0) scale(1)}   100%{opacity:0;transform:translate(14px,-28px) scale(.2)} }
@keyframes fd5 { 0%{opacity:.8;transform:translate(0,0) scale(1)}     100%{opacity:0;transform:translate(2px,-44px) scale(.15)} }
.fd1 { animation: fd1 .45s ease-out .08s forwards; }
.fd2 { animation: fd2 .5s  ease-out .12s forwards; }
.fd3 { animation: fd3 .48s ease-out .06s forwards; }
.fd4 { animation: fd4 .42s ease-out .15s forwards; }
.fd5 { animation: fd5 .52s ease-out .1s  forwards; }

/* ── Golden Beer Indicator (top-left) ─────────────────── */
#gold-beer {
  position: fixed;
  top: max(60px, calc(env(safe-area-inset-top) + 56px));
  left: 14px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  cursor: pointer;
  transition: filter 0.3s;
}
#gold-beer.full { pointer-events: auto; }

#gold-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-top: 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
  opacity: 0.75;
  min-height: 1em;
}

@keyframes gold-glow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(232,164,32,0.2)); }
  50%      { filter: drop-shadow(0 0 20px rgba(232,164,32,0.7)); }
}
#gold-beer.full { animation: gold-glow 1.2s ease-in-out infinite; }
#gold-beer.rushing {
  filter: drop-shadow(0 0 16px rgba(255,215,0,0.5));
  animation: none;
}
#gold-beer.rushing #gold-label {
  opacity: 1;
  color: var(--gold);
  font-size: 0.72rem;
}

/* ── Gold Rush Screen Effects ──────────────────────────── */
#gold-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.6s;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(232,164,32,0.12) 100%);
}
#gold-vignette.active { opacity: 1; }

body.gold-rush #house {
  filter: drop-shadow(0 8px 28px rgba(0,0,0,0.6)) drop-shadow(0 0 24px rgba(232,164,32,0.35));
}

body.gold-rush .float-text {
  color: var(--gold);
  font-size: 1.5rem;
  text-shadow: 0 0 10px rgba(255,215,0,0.5), 0 1px 4px rgba(0,0,0,0.7);
}

body.gold-rush #stats-bar {
  border-bottom-color: rgba(255,215,0,0.25);
}

/* ── Dancing Taneli (gold rush only) ────────────────────── */
#taneli-dancer {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease, left 0.7s ease-in-out, top 0.7s ease-in-out;
  will-change: left, top, opacity;
}
#taneli-dancer.active {
  opacity: 1;
}
#taneli-dancer img {
  display: block;
  width: min(28vw, 160px);
  height: auto;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.6))
          drop-shadow(0 0 20px rgba(255,215,0,0.3));
}
@keyframes taneli-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-8px) scale(1.03); }
}
#taneli-dancer.active img {
  animation: taneli-bounce 0.35s ease-in-out infinite;
}

/* ── Cat Sprite ───────────────────────────────────────── */
#cat-sprite {
  position: fixed;
  z-index: 6;
  pointer-events: none;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 0;
  will-change: left;
}
#cat-sprite img {
  display: block;
  width: min(18vw, 110px);
  height: auto;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5));
}
#cat-sprite.flip img {
  transform: scaleX(-1);
}
#cat-sprite.clickable {
  pointer-events: auto;
  cursor: pointer;
}
@keyframes cat-glow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(255,215,0,0.2)) drop-shadow(0 3px 8px rgba(0,0,0,0.5)); }
  50%      { filter: drop-shadow(0 0 22px rgba(255,215,0,0.9)) drop-shadow(0 3px 8px rgba(0,0,0,0.5)); }
}
#cat-sprite.clickable img {
  animation: cat-glow 0.7s ease-in-out infinite;
}
#cat-catch-label {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
#cat-sprite.clickable #cat-catch-label {
  opacity: 1;
}
@keyframes cat-label-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-5px); }
}
#cat-sprite.clickable #cat-catch-label {
  animation: cat-label-bob 0.6s ease-in-out infinite;
}

/* ── Tapsa Sprite ────────────────────────────────────── */
#tapsa-sprite {
  position: fixed;
  z-index: 7;
  pointer-events: none;
  left: 0;
  top: 0;
  will-change: left, top;
  display: none;
}
#tapsa-sprite.active { display: block; pointer-events: none; }
#tapsa-sprite img {
  display: block;
  width: min(22vw, 130px);
  height: auto;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.6));
  image-rendering: pixelated;
}
#tapsa-sprite.flip img { transform: scaleX(-1); }
@keyframes tapsa-glow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(160,200,255,0.15)) drop-shadow(0 4px 12px rgba(0,0,0,0.6)); }
  50%      { filter: drop-shadow(0 0 18px rgba(160,200,255,0.6)) drop-shadow(0 4px 12px rgba(0,0,0,0.6)); }
}
#tapsa-sprite.glow img { animation: tapsa-glow 1.2s ease-in-out infinite; }

/* ── Tapsa Speech Bubble ─────────────────────────────── */
#tapsa-bubble {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #fffef5;
  color: #2a2218;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
  padding: 12px 18px;
  border-radius: 18px;
  border: 2.5px solid #3d3020;
  box-shadow: 0 3px 12px rgba(0,0,0,0.35);
  width: max-content;
  max-width: min(85vw, 320px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s;
  z-index: 9999;
}
#tapsa-bubble.show { opacity: 1; }

/* ── Tapsa Choice Buttons ────────────────────────────── */
#tapsa-choice {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding-top: 60px;
  display: none;
  gap: 10px;
  z-index: 9999;
}
#tapsa-choice.show { display: flex; }
.tapsa-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
  transition: transform 0.15s;
  white-space: nowrap;
}
.tapsa-btn:active { transform: scale(0.94); }
#tapsa-btn-take {
  background: linear-gradient(135deg, #3a8a28 0%, #2d6a1e 100%);
  color: #fff;
}
#tapsa-btn-gamble {
  background: linear-gradient(135deg, #e8b830 0%, #c89020 100%);
  color: #2a1800;
}

/* ── Tapsa Cup Game Overlay ──────────────────────────── */
#tapsa-cups {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(10,8,4,0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#tapsa-cups.show { display: flex; }
.cup-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 28px;
  text-align: center;
}
.cup-row {
  display: flex;
  gap: clamp(12px, 4vw, 24px);
  margin-bottom: 20px;
}
.cup-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.15s;
  min-width: 56px;
}
.cup-slot:hover { transform: translateY(-4px); }
.cup-slot.picked { pointer-events: none; }
.cup-slot .cup-icon {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  transition: transform 0.45s ease, opacity 0.45s;
  line-height: 1;
}
.cup-slot.revealed .cup-icon {
  transform: translateY(-22px) rotateX(40deg);
  opacity: 0.45;
}
.cup-result {
  font-size: 1.4rem;
  min-height: 1.6em;
  margin-top: 2px;
  opacity: 0;
  transition: opacity 0.35s 0.2s;
}
.cup-slot.revealed .cup-result { opacity: 1; }
.cup-outcome {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 18px;
  min-height: 1.4em;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s;
}
.cup-outcome.visible { opacity: 1; }
.cup-outcome.win  { color: #5cde5c; }
.cup-outcome.lose { color: #e85050; }

#cup-result-icon {
  width: 90px;
  height: 90px;
  margin: 8px 0 4px;
  opacity: 0;
  transform: scale(0);
}
#cup-result-icon svg { width: 100%; height: 100%; }
@keyframes cup-skull-in {
  0%   { opacity: 0; transform: scale(0) rotate(0deg); }
  50%  { opacity: 1; transform: scale(1.15) rotate(-6deg); }
  65%  { transform: scale(1.05) rotate(4deg); }
  80%  { transform: scale(1.1) rotate(-2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
@keyframes cup-clover-in {
  0%   { opacity: 0; transform: scale(0) rotate(0deg); }
  60%  { opacity: 1; transform: scale(1.25) rotate(360deg); }
  80%  { transform: scale(0.95) rotate(360deg); }
  100% { opacity: 1; transform: scale(1) rotate(360deg); }
}
#cup-result-icon.skull  { animation: cup-skull-in  0.6s ease-out forwards; }
#cup-result-icon.clover { animation: cup-clover-in 0.7s ease-out forwards; }

/* ── Memory Fragment Counter ─────────────────────────── */
#memory-counter {
  position: fixed;
  top: max(60px, calc(env(safe-area-inset-top) + 56px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: none;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  opacity: 0.85;
}
#memory-counter.active { display: flex; }
.memory-icon { font-size: 1.1rem; }
.memory-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: #c8b8e8;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}
@keyframes memory-pop {
  0%   { transform: translateX(-50%) scale(1); }
  50%  { transform: translateX(-50%) scale(1.35); }
  100% { transform: translateX(-50%) scale(1); }
}
#memory-counter.pop { animation: memory-pop 0.4s ease; }

/* ── Shop FAB (floating action button) ────────────────── */
#shop-btn {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: 20px;
  z-index: 15;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 18px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#shop-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 26px var(--accent-glow);
}
#shop-btn.hidden { display: none; }

#shop-btn svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Backdrop ─────────────────────────────────────────── */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.backdrop.active { opacity: 1; pointer-events: auto; }

/* ── Drawer (slide-up shop panel) ─────────────────────── */
#drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 72vh;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.5);
}
#drawer.open { transform: translateY(0); }

#drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

#drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px 8px;
  flex-shrink: 0;
}
#drawer-header h2 {
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 700;
}
#drawer-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#drawer-close:hover { background: var(--surface-3); color: var(--text); }

/* ── Tabs ─────────────────────────────────────────────── */
#tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--surface-2);
  padding: 0 8px;
}

.tab {
  flex: 1;
  padding: 10px 6px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Shop Panels ──────────────────────────────────────── */
#shop {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.panel { display: none; }
.panel.active { display: block; }

/* ── Chat ────────────────────────────────────────────── */
#shop:has(#panel-chat.active) {
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}
#panel-chat.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
#chat-messages:empty::after {
  content: "No messages yet — say hi!";
  color: var(--text-dim);
  text-align: center;
  margin-top: 40px;
  font-size: 14px;
}
.chat-day-sep {
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  margin: 10px 0 6px;
  letter-spacing: 0.5px;
}
.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}
.chat-bubble-wrap.own {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-bubble-wrap.other {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
  padding-left: 6px;
}
.chat-bubble {
  padding: 7px 11px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.chat-bubble-wrap.own .chat-bubble {
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.chat-bubble-wrap.other .chat-bubble {
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble .chat-ts {
  font-size: 10px;
  opacity: 0.55;
  margin-left: 8px;
  white-space: nowrap;
  float: right;
  margin-top: 4px;
}
.chat-bubble-wrap.own .chat-bubble .chat-ts { opacity: 0.5; }
.chat-bubble.sending { opacity: 0.55; }
.chat-bubble.error { outline: 1.5px solid #e05050; opacity: 0.8; }

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  background: var(--surface-2);
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
#chat-input::placeholder { color: var(--text-dim); }
#chat-input:focus { box-shadow: 0 0 0 1.5px var(--accent); }
#chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
#chat-send:active { opacity: 0.7; }

/* ── Building & Upgrade Items ─────────────────────────── */
.item {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

.item-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 0.92rem; margin-bottom: 2px; }
.item-desc { font-size: 0.72rem; color: var(--text-dim); }
.item-meta { font-size: 0.68rem; color: var(--text-dim); margin-top: 3px; }

.item-right { text-align: right; flex-shrink: 0; }
.item-owned {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.btn-buy {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--buy);
  color: #fff;
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn-buy:hover:not(:disabled) {
  background: var(--buy-hover);
  transform: scale(1.04);
}
.btn-buy:disabled {
  background: var(--surface-3);
  color: var(--text-dim);
  cursor: not-allowed;
}
.btn-buy.owned {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--surface-3);
}
.btn-buy.btn-mem {
  background: linear-gradient(135deg, #6a4fb8 0%, #5040a0 100%);
}
.btn-buy.btn-mem:hover:not(:disabled) {
  background: linear-gradient(135deg, #7a5fd0 0%, #6050b8 100%);
  transform: scale(1.04);
}

/* ── Memory Shop Header ────────────────────────────── */
.mem-shop-header {
  text-align: center;
  padding: 10px 8px 14px;
  font-size: 1rem;
  font-weight: 700;
  color: #c8b8e8;
}
.mem-shop-count { vertical-align: middle; }

/* ── Settings Panel ──────────────────────────────────── */
.setting-group {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.setting-group h3 {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 0.88rem;
}
.setting-row + .setting-row { border-top: 1px solid var(--surface-3); }

.toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--surface-3);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  outline: none;
  flex-shrink: 0;
}
.toggle:checked { background: var(--buy); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle:checked::after { transform: translateX(20px); }

.btn-action {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary { background: var(--surface-3); color: var(--text); }
.btn-secondary:hover { background: #4a3d28; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a02a1a; }

.last-saved {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 12px;
}

.settings-version {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 16px;
  opacity: 0.6;
}
.settings-version .version-new {
  color: #4caf50;
  font-weight: 700;
  opacity: 1;
}

/* ── Leaderboard ──────────────────────────────────────── */
.lb-list { list-style: none; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  margin-bottom: 6px;
  transition: background 0.15s;
}
.lb-row.lb-self { background: rgba(232, 164, 32, 0.12); border: 1px solid rgba(232, 164, 32, 0.25); }
.lb-rank {
  font-weight: 800;
  font-size: 1rem;
  color: var(--text-dim);
  min-width: 24px;
  text-align: center;
}
.lb-row:nth-child(1) .lb-rank { color: #ffd700; }
.lb-row:nth-child(2) .lb-rank { color: #c0c0c0; }
.lb-row:nth-child(3) .lb-rank { color: #cd7f32; }
.lb-name { flex: 1; font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-size: 0.85rem; color: var(--accent); font-weight: 700; }
.lb-cps { font-size: 0.65rem; color: var(--text-dim); margin-left: -4px; }
.lb-mem { font-size: 0.6rem; color: #c8b8e8; margin-left: 4px; opacity: 0.85; }
.lb-status {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 20px 10px;
}
.lb-updated {
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-top: 8px;
  opacity: 0.7;
}
.player-name-input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--surface-3);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s;
  min-width: 0;
}
.player-name-input:focus { border-color: var(--accent); }
.player-name-input::placeholder { color: var(--text-dim); font-weight: 400; }
.name-row { display: flex; gap: 8px; align-items: center; }
.btn-set-name {
  padding: 9px 14px;
  border: none;
  border-radius: 6px;
  background: var(--buy);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-set-name:hover { background: var(--buy-hover); }

/* ── Offline Overlay ──────────────────────────────────── */
#offline-overlay {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#offline-overlay.hidden { display: none; }
.offline-box {
  text-align: center;
  padding: 32px 28px 24px;
  max-width: 340px;
  width: 90%;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--surface-3);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.offline-box h2 {
  font-size: 1.3rem;
  color: var(--accent);
  margin: 0 0 4px;
}
.offline-box .offline-time {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-bottom: 20px;
}
.offline-box .offline-rows {
  text-align: left;
  margin-bottom: 18px;
}
.offline-box .offline-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
  color: var(--text);
  border-bottom: 1px solid var(--surface-2);
}
.offline-box .offline-row:last-child { border-bottom: none; }
.offline-box .offline-row .label { color: var(--text-dim); }
.offline-box .offline-row .value { color: var(--accent); font-weight: 700; }
.offline-box .offline-total {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 18px;
}
.offline-box .btn-collect {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--buy);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.offline-box .btn-collect:active { background: var(--buy-hover); }

/* ── Login Overlay ────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background: radial-gradient(ellipse at 50% 40%, #1e1610 0%, #110d07 70%);
}
#login-overlay.hidden { display: none; }
.login-box {
  text-align: center;
  padding: 32px 28px;
  max-width: 340px;
  width: 90%;
}
.login-box h1 {
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 6px;
}
.login-box p {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-bottom: 24px;
}
.login-code-input {
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  border: 2px solid var(--surface-3);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s;
}
.login-code-input:focus { border-color: var(--accent); }
.login-code-input::placeholder { color: var(--text-dim); font-weight: 400; font-size: 0.9rem; letter-spacing: 0.05em; }
.btn-login {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 16px;
  border: none;
  border-radius: 8px;
  background: var(--buy);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-login:hover { background: var(--buy-hover); }
.btn-login:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 12px;
  min-height: 1.2em;
}
.login-divider {
  display: flex;
  align-items: center;
  margin: 20px 0 16px;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface-3);
}
.login-divider span { padding: 0 12px; }
.login-sub {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-bottom: 14px;
  line-height: 1.5;
}
.login-hint {
  font-size: 0.7rem;
  opacity: 0.7;
}
.login-name-input {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 2px solid var(--surface-3);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}
.login-name-input:focus { border-color: var(--accent); }
.login-name-input::placeholder { color: var(--text-dim); }
.btn-register-style {
  background: var(--surface-3);
  color: var(--text);
}
.btn-register-style:hover { background: #4a3d28; }
.code-reveal {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 0.4em;
  color: var(--accent);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 16px 24px;
  margin: 16px auto;
  display: inline-block;
  user-select: all;
  -webkit-user-select: all;
}
.code-warn {
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.login-box.hidden { display: none; }

/* ── Modal ────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-box {
  position: relative;
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  width: 90%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-box h3 { margin-bottom: 12px; font-size: 1rem; color: var(--accent); }
.modal-box textarea {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--surface-3);
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  resize: vertical;
}
.modal-btns {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}
.modal-btns button {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.modal-ok { background: var(--buy); color: #fff; }
.modal-ok:hover { background: var(--buy-hover); }
.modal-cancel { background: var(--surface-2); color: var(--text); }
.modal-cancel:hover { background: var(--surface-3); }

.empty-msg {
  text-align: center;
  color: var(--text-dim);
  padding: 28px 16px;
  font-size: 0.88rem;
}

/* ── Score Pulse on Click ─────────────────────────────── */
@keyframes score-pulse {
  0%   { transform: scale(1); text-shadow: none; }
  40%  { transform: scale(1.28); text-shadow: 0 0 14px rgba(232,164,32,0.8); }
  100% { transform: scale(1); text-shadow: none; }
}
#d-coins.pulse { animation: score-pulse 0.25s ease-out; }

/* ── Responsive ──────────────────────────────────────── */
@media (min-width: 768px) {
  #drawer {
    top: 0;
    left: auto;
    right: 0;
    bottom: 0;
    width: 380px;
    max-height: none;
    border-radius: 18px 0 0 18px;
    transform: translateX(100%);
  }
  #drawer.open { transform: translateX(0); }
  #drawer-handle { display: none; }
  #house { max-width: 530px; max-height: 68vh; }
}

/* ── Rolling Pin Fly-By ────────────────────────────────── */
#rolling-pin-flyby {
  position: fixed;
  top: 38%;
  left: 0;
  z-index: 20;
  width: min(55vw, 260px);
  pointer-events: none;
  display: none;
  filter: drop-shadow(0 0 14px rgba(230,185,129,0.6));
  transform: translateX(-100%);
}
#rolling-pin-flyby.flying {
  display: block;
  pointer-events: auto;
  cursor: pointer;
  animation: rp-fly 9s linear forwards;
}
@keyframes rp-fly {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100vw); }
}

#rolling-pin-flyby .rp-wood-texture {
  animation: rp-rollTexture 0.7s linear infinite;
}
@keyframes rp-rollTexture {
  from { transform: translateX(-120px); }
  to   { transform: translateX(0px); }
}
#rolling-pin-flyby .rp-wind {
  stroke-dasharray: 40 100;
  stroke-linecap: round;
  animation: rp-swoosh 0.6s linear infinite;
}
#rolling-pin-flyby .rp-wind:nth-child(1) { animation-delay: 0.0s; animation-duration: 0.5s; stroke-width: 4; }
#rolling-pin-flyby .rp-wind:nth-child(2) { animation-delay: -0.2s; animation-duration: 0.7s; stroke-width: 2; }
#rolling-pin-flyby .rp-wind:nth-child(3) { animation-delay: -0.4s; animation-duration: 0.6s; stroke-width: 3; }
#rolling-pin-flyby .rp-wind:nth-child(4) { animation-delay: -0.1s; animation-duration: 0.8s; stroke-width: 2; }
#rolling-pin-flyby .rp-wind:nth-child(5) { animation-delay: -0.3s; animation-duration: 0.5s; stroke-width: 3; }
@keyframes rp-swoosh {
  from { stroke-dashoffset: -40; opacity: 0; }
  20%  { opacity: 0.8; }
  80%  { opacity: 0.8; }
  to   { stroke-dashoffset: 100; opacity: 0; }
}
#rolling-pin-flyby .rp-flour {
  animation: rp-flyOff 0.8s ease-out infinite;
}
#rolling-pin-flyby .rp-flour:nth-child(6)  { animation-delay: 0.1s; }
#rolling-pin-flyby .rp-flour:nth-child(7)  { animation-delay: 0.4s; }
#rolling-pin-flyby .rp-flour:nth-child(8)  { animation-delay: 0.2s; }
#rolling-pin-flyby .rp-flour:nth-child(9)  { animation-delay: 0.6s; }
#rolling-pin-flyby .rp-flour:nth-child(10) { animation-delay: 0.3s; }
@keyframes rp-flyOff {
  0%   { transform: translate(0px, 0px) scale(1); opacity: 0.9; }
  100% { transform: translate(-80px, -20px) scale(0); opacity: 0; }
}

/* Rolling Pin Boost Indicator (top-right) */
#rolling-pin-indicator {
  position: fixed;
  top: max(60px, calc(env(safe-area-inset-top) + 56px));
  right: 14px;
  z-index: 12;
  display: none;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
#rolling-pin-indicator.active {
  display: flex;
  animation: rp-indicator-glow 1.5s ease-in-out infinite;
}
@keyframes rp-indicator-glow {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(230,185,129,0.2)); }
  50%      { filter: drop-shadow(0 0 18px rgba(230,185,129,0.8)); }
}
#rp-icon {
  font-size: 1.8rem;
}
#rp-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: #e6b981;
  text-align: center;
  margin-top: 2px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
}

/* Rolling Pin Boost Vignette */
#rp-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.6s;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(184,133,79,0.10) 100%);
}
#rp-vignette.active { opacity: 1; }

body.rp-boost #stats-bar {
  border-bottom-color: rgba(230,185,129,0.25);
}

/* ── Reduced Motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .float-text   { animation-duration: 0.01s !important; }
  .can-burst *  { animation-duration: 0.01s !important; }
  #house.pop    { animation: none !important; }
  #gold-beer.full { animation: none !important; }
  #d-coins.pulse { animation: none !important; }

  #rolling-pin-flyby .rp-wood-texture,
  #rolling-pin-flyby .rp-wind,
  #rolling-pin-flyby .rp-flour { animation: none !important; }
  #rolling-pin-indicator.active { animation: none !important; }
  #tapsa-sprite.glow img { animation: none !important; }
  #memory-counter.pop { animation: none !important; }
  #cup-result-icon.skull, #cup-result-icon.clover { animation: none !important; opacity: 1 !important; transform: scale(1) !important; }
  #update-banner { animation: none !important; }

  *, *::before, *::after { transition-duration: 0.01s !important; }
}

/* ── Gift Notification Toast ─────────────────────────── */
.gift-toast {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: linear-gradient(135deg, #2d6a1e 0%, #3a8a28 100%);
  color: #fff;
  padding: 14px 26px;
  border-radius: 0 0 14px 14px;
  font-weight: 700;
  font-size: 1.05rem;
  z-index: 9999;
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
  pointer-events: none;
  white-space: nowrap;
  animation: gift-slide 4s ease forwards;
}
@keyframes gift-slide {
  0%   { transform: translateX(-50%) translateY(-100%); opacity: 0; }
  10%  { transform: translateX(-50%) translateY(18px);  opacity: 1; }
  78%  { transform: translateX(-50%) translateY(18px);  opacity: 1; }
  100% { transform: translateX(-50%) translateY(-100%); opacity: 0; }
}

/* ── Tähti Prestige System ────────────────────────────── */
.tahti-header {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 10px 0 14px;
  color: #f0c040;
}

.btn-tahti {
  background: linear-gradient(135deg, #6b5b1e 0%, #a08820 100%) !important;
  color: #fff !important;
}
.btn-tahti:disabled {
  opacity: 0.45;
}

.item-locked {
  opacity: 0.4;
  pointer-events: none;
}

.item-req {
  font-size: 0.75rem;
  color: #c09030;
  margin-top: 2px;
  font-style: italic;
}

.btn-prestige {
  background: linear-gradient(135deg, #5a3a10 0%, #a08020 100%);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  width: 100%;
  margin-top: 6px;
  transition: background 0.2s;
}
.btn-prestige:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn-prestige.btn-confirm {
  background: linear-gradient(135deg, #8b2020 0%, #c03030 100%);
  animation: pulse-warn 0.5s infinite alternate;
}
@keyframes pulse-warn {
  from { box-shadow: 0 0 4px rgba(200,40,40,0.3); }
  to   { box-shadow: 0 0 14px rgba(200,40,40,0.7); }
}

.prestige-preview {
  font-size: 0.85rem;
  color: #d0b060;
  margin-bottom: 4px;
}

.tahti-toggle {
  margin-top: 16px;
}

.perma-slot-row {
  margin: 6px 0;
}

.perma-slot-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #5a4a2a;
  background: #2a2210;
  color: #e0d0a0;
  font-size: 0.85rem;
}
