:root {
  --bg: #f5f0e8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #4a4a4a;
  --primary: #1b5e4a;
  --primary-hover: #144a3a;
  --secondary: #5c4d3c;
  --border: #c9bfb0;
  --success: #2e7d32;
  --warning: #e65100;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --font: "Source Sans 3", system-ui, sans-serif;
  --touch-min: 56px;
}

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

html {
  font-size: 20px;
  scroll-padding-top: 7rem;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.main-content {
  flex: 1 1 auto;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 1rem 0;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 1.5rem;
}

.btn-home {
  display: none;
  align-items: center;
  gap: 0.35rem;
  min-height: var(--touch-min);
  padding: 0.5rem 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--primary);
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.btn-home.visible {
  display: inline-flex;
}

.btn-home:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

a.btn-home {
  text-decoration: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 2rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.header-sub {
  margin: 0.25rem 0 0 2.75rem;
  color: var(--text-muted);
  font-size: 1rem;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

.welcome {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.welcome h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.welcome p {
  margin: 0;
  color: var(--text-muted);
}

.stats-bar {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

.stats-bar:empty {
  display: none;
}

/* Categories */
.categories {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.category-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border-left: 6px solid var(--primary);
}

.category-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.category-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.category-card > p {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.game-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.disclaimer {
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0 1rem;
}

/* Footer */
.app-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
  text-align: center;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.footer-nav a {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}

.footer-nav a:hover,
.footer-nav a:focus-visible {
  text-decoration: underline;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.footer-nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: underline;
}

.footer-copy {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.footer-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-width: 36rem;
  margin-inline: auto;
}

/* Legal pages */
.app-header--legal {
  position: static;
}

.legal-page {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  box-shadow: var(--shadow);
}

.legal-page > h1 {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  color: var(--primary);
}

.legal-updated {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.legal-page section {
  margin-bottom: 1.25rem;
}

.legal-page section:last-child {
  margin-bottom: 0;
}

.legal-page h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.legal-page p,
.legal-page li {
  margin: 0 0 0.65rem;
  line-height: 1.55;
  color: var(--text);
}

.legal-page ul {
  margin: 0 0 0.65rem;
  padding-left: 1.25rem;
}

.legal-page a {
  color: var(--primary);
  font-weight: 600;
}

.legal-page code {
  font-size: 0.9em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.legal-table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0 1rem;
}

.legal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.legal-table th,
.legal-table td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.65rem;
  text-align: left;
  vertical-align: top;
}

.legal-table th {
  background: var(--bg);
  font-weight: 700;
}

.legal-page ol {
  margin: 0 0 0.65rem;
  padding-left: 1.35rem;
}

.legal-page ol li {
  margin-bottom: 0.35rem;
  line-height: 1.55;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0.75rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-secondary:hover:not(:disabled) {
  background: #4a3d30;
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-game {
  width: 100%;
  background: var(--primary);
  color: #fff;
}

.btn-game:hover {
  background: var(--primary-hover);
}

.btn-lg {
  min-height: 60px;
  font-size: 1.2rem;
  padding: 0.85rem 2rem;
}

/* Game common */
.game-header {
  margin-bottom: 1.25rem;
}

.game-header h2 {
  margin: 0 0 0.5rem;
  font-size: 1.6rem;
  color: var(--primary);
}

.game-header p {
  margin: 0;
  color: var(--text-muted);
}

.game-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.game-controls .btn-start,
.game-controls .btn-secondary,
.game-controls .btn-primary:not(.lista-check) {
  width: 100%;
}

.game-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.25rem;
}

.control-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
}

/* Large choice buttons (replaces dropdown) */
.choice-group {
  flex: 1 1 100%;
  margin: 0;
  padding: 0;
  border: none;
}

.choice-legend {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.75rem;
  padding: 0;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 72px;
  padding: 0.85rem 1rem;
  font-family: inherit;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.choice-btn:hover {
  border-color: var(--primary);
}

.choice-btn.selected {
  background: #e8f5e9;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(27, 94, 74, 0.25);
}

.choice-btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.choice-label {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.choice-detail {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.btn-start {
  flex: 1 1 100%;
  width: 100%;
}

.btn-help {
  flex: 1 1 100%;
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--primary);
  background: var(--surface);
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-help:hover {
  background: #e8f5e9;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
}

/* Game guide overlay */
body.guide-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

body.guide-open .app-header {
  z-index: 1;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.game-list li + li {
  margin-top: 0.75rem;
}

.guide-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

.guide-backdrop {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
}

.guide-ring {
  position: fixed;
  box-sizing: border-box;
  border: 3px solid #fff;
  outline: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.68);
  pointer-events: none;
  z-index: 1001;
  transition: top 0.28s ease, left 0.28s ease, width 0.28s ease, height 0.28s ease;
  animation: guide-ring-pulse 2s ease-in-out infinite;
}

@keyframes guide-ring-pulse {
  0%, 100% { outline-color: var(--primary); }
  50% { outline-color: #2e8b6e; }
}

.guide-tooltip {
  position: fixed;
  z-index: 1002;
  width: min(340px, calc(100vw - 32px));
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  border: 3px solid var(--primary);
  pointer-events: auto;
  transition: top 0.28s ease, left 0.28s ease;
}

.guide-tooltip::before {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border: 10px solid transparent;
}

.guide-tooltip[data-placement='below']::before {
  top: -20px;
  border-bottom-color: var(--primary);
}

.guide-tooltip[data-placement='above']::before {
  bottom: -20px;
  border-top-color: var(--primary);
}

.guide-tooltip--dock::before {
  display: none;
}

.guide-tooltip--dock {
  max-width: none;
  left: 16px !important;
  right: 16px !important;
  width: auto !important;
}

.guide-root--mobile .guide-ring {
  max-height: calc(100vh - 240px);
}

.guide-step {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.guide-title {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  color: var(--text);
}

.guide-text {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.guide-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.guide-actions .btn {
  flex: 1;
  min-width: 120px;
}

@media (prefers-reduced-motion: reduce) {
  .guide-ring {
    animation: none;
    transition: none;
  }

  .guide-tooltip {
    transition: none;
  }
}

.select-lg {
  min-height: var(--touch-min);
  padding: 0.5rem 1rem;
  font-size: 1.1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.game-status {
  min-height: 2.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1.1rem;
}

.game-status.success {
  background: #e8f5e9;
  color: var(--success);
}

.game-status.info {
  background: #e3f2fd;
  color: #1565c0;
}

/* Memotest */
.memotest-board {
  display: grid;
  gap: 0.75rem;
  justify-content: center;
  margin: 0 auto;
}

.memotest-board.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: min(360px, 100%);
  width: 100%;
}

.memotest-board.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: min(420px, 100%);
  width: 100%;
}

.memotest-card {
  aspect-ratio: 1;
  min-height: 90px;
  font-size: 2.5rem;
  background: var(--primary);
  color: #fff;
  border: 3px solid var(--primary-hover);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
  user-select: none;
}

.memotest-card:hover:not(.matched):not(.face-up) {
  background: var(--primary-hover);
}

.memotest-card.face-up {
  background: var(--surface);
  border-color: var(--border);
  cursor: default;
}

.memotest-card.matched {
  background: #c8e6c9;
  border-color: var(--success);
  cursor: default;
  opacity: 0.85;
}

.memotest-card .back {
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.9);
}

.memotest-card.face-up .back,
.memotest-card.matched .back {
  display: none;
}

.memotest-card .front {
  display: none;
}

.memotest-card.face-up .front,
.memotest-card.matched .front {
  display: block;
}

/* Simón */
.simon-score {
  text-align: center;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.simon-pad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: min(340px, 100%);
  width: 100%;
  margin: 0 auto;
}

.simon-btn {
  aspect-ratio: 1;
  min-height: 120px;
  border: 4px solid rgba(0, 0, 0, 0.2);
  border-radius: var(--radius);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.1s, transform 0.1s;
}

.simon-btn:disabled {
  cursor: not-allowed;
}

.simon-btn.lit {
  opacity: 1;
  transform: scale(1.05);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.3);
}

.simon-red { background: #c62828; }
.simon-green { background: #2e7d32; }
.simon-yellow { background: #f9a825; }
.simon-blue { background: #1565c0; }

/* Bingo */
.bingo-current {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  min-height: 3rem;
  margin-bottom: 0.5rem;
}

.bingo-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  max-width: min(400px, 100%);
  width: 100%;
  margin: 0 auto 1.5rem;
}

.bingo-cell {
  aspect-ratio: 1;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}

.bingo-cell.free {
  background: #fff9c4;
  cursor: default;
  font-size: 0.85rem;
}

.bingo-cell.marked {
  background: #c8e6c9;
  border-color: var(--success);
}

.bingo-cell.called:not(.marked):not(.free) {
  border-color: var(--warning);
  border-width: 3px;
}

.bingo-cell.win {
  background: #a5d6a7;
  animation: pulse 0.6s ease;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.bingo-called h3 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  color: var(--text-muted);
}

.bingo-called-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.bingo-called-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
}

/* Recuerda la lista */
.lista-study,
.lista-pick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
}

.lista-study-item,
.lista-pick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 88px;
  padding: 0.75rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  cursor: pointer;
}

.lista-pick-item.selected {
  background: #e8f5e9;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(27, 94, 74, 0.2);
}

.lista-emoji {
  font-size: 2rem;
}

.lista-label {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

.lista-check {
  grid-column: 1 / -1;
  width: 100%;
}

/* Sumas al objetivo */
.sumas-target-wrap {
  text-align: center;
  margin-bottom: 1rem;
}

.sumas-target-label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.sumas-target {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.sumas-picked {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--text);
}

.sumas-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  max-width: min(320px, 100%);
  width: 100%;
  margin: 0 auto;
}

.sumas-num {
  min-height: 72px;
  font-size: 1.75rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.sumas-num:hover {
  border-color: var(--primary);
  background: #e8f5e9;
}

.sumas-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.sumas-actions .btn {
  width: 100%;
}

/* Tres en raya */
.ttt-score {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  max-width: min(320px, 100%);
  width: 100%;
  margin: 0 auto;
}

.ttt-cell {
  aspect-ratio: 1;
  min-height: 88px;
  font-size: 2.5rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.ttt-cell:disabled {
  cursor: default;
}

.ttt-cell.ttt-x {
  color: var(--primary);
  background: #e8f5e9;
  border-color: var(--primary);
}

.ttt-cell.ttt-o {
  color: #1565c0;
  background: #e3f2fd;
  border-color: #1565c0;
}

@media (min-width: 600px) {
  html {
    font-size: 22px;
  }

  .categories {
    display: grid;
    grid-template-columns: 1fr;
  }

  .game-controls {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .game-controls .choice-group {
    flex: 1 1 100%;
  }

  .game-controls .btn-start,
  .game-controls .btn-secondary {
    flex: 1 1 calc(50% - 0.5rem);
    width: auto;
  }

  .game-controls .btn-help {
    flex: 1 1 100%;
  }
}

@media (max-width: 380px) {
  .memotest-card {
    min-height: 72px;
    font-size: 2rem;
  }

  .bingo-cell {
    min-height: 52px;
    font-size: 1rem;
  }

  .ttt-cell {
    min-height: 72px;
    font-size: 2rem;
  }
}
