:root {
  --glass: #12160fd9; --line: #ffffff24; --ink: #f6f2e8; --muted: #c9c4b4; --accent: #e9a35a; --accent-ink: #20170d;
  --r: 18px; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #10130f; font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--ink); overscroll-behavior: none; }
button, a, textarea, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
svg.fill { fill: currentColor; stroke: none; }
#stage { position: fixed; inset: 0; } #stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; text-align: center; transition: opacity .6s;
  background: linear-gradient(#10130fcc, #10130f), url(/assets/opt/backdrops/arbol_2k.webp) center/cover; }
#loading img { display: block; margin: 0 auto 14px; border-radius: 20px; }
#loading span { display: block; color: var(--muted); margin-top: 6px; font-size: 13px; }
#loading.done { opacity: 0; pointer-events: none; }
/* indicador de carga genérico */
#loading .spin { display: block; width: 26px; height: 26px; margin: 4px auto 0; border-radius: 50%; border: 3px solid #ffffff22; border-top-color: var(--accent); animation: lapSpin 0.9s linear infinite; }
@keyframes lapSpin { to { transform: rotate(360deg); } }

.hud { position: fixed; z-index: 10; }
.card { background: var(--glass); border: 1px solid var(--line); border-radius: var(--r); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

/* ---------- arriba ---------- */
#top { top: calc(var(--safe-t) + 12px); left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; pointer-events: none; }
#top > * { pointer-events: auto; }
#statusCard { display: grid; gap: 3px; text-align: left; padding: 10px 14px 11px; min-width: 190px; max-width: min(300px, 62vw); }
.who { display: flex; align-items: baseline; gap: 8px; }
.who b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who i { font-style: normal; font-size: 12px; color: var(--accent); white-space: nowrap; }
#status { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.meters i { display: block; height: 5px; border-radius: 99px; background: #ffffff22; overflow: hidden; }
.meters b { display: block; height: 100%; border-radius: 99px; transition: width .4s; }
#nEnergy { background: #f2c14e; } #nFun { background: #6fc2e8; } #nSocial { background: #f08aa6; }
#tabs { display: flex; padding: 4px; gap: 2px; border-radius: 99px; }
#tabs a { text-decoration: none; padding: 8px 14px; border-radius: 99px; font-size: 13.5px; white-space: nowrap; color: var(--muted); }
#tabs a.on { background: var(--ink); color: #1c1a17; font-weight: 600; }

/* ---------- etiquetas sobre las mascotas ---------- */
#tags { position: fixed; inset: 0; z-index: 6; pointer-events: none; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); padding: 3px 10px; border-radius: 99px; font-size: 12px; white-space: nowrap;
  background: #0b0e09b3; border: 1px solid #ffffff2e; color: var(--ink); pointer-events: auto; cursor: pointer; will-change: transform; }
.tag.on { border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- menú alrededor de la mascota ---------- */
#ring { position: fixed; left: 0; top: 0; z-index: 12; width: 0; height: 0; }
#ring[hidden] { display: none; }
#ring button { position: absolute; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transform: translate(var(--x), var(--y)) scale(1); transition: transform .22s cubic-bezier(.2, 1.4, .4, 1), opacity .15s; }
#ring.closed button { transform: translate(0, 0) scale(.3); opacity: 0; }
#ring button span { position: absolute; top: 100%; margin-top: 3px; font-size: 11px; white-space: nowrap; text-shadow: 0 1px 3px #000; }
#ring button:active { background: var(--accent); color: var(--accent-ink); }
#ring button[data-cmd="pet"] { color: #ff9ab3; }

/* ---------- barra inferior ---------- */
#dock { left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%); display: flex; padding: 6px; gap: 2px; border-radius: 24px; max-width: calc(100vw - 20px); }
#dock button { display: grid; justify-items: center; gap: 2px; min-width: 66px; padding: 8px 8px 6px; border-radius: 18px; font-size: 11.5px; color: var(--muted); }
#dock button svg { width: 24px; height: 24px; color: var(--ink); }
#dock button:active, #dock button.on { background: #ffffff1c; color: var(--ink); }
#dock button.armed { background: var(--accent); color: var(--accent-ink); }
/* cámara desplazada: botón para volver a seguir a la mascota */
#camBack { left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translateX(-50%); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; min-height: 44px; }
#camBack[hidden] { display: none; }
#dock button.armed svg { color: var(--accent-ink); }
#dock.dim { opacity: 0; pointer-events: none; transition: opacity 0.4s; } /* durante la entrada a la habitación */
/* barra del modo edición: misma posición que la barra de acciones */
#editbar { left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%); display: flex; align-items: center; padding: 6px 6px 6px 16px; gap: 4px; border-radius: 24px; max-width: calc(100vw - 20px); }
#editbar[hidden] { display: none; }
#editHint { font-size: 12.5px; color: var(--muted); margin-right: 8px; max-width: 220px; }
#editbar button { display: grid; justify-items: center; gap: 2px; min-width: 64px; padding: 8px 8px 6px; border-radius: 18px; font-size: 11.5px; color: var(--muted); }
#editbar button svg { width: 24px; height: 24px; color: var(--ink); }
#editbar button:disabled { opacity: 0.4; }
#editbar button.primary { background: var(--accent); color: var(--accent-ink); }
#editbar button.primary svg { color: var(--accent-ink); }
#invList { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
#invList button { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 14px; background: #ffffff12; color: var(--ink); }
#invList button span { color: var(--muted); }
#styleBody h3 { margin: 14px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
#styleBody .swatches { display: flex; flex-wrap: wrap; gap: 8px; }
#styleBody .sw { display: grid; justify-items: center; gap: 4px; padding: 6px; border-radius: 12px; font-size: 11px; color: var(--muted); }
#styleBody .sw i { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 0 0 2px #ffffff22; }
#styleBody .sw.on i, #styleBody .vw.on img { box-shadow: 0 0 0 3px var(--accent); }
#styleBody .views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#styleBody .vw { display: grid; gap: 4px; font-size: 11px; color: var(--muted); }
#styleBody .vw img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; }
/* tienda */
#sheet-shop header .balance { margin-left: auto; margin-right: 8px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
#sheet-shop header .balance b { color: var(--ink); font-size: 15px; }
.paw { display: inline-block; width: 14px; height: 14px; background: currentColor; -webkit-mask: radial-gradient(circle at 50% 70%, #000 32%, transparent 34%), radial-gradient(circle at 18% 38%, #000 13%, transparent 15%), radial-gradient(circle at 39% 18%, #000 13%, transparent 15%), radial-gradient(circle at 61% 18%, #000 13%, transparent 15%), radial-gradient(circle at 82% 38%, #000 13%, transparent 15%); mask: radial-gradient(circle at 50% 70%, #000 32%, transparent 34%), radial-gradient(circle at 18% 38%, #000 13%, transparent 15%), radial-gradient(circle at 39% 18%, #000 13%, transparent 15%), radial-gradient(circle at 61% 18%, #000 13%, transparent 15%), radial-gradient(circle at 82% 38%, #000 13%, transparent 15%); }
#shopTabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; }
#shopTabs button { padding: 7px 12px; border-radius: 999px; background: #ffffff12; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
#shopTabs button.on { background: var(--accent); color: var(--accent-ink); }
#shopGrid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
#shopGrid .card { display: grid; gap: 6px; padding: 10px; border-radius: 16px; background: #ffffff0d; }
#shopGrid .card img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #ffffff1c, #ffffff05); }
#shopGrid .card b { font-size: 13px; font-weight: 600; }
#shopGrid .card button { display: flex; justify-content: center; align-items: center; gap: 6px; padding: 8px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#shopGrid .card button:disabled { background: #ffffff14; color: var(--muted); }
#styleBody .locked { position: relative; opacity: 0.55; }
#styleBody .locked::after { content: '🔒'; position: absolute; top: 2px; right: 4px; font-size: 12px; }
#invList .empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { #editHint { display: none; } #editbar { left: 8px; right: 8px; transform: none; justify-content: space-between; } #editbar button { flex: 1 1 0; min-width: 0; } }

#coach, #toast { position: fixed; left: 50%; transform: translateX(-50%); z-index: 11; text-align: center; max-width: min(460px, calc(100vw - 28px)); margin: 0; }
#coach { bottom: calc(var(--safe-b) + 92px); font-size: 13px; color: #fff; text-shadow: 0 1px 4px #000c; pointer-events: none; }
#toast { bottom: calc(var(--safe-b) + 96px); background: #12160ff2; border: 1px solid #ffd27a80; border-radius: 14px; padding: 10px 16px; font-size: 14px; z-index: 30; }

/* ---------- hojas ---------- */
#scrim { position: fixed; inset: 0; z-index: 20; background: #0006; }
.sheet { position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-height: 78dvh; overflow: auto; padding: 8px 18px calc(var(--safe-b) + 18px);
  background: #151a12f7; border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; animation: up .24s ease-out; }
.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 99px; background: #ffffff40; margin: 0 auto 6px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { font-size: 17px; margin: 6px 0; } .sheet h3 { font-size: 12.5px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.x { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #ffffff14; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.primary, .ghost { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 99px; font-weight: 600; text-decoration: none; flex: 1 1 auto; }
.primary { background: var(--accent); color: var(--accent-ink); } .ghost { border: 1px solid #ffffff4d; }
.primary:disabled { opacity: .5; }
textarea { width: 100%; margin: 8px 0 10px; resize: none; background: #0006; border: 1px solid var(--line); border-radius: 14px; padding: 12px; font-size: 16px; }
/* placa del jardín: fechas y frase */
#plaqueBlock .dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#plaqueBlock label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
#plaqueBlock .phrase { margin: 10px 0 12px; }
#plaqueBlock input { width: 100%; min-width: 0; min-height: 44px; background: #0006; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 16px; color: var(--ink); color-scheme: dark; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
ul { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
#friendList li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; padding: 11px 14px; border-radius: 14px; background: #ffffff0f; border: 1px solid transparent; cursor: pointer; }
#friendList li.on { border-color: var(--accent); }
#friendList small, #memList small { color: var(--muted); font-size: 12.5px; }
#friendList small { grid-column: 1; } #friendList em { grid-row: 1 / span 2; grid-column: 2; font-style: normal; font-size: 12px; color: var(--accent); }
#memList li { padding: 11px 14px; border-radius: 14px; background: #ffffff0f; font-size: 14px; }
#memList small { display: block; margin-top: 2px; }
.spaces { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spaces a { position: relative; border-radius: 14px; overflow: hidden; border: 2px solid transparent; text-decoration: none; aspect-ratio: 16 / 9; }
.spaces a.on { border-color: var(--accent); }
.spaces img { width: 100%; height: 100%; object-fit: cover; display: block; }
.spaces span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 10px 7px; font-size: 13px; font-weight: 600; background: linear-gradient(#0000, #000c); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { padding: 9px 14px; border-radius: 99px; background: #ffffff12; border: 1px solid transparent; font-size: 13.5px; }
.chips button.on { border-color: var(--accent); background: #ffffff22; }
.switch { display: flex; gap: 12px; align-items: center; margin-top: 18px; min-height: 44px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- escritorio: las hojas son un panel a la derecha ---------- */
@media (min-width: 900px) and (orientation: landscape) {
  #scrim { background: transparent; }
  .sheet { left: auto; right: 16px; bottom: 100px; width: 372px; max-height: calc(100dvh - 190px); border-radius: 22px; border-bottom: 1px solid var(--line); padding: 14px 18px 18px; animation: side .2s ease-out; }
  .sheet::before { display: none; }
  @keyframes side { from { transform: translateX(24px); opacity: 0; } }
  #dock button { min-width: 78px; font-size: 12px; }
}
/* ---------- vertical angosto ---------- */
@media (max-width: 520px) {
  #top { left: 8px; right: 8px; gap: 6px; }
  #statusCard { min-width: 0; padding: 8px 12px 9px; flex: 1 1 auto; }
  .who b { font-size: 15px; } #status { font-size: 12.5px; }
  #tabs a { padding: 8px 10px; font-size: 12.5px; }
  #dock { left: 8px; right: 8px; transform: none; justify-content: space-between; }
  #dock button { min-width: 0; flex: 1 1 0; padding: 8px 2px 6px; }
}
/* ---------- celular acostado ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #top { top: calc(var(--safe-t) + 6px); }
  .meters { display: none; }
  #dock { bottom: calc(var(--safe-b) + 6px); padding: 3px; }
  #dock button { padding: 5px 8px 4px; }
  #dock button span { display: none; }
  .sheet { left: auto; right: 8px; bottom: 8px; width: min(360px, 60vw); max-height: calc(100dvh - 16px); border-radius: 18px; border-bottom: 1px solid var(--line); }
  #coach { bottom: 60px; } #toast { bottom: 62px; }
}
@media (prefers-reduced-motion: reduce) { .sheet, #ring button { animation: none; transition: none; } }
.loadActions { display: flex; gap: 10px; justify-content: center; margin: 16px 0 0; }
.loadActions a { color: #fff; text-decoration: none; padding: 10px 16px; border-radius: 99px; border: 1px solid #ffffff55; font-size: 14px; }
.loadActions a:first-child { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
#loading > div { max-width: min(420px, 86vw); }

/* el ícono de la plaza es alto y angosto: se agranda un poco para que pese igual que los demás */
#toPlaza .ico { transform: scale(1.3); }
