:root {
  --bg: #e8f0fe;
  --board-bg: #ffffff;
  --cell-bg: #f5f8ff;
  --cell-hover: #dbe8ff;
  --cell-selected: #a8ccff;
  --cell-highlight: #e4edfa;
  --cell-given: #1a2a4a;
  --cell-user: #2b6cb0;
  --cell-error: #e53e3e;
  --cell-correct-flash: #48bb78;
  --text: #1a2a4a;
  --text-dim: #718096;
  --accent: #3b82f6;
  --accent-glow: rgba(59,130,246,0.25);
  --panel-bg: #ffffff;
  --thin-line: #d0d8e8;
  --thick-line: #3b82f6;
  --key-shadow: #a0aec0;
  --key-bg: #e2ecf9;
  --key-hover: #cddcf3;
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== TITLE SCREEN ===== */
.title-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  background: linear-gradient(135deg, #e8f0fe 0%, #d0e0ff 50%, #e8f0fe 100%);
  position: relative;
  overflow: hidden;
}

.title-card {
  background: var(--board-bg);
  border-radius: 24px;
  padding: 48px 56px;
  text-align: center;
  box-shadow: 0 8px 48px rgba(59,130,246,0.15), 0 0 0 1px rgba(59,130,246,0.08);
  position: relative;
  z-index: 1;
  max-width: 440px;
  width: 100%;
}

/* Floating background digits */
.title-digits {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.float-digit {
  position: absolute;
  font-size: 80px;
  font-weight: 900;
  color: rgba(59,130,246,0.06);
  animation: floatUp 8s ease-in-out infinite;
}
.float-digit:nth-child(1) { left: 5%; top: 10%; animation-delay: 0s; }
.float-digit:nth-child(2) { left: 80%; top: 5%; animation-delay: 1s; }
.float-digit:nth-child(3) { left: 15%; top: 70%; animation-delay: 2s; }
.float-digit:nth-child(4) { left: 70%; top: 65%; animation-delay: 3s; }
.float-digit:nth-child(5) { left: 40%; top: 85%; animation-delay: 4s; }
.float-digit:nth-child(6) { left: 90%; top: 40%; animation-delay: 5s; }
.float-digit:nth-child(7) { left: 50%; top: 15%; animation-delay: 6s; }
.float-digit:nth-child(8) { left: 25%; top: 45%; animation-delay: 7s; }

@keyframes floatUp {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.5; }
  50% { transform: translateY(-20px) rotate(10deg); opacity: 1; }
}

.title-icon {
  font-size: 64px;
  margin-bottom: 8px;
  animation: pulse 2s ease-in-out infinite;
}

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

.title-name {
  font-size: 42px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -1px;
  margin-bottom: 6px;
}

.title-tagline {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.title-divider {
  width: 60px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin: 0 auto 24px;
}

.title-pick {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.title-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.title-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--cell-bg);
  border: 2px solid var(--thin-line);
  border-radius: 14px;
  padding: 18px 22px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 100px;
}

.title-btn:hover {
  border-color: var(--accent);
  background: var(--cell-hover);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.title-btn:active { transform: translateY(0); }

.title-btn-icon { font-size: 28px; }
.title-btn-label { font-size: 15px; font-weight: 700; color: var(--text); }
.title-btn-sub { font-size: 11px; color: var(--text-dim); }

/* ===== GAME SCREEN ===== */
.game-container {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  max-height: 100vh;
  padding: 12px;
}

.board-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board-container {
  background: var(--board-bg);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 2px 16px rgba(59,130,246,0.1);
  min-width: 460px;
}

.game-header {
  text-align: center;
  margin-bottom: 14px;
}
.game-header-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}

/* Hint area */
.hint-area {
  background: var(--cell-bg);
  border: 1px solid var(--thin-line);
  border-radius: 8px;
  padding: 18px 22px;
  margin-bottom: 16px;
  min-height: 100px;
  max-height: 340px;
  overflow-y: auto;
}

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

.hint-counter {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hint-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  padding: 8px 0;
  font-weight: 600;
}

.hint-history { margin-top: 10px; border-top: 1px solid var(--thin-line); padding-top: 8px; }
.hint-history:empty { display: none; }
.hint-history-item { font-size: 12px; color: var(--text-dim); padding: 3px 0; }
.hint-history-item .hint-num { color: var(--accent); font-weight: 700; margin-right: 4px; }

.next-hint-btn {
  background: var(--key-bg);
  border: 1.5px solid var(--thin-line);
  color: var(--text);
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.next-hint-btn:hover { border-color: var(--accent); background: var(--cell-hover); }
.next-hint-btn:disabled { opacity: 0.3; cursor: default; }

/* Input area */
.digit-boxes {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
}

.digit-box {
  width: 48px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: 2px solid var(--thin-line);
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: 26px;
  font-weight: 700;
  color: var(--cell-given);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.digit-box:hover { background: var(--cell-hover); }
.digit-box.selected {
  border-color: var(--accent);
  background: var(--cell-selected);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.digit-box.filled { color: var(--cell-user); }
.digit-box.correct-digit { background: rgba(72,187,120,0.25); border-color: var(--cell-correct-flash); color: var(--cell-correct-flash); }
.digit-box.close-digit { background: rgba(250,204,21,0.22); border-color: rgba(250,204,21,0.6); color: #b8960a; }
.digit-box.wrong-digit { background: rgba(160,174,192,0.18); border-color: rgba(160,174,192,0.4); color: var(--key-shadow); }
.digit-box.hint-ref { background: rgba(250,204,21,0.18); border-color: rgba(250,204,21,0.5); }

.digit-box-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 600;
  font-family: 'Segoe UI', sans-serif;
}

.digit-box { position: relative; }

/* Numpad */
.numpad {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}

.num-key {
  background: var(--key-bg);
  color: var(--text);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 0 var(--key-shadow);
  transition: all 0.1s;
}
.num-key:hover { background: var(--key-hover); transform: translateY(-1px); }
.num-key:active { transform: translateY(1px); box-shadow: none; }
.erase-key { width: 50px; }

.input-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.submit-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 0 #2563a8;
  transition: all 0.1s;
}
.submit-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px var(--accent-glow); }
.submit-btn:active { transform: translateY(1px); box-shadow: none; }
.submit-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* Feedback */
.feedback {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 8px;
}
.feedback.correct {
  background: rgba(72,187,120,0.12);
  color: var(--cell-correct-flash);
  border: 1px solid var(--cell-correct-flash);
}
.feedback.wrong {
  background: rgba(229,62,62,0.1);
  color: var(--cell-error);
  border: 1px solid var(--cell-error);
}

/* Right panel */
.panel-side {
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 180px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  align-self: stretch;
}

.stat-block { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 18px; font-weight: bold; color: var(--accent); }

.panel-divider { height: 1px; background: var(--thin-line); margin: 2px 0; }

.diff-buttons { display: flex; gap: 4px; }

.panel-btn {
  background: var(--key-bg);
  border: 1.5px solid var(--thin-line);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  text-align: center;
}
.panel-btn:hover { border-color: var(--accent); background: var(--cell-hover); }
.panel-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.diff-btn { width: auto; flex: 1; padding: 5px 8px; font-size: 12px; }

/* Overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.win-content {
  background: linear-gradient(145deg, #ffffff, #e8f0fe);
  border: 3px solid var(--accent);
  border-radius: 24px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 0 12px 60px rgba(59,130,246,0.3), 0 0 80px rgba(59,130,246,0.1);
  animation: winPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
  position: relative;
  overflow: hidden;
}

@keyframes winPop {
  0% { transform: scale(0.5) rotate(-3deg); opacity: 0; }
  60% { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.win-trophy {
  font-size: 64px;
  animation: trophyBounce 1s ease infinite;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 12px rgba(255,193,7,0.4));
}

@keyframes trophyBounce {
  0%,100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.05); }
}

.win-heading { font-size: 28px; font-weight: 800; color: var(--accent); margin-bottom: 16px; }

.win-stats { display: flex; justify-content: center; gap: 20px; margin-bottom: 16px; }

.win-stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(59,130,246,0.08); border-radius: 12px; padding: 10px 18px;
}
.win-stat-icon { font-size: 22px; }
.win-stat-val { font-size: 16px; font-weight: 700; color: var(--text); }

.win-rating { font-size: 32px; margin-bottom: 18px; letter-spacing: 4px; }

.win-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 32px; border-radius: 10px; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(59,130,246,0.3);
}
.win-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(59,130,246,0.4); }

.win-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.overlay-content {
  background: #fff;
  border: 2px solid var(--cell-error);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  animation: winPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
.overlay-content h2 { color: var(--cell-error); font-size: 24px; margin-bottom: 8px; }
.overlay-content p { color: var(--text-dim); font-size: 16px; margin-bottom: 20px; }
.overlay-content p span { color: var(--accent); font-weight: 700; font-family: 'Courier New', monospace; letter-spacing: 4px; font-size: 20px; }
.confetti-piece {
  position: absolute; width: 8px; height: 8px; border-radius: 2px;
  top: -10px; animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(350px) rotate(720deg); opacity: 0; }
}
