:root {
  --cafe: #5d3a1a;
  --cafe2: #8b5a2b;
  --crema: #fff6e9;
  --crema2: #f3e2c7;
  --verde: #3e9b4f;
  --rojo: #d64541;
  --texto: #2b1a0e;
  --sombra: 0 6px 20px rgba(40, 20, 0, .25);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2d1c0e; color: var(--texto); }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* Acceso */
#auth { display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #8b5a2b, #2d1c0e 70%); padding: 16px; }
.auth-card { width: min(380px, 100%); background: var(--crema); border-radius: 18px; padding: 28px 24px; box-shadow: var(--sombra); }
.auth-card h1 { margin: 0 0 6px; color: var(--cafe); text-align: center; }
.tagline { text-align: center; margin: 0 0 18px; color: #6b4a2b; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { flex: 1; padding: 9px; background: var(--crema2); color: var(--cafe); }
.tab.active { background: var(--cafe); color: #fff; }
form label { display: block; font-size: 14px; margin-bottom: 12px; color: #5a3d22; }
form input { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border: 2px solid var(--crema2); border-radius: 10px; font-size: 16px; background: #fff; }
form input:focus { outline: none; border-color: var(--cafe2); }
.primary { width: 100%; padding: 12px; background: var(--verde); color: #fff; font-weight: 700; font-size: 16px; }
.primary:disabled { opacity: .6; }
.error { color: var(--rojo); min-height: 1.2em; margin: 4px 0 10px; font-size: 14px; }

/* Juego */
#game { background: #3b2412; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; z-index: 2; pointer-events: none; }
#hud > * { pointer-events: auto; background: rgba(255, 246, 233, .95); border-radius: 12px; padding: 6px 10px; box-shadow: var(--sombra); }
.hud-level { display: flex; align-items: center; gap: 8px; }
.badge { display: inline-grid; place-items: center; min-width: 30px; height: 30px; border-radius: 50%; background: var(--cafe); color: #fff; font-weight: 800; }
.xpbar { width: 110px; height: 10px; background: var(--crema2); border-radius: 6px; overflow: hidden; }
#hud-xp { height: 100%; width: 0; background: linear-gradient(90deg, #f6b93b, #e58e26); transition: width .4s; }
.hud-stat b { font-variant-numeric: tabular-nums; }
.hud-user { margin-left: auto; font-weight: 600; color: var(--cafe); }

#toolbar { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; background: rgba(255, 246, 233, .96); padding: 6px; border-radius: 16px; box-shadow: var(--sombra); z-index: 2; max-width: calc(100% - 16px); overflow-x: auto; }
#toolbar button { display: flex; flex-direction: column; align-items: center; font-size: 22px; padding: 6px 10px; background: transparent; color: var(--cafe); min-width: 58px; }
#toolbar button span { font-size: 11px; font-weight: 600; margin-top: 2px; }
#toolbar button.small { min-width: 40px; font-size: 18px; justify-content: center; }
#toolbar button:hover, #toolbar button.active { background: var(--crema2); }

#mode-bar { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: var(--cafe); color: #fff; padding: 8px 10px 8px 14px; border-radius: 12px; display: flex; gap: 10px; align-items: center; z-index: 3; box-shadow: var(--sombra); max-width: calc(100% - 16px); }
#mode-bar button { padding: 6px 12px; background: #fff; color: var(--cafe); font-weight: 700; }
#mode-bar button.danger { background: var(--rojo); color: #fff; }

#toasts { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 4; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: rgba(43, 26, 14, .92); color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--sombra); animation: toast-in .2s ease-out; text-align: center; }
.toast.err { background: rgba(176, 40, 36, .95); }
.toast.ok { background: rgba(46, 125, 50, .95); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Ventana */
#modal { position: fixed; inset: 0; background: rgba(20, 10, 0, .55); display: grid; place-items: center; z-index: 10; padding: 12px; }
.modal-card { width: min(560px, 100%); max-height: 86vh; display: flex; flex-direction: column; background: var(--crema); border-radius: 16px; box-shadow: var(--sombra); overflow: hidden; }
.modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--cafe); color: #fff; }
.modal-card h2 { margin: 0; font-size: 18px; }
#modal-close { background: transparent; color: #fff; font-size: 18px; padding: 4px 8px; }
#modal-body { padding: 14px 16px; overflow-y: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { background: #fff; border: 2px solid var(--crema2); border-radius: 12px; padding: 10px; text-align: left; display: flex; flex-direction: column; gap: 4px; color: var(--texto); }
.card:hover:not(:disabled) { border-color: var(--cafe2); }
.card:disabled { opacity: .5; cursor: not-allowed; }
.card .ico { font-size: 30px; }
.card .name { font-weight: 700; }
.card .meta { font-size: 12px; color: #6b4a2b; }
.card .price { font-weight: 700; color: var(--cafe); }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid rgba(0,0,0,.15); }
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.subtabs button { padding: 7px 12px; background: var(--crema2); color: var(--cafe); }
.subtabs button.active { background: var(--cafe); color: #fff; }
.rank { width: 100%; border-collapse: collapse; }
.rank td, .rank th { padding: 7px 6px; border-bottom: 1px solid var(--crema2); text-align: left; }
.help p { margin: 0 0 10px; line-height: 1.45; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.row button { padding: 9px 14px; background: var(--crema2); color: var(--cafe); font-weight: 700; }
.row button.go { background: var(--verde); color: #fff; }
.row button.danger { background: var(--rojo); color: #fff; }

@media (max-width: 560px) {
  .xpbar { width: 70px; }
  .hud-user { display: none; }
  #toolbar button { min-width: 50px; padding: 5px 6px; }
}
