@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #313338;
  --surface:   #2b2d31;
  --surface2:  #1e1f22;
  --accent:    #5865f2;
  --accent-h:  #4752c4;
  --green:     #57f287;
  --red:       #ed4245;
  --yellow:    #fee75c;
  --text:      #dbdee1;
  --text-muted:#949ba4;
  --radius:    8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'gg sans', 'Inter', 'Noto Sans', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}

.tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all .15s;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.tab:hover:not(.active) {
  background: var(--surface);
  color: var(--text);
}

/* ── Sections ── */
.section { display: none; width: 100%; max-width: 640px; }
.section.visible { display: block; }

/* ── Game ── */
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
  position: relative;
}

.connectors-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.column-label {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.game-grid > div {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  font-size: 0.88rem;
  text-align: center;
  transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
  user-select: none;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.card:active { transform: scale(0.97); }

.card:hover:not(.paired):not(.correct):not(.wrong) {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(88,101,242,0.2);
}

@keyframes pulse-selected {
  0%, 100% { box-shadow: 0 0 0 0 rgba(88,101,242,0); }
  50%       { box-shadow: 0 0 0 6px rgba(88,101,242,0.18); }
}

.card.selected {
  border-color: var(--accent);
  background: #3c3f8c44;
  animation: pulse-selected 1.6s ease-in-out infinite;
}

.card.paired { cursor: default; }
.card.paired:hover { transform: none; box-shadow: none; }

@keyframes pair-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}
.card.pair-pop { animation: pair-pop 0.35s cubic-bezier(0.36,.07,.19,.97) both; }

.card.correct { border-color: var(--green) !important; background: #57f28722 !important; cursor: default; }
.card.correct:hover { transform: none; box-shadow: none; }
.card.wrong   { border-color: var(--red)   !important; background: #ed424522 !important; cursor: default; }
.card.wrong:hover   { transform: none; box-shadow: none; }

.connection-line {
  position: absolute;
  pointer-events: none;
}

/* ── Botones ── */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:hover { background: var(--surface2); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ── Score ── */
@keyframes score-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.score-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  margin-bottom: 16px;
  animation: score-slide-up 0.4s ease both;
}

.score-number {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}

.score-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ── Pares conectados ── */
.pairs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

@keyframes pair-row-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pair-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  animation: pair-row-in 0.35s ease both;
}

.pair-term { font-weight: 600; min-width: 0; flex-shrink: 0; }
.pair-defs { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.pair-defs > span { color: var(--text-muted); }
.pair-wrong-def { text-decoration: line-through; opacity: 0.6; }
.pair-correct-def { color: var(--green) !important; font-weight: 600; }
.pair-row .arrow { flex-shrink: 0; }
.pair-row.correct { border-left: 3px solid var(--green); }
.pair-row.wrong   { border-left: 3px solid var(--red); }
.pair-row.correct .arrow { color: var(--green); }
.pair-row.wrong   .arrow { color: var(--red); }

/* ── Confetti ── */
.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
  overflow: hidden;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(105vh) rotate(600deg); opacity: 0; }
}

.confetti-piece {
  position: absolute;
  top: -20px;
  animation: confetti-fall linear forwards;
}

/* ── Inputs ── */
input[type="text"] {
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color .15s;
}

input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-muted); }

/* ── Botón pequeño ── */
.btn-sm { padding: 7px 16px; font-size: 0.85rem; }

/* ── Del button (global) ── */
.del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.del-btn:hover { color: var(--red); background: #ed424522; }

/* ── Lista de definiciones ── */
.def-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.def-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.88rem;
}

.def-term { font-weight: 600; color: var(--text); white-space: nowrap; }
.def-body { flex: 1; color: var(--text-muted); }
.def-item .sep { color: var(--text-muted); flex-shrink: 0; }

/* ── Admin: bloques ── */
.admin-block-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 640px;
}

.admin-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.admin-block-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.admin-mg-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.admin-mg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-radius: 6px;
  padding: 10px 12px;
}

.admin-mg-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.admin-mg-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.admin-add-mg-row { margin-top: 4px; }

/* ── Add-block details ── */
.add-block-details {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 640px;
}

.add-block-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.9rem;
  user-select: none;
  list-style: none;
}

.add-block-details summary::-webkit-details-marker { display: none; }

/* ── CSV import ── */
.csv-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.csv-file-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 2px dashed #ffffff18;
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: border-color .15s, color .15s;
  min-width: 0;
}

.csv-file-label:hover { border-color: var(--accent); color: var(--text); }
.csv-file-label input[type="file"] { display: none; }
.csv-file-icon { flex-shrink: 0; }

#csv-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.csv-hint {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.csv-hint code {
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
  color: var(--accent);
}

/* ── Notificación toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--surface2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #ffffff18;
  transition: transform .3s ease;
  z-index: 100;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Loading / empty ── */
.loading, .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-size: 0.95rem;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--surface);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Navegación ── */
.screen-header {
  width: 100%;
  max-width: 640px;
  margin-bottom: 20px;
}

.screen-header h1 { margin-top: 6px; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: none;
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px 6px 8px;
  margin-bottom: 10px;
  transition: background .15s, color .15s;
  letter-spacing: .01em;
}

.btn-back::before {
  content: '‹';
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 400;
}

.btn-back:hover {
  background: var(--surface);
  color: var(--text);
}

/* ── Bloques / Minijuegos ── */
.card-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 640px;
}

.block-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-left: 4px solid var(--block-color, var(--accent));
  border-radius: var(--radius);
  padding: 20px 20px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 84px;
  transition: background .15s, transform .15s, border-color .15s;
}

.block-card:hover {
  background: #ffffff08;
  transform: translateX(4px);
  border-color: var(--block-color, var(--accent));
  border-left-color: var(--block-color, var(--accent));
}

.block-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  flex-shrink: 0;
  box-shadow: 0 0 0 1.5px var(--block-color, var(--accent));
}

.block-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.block-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.block-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.block-arrow {
  color: var(--block-color, var(--accent));
  font-size: 1.8rem;
  font-weight: 300;
  line-height: 1;
  opacity: 0.7;
}

.block-number {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--block-color, var(--accent));
}

.block-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Minigame cards */
.mg-card { border-left-color: var(--accent); }
.mg-card:hover { border-color: var(--accent); border-left-color: var(--accent); }

.mg-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.mg-def-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Admin section ── */
.admin-section {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.admin-section h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.form-row input, .form-row select {
  flex: 1;
  min-width: 120px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.form-row input:focus, .form-row select:focus { border-color: var(--accent); }
.form-row select option { background: var(--surface2); }

.empty-small {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}
