:root {
  --bg: #0f1626;
  --panel: #1b2a4a;
  --panel-2: #243a63;
  --cell: #2c4775;
  --cell-sel: #f5a623;
  --cell-found: #3ddc84;
  --text: #eaf0ff;
  --muted: #9fb0d4;
  --accent: #f5a623;
  --line: rgba(245, 166, 35, 0.55);
}

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

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

#app {
  max-width: 540px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen { display: none; flex-direction: column; height: 100%; padding: 16px; }
.screen.active { display: flex; }

/* ---------- Menu ---------- */
.menu-header { text-align: center; margin: 16px 0 2px; }
.menu-header h1 { margin: 0; font-size: 1.9rem; letter-spacing: 1px; }
.tagline { color: var(--muted); margin: 6px 0 0; font-size: .9rem; }

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.tab {
  flex: 1;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--panel-2);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.tab.active {
  background: var(--panel);
  color: var(--text);
  border-color: var(--accent);
}
.tab:active { transform: scale(0.97); }

.level-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: start;
  margin-top: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 10px;
}

.level-card {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 13px 14px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
}
.level-card:active { transform: scale(0.97); }
.level-card .num {
  color: var(--muted);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.level-card .name { font-size: 1.1rem; font-weight: 700; margin: 5px 0 8px; line-height: 1.15; }
.level-card .meta { color: var(--muted); font-size: .74rem; }
.level-card.done {
  border-color: rgba(61, 220, 132, 0.5);
  background: linear-gradient(180deg, rgba(61, 220, 132, 0.09), var(--panel));
}
.level-card .badge {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cell-found);
  color: #0f1626;
  font-size: .78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Game ---------- */
.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.game-title { flex: 1; text-align: center; }
#level-name { display: block; font-size: 1.15rem; font-weight: 600; }
.counter { color: var(--muted); font-size: .85rem; }

.icon-btn {
  background: var(--panel);
  border: none;
  color: var(--text);
  width: 44px; height: 44px;
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
}
.icon-btn:active { background: var(--panel-2); }

.grid-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; touch-action: none; }

.grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 3px;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell);
  border-radius: 6px;
  font-weight: 700;
  font-size: clamp(0.7rem, 4.5vw, 1.4rem);
  color: var(--text);
  transition: background .1s ease, color .1s ease;
}
.lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Bar that reserves space below the grid for the word bubble */
.bubble-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 12px;
}

.drag-bubble {
  --bubble-color: var(--accent);
  pointer-events: none;
  background: var(--bubble-color);
  color: #1b2a4a;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 1.2rem;
  min-width: 48px;
  text-align: center;
  padding: 8px 18px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  transform: scale(0.7);
  opacity: 0;
  transition: opacity .12s ease, transform .12s ease, background .12s ease;
}
.drag-bubble.show { opacity: 1; transform: scale(1); }

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  align-content: flex-start;
  margin-top: 18px;
  overflow-y: auto;
}
.word-chip {
  font-size: 1rem;
  letter-spacing: 1px;
  color: var(--text);
  padding: 4px 4px;
}
.word-chip.found { color: var(--muted); text-decoration: line-through; }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 10, 22, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.overlay.active { display: flex; }
.win-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  width: 100%;
  max-width: 360px;
}
.win-card h2 { margin: 0 0 8px; }
#win-stats { color: var(--muted); margin: 0 0 20px; }
.win-actions { display: flex; gap: 12px; }

.primary-btn, .ghost-btn {
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.win-actions .primary-btn, .win-actions .ghost-btn { flex: 1; }
.primary-btn { background: var(--accent); color: #1b2a4a; }
.ghost-btn { background: transparent; color: var(--muted); border: 1px solid var(--panel-2); }

#reset-progress {
  flex: 0 0 auto;
  align-self: center;
  margin: 8px auto 4px;
  padding: 9px 18px;
  font-size: .82rem;
}
