:root {
  --bg: #0b0716;
  --bg-2: #140d26;
  --panel: rgba(30, 20, 56, 0.82);
  --panel-2: #22173f;
  --border: rgba(212, 175, 95, 0.25);
  --gold: #d4af5f;
  --gold-2: #f3dc9b;
  --text: #ece6f7;
  --muted: #a99cc4;
  --danger: #e2657a;
  --ok: #6fd3a0;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at top, #2a1850 0%, var(--bg) 55%) fixed, var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image:
    radial-gradient(1.5px 1.5px at 20% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 20%, #fff7 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 40% 80%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 65%, #fff8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 10% 70%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 45%, #fff6 50%, transparent 51%);
  background-size: 600px 600px;
  animation: twinkle 8s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .5; } to { opacity: 1; } }

h1, h2, h3, .brand { font-family: 'Cinzel', serif; letter-spacing: .04em; }
h1 { color: var(--gold-2); }
h2 { color: var(--gold); margin: 0 0 1rem; font-size: 1.3rem; }
h3 { margin: 0 0 .5rem; }
a { color: var(--gold-2); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1.2rem; border-bottom: 1px solid var(--border);
  background: rgba(11, 7, 22, .7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { font-size: 1.25rem; color: var(--gold-2); display: flex; align-items: center; gap: .5rem; }
.topbar .right { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.container { max-width: 1150px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem; box-shadow: var(--shadow);
}

.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.tab {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: .55rem 1rem; border-radius: 999px; cursor: pointer; font: inherit;
}
.tab.active { background: var(--gold); color: #1a1030; border-color: var(--gold); font-weight: 600; }

.grid { display: grid; gap: 1rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1.2rem; }
.stat { text-align: center; }
.stat b { display: block; font-size: 2rem; color: var(--gold-2); font-family: 'Cinzel', serif; }

/* ---------- Formularios ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin: .7rem 0 .3rem; }
input, select, textarea {
  width: 100%; padding: .65rem .8rem; border-radius: 10px; font: inherit;
  background: #120b24; color: var(--text); border: 1px solid var(--border);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .row { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: .6rem 1.05rem; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500;
  text-decoration: none; transition: transform .1s, background .2s;
}
.btn:hover { background: #2e2054; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--gold), #b98d3a); color: #1a1030; border: none; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: rgba(226, 101, 122, .4); }
.btn.sm { padding: .35rem .7rem; font-size: .85rem; }
.btn.big { padding: .9rem 1.6rem; font-size: 1.1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.alert { padding: .7rem 1rem; border-radius: 10px; margin: .8rem 0; font-size: .92rem; }
.alert.error { background: rgba(226, 101, 122, .15); border: 1px solid rgba(226, 101, 122, .4); color: #ffc2cc; }
.alert.info { background: rgba(212, 175, 95, .12); border: 1px solid var(--border); color: var(--gold-2); }
.alert.ok { background: rgba(111, 211, 160, .12); border: 1px solid rgba(111, 211, 160, .4); color: #b9f3d6; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--border); color: var(--muted); }
.badge.gold { color: #1a1030; background: var(--gold); border-color: var(--gold); }
.badge.off { color: var(--danger); border-color: rgba(226, 101, 122, .4); }
.badge.ok { color: var(--ok); border-color: rgba(111, 211, 160, .4); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid rgba(212, 175, 95, .12); vertical-align: top; }
th { color: var(--gold); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Cartas ---------- */
.cards-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tarot {
  position: relative; border-radius: 14px; overflow: hidden;
  background: linear-gradient(160deg, #2b1d52, #150d2b);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.tarot .img {
  aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #3b2a6e, #170e30);
  font-family: 'Cinzel', serif; color: var(--gold); font-size: 2.4rem; text-align: center;
  border-bottom: 1px solid var(--border);
}
.tarot .img img { width: 100%; height: 100%; object-fit: cover; }
.tarot .body { padding: .7rem .8rem; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.tarot .name { font-family: 'Cinzel', serif; color: var(--gold-2); font-size: 1rem; }
.tarot .code { font-family: ui-monospace, monospace; font-size: .72rem; color: var(--muted); word-break: break-all; }
.tarot.off { opacity: .45; }
.tarot.sel { outline: 2px solid var(--gold); outline-offset: 2px; }
.tarot .pick { position: absolute; top: .5rem; left: .5rem; width: 22px; height: 22px; accent-color: var(--gold); cursor: pointer; z-index: 2; }
.selbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 12px; background: rgba(0,0,0,.2); }
.chk { display: inline-flex; align-items: center; gap: .45rem; margin: 0; color: var(--text); font-size: .92rem; cursor: pointer; }
.chk input { width: auto; accent-color: var(--gold); }
.dropzone {
  display: flex; gap: 1rem; align-items: center; padding: .8rem; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: 12px; background: rgba(0,0,0,.2); transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--gold); background: rgba(212,175,95,.08); outline: none; }
.dz-preview {
  flex: 0 0 72px; height: 100px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--gold); font-size: 1.6rem; background: #120b24;
}
.dz-preview img { width: 100%; height: 100%; object-fit: cover; }
.dz-text { font-size: .92rem; }
.dz-estado { margin-top: .3rem; }
.dz-estado.ok { color: var(--ok); }
.dz-estado.error { color: #ffc2cc; }
kbd { font-family: inherit; font-size: .8em; padding: .05rem .35rem; border: 1px solid var(--border); border-radius: 4px; }
.opciones { display: grid; gap: .5rem; }
.opcion { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; margin: 0; color: var(--text); font-size: .92rem; }
.opcion input { width: auto; margin-top: .25rem; accent-color: var(--gold); }
.opcion:has(input:checked) { border-color: var(--gold); background: rgba(212,175,95,.08); }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(5, 2, 12, .75); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 3vh 16px; overflow-y: auto;
}
.modal { width: 100%; max-width: 640px; }
.modal .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.x { background: none; border: none; color: var(--muted); font-size: 1.6rem; cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 400px; text-align: center; }
.login form { text-align: left; }
.moon { font-size: 3.4rem; filter: drop-shadow(0 0 18px #f3dc9b88); }

/* ---------- Lector ---------- */
.steps { display: flex; gap: .5rem; justify-content: center; margin-bottom: 1.2rem; flex-wrap: wrap; }
.step { padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.step.on { border-color: var(--gold); color: var(--gold-2); }

.scan-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; }
@media (max-width: 860px) { .scan-layout { grid-template-columns: 1fr; } }

#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; min-height: 260px; }
#reader video { border-radius: 12px; }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .8rem; }
.slot {
  border: 1.5px dashed var(--border); border-radius: 12px; aspect-ratio: 3 / 4.6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: .5rem; color: var(--muted); font-size: .8rem; position: relative; overflow: hidden;
}
.slot .pos { position: absolute; top: .4rem; left: 0; right: 0; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); }
.slot.filled { border-style: solid; border-color: var(--gold); background: linear-gradient(160deg, #2b1d52, #150d2b); animation: flip .6s ease; }
.slot.filled .card-name { font-family: 'Cinzel', serif; color: var(--gold-2); font-size: .95rem; margin-top: .4rem; }
.slot img { width: 70%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; margin-top: 1rem; }
.slot .num { font-family: 'Cinzel', serif; font-size: 1.8rem; color: var(--gold); margin-top: 1rem; }
.slot .remove { position: absolute; bottom: .3rem; right: .3rem; }
.slot.next { border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(243, 220, 155, .15) inset; }
@keyframes flip { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0); opacity: 1; } }

.oracle { text-align: center; padding: 2.5rem 1rem; }
.orb {
  width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 1.2rem;
  background: radial-gradient(circle at 35% 30%, #fff6d8, #d4af5f 35%, #6b3fa0 70%, #1b0f3a);
  box-shadow: 0 0 60px #d4af5f88, 0 0 120px #6b3fa066; animation: pulse 2.2s ease-in-out infinite;
}
.orb.speaking { animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); filter: brightness(1); } 50% { transform: scale(1.07); filter: brightness(1.25); } }

.guion { font-size: 1.08rem; line-height: 1.8; white-space: pre-wrap; text-align: left; max-width: 760px; margin: 1rem auto; }
.tirada-final { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin: 1rem 0; }
.tirada-final .mini { width: 110px; text-align: center; }
.tirada-final .mini .tarot .img { font-size: 1.5rem; }
.tirada-final .mini small { display: block; color: var(--gold); font-size: .7rem; text-transform: uppercase; margin-top: .3rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80;
  background: var(--panel-2); border: 1px solid var(--gold); color: var(--gold-2);
  padding: .7rem 1.2rem; border-radius: 999px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* ---------- Impresión de QR ---------- */
@media print {
  body { background: #fff !important; color: #000; }
  body::before, .no-print { display: none !important; }
}
