/* ===========================
   SUDOKU GAME — MASTER STYLESHEET
   =========================== */

:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a24;
  --surface: #16161f;
  --surface2: #1e1e2a;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --accent: #e8c547;
  --accent2: #f0d060;
  --accent-dim: rgba(232,197,71,0.15);
  --accent-glow: rgba(232,197,71,0.3);
  --red: #ff4d6d;
  --red-dim: rgba(255,77,109,0.15);
  --blue: #60a5fa;
  --blue-dim: rgba(96,165,250,0.15);
  --green: #4ade80;
  --text: #f0f0f5;
  --text2: #a0a0b8;
  --text3: #606078;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 20px 60px rgba(0,0,0,0.6);
}

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

html, body {
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── BACKGROUND ── */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(232,197,71,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232,197,71,0.03) 1px, transparent 1px);
  background-size: 44px 44px;
}
.noise-overlay {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.6;
}

/* ── SCREENS ── */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ── LANDING SCREEN ── */
.landing-inner {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 36px;
}

.logo-area {
  text-align: center;
  animation: fadeUp 0.7s ease both;
}
.logo-badge {
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--accent);
  color: var(--bg);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 38px; line-height: 64px; text-align: center;
  margin: 0 auto 16px;
  box-shadow: 0 0 40px var(--accent-glow), 0 8px 24px rgba(0,0,0,0.4);
}
.game-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(48px, 14vw, 72px);
  letter-spacing: 8px;
  background: linear-gradient(135deg, var(--accent2), var(--accent), #c8a030);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  line-height: 1;
}
.game-tagline {
  margin-top: 8px;
  color: var(--text2); font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
}

/* ── LEVEL CARDS ── */
.level-cards {
  width: 100%;
  display: flex; flex-direction: column; gap: 12px;
  animation: fadeUp 0.7s 0.15s ease both;
}
.level-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; align-items: center; gap: 16px;
  cursor: pointer;
  transition: all 0.25s;
  overflow: hidden;
}
.level-card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.02));
  transition: opacity 0.3s;
}
.level-card:hover, .level-card:active {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(232,197,71,0.15);
}
.level-card.featured {
  border-color: rgba(232,197,71,0.4);
  background: linear-gradient(135deg, var(--surface) 60%, rgba(232,197,71,0.08));
}
.level-glow {
  position: absolute; inset: -1px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-dim), transparent);
  z-index: 0;
}
.level-icon {
  font-size: 28px; color: var(--accent); z-index: 1;
  width: 40px; text-align: center;
}
.level-info {
  display: flex; flex-direction: column; z-index: 1; flex: 1;
}
.level-name {
  font-family: 'Bebas Neue', sans-serif; font-size: 22px; letter-spacing: 2px;
}
.level-desc { font-size: 12px; color: var(--text3); letter-spacing: 0.5px; }
.level-dots {
  display: flex; gap: 5px; z-index: 1;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border2);
}
.dot.active { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.popular-tag {
  position: absolute; top: -1px; right: 16px;
  background: var(--accent); color: var(--bg);
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  padding: 3px 10px; border-radius: 0 0 8px 8px;
}

/* ── STATS BAR ── */
.landing-stats {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  display: flex; align-items: center; justify-content: space-around;
  animation: fadeUp 0.7s 0.3s ease both;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-val { font-family: 'Bebas Neue', sans-serif; font-size: 26px; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text3); letter-spacing: 1px; text-transform: uppercase; }
.stat-divider { width: 1px; height: 40px; background: var(--border); }

/* ── GAME SCREEN ── */
#game-screen { justify-content: flex-start; padding: 0; }

.game-header {
  width: 100%; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.header-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.level-badge {
  font-family: 'Bebas Neue', sans-serif; font-size: 11px; letter-spacing: 3px;
  color: var(--accent); border: 1px solid var(--accent-dim);
  padding: 2px 10px; border-radius: 20px;
}
.timer-display {
  font-family: 'JetBrains Mono', monospace; font-size: 26px; font-weight: 700;
  color: var(--text); letter-spacing: 2px;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover, .icon-btn:active {
  background: var(--surface2); border-color: var(--border2); color: var(--text);
}
.hint-btn { position: relative; }
.hint-count {
  position: absolute; top: -4px; right: -4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); color: var(--bg);
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ── GAME AREA ── */
.game-area {
  flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center;
  padding: 12px 12px 24px; gap: 16px; overflow-y: auto;
}
.mistake-bar {
  display: flex; align-items: center; gap: 12px;
  width: 100%; max-width: 380px;
}
.mistake-label { font-size: 12px; color: var(--text3); letter-spacing: 1px; }
.mistake-dots { display: flex; gap: 8px; }
.m-dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--border2); display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; transition: all 0.3s;
}
.m-dot.active { background: var(--red-dim); border-color: var(--red); color: var(--red); }

/* ── SUDOKU BOARD ── */
.board-wrap {
  width: 100%; max-width: 380px; aspect-ratio: 1;
}
.sudoku-board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  width: 100%; aspect-ratio: 1;
  border: 2px solid rgba(232,197,71,0.5);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(232,197,71,0.08), var(--shadow);
}
.cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(12px, 3.5vw, 20px); font-weight: 700;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  cursor: pointer; transition: all 0.15s;
  position: relative;
  color: var(--text);
}
/* 3x3 box thick borders */
.cell:nth-child(3n) { border-right: 2px solid rgba(255,255,255,0.18); }
.cell:nth-child(9n) { border-right: none; }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid rgba(255,255,255,0.18); }
.cell.given {
  color: var(--text); font-weight: 700;
  background: var(--bg3);
}
.cell.given .cell-num { color: var(--text2); }
.cell.user-fill .cell-num { color: var(--accent); }
.cell.selected {
  background: var(--accent-dim) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
  z-index: 2;
}
.cell.highlighted { background: rgba(232,197,71,0.06); }
.cell.same-number { background: rgba(232,197,71,0.1); }
.cell.wrong .cell-num { color: var(--red) !important; animation: shake 0.4s ease; }
.cell.correct-flash { animation: flashGreen 0.5s ease; }
.cell.hint-reveal { animation: hintPulse 0.8s ease; }
.cell-num { font-size: inherit; pointer-events: none; }
.cell-notes {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 0; width: 100%; height: 100%; padding: 1px;
  pointer-events: none;
}
.note-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(5px, 1.2vw, 7px);
  color: var(--blue); text-align: center; line-height: 1.2;
  display: flex; align-items: center; justify-content: center;
}
.note-num.empty { opacity: 0; }

/* ── NUMPAD ── */
.numpad {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: 8px; width: 100%; max-width: 380px;
}
.num-btn {
  aspect-ratio: 1;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: clamp(16px,4vw,22px); font-weight: 700;
  cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.num-btn:hover, .num-btn:active {
  background: var(--surface2); border-color: var(--accent);
  color: var(--accent); transform: scale(0.95);
}
.erase-btn svg, .notes-btn svg { width: 18px; height: 18px; }
.erase-btn { color: var(--red); border-color: var(--red-dim); }
.notes-btn { color: var(--blue); border-color: var(--blue-dim); }
.notes-btn.active { background: var(--blue-dim); border-color: var(--blue); }

/* ── OVERLAYS ── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(8px);
  padding: 20px;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 20px; padding: 36px 28px;
  text-align: center; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow);
  animation: popIn 0.3s ease;
}
.overlay-icon { font-size: 48px; }
.overlay-box h2 {
  font-family: 'Bebas Neue', sans-serif; font-size: 32px; letter-spacing: 3px;
  color: var(--text);
}
.overlay-box p { color: var(--text2); font-size: 14px; }

/* WIN SCREEN */
.win-box { overflow: hidden; }
.win-confetti { position: absolute; top: 0; left: 0; right: 0; height: 100px; pointer-events: none; }
.win-trophy { font-size: 56px; }
.win-stats { display: flex; gap: 12px; justify-content: center; }
.win-stat {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1;
}
.win-stat span { font-family: 'Bebas Neue', sans-serif; font-size: 24px; color: var(--accent); }
.win-stat small { font-size: 10px; color: var(--text3); letter-spacing: 1px; }

/* ── POPUP (LOGIN) ── */
.popup {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.popup.hidden { display: none; }
.popup-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
}
.popup-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 24px 24px 0 0;
  padding: 32px 24px 36px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.popup-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); width: 32px; height: 32px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.popup-header { text-align: center; margin-bottom: 24px; }
.popup-icon { font-size: 36px; margin-bottom: 12px; }
.popup-header h2 {
  font-family: 'Bebas Neue', sans-serif; font-size: 26px; letter-spacing: 3px;
}
.popup-header p { font-size: 13px; color: var(--text2); margin-top: 6px; }

/* TAB SWITCH */
.tab-switch {
  display: flex; background: var(--bg2); border-radius: 10px; padding: 4px; margin-bottom: 20px;
}
.tab {
  flex: 1; padding: 8px; border-radius: 8px;
  border: none; background: transparent; color: var(--text3);
  font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 600;
  letter-spacing: 1px; cursor: pointer; transition: all 0.2s;
}
.tab.active { background: var(--surface2); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

/* INPUTS */
.game-input {
  width: 100%; padding: 14px 16px; margin-bottom: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 15px;
  outline: none; transition: border 0.2s;
}
.game-input:focus { border-color: var(--accent); }
.game-input::placeholder { color: var(--text3); }
.form-error {
  background: var(--red-dim); border: 1px solid var(--red);
  color: var(--red); font-size: 13px; padding: 10px 14px;
  border-radius: 8px; margin-bottom: 12px;
}
.form-error.hidden { display: none; }

/* BUTTONS */
.btn-primary {
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 12px; padding: 14px 24px;
  font-family: 'Bebas Neue', sans-serif; font-size: 18px; letter-spacing: 2px;
  cursor: pointer; transition: all 0.2s; width: auto;
}
.btn-primary.full { width: 100%; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 24px;
  font-family: 'DM Sans', sans-serif; font-size: 14px;
  cursor: pointer; transition: all 0.2s;
}
.btn-ghost.full { width: 100%; margin-top: 4px; }
.btn-ghost:hover { border-color: var(--border2); color: var(--text); }
.skip-btn { margin-top: 8px; font-size: 13px; color: var(--text3); }

/* ── PROFILE BAR ── */
.profile-bar {
  position: fixed; top: 0; right: 0; z-index: 300;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 0 12px; padding: 6px 12px;
  font-size: 13px; color: var(--text2);
}
.profile-bar.hidden { display: none; }
.tiny-btn {
  background: transparent; border: none; color: var(--red);
  font-size: 12px; cursor: pointer; padding: 2px 6px;
}

/* ── ANIMATIONS ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes flashGreen {
  0% { background: var(--accent-dim); }
  50% { background: rgba(74,222,128,0.3); }
  100% { background: var(--surface); }
}
@keyframes hintPulse {
  0% { box-shadow: inset 0 0 0 2px var(--blue); background: var(--blue-dim); }
  50% { box-shadow: inset 0 0 0 2px var(--blue), 0 0 20px var(--blue-dim); }
  100% { background: var(--surface); }
}
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100px) rotate(360deg); opacity: 0; }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── RESPONSIVE ── */
@media (min-width: 480px) {
  .popup-box { border-radius: 24px; margin-bottom: 40px; }
  .popup { align-items: center; }
  .sudoku-board { max-width: 400px; }
}
@media (max-width: 360px) {
  .numpad { gap: 5px; }
  .game-area { padding: 8px 8px 16px; gap: 10px; }
}
