:root {
  color-scheme: dark;
  --bg: #08050f;
  --bg-glow-1: #2a1a55;
  --bg-glow-2: #1a1038;
  --text: #f5efff;
  --muted: #a89cc6;
  --line: rgba(214, 188, 255, 0.16);
  --surface: rgba(28, 20, 52, 0.72);
  --surface-2: rgba(255, 255, 255, 0.04);
  --gold: #f2c56d;
  --gold-2: #d99a3a;
  --gold-soft: rgba(242, 197, 109, 0.12);
  --danger: #ff9b9b;
  --radius: 20px;
  --max: 680px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse 80% 55% at 20% -10%, color-mix(in srgb, var(--bg-glow-1) 85%, transparent) 0%, transparent 60%),
    radial-gradient(ellipse 70% 50% at 85% 108%, color-mix(in srgb, var(--bg-glow-2) 90%, transparent) 0%, transparent 65%),
    var(--bg);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 42px 64px, rgba(255, 255, 255, 0.35), transparent 100%),
    radial-gradient(1px 1px at 168px 18px, rgba(255, 255, 255, 0.22), transparent 100%),
    radial-gradient(1.5px 1.5px at 108px 142px, rgba(242, 197, 109, 0.3), transparent 100%),
    radial-gradient(1px 1px at 198px 104px, rgba(255, 255, 255, 0.18), transparent 100%);
  background-size: 240px 240px;
  opacity: 0.8;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.15rem; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; margin-bottom: 1rem; }
p { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding:
    0.9rem max(1rem, calc((100% - var(--max)) / 2 + 1rem)) 0.7rem;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--bg) 92%, transparent),
    color-mix(in srgb, var(--bg) 72%, transparent)
  );
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.brand img { border-radius: 9px; }

.net-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.net-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #7ee0a8;
  box-shadow: 0 0 8px rgba(126, 224, 168, 0.6);
}

.net-status[data-offline="true"]::before {
  background: var(--gold);
  box-shadow: 0 0 8px rgba(242, 197, 109, 0.6);
}

.header-actions { display: flex; align-items: center; gap: 0.4rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1rem 0.5rem;
}

.tabs a {
  flex: 1;
  padding: 0.55rem 0.75rem;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 12px;
}

.tabs a[aria-current="page"] {
  color: var(--gold);
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 1px rgba(242, 197, 109, 0.25);
}

.count {
  display: inline-block;
  min-width: 1.4rem;
  margin-left: 0.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(242, 197, 109, 0.18);
  color: var(--gold);
  font-size: 0.72rem;
  line-height: 1.35rem;
  text-align: center;
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.5rem 1rem 2rem;
}

.view[hidden] { display: none; }

.deck-info {
  margin-top: 0.25rem;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.new-badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.16rem 0.55rem;
  border: 1px solid rgba(242, 197, 109, 0.45);
  border-radius: 999px;
  background: rgba(242, 197, 109, 0.14);
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: none;
  vertical-align: 0.12em;
  animation: new-glow 2.6s ease-in-out infinite;
}

.new-badge[hidden] { display: none; }

.table {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1.4rem;
  margin: 1rem 0 1.2rem;
}

.card-stage {
  width: 100%;
  perspective: 1100px;
}

.card {
  position: relative;
  display: grid;
  align-content: center;
  gap: 0.75rem;
  min-height: 17.5rem;
  padding: 2.4rem 1.5rem;
  text-align: center;
  background:
    radial-gradient(ellipse 85% 55% at 50% -12%, rgba(242, 197, 109, 0.15), transparent 65%),
    linear-gradient(160deg, rgba(45, 31, 82, 0.9), rgba(19, 12, 38, 0.96));
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 8px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0.55rem;
  border: 1px solid rgba(242, 197, 109, 0.18);
  border-radius: calc(var(--radius) + 2px);
  pointer-events: none;
}

.card.is-placeholder::before { display: none; }

.card.is-drawing {
  animation: draw-from-deck 700ms cubic-bezier(0.2, 0.55, 0.3, 1) both;
  transform-origin: 50% 88%;
  z-index: 3;
}

.card-corner {
  position: absolute;
  color: var(--gold);
  font-size: 1rem;
  line-height: 1;
  opacity: 0.5;
  pointer-events: none;
}

.card-corner-tl { top: 1.05rem; left: 1.15rem; }
.card-corner-br { right: 1.15rem; bottom: 1.05rem; transform: rotate(180deg); }
.card.is-placeholder .card-corner { display: none; }

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(ellipse 70% 60% at 50% 0%, rgba(242, 197, 109, 0.1), transparent 70%);
  opacity: 0;
  transition: opacity 240ms ease;
}

.card.is-active {
  border-color: rgba(242, 197, 109, 0.5);
  box-shadow: var(--shadow), 0 0 0 1px rgba(242, 197, 109, 0.12), 0 0 60px rgba(242, 197, 109, 0.08);
}

.card.is-active::after { opacity: 1; }

.card.is-placeholder {
  background: rgba(255, 255, 255, 0.02);
  border-style: dashed;
  box-shadow: none;
}

.card.is-placeholder .card-text {
  font-family: inherit;
  font-size: 1rem;
  color: var(--muted);
  font-style: normal;
}

.card-text {
  font-family: var(--serif);
  font-size: clamp(1.35rem, 4.8vw, 1.8rem);
  line-height: 1.45;
  letter-spacing: 0.005em;
  text-wrap: balance;
}

.card-description {
  max-width: 34ch;
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  text-wrap: pretty;
}

.card-badge {
  position: absolute;
  top: 1.05rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.22rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(242, 197, 109, 0.45);
  background: rgba(242, 197, 109, 0.12);
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Mazo: pila de dorsos de carta */
.deck {
  position: relative;
  width: 116px;
  height: 154px;
  margin-top: 0.15rem;
  transition: opacity 240ms ease;
}

.deck-stack {
  position: absolute;
  inset: 0;
  transition: opacity 300ms ease;
}

.deck:not(.is-ready) .deck-stack { opacity: 0.55; }

.deck-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 136px;
  overflow: hidden;
  border: 1px solid rgba(242, 197, 109, 0.34);
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 42%, rgba(242, 197, 109, 0.18), transparent 58%),
    linear-gradient(155deg, #2a1f4d, #140d2a 65%, #0d0820);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
}

.deck-card::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(242, 197, 109, 0.22);
  border-radius: 8px;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(242, 197, 109, 0.07) 0 1px,
    transparent 1px 7px
  );
}

.deck-card::after {
  content: "✦";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(242, 197, 109, 0.55);
  font-size: 1.1rem;
}

.deck-card:nth-child(1) { z-index: 4; transform: rotate(-1.5deg); }
.deck-card:nth-child(2) { z-index: 3; transform: translate(5px, 5px) rotate(2deg); }
.deck-card:nth-child(3) { z-index: 2; transform: translate(9px, 10px) rotate(-2.5deg); }
.deck-card:nth-child(4) { z-index: 1; transform: translate(13px, 15px) rotate(1.5deg); }

.deck.is-ready .deck-card:nth-child(1) {
  animation: deck-breathe 3.6s ease-in-out infinite;
}

.deck.is-empty .deck-card { display: none; }

.deck.is-empty::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 136px;
  border: 1px dashed rgba(214, 188, 255, 0.22);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.hint {
  min-height: 1.4rem;
  margin-top: 0.9rem;
  text-align: center;
  font-size: 0.86rem;
  color: var(--muted);
}

.reset-row {
  display: flex;
  justify-content: center;
  margin-top: 1.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.62rem 1.1rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}

.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn[hidden] { display: none; }

.btn.primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  border-color: transparent;
  color: #1d1204;
  box-shadow: 0 10px 30px rgba(242, 197, 109, 0.18);
}

.btn.danger-solid {
  background: linear-gradient(135deg, #f87171, #dc2626);
  border-color: transparent;
  color: #2a0505;
  box-shadow: 0 10px 30px rgba(220, 38, 38, 0.22);
}

.btn.ghost { background: transparent; }
.btn.small { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn.danger { color: var(--danger); border-color: rgba(255, 155, 155, 0.35); }

.btn:focus-visible,
.tabs a:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.completed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.8rem;
}

.completed-item {
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.completed-item .message {
  font-family: var(--serif);
  font-size: 1.14rem;
  line-height: 1.4;
  margin-bottom: 0.6rem;
  text-wrap: balance;
}

.completed-item .description {
  margin: -0.2rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
  text-wrap: pretty;
}

.completed-item blockquote {
  margin: 0;
  padding-left: 0.8rem;
  border-left: 2px solid rgba(242, 197, 109, 0.6);
  color: var(--muted);
  font-style: italic;
  font-size: 0.94rem;
  overflow-wrap: anywhere;
}

.empty {
  margin-top: 1rem;
  padding: 2.2rem 1.2rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Diálogo de comentario */
.dialog {
  width: min(92vw, 480px);
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  margin: auto;
}

.dialog::backdrop {
  background: rgba(4, 2, 10, 0.72);
  backdrop-filter: blur(6px);
}

.dialog-body {
  display: grid;
  gap: 0.45rem;
  padding: 1.5rem;
  background: linear-gradient(165deg, #241a44, #110b24);
  border: 1px solid rgba(242, 197, 109, 0.28);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.dialog-body h2 { font-size: 1.25rem; margin-bottom: 0; }

.dialog-card {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--gold);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
  text-wrap: balance;
}

.dialog-description {
  margin: -0.1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
  text-wrap: pretty;
}

.dialog-warning {
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(255, 155, 155, 0.35);
  border-radius: 12px;
  background: rgba(255, 155, 155, 0.08);
  color: #ffd9d9;
  font-size: 0.9rem;
  line-height: 1.5;
}

.dialog-warning strong { color: #fff; }

.dialog-note { font-size: 0.8rem; color: var(--muted); }

.dialog-body label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.3rem;
}

input,
textarea,
select,
button { font: inherit; color: inherit; }

textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  resize: vertical;
  min-height: 4.6rem;
}

textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.dialog-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 1.3rem;
}

.char-count { margin-left: auto; font-size: 0.75rem; color: var(--muted); }

.error { color: var(--danger); font-size: 0.82rem; }
.error[hidden] { display: none; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(92vw, 460px);
  padding: 0.7rem 0.95rem;
  background: #f5efff;
  color: #140d2a;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: 0.88rem;
}

.toast[hidden] { display: none; }
.toast .btn { color: inherit; border-color: rgba(20, 13, 42, 0.25); }

.noscript {
  margin: 2rem auto;
  max-width: 40rem;
  text-align: center;
  color: var(--danger);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.6rem 1rem;
  background: var(--gold);
  color: #1d1204;
  z-index: 100;
}

.skip-link:focus { left: 0; }

@keyframes draw-from-deck {
  0% {
    transform: translate(var(--draw-x, 0px), var(--draw-y, 0px)) rotate(-8deg) scale(0.5);
    opacity: 0.1;
  }
  35% { opacity: 1; }
  72% {
    transform: translate(calc(var(--draw-x, 0px) * 0.1), calc(var(--draw-y, 0px) * 0.1))
      rotate(1.5deg) scale(1.02);
  }
  100% { transform: none; opacity: 1; }
}

@keyframes deck-breathe {
  0%, 100% { box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45), 0 0 0 rgba(242, 197, 109, 0); }
  50% { box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45), 0 0 28px rgba(242, 197, 109, 0.25); }
}

@keyframes new-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(242, 197, 109, 0); }
  50% { box-shadow: 0 0 14px rgba(242, 197, 109, 0.35); }
}

@media (max-width: 480px) {
  .card { min-height: 15.5rem; padding: 2.2rem 1.2rem; }
  .deck { width: 104px; height: 140px; }
  .deck-card,
  .deck.is-empty::before { width: 90px; height: 124px; }
  .app-footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
