/* Tiny Potion Shop: estilos. La escena es un canvas; todo lo demas es HTML. */
:root {
  --bg: #150d24;
  --panel: #1d1331;
  --card: #291c44;
  --card-hi: #352659;
  --line: #44306c;
  --text: #f7f1ff;
  --muted: #b5a6d6;
  --gold: #ffd166;
  --gold-d: #b97c12;
  --green: #45e0a0;
  --green-d: #1b9963;
  --blue: #63b0ff;
  --blue-d: #2c6fcc;
  --font: 'Fredoka', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { font-size: clamp(12px, 0.8vmin + 9px, 18px); }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ---------- Distribucion: escena arriba en vertical, a la izquierda en horizontal ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#stage { position: relative; flex: 0 0 42%; min-height: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#panel {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 3px solid var(--line);
}
@media (min-aspect-ratio: 1/1) {
  #app { flex-direction: row; }
  #stage { flex: 1 1 0; min-width: 0; }
  #panel { flex: 0 0 clamp(290px, 42%, 520px); border-top: 0; border-left: 3px solid var(--line); }
}

/* ---------- Marcador ---------- */
#hud {
  position: absolute;
  top: .6rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 9rem;
  padding: .35rem 1rem .4rem;
  border-radius: 1rem;
  background: rgba(12, 6, 24, .6);
  pointer-events: none;
}
#hud-coins { display: flex; align-items: center; gap: .4rem; font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
#hud-coins.bump { animation: bump .25s ease-out; }
#hud-sub { display: flex; gap: .8rem; font-size: .8rem; color: var(--muted); white-space: nowrap; }
#rate { color: var(--green); }
#rate:empty { display: none; }
@keyframes bump { 40% { transform: scale(1.12); } }

.coin {
  display: inline-block;
  flex: none;
  width: .95em;
  height: .95em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff6c4 0 18%, #ffd166 40%, #d9951c 100%);
  box-shadow: inset 0 0 0 .07em #a66b0c;
}

#toast {
  position: absolute;
  left: 50%;
  top: 5rem;
  max-width: 92%;
  padding: .45rem .9rem;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2500;
  font-weight: 700;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translate(-50%, -.5rem);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#hint {
  position: absolute;
  left: 50%;
  bottom: .7rem;
  width: max-content;
  max-width: 92%;
  padding: .45rem .9rem;
  border-radius: 999px;
  border: 2px solid var(--gold);
  background: rgba(12, 6, 24, .8);
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
  animation: hint 1.6s ease-in-out infinite;
}
#hint:empty { display: none; }
@keyframes hint { 50% { transform: translate(-50%, -.25rem); } }

/* ---------- Pestanas y multiplicador de compra ---------- */
#tabs { flex: none; display: flex; align-items: center; gap: .3rem; padding: .55rem .6rem .15rem; }
.tab {
  position: relative;
  padding: .45rem .8rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
}
.tab.on { background: var(--card-hi); color: var(--text); }
.tab .dot {
  position: absolute;
  top: .2rem;
  right: .25rem;
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: var(--gold);
  display: none;
}
.tab.has .dot { display: block; }
#mult { margin-left: auto; display: flex; flex: none; padding: .18rem; border-radius: 999px; background: #120a20; }
#mult button { padding: .3rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; color: var(--muted); }
#mult button.on { background: var(--gold); color: #3a2500; }

.list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 0 .6rem .9rem;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* ---------- Tarjetas ---------- */
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-top: .5rem;
  padding: .55rem .6rem;
  border-radius: 1rem;
  border: 2px solid var(--line);
  background: var(--card);
}
.card.locked { border-style: dashed; }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .32rem; }
.row1 { display: flex; align-items: center; gap: .4rem; }
.name { flex: 1; min-width: 0; font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl { flex: none; padding: .05rem .45rem; border-radius: 999px; background: #140c22; color: var(--gold); font-size: .8rem; font-weight: 600; }
.lvl:empty { display: none; }
.desc { font-size: .8rem; color: var(--muted); }

.bar { position: relative; height: 1.3rem; border-radius: 999px; background: #120a20; overflow: hidden; }
.fill {
  position: absolute;
  inset: 0;
  background: var(--c);
  transform-origin: 0 50%;
  transform: scaleX(0);
  box-shadow: inset 0 .35rem 0 rgba(255, 255, 255, .22);
}
.bar.fast .fill {
  transform: none !important;
  background-image: repeating-linear-gradient(-45deg, rgba(255, 255, 255, .28) 0 .5rem, transparent .5rem 1rem);
  background-size: 1.414rem 100%;
  animation: stripes .5s linear infinite;
}
@keyframes stripes { to { background-position: 1.414rem 0; } }
.bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  font-size: .78rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .85);
  white-space: nowrap;
}
.card.locked .bar-text { color: var(--muted); }

.btns { display: flex; gap: .4rem; }
.btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: .2rem .45rem;
  border-radius: .75rem;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: 0 .22rem 0 var(--sh);
  transition: transform .06s, box-shadow .06s;
}
.btn .top { font-size: .7rem; opacity: .85; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.btn .cost { display: flex; align-items: center; gap: .25rem; font-size: .92rem; }
.btn:active:not(:disabled) { transform: translateY(.16rem); box-shadow: 0 .06rem 0 var(--sh); }
.btn:disabled { filter: saturate(.25) brightness(.6); cursor: default; }
.btn.buy { background: var(--green); color: #052a19; --sh: var(--green-d); }
.btn.hire { background: var(--blue); color: #061f3d; --sh: var(--blue-d); }
.btn.gold { background: var(--gold); color: #3a2500; --sh: var(--gold-d); }

.nudge { animation: nudge 1s ease-in-out infinite; }
@keyframes nudge {
  50% { transform: scale(1.06); box-shadow: 0 0 0 .25rem rgba(255, 209, 102, .6), 0 .22rem 0 var(--sh, transparent); }
}

.float {
  position: absolute;
  left: 2.8rem;
  top: 1.9rem;
  z-index: 2;
  color: var(--gold);
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  animation: floatup .9s ease-out forwards;
}
@keyframes floatup {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -1.5rem); }
}

/* ---------- Caldero dibujado con CSS ---------- */
.pot {
  position: relative;
  flex: none;
  width: 4.4rem;
  height: 4.4rem;
  border-radius: 1rem;
  background: radial-gradient(circle at 50% 80%, #2a1a45, #170e29 70%);
  overflow: hidden;
}
.pot > span { position: absolute; display: block; }
.pot .fire {
  left: 26%;
  right: 26%;
  bottom: .62rem;
  height: .75rem;
  border-radius: 50% 50% 40% 40%;
  background: radial-gradient(ellipse at 50% 100%, #ffd27a, #ff7b2e 55%, transparent 72%);
  opacity: 0;
}
.pot.on .fire { opacity: 1; animation: flicker .25s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: scaleY(1.25) translateY(-.05rem); } }
.pot .body {
  left: 14%;
  right: 14%;
  top: 33%;
  bottom: 24%;
  border-radius: 30% 30% 46% 46% / 22% 22% 60% 60%;
  background: radial-gradient(circle at 35% 30%, #5a5170, #2b2440 60%, #1b1629);
}
.pot .rim {
  left: 9%;
  right: 9%;
  top: 26%;
  height: 15%;
  border-radius: 50%;
  background: #3d3554;
  box-shadow: inset 0 -.15rem 0 #241e36;
}
.pot .liquid {
  left: 16%;
  right: 16%;
  top: 28.5%;
  height: 9%;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 .8rem var(--c);
}
.pot .bub {
  top: 27%;
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: var(--c);
  opacity: 0;
}
.pot .b1 { left: 30%; }
.pot .b2 { left: 48%; }
.pot .b3 { left: 63%; }
.pot.on .bub { animation: bub 1.1s ease-in infinite; }
.pot.on .b2 { animation-delay: .37s; }
.pot.on .b3 { animation-delay: .74s; }
@keyframes bub {
  0% { opacity: .9; transform: translateY(0) scale(.6); }
  100% { opacity: 0; transform: translateY(-1.3rem) scale(1.1); }
}
.pot .auto {
  top: .2rem;
  left: .2rem;
  padding: .05rem .3rem;
  border-radius: .3rem;
  background: var(--blue);
  color: #061f3d;
  font-size: .55rem;
  font-weight: 700;
  display: none;
}
.pot.hired .auto { display: block; }
.pot .ms {
  left: .4rem;
  right: .4rem;
  bottom: .3rem;
  height: .28rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  overflow: hidden;
}
.pot .ms-fill {
  position: absolute;
  inset: 0;
  background: var(--gold);
  transform-origin: 0 50%;
  transform: scaleX(0);
}
.pot.tapped { animation: tap .18s ease-out; }
@keyframes tap { 50% { transform: scale(.9); } }
.card.locked .pot { filter: grayscale(1) brightness(.55); }
.card.locked .pot .ms { display: none; }

/* ---------- Mejoras ---------- */
.up-icon {
  flex: none;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: .8rem;
  background: var(--c);
  color: #1a1030;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: inset 0 -.25rem 0 rgba(0, 0, 0, .2);
}
.card.up .btn { flex: 0 0 auto; min-width: 6.5rem; }
.card.owned { opacity: .55; }
.owned-tag { flex: none; color: var(--green); font-size: .85rem; font-weight: 600; padding: 0 .4rem; }
.note {
  margin: .8rem .2rem 0;
  padding: .7rem .8rem;
  border-radius: .8rem;
  background: #140c22;
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
}

/* ---------- Ventana de "hola de nuevo" ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 4, 16, .72);
}
#modal .box {
  width: min(22rem, 92vw);
  display: flex;
  flex-direction: column;
  gap: .7rem;
  padding: 1.3rem 1.2rem 1.2rem;
  border-radius: 1.2rem;
  border: 3px solid var(--gold);
  background: var(--card);
  text-align: center;
  animation: pop .3s ease-out;
}
#modal-title { font-size: 1.5rem; font-weight: 700; color: var(--gold); }
#modal-text { font-size: .95rem; color: var(--muted); }
#modal-amount { display: flex; align-items: center; justify-content: center; gap: .5rem; font-size: 2rem; font-weight: 700; }
#modal .btn { flex: none; min-height: 2.8rem; font-size: 1.1rem; }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }

/* ---------- Carga ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.spinner {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: .35rem solid #3a2a5a;
  border-top-color: var(--gold);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Con onPause del SDK se congela todo, tambien las animaciones CSS */
body.paused *, body.paused *::before, body.paused *::after {
  animation-play-state: paused !important;
  transition: none !important;
}
