/* ============ Bou — virtual pet game ============ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input[type="text"] {
  -webkit-user-select: text;
  user-select: text;
}

:root {
  --bg-dark: #1c2333;
  --panel: #2a3247;
  --panel-light: #38415c;
  --accent: #ffb53e;
  --accent-2: #6ee7a0;
  --danger: #ff6b6b;
  --text: #f3f5fb;
  --text-dim: #9aa5c0;
  --radius: 16px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  user-select: none;
  overscroll-behavior: none;
  /* disable double-tap-to-zoom on mobile */
  touch-action: manipulation;
}

button, .modal, .modal-card, #app {
  touch-action: manipulation;
}

#app {
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  box-shadow: 0 0 60px rgba(0,0,0,.6);
  position: relative;
}

/* ============ HUD ============ */
#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px 6px;
  gap: 8px;
}
.hud-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
#pet-name-tag {
  font-weight: 800;
  font-size: 1.25rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
#level-box { display: flex; flex-direction: column; gap: 2px; }
#level-label { font-size: .72rem; font-weight: 700; color: var(--accent); }
#xp-bar {
  width: 80px; height: 7px;
  background: var(--panel);
  border-radius: 4px;
  overflow: hidden;
}
#xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ffb53e, #ffd97a); transition: width .4s; }

.hud-right { display: flex; align-items: center; gap: 6px; }
#coin-box {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel);
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 700;
}
.coin-icon {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, #f5b93c 60%, #c4862a);
  display: inline-block;
  border: 1px solid #a06d1c;
}
.hud-btn {
  background: var(--panel);
  border: none;
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.hud-btn:hover { background: var(--panel-light); transform: scale(1.08); }
.hud-btn.muted { opacity: .4; }

/* ============ Stat bars ============ */
#stats-bar {
  display: flex;
  gap: 6px;
  padding: 4px 14px 8px;
}
.stat { flex: 1; display: flex; align-items: center; gap: 4px; }
.stat-icon { font-size: .85rem; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.stat .bar {
  flex: 1; height: 10px;
  background: var(--panel);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.45);
}
.stat .fill {
  height: 100%; width: 100%;
  border-radius: 6px;
  transition: width .5s, background-color .5s;
  background: var(--accent-2);
}
.stat .fill.warn { background: #ffd166; }
.stat .fill.low  { background: var(--danger); animation: pulse-bar 1s infinite; }
@keyframes pulse-bar { 50% { opacity: .55; } }

/* ============ Room ============ */
#room {
  flex: 1;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
  margin: 0 8px;
  min-height: 0;
}
#room-bg {
  position: absolute; inset: 0;
  transition: background 1s;
}
#room-decor { position: absolute; inset: 0; pointer-events: none; }

#pet-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

#lights-overlay {
  position: absolute; inset: 0;
  background: rgba(4, 8, 24, .88);
  pointer-events: none;
  transition: opacity .8s;
  opacity: 1;
  z-index: 5;
}
#lights-overlay.hidden { display: block; opacity: 0; }

#speech-bubble {
  position: absolute;
  background: white;
  color: #222;
  padding: 8px 14px;
  border-radius: 14px;
  font-weight: 700;
  font-size: .9rem;
  z-index: 6;
  pointer-events: none;
  transform: translate(-50%, -100%);
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  animation: bubble-in .25s ease-out;
  max-width: 220px;
  text-align: center;
}
#speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -8px;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: white;
  border-bottom: none;
}
@keyframes bubble-in { from { opacity: 0; transform: translate(-50%, -90%) scale(.8); } }

/* ============ Action trays (food/bath/lab) ============ */
.action-tray {
  position: absolute;
  bottom: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(20, 26, 44, .82);
  backdrop-filter: blur(6px);
  border-radius: 18px;
  z-index: 7;
  max-width: 94%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: thin;
}
.tray-item {
  flex: 0 0 auto;
  touch-action: pan-x;
  width: 58px; height: 66px;
  border: none;
  border-radius: 12px;
  background: var(--panel-light);
  color: var(--text);
  font-size: 1.5rem;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .12s;
  position: relative;
}
.tray-item:hover { transform: translateY(-4px); }
.tray-item .count {
  font-size: .62rem;
  font-weight: 700;
  color: var(--accent);
}
.tray-item.empty { opacity: .35; cursor: not-allowed; }
.tray-item .item-emoji { pointer-events: none; }
.tray-item svg { width: 32px; height: 32px; display: block; }

.item-emoji, .mem-face, .plot-emoji, .stat-icon {
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

#drag-ghost {
  position: fixed;
  font-size: 2.2rem;
  pointer-events: none;
  z-index: 100;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.4));
}
#drag-ghost svg { width: 46px; height: 46px; }

/* ============ Garden ============ */
#garden-plots {
  position: absolute;
  bottom: 96px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 7;
}
.plot {
  width: 92px;
  border: 2px solid rgba(94, 64, 30, .6);
  border-radius: 14px;
  background: linear-gradient(rgba(118, 81, 40, .88), rgba(86, 57, 26, .92));
  color: var(--text);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform .12s;
  box-shadow: 0 6px 14px rgba(0,0,0,.3);
}
.plot:hover { transform: translateY(-3px); }
.plot.ready { border-color: var(--accent); animation: plot-glow 1.2s infinite; }
@keyframes plot-glow { 50% { box-shadow: 0 0 18px rgba(255, 181, 62, .8); } }
.plot-emoji { font-size: 1.7rem; line-height: 1.2; pointer-events: none; }
.plot-bar {
  width: 100%; height: 6px;
  background: rgba(0,0,0,.4);
  border-radius: 4px;
  overflow: hidden;
  pointer-events: none;
}
.plot-bar .plot-fill {
  height: 100%;
  background: var(--accent-2);
  transition: width 1s linear;
}
.plot-label {
  font-size: .58rem;
  font-weight: 700;
  color: #ffe9c4;
  text-align: center;
  pointer-events: none;
}

/* ============ Bedroom ============ */
#bedroom-controls {
  position: absolute;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 7;
}
.big-action-btn {
  background: var(--accent);
  color: #3a2a07;
  border: none;
  font-size: 1rem;
  font-weight: 800;
  padding: 12px 26px;
  border-radius: 24px;
  cursor: pointer;
  box-shadow: 0 4px 0 #c78a25;
  transition: transform .1s;
}
.big-action-btn:active { transform: translateY(3px); box-shadow: none; }

/* ============ Playroom menu ============ */
#playroom-menu {
  position: absolute; inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 8px;
  overflow-y: auto;
  scrollbar-width: thin;
  background: rgba(16, 20, 36, .55);
  backdrop-filter: blur(3px);
}
#playroom-menu h2 { font-size: 1.5rem; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.minigame-grid {
  display: grid;
  grid-template-columns: repeat(2, 150px);
  gap: 12px;
  margin: auto 0;
}
.minigame-card {
  background: var(--panel);
  border: 2px solid var(--panel-light);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform .12s, border-color .15s;
}
.minigame-card:hover { transform: translateY(-4px) scale(1.03); border-color: var(--accent); }
.mg-icon { font-size: 1.7rem; }
.mg-name { font-weight: 800; }
.mg-best { font-size: .72rem; color: var(--text-dim); }

/* ============ Room nav ============ */
#room-nav {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px 4px;
}
.room-btn {
  width: 46px; height: 42px;
  font-size: 1.2rem;
  border: none;
  border-radius: 14px;
  background: var(--panel);
  cursor: pointer;
  transition: transform .12s, background .15s;
  filter: grayscale(.45);
}
.room-btn:hover { transform: translateY(-3px); }
.room-btn.active {
  background: var(--accent);
  filter: none;
  box-shadow: 0 3px 0 #c78a25;
}

/* ============ Action bar ============ */
#action-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px 14px;
}
.action-btn {
  flex: 1;
  max-width: 150px;
  background: var(--panel);
  border: none;
  color: var(--text);
  font-weight: 700;
  font-size: .85rem;
  padding: 9px 6px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s, transform .1s;
}
.action-btn span { font-size: 1.1rem; }
.action-btn:hover { background: var(--panel-light); transform: translateY(-2px); }

/* ============ Modals ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(8, 11, 22, .72);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-card {
  background: var(--panel);
  border-radius: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  animation: modal-in .22s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: scale(.92) translateY(16px); } }
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-head h2 { flex: 1; font-size: 1.25rem; }
.modal-coins { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.modal-close {
  background: var(--panel-light);
  border: none;
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}
.modal-hint { font-size: .78rem; color: var(--text-dim); margin-bottom: 10px; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.tab-btn {
  background: var(--panel-light);
  border: none;
  color: var(--text-dim);
  font-weight: 700;
  font-size: .78rem;
  padding: 7px 13px;
  border-radius: 18px;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: #3a2a07; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
}
.item-card {
  background: var(--panel-light);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--text);
  transition: transform .12s, border-color .15s;
  position: relative;
}
.item-card:hover { transform: translateY(-3px); }
.item-card .item-emoji { font-size: 1.7rem; }
.item-card .item-name { font-size: .68rem; font-weight: 700; text-align: center; }
.item-card .item-price {
  display: flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 800; color: var(--accent);
}
.item-card .item-price .coin-icon { width: 11px; height: 11px; }
.item-card .item-count {
  position: absolute;
  top: 4px; right: 6px;
  font-size: .66rem;
  font-weight: 800;
  color: var(--accent-2);
}
.item-card.owned { border-color: var(--accent-2); }
.item-card.equipped { border-color: var(--accent); background: #4a4023; }
.item-card.locked { opacity: .45; }
.item-card .swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5);
}
.item-card .item-desc { font-size: .6rem; color: var(--text-dim); text-align: center; }

/* ============ Settings ============ */
.settings-body { display: flex; flex-direction: column; gap: 14px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
  font-size: .9rem;
}
.settings-row input[type="text"] {
  background: var(--panel-light);
  border: 1px solid #50597a;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: .9rem;
  width: 170px;
}
.settings-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.primary-btn {
  background: var(--accent-2);
  color: #0b3a22;
  border: none;
  font-weight: 800;
  padding: 10px 24px;
  border-radius: 12px;
  cursor: pointer;
  font-size: .92rem;
}
.ghost-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
  font-weight: 700;
  padding: 9px 22px;
  border-radius: 12px;
  cursor: pointer;
}
.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
}
.danger-btn:hover { background: rgba(255, 107, 107, .12); }
hr { border-color: var(--panel-light); }

/* ============ Achievements ============ */
#achievements-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.ach-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-light);
  border-radius: 12px;
  padding: 10px 12px;
}
.ach-row.locked { opacity: .45; }
.ach-row .ach-icon { font-size: 1.5rem; }
.ach-row .ach-info { flex: 1; }
.ach-row .ach-title { font-weight: 800; font-size: .88rem; }
.ach-row .ach-desc { font-size: .72rem; color: var(--text-dim); }
.ach-row .ach-reward { font-size: .75rem; font-weight: 800; color: var(--accent); white-space: nowrap; }

/* ============ Mini-games ============ */
#minigame-overlay {
  position: fixed; inset: 0;
  background: #101524;
  z-index: 80;
  display: flex;
  flex-direction: column;
}
#minigame-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  z-index: 82;
}
#minigame-quit {
  background: var(--panel);
  border: none;
  color: var(--text);
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 18px;
  cursor: pointer;
}
#minigame-score { font-weight: 800; font-size: 1.05rem; }
#minigame-overlay { touch-action: manipulation; }
#minigame-canvas { flex: 1; width: 100%; touch-action: none; }
#memory-board { touch-action: manipulation; }

#memory-board {
  position: absolute;
  inset: 60px 0 0 0;
  display: grid;
  place-content: center;
  grid-template-columns: repeat(4, minmax(58px, 80px));
  gap: 10px;
  padding: 16px;
}
.mem-card {
  aspect-ratio: 3/4;
  border-radius: 14px;
  border: none;
  background: transparent;
  font-size: 1.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .22s ease, filter .22s ease;
  position: relative;
  overflow: hidden;
  padding: 0;
  box-shadow:
    0 8px 18px rgba(4, 10, 22, .38),
    0 2px 0 rgba(255, 255, 255, .06) inset;
}
.mem-card:hover:not(.flipped):not(.matched) {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.06);
}
.mem-card:active:not(.flipped):not(.matched) {
  transform: scale(.97);
}
.mem-card .mem-face {
  visibility: hidden;
  position: relative;
  z-index: 2;
  width: 72%;
  height: 72%;
  display: block;
}
.mem-back {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 224, 150, .38), transparent 38%),
    radial-gradient(circle at 80% 88%, rgba(110, 231, 160, .18), transparent 42%),
    linear-gradient(155deg, #4a628f 0%, #2c4063 42%, #1a2740 100%);
  border: 2px solid rgba(255, 206, 110, .55);
  box-shadow:
    inset 0 0 0 4px rgba(16, 26, 46, .72),
    inset 0 0 0 5px rgba(255, 210, 120, .22);
}
.mem-back-glow {
  position: absolute;
  inset: 9px;
  border-radius: 9px;
  border: 1px solid rgba(255, 220, 150, .28);
  background:
    linear-gradient(180deg, rgba(255,255,255,.12), transparent 40%),
    radial-gradient(circle at 50% 110%, rgba(255, 181, 62, .16), transparent 55%);
  pointer-events: none;
}
.mem-back-pattern {
  position: absolute;
  inset: 11px;
  border-radius: 8px;
  opacity: .7;
  background:
    radial-gradient(circle at center, transparent 28%, rgba(255, 201, 98, .08) 29% 34%, transparent 35%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 201, 98, .2) 0 5px,
      transparent 5px 12px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, .07) 0 5px,
      transparent 5px 12px
    );
  mask-image: radial-gradient(circle at center, #000 20%, transparent 82%);
  -webkit-mask-image: radial-gradient(circle at center, #000 20%, transparent 82%);
  pointer-events: none;
}
.mem-back-emblem {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  aspect-ratio: 1;
  transform: translate(-50%, -52%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff0c4, #ffc85a 42%, #ffb53e 68%, #c4862a 100%);
  box-shadow:
    0 0 0 3px rgba(255, 220, 150, .35),
    0 0 0 6px rgba(20, 30, 52, .35),
    0 5px 12px rgba(0, 0, 0, .32),
    inset 0 2px 0 rgba(255, 255, 255, .45);
  pointer-events: none;
}
.mem-back-emblem::before,
.mem-back-emblem::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
/* Eyes */
.mem-back-emblem::before {
  top: 34%;
  left: 0;
  right: 0;
  height: 22%;
  background:
    radial-gradient(circle at 32% 50%, #1c2333 0 38%, transparent 40%),
    radial-gradient(circle at 68% 50%, #1c2333 0 38%, transparent 40%);
}
/* Smile + blush */
.mem-back-emblem::after {
  left: 50%;
  top: 58%;
  width: 34%;
  height: 18%;
  transform: translateX(-50%);
  border: 2.5px solid #1c2333;
  border-color: transparent transparent #1c2333;
  border-radius: 0 0 60% 60%;
  box-shadow:
    -11px -2px 0 -1px rgba(255, 130, 140, .45),
    11px -2px 0 -1px rgba(255, 130, 140, .45);
}
.mem-card.flipped,
.mem-card.matched {
  background: linear-gradient(180deg, #ffe08a, var(--accent) 55%, #e09a28);
  box-shadow:
    0 10px 20px rgba(4, 10, 22, .32),
    inset 0 1px 0 rgba(255, 255, 255, .35);
}
.mem-card.flipped {
  transform: scale(1.06);
}
.mem-card.matched {
  background: linear-gradient(180deg, #9af0c0, var(--accent-2) 60%, #3dbf7a);
  cursor: default;
  filter: none;
}
.mem-card.flipped .mem-face,
.mem-card.matched .mem-face {
  visibility: visible;
}
.mem-card.flipped .mem-back,
.mem-card.matched .mem-back {
  display: none;
}

/* legacy atlas back no longer used */
.mem-card::after { content: none; }

#minigame-end {
  position: absolute; inset: 0;
  background: rgba(8, 11, 22, .78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 85;
}
.mg-end-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: modal-in .25s ease-out;
}
#mg-end-score { font-size: 1.3rem; font-weight: 800; color: var(--accent); }
#mg-end-reward { color: var(--accent-2); font-weight: 700; }

/* ============ Toasts ============ */
#toast-stack {
  position: fixed;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  color: var(--text);
  font-weight: 700;
  font-size: .85rem;
  padding: 10px 20px;
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  animation: toast-in .3s ease-out, toast-out .4s ease-in forwards;
  animation-delay: 0s, 2.6s;
  white-space: nowrap;
}
.toast.gold { border-color: var(--accent); color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-16px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ============ Floating reward text ============ */
.float-text {
  position: absolute;
  font-weight: 900;
  font-size: 1.05rem;
  pointer-events: none;
  z-index: 20;
  animation: float-up 1.1s ease-out forwards;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}
@keyframes float-up {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-46px); }
}

.hidden { display: none !important; }

@media (max-width: 430px) {
  .minigame-grid { grid-template-columns: repeat(2, 132px); }
  #pet-name-tag { font-size: 1.05rem; max-width: 90px; }
}

/* ============ Storybook visual refresh ============ */
:root {
  --bg-dark: #111a2c;
  --panel: #202c43;
  --panel-light: #2c3a56;
  --accent: #ffb63f;
  --accent-2: #69dfa2;
  --danger: #ff6f72;
  --text: #fffaf1;
  --text-dim: #aeb9ce;
  --radius: 20px;
  --outline: rgba(255, 250, 241, .09);
  --deep-shadow: 0 14px 36px rgba(4, 9, 20, .34);
}

html,
body {
  background:
    radial-gradient(circle at 18% 12%, rgba(65, 94, 130, .24), transparent 34%),
    radial-gradient(circle at 82% 88%, rgba(32, 107, 92, .16), transparent 32%),
    #0b1220;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

button {
  font-family: inherit;
}

button:focus-visible,
#pet-name-tag:focus-visible {
  outline: 3px solid rgba(255, 194, 83, .78);
  outline-offset: 3px;
}

#app {
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), transparent 18%),
    var(--bg-dark);
  box-shadow: 0 0 0 1px rgba(255,255,255,.025), 0 30px 90px rgba(0,0,0,.58);
  isolation: isolate;
}

#hud {
  min-height: 56px;
  padding: 12px 16px 7px;
}

.hud-left {
  gap: 12px;
}

#pet-name-tag {
  color: #fffaf1;
  font-size: 1.35rem;
  letter-spacing: -.045em;
  text-shadow: 0 2px 0 rgba(0,0,0,.2);
}

#level-box {
  gap: 4px;
}

#level-label {
  color: #ffc653;
  font-size: .72rem;
  letter-spacing: .02em;
}

#xp-bar {
  width: 88px;
  height: 7px;
  background: rgba(255,255,255,.075);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.35);
}

#xp-fill {
  background: linear-gradient(90deg, #ffae38, #ffd876);
  box-shadow: 0 0 8px rgba(255, 190, 70, .28);
}

.hud-right {
  gap: 7px;
}

#coin-box,
.hud-btn {
  background: linear-gradient(180deg, rgba(255,255,255,.075), rgba(255,255,255,.025)), var(--panel);
  border: 1px solid var(--outline);
  box-shadow: 0 5px 12px rgba(4, 9, 20, .22), inset 0 1px 0 rgba(255,255,255,.06);
}

#coin-box {
  min-height: 38px;
  padding: 5px 13px 5px 8px;
}

.coin-icon {
  width: 19px;
  height: 19px;
  border: 2px solid rgba(130, 81, 14, .52);
  box-shadow: inset 2px 2px 4px rgba(255,255,255,.55), 0 2px 4px rgba(0,0,0,.25);
}

.hud-btn {
  width: 38px;
  height: 38px;
}

.hud-btn:hover {
  background-color: #33425f;
  transform: translateY(-2px) scale(1.03);
}

#stats-bar {
  gap: 10px;
  padding: 5px 16px 11px;
}

.stat {
  gap: 5px;
}

.stat-icon {
  font-size: .82rem;
  transform: translateY(-.5px);
}

.stat .bar {
  height: 9px;
  background: rgba(0, 0, 0, .24);
  border: 1px solid rgba(255,255,255,.055);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.32), 0 1px 0 rgba(255,255,255,.035);
}

.stat .fill {
  background: linear-gradient(90deg, #55d592, #78e6ad);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3);
}

#room {
  margin: 0 9px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 27px;
  background: #1a2635;
  box-shadow: var(--deep-shadow), inset 0 0 0 1px rgba(255,255,255,.03);
  transform: translateZ(0);
}

#room-bg {
  overflow: hidden;
  background-color: #26394a;
}

#room-bg::before,
#room-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#room-bg::before {
  background-image: var(--room-art);
  background-position: center 47%;
  background-repeat: no-repeat;
  background-size: cover;
  opacity: .96;
  transform: scale(1.015);
  transition: opacity .35s ease, transform 1.2s cubic-bezier(.2,.75,.2,1);
}

#room-bg::after {
  background:
    linear-gradient(180deg, rgba(10,18,28,.025) 45%, rgba(8,14,24,.2) 100%),
    radial-gradient(ellipse at 50% 45%, transparent 54%, rgba(8,14,24,.15) 100%);
  box-shadow: inset 0 0 42px rgba(8, 14, 24, .14);
}

.tray-empty {
  color: #cdd5ea;
  font-size: .82rem;
  font-weight: 700;
  padding: 10px;
}

.inventory-empty {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: .85rem;
  text-align: center;
  padding: 20px;
}

.item-desc.owned-label {
  color: var(--accent-2);
  font-weight: 800;
}

#room-decor {
  display: none;
}

#app:has(.room-btn[data-room="living"].active) #room-bg { --room-art: url("../assets/rooms/living.jpg"); }
#app:has(.room-btn[data-room="kitchen"].active) #room-bg { --room-art: url("../assets/rooms/kitchen.jpg"); }
#app:has(.room-btn[data-room="bathroom"].active) #room-bg { --room-art: url("../assets/rooms/bathroom.jpg"); }
#app:has(.room-btn[data-room="bedroom"].active) #room-bg { --room-art: url("../assets/rooms/bedroom.jpg"); }
#app:has(.room-btn[data-room="garden"].active) #room-bg { --room-art: url("../assets/rooms/garden.jpg"); }
#app:has(.room-btn[data-room="playroom"].active) #room-bg { --room-art: url("../assets/rooms/playroom.jpg"); }
#app:has(.room-btn[data-room="lab"].active) #room-bg { --room-art: url("../assets/rooms/lab.jpg"); }

#pet-canvas {
  filter: drop-shadow(0 18px 14px rgba(35, 20, 7, .2));
}

#speech-bubble {
  color: #2f2c28;
  background: #fffaf0;
  border: 1px solid rgba(94, 67, 35, .15);
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(16, 21, 30, .24);
}

#speech-bubble::after {
  border-top-color: #fffaf0;
}

.action-tray {
  bottom: 12px;
  padding: 9px 11px;
  background: rgba(15, 25, 42, .84);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 22px;
  box-shadow: 0 12px 26px rgba(3,8,16,.3), inset 0 1px 0 rgba(255,255,255,.04);
  backdrop-filter: blur(12px) saturate(1.1);
}

.tray-item {
  background: linear-gradient(180deg, #34435f, #28364f);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 15px;
  box-shadow: 0 5px 11px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.06);
}

.tray-item:hover {
  transform: translateY(-5px) rotate(-1deg);
}

.plot {
  border-color: rgba(255, 218, 151, .34);
  background: linear-gradient(180deg, rgba(125,84,43,.94), rgba(72,48,27,.96));
  border-radius: 18px;
  box-shadow: 0 9px 18px rgba(30,20,10,.3), inset 0 1px 0 rgba(255,255,255,.08);
}

.big-action-btn,
.primary-btn {
  background: linear-gradient(180deg, #ffd06c, var(--accent));
  color: #3d2c0b;
  border: 1px solid rgba(255,238,179,.5);
  box-shadow: 0 5px 0 #bd7a1f, 0 10px 18px rgba(34,20,6,.2), inset 0 1px 0 rgba(255,255,255,.5);
}

#playroom-menu {
  padding: 18px 10px;
  background: rgba(15, 24, 40, .48);
  backdrop-filter: blur(6px) saturate(.85);
}

#playroom-menu h2 {
  font-size: 1.45rem;
  letter-spacing: -.025em;
  text-shadow: 0 2px 10px rgba(0,0,0,.42);
}

.minigame-grid {
  gap: 10px;
}

.minigame-card {
  background: linear-gradient(180deg, rgba(45,60,87,.96), rgba(28,40,61,.96));
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 17px;
  box-shadow: 0 8px 16px rgba(4,9,20,.24), inset 0 1px 0 rgba(255,255,255,.06);
}

.minigame-card:hover {
  border-color: rgba(255, 190, 71, .8);
  box-shadow: 0 12px 22px rgba(4,9,20,.32), 0 0 0 2px rgba(255,182,63,.16);
}

#room-nav {
  gap: 7px;
  padding: 11px 8px 5px;
}

.room-btn {
  width: 47px;
  height: 46px;
  color: var(--text);
  background: linear-gradient(180deg, #293650, #202b41);
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 15px;
  filter: saturate(.72) brightness(.88);
  box-shadow: 0 5px 11px rgba(4,9,20,.2), inset 0 1px 0 rgba(255,255,255,.055);
}

.room-btn:hover {
  transform: translateY(-4px);
  filter: none;
}

.room-btn.active {
  color: #342306;
  background: linear-gradient(180deg, #ffd266, var(--accent));
  border-color: rgba(255, 229, 157, .7);
  filter: none;
  box-shadow: 0 4px 0 #bd7a1f, 0 9px 15px rgba(43,25,5,.25), inset 0 1px 0 rgba(255,255,255,.48);
  transform: translateY(-2px);
}

#action-bar {
  gap: 9px;
  padding: 8px 14px 14px;
}

.action-btn {
  min-height: 44px;
  background: linear-gradient(180deg, #27344e, #202b42);
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 15px;
  box-shadow: 0 6px 14px rgba(4,9,20,.2), inset 0 1px 0 rgba(255,255,255,.055);
}

.action-btn:hover {
  background: linear-gradient(180deg, #34445f, #273650);
  transform: translateY(-3px);
}

.modal {
  background: rgba(5, 10, 19, .72);
  backdrop-filter: blur(7px);
}

.modal-card,
.mg-end-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.035), transparent 28%),
    #202c43;
  border: 1px solid rgba(255,255,255,.105);
  border-radius: 24px;
  box-shadow: 0 26px 70px rgba(0,0,0,.56), inset 0 1px 0 rgba(255,255,255,.045);
}

.modal-head h2,
.mg-end-card h2 {
  color: #fff8ec;
  letter-spacing: -.025em;
}

.modal-close,
.tab-btn,
#minigame-quit {
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}

.tab-btn.active {
  color: #342306;
  background: linear-gradient(180deg, #ffd266, var(--accent));
}

.item-card,
.ach-row {
  background: linear-gradient(180deg, rgba(54,68,96,.94), rgba(43,56,82,.94));
  border-color: rgba(255,255,255,.075);
  box-shadow: 0 6px 14px rgba(3,8,16,.16), inset 0 1px 0 rgba(255,255,255,.04);
}

#minigame-overlay {
  background: radial-gradient(circle at 50% 25%, #182844, #0d1525 72%);
}

.toast {
  background: rgba(25, 37, 58, .95);
  border-color: rgba(255,255,255,.11);
  box-shadow: 0 12px 28px rgba(0,0,0,.38), inset 0 1px 0 rgba(255,255,255,.04);
  backdrop-filter: blur(8px);
}

@media (max-width: 430px) {
  #hud { padding-inline: 12px; }
  #stats-bar { gap: 6px; padding-inline: 12px; }
  .hud-right { gap: 4px; }
  .hud-btn { width: 35px; height: 35px; }
  #coin-box { min-height: 35px; padding-right: 10px; }
  #xp-bar { width: 64px; }
  #room { margin-inline: 6px; border-radius: 23px; }
  #room-nav { gap: 5px; padding-top: 9px; }
  .room-btn { width: 42px; height: 42px; border-radius: 14px; }
  #action-bar { padding-inline: 10px; gap: 7px; }
  .action-btn { font-size: .78rem; min-height: 42px; }
  .minigame-grid { grid-template-columns: repeat(2, minmax(118px, 138px)); }
}

@media (max-height: 720px) {
  #hud { min-height: 48px; padding-top: 7px; }
  #stats-bar { padding-bottom: 7px; }
  #room-nav { padding-top: 7px; }
  .room-btn { width: 42px; height: 40px; }
  #action-bar { padding-top: 5px; padding-bottom: 8px; }
  .action-btn { min-height: 38px; padding-block: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ============ Generated sprite assets ============ */
.art-sprite {
  display: inline-block;
  flex: 0 0 auto;
  width: 1.5em;
  height: 1.5em;
  background-repeat: no-repeat;
  vertical-align: middle;
  font-size: inherit;
  color: transparent;
  pointer-events: none;
  overflow: hidden;
}

.hud-btn .art-sprite { width: 21px; height: 21px; }
.stat-icon.art-sprite { width: 18px; height: 18px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.26)); }
.room-btn .art-sprite { width: 29px; height: 29px; }
.action-btn .art-sprite { width: 24px; height: 24px; }
.mg-icon.art-sprite { width: 39px; height: 39px; }
.item-emoji.art-sprite { width: 52px; height: 52px; }
.tray-item .item-emoji.art-sprite { width: 40px; height: 40px; }
.ach-icon.art-sprite { width: 44px; height: 44px; }
.plot-emoji.art-sprite { width: 48px; height: 48px; }
.mem-face.art-sprite { width: 44px; height: 44px; }
.big-action-btn .art-sprite { width: 25px; height: 25px; margin-right: 7px; }
#drag-ghost.art-sprite { width: 58px; height: 58px; font-size: 0; }

.coin-icon.art-sprite {
  width: 19px;
  height: 19px;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  box-shadow: none;
}

.room-btn,
.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.item-card .item-emoji.art-sprite,
.tray-item .item-emoji.art-sprite,
.ach-icon.art-sprite,
.plot-emoji.art-sprite,
.mg-icon.art-sprite {
  filter: drop-shadow(0 4px 5px rgba(5,10,18,.22));
}
