:root {
  --bg: #0e1116;
  --panel: #151a23;
  --chip: #1c2433;
  --chip-border: #31405c;
  --text: #eef1f7;
  --muted: #8b95a8;
  --accent: #7c5cff;
  --gold: #ffcc4d;
  --ok: #4ade80;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; overflow: hidden; }

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid #222b3a;
  flex: 0 0 auto;
}

.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: .02em; }
.brand .loop { color: var(--accent); font-size: 1.6rem; vertical-align: -.1em; }
.stats { color: var(--muted); font-size: .9rem; flex: 1; }
.stats b { color: var(--text); }
.stats .sep { margin: 0 .35rem; }
.actions { display: flex; gap: .5rem; }

button {
  font: inherit;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--chip-border);
  border-radius: 10px;
  padding: .45rem .8rem;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 700; padding: .7rem 1rem; width: 100%; margin-top: 1rem; }

main { flex: 1 1 auto; display: grid; grid-template-columns: 1fr 320px; min-height: 0; }

#stage {
  position: relative;
  overflow: hidden;
  background-image: radial-gradient(circle, #1f2736 1.2px, transparent 1.2px);
  background-size: 26px 26px;
  touch-action: none;
}

#hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #4a566d;
  font-size: 1.2rem;
  line-height: 1.6;
  pointer-events: none;
  transition: opacity .3s;
  padding: 2rem;
}
#hint small { font-size: .85rem; }
#stage.has-chips #hint { opacity: 0; }

.chip {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem .85rem;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  border-radius: 12px;
  font-size: 1.05rem;
  white-space: nowrap;
  user-select: none;
  touch-action: none;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  animation: pop .22s ease-out;
}
.chip .emoji { font-size: 1.3rem; }
.chip.dragging { cursor: grabbing; z-index: 50; box-shadow: 0 10px 28px rgba(0, 0, 0, .55); transform: scale(1.05); }
.chip.target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .45); }
.chip.loading { pointer-events: none; border-color: var(--accent); animation: pulse .9s ease-in-out infinite; }
.chip.loading .emoji { animation: spin 1s linear infinite; display: inline-block; }
.chip.first { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 204, 77, .35); }

@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(124, 92, 255, .35); } }
@keyframes spin { to { transform: rotate(360deg); } }

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid #222b3a;
}
#sidebar.drop { background: #2a1a24; }

#search {
  margin: .7rem;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--chip-border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

#list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 .7rem .7rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: .5rem;
  touch-action: pan-y;
}

#list .chip { position: static; animation: none; cursor: pointer; touch-action: pan-y; }
#list .chip.new { border-color: var(--ok); }

#toasts {
  position: fixed;
  top: calc(4rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  z-index: 200;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  background: #222b3d;
  border: 1px solid var(--chip-border);
  border-radius: 12px;
  padding: .6rem 1rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  animation: pop .25s ease-out;
  text-align: center;
}
.toast.gold { background: #3a2f10; border-color: var(--gold); color: #ffe39a; font-weight: 700; }
.toast.new { border-color: var(--ok); }
.toast.error { border-color: var(--danger); color: #ffb3b3; }

.confetti { position: fixed; z-index: 150; pointer-events: none; font-size: 1.6rem; animation: fall 1.4s ease-out forwards; }
@keyframes fall { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(5, 7, 10, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid #2a3447;
  border-radius: 18px;
  padding: 1.5rem;
  width: min(100%, 380px);
  max-height: 90vh;
  overflow-y: auto;
}
.card.wide { width: min(100%, 520px); }
.card h1, .card h2, .card h3 { margin: .2rem 0 .5rem; }
.card .big { font-size: 3rem; color: var(--accent); text-align: center; line-height: 1; }
.card h1 { text-align: center; }
.card p { color: var(--muted); }
.card label { display: block; margin: 1rem 0 .3rem; color: var(--muted); font-size: .9rem; }
.card input {
  width: 100%;
  padding: .7rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--chip-border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1.1rem;
}
.error { color: var(--danger); min-height: 1.2rem; margin-top: .6rem; text-align: center; }
.muted { color: var(--muted); }
.close { position: absolute; top: .7rem; right: .7rem; padding: .3rem .6rem; }

ol#rows { padding-left: 1.4rem; margin: .6rem 0 1rem; }
ol#rows li { padding: .35rem 0; display: flex; gap: .6rem; }
ol#rows li .who { flex: 1; }
ol#rows li .score { color: var(--gold); font-weight: 700; }
ol#rows li .total { color: var(--muted); font-size: .85rem; align-self: center; }
ul#feed { list-style: none; padding: 0; margin: 0; }
ul#feed li { padding: .3rem 0; color: var(--muted); font-size: .95rem; }
ul#feed li b { color: var(--text); }

@media (max-width: 760px), (max-aspect-ratio: 4/5) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr 38vh; }
  #sidebar { border-left: 0; border-top: 1px solid #222b3a; }
  header { gap: .5rem; padding: .5rem .7rem; padding-top: calc(.5rem + env(safe-area-inset-top)); }
  .actions .label { display: none; }
  .stats { font-size: .8rem; }
}

.brand .home { color: var(--muted); text-decoration: none; margin-right: .3rem; }

/* ---- Renovación visual ---- */
html, body { background: #0a0d16; }
body { background: radial-gradient(900px 500px at 50% -10%, rgba(124,92,255,.22), transparent 65%), radial-gradient(700px 400px at 100% 110%, rgba(236,72,153,.1), transparent 60%), linear-gradient(180deg, #0a0d16, #0c1122 60%, #090c14); }
header { background: rgba(21, 26, 40, .72); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(148,163,200,.16); }
.brand .loop { text-shadow: 0 0 18px rgba(124,92,255,.9); display: inline-block; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.12); } }
button { background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02)), var(--chip); box-shadow: 0 3px 0 rgba(0,0,0,.35); font-weight: 600; transition: transform .08s, border-color .15s; }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
button.primary { color: #0b0e16; background: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 55%), var(--accent); border-color: transparent; }
#stage { background-image: radial-gradient(circle, rgba(255,255,255,.07) 1.2px, transparent 1.2px), radial-gradient(ellipse at 50% 40%, rgba(124,92,255,.08), transparent 70%); background-size: 26px 26px, 100% 100%; }
.chip { --h: 250; background: linear-gradient(160deg, hsl(var(--h) 45% 22%), hsl(var(--h) 40% 15%)); border: 1px solid hsl(var(--h) 55% 38%); box-shadow: 0 3px 10px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.1); transition: box-shadow .12s, border-color .12s; }
.chip:hover { border-color: hsl(var(--h) 80% 62%); box-shadow: 0 6px 16px rgba(0,0,0,.45), 0 0 0 2px hsl(var(--h) 80% 55% / .25); }
.chip.target { border-color: #fff; box-shadow: 0 0 0 4px rgba(124,92,255,.6), 0 0 28px rgba(124,92,255,.7); }
.chip.first { border-color: var(--gold); animation: pop .22s ease-out, goldpulse 1.6s ease-in-out 3; }
@keyframes goldpulse { 50% { box-shadow: 0 0 0 6px rgba(255,204,77,.35), 0 0 34px rgba(255,204,77,.7); } }
#list .chip { box-shadow: 0 2px 6px rgba(0,0,0,.3); }
#list .chip.new { border-color: var(--ok); }
#sidebar { background: rgba(18, 23, 38, .85); backdrop-filter: blur(8px); }
#search { background: rgba(8,11,20,.7); }
#search:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.25); }
.toast { background: linear-gradient(180deg, #27314c, #1c2438); box-shadow: 0 10px 30px rgba(0,0,0,.55); }
.card { background: linear-gradient(180deg, rgba(36,45,74,.96), rgba(20,26,44,.96)); border-radius: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.6), 0 0 80px -30px rgba(124,92,255,.5); }
.modal { backdrop-filter: blur(8px); }
