/* ============================
   Guess the Number — Style
   Style: Board Game
   ============================ */
:root {
  --bg-felt: #1a1d36;
  --bg-felt-light: #232748;
  --surface: #f5f0e1;
  --surface-white: #ffffff;
  --ink: #1a1a2e;
  --ink-muted: #5a5a6e;
  --gold: #f5b342;
  --gold-light: #fce8a8;
  --green: #2ecc71;
  --green-dark: #1d9e56;
  --coral: #e74c3c;
  --orange: #e67e22;
  --star-fill: #f1c40f;
  --star-empty: #d5d5d5;
  --shadow-color: rgba(15, 13, 30, 0.35);
  --border-thick: 4px;
  --border-med: 3px;
  --radius-card: 24px;
  --radius-chip: 14px;
  --radius-btn: 16px;
  --radius-key: 14px;
  --font-title: Georgia, Cambria, serif;
  --font-hud: Inter, system-ui, -apple-system, sans-serif;
  --shadow-card: 0 8px 0 rgba(15, 13, 30, 0.3), 0 24px 50px var(--shadow-color);
  --shadow-btn: 0 6px 0 rgba(15, 13, 30, 0.3), 0 14px 28px var(--shadow-color);
  --shadow-key: 0 4px 0 rgba(15, 13, 30, 0.25);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: var(--font-hud);
  background: var(--bg-felt);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Scene base ---------- */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}
.scene.hidden { display: none; }

/* ---------- Title Scene ---------- */
#scene-title {
  gap: 10px;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-felt-light), var(--bg-felt));
}

.title-deco {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(245, 179, 66, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(46, 204, 113, 0.05) 0%, transparent 40%);
}

.game-title {
  font-family: var(--font-title);
  font-size: clamp(2.4rem, 8vw, 4.2rem);
  color: var(--surface);
  text-align: center;
  line-height: 1.05;
  text-shadow: 0 3px 0 rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.5);
  position: relative;
  z-index: 1;
}
.title-number {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold), var(--orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  color: rgba(245, 240, 225, 0.55);
  margin-bottom: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ---------- Mode grid ---------- */
.mode-grid {
  display: flex;
  gap: 12px;
  margin: 8px 0 20px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 1;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 22px;
  border: var(--border-med) solid rgba(245, 240, 225, 0.2);
  border-radius: var(--radius-card);
  background: rgba(245, 240, 225, 0.08);
  color: var(--surface);
  cursor: pointer;
  font-family: var(--font-hud);
  transition: all 0.2s ease;
  min-width: 110px;
}
.mode-btn:hover {
  background: rgba(245, 240, 225, 0.15);
  border-color: rgba(245, 240, 225, 0.4);
}
.mode-btn.mode-active {
  background: rgba(245, 179, 66, 0.18);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(245, 179, 66, 0.15);
}
.mode-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--surface);
}
.mode-range {
  font-size: 0.8rem;
  color: rgba(245, 240, 225, 0.6);
}
.mode-stars {
  font-size: 0.7rem;
  color: var(--gold-light);
  opacity: 0.8;
}
.best-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--green);
  background: rgba(46, 204, 113, 0.12);
  padding: 2px 10px;
  border-radius: 999px;
  margin-top: 4px;
}

/* ---------- Buttons ---------- */
.game-btn {
  border: var(--border-med) solid rgba(15, 13, 30, 0.3);
  border-radius: var(--radius-btn);
  font-family: var(--font-hud);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.1s ease;
  padding: 14px 32px;
}
.play-btn {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  color: var(--ink);
  box-shadow: var(--shadow-btn);
  z-index: 1;
}
.play-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(15, 13, 30, 0.3), 0 8px 18px var(--shadow-color);
}
.ghost-btn {
  background: transparent;
  color: rgba(245, 240, 225, 0.7);
  border-color: rgba(245, 240, 225, 0.2);
  box-shadow: none;
  font-size: 0.9rem;
  padding: 10px 20px;
}
.ghost-btn:hover {
  color: var(--surface);
  border-color: rgba(245, 240, 225, 0.4);
}
.how-btn {
  margin-top: 4px;
}

/* ---------- Play Scene ---------- */
#scene-play {
  padding: 0;
  gap: 0;
  background: var(--bg-felt);
  justify-content: flex-start;
}
.play-header {
  width: 100%;
  padding: 10px 16px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-felt-light), transparent);
}
.hud-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 2px solid rgba(245, 240, 225, 0.15);
  border-radius: 999px;
  background: rgba(245, 240, 225, 0.07);
  color: var(--surface);
  font-size: 0.8rem;
  font-weight: 700;
}
.hud-chip strong {
  color: var(--gold);
}

.play-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.range-hint {
  font-size: 0.85rem;
  color: rgba(245, 240, 225, 0.5);
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ---------- Guess display ---------- */
.guess-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 90px;
}
.guess-digits {
  font-family: var(--font-hud);
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 900;
  color: var(--surface);
  letter-spacing: 4px;
  transition: all 0.15s ease;
}
.guess-digits.pop {
  animation: digitPop 0.25s ease;
}
@keyframes digitPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.guess-digits.has-value {
  color: var(--gold);
}
.guess-digits.correct {
  color: var(--green);
  animation: digitCorrect 0.4s ease;
}
@keyframes digitCorrect {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); text-shadow: 0 0 40px rgba(46, 204, 113, 0.6); }
  100% { transform: scale(1); }
}
.guess-cursor {
  font-size: clamp(2.8rem, 10vw, 4.5rem);
  font-weight: 200;
  color: var(--gold);
  animation: blink 0.9s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- Feedback area ---------- */
.feedback-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.feedback-text {
  font-size: clamp(1rem, 4vw, 1.3rem);
  font-weight: 700;
  color: var(--surface);
  min-height: 1.6em;
  text-align: center;
  transition: color 0.2s;
}
.feedback-text.higher { color: var(--orange); }
.feedback-text.lower { color: #6eb5ff; }
.feedback-text.correct { color: var(--green); }

.feedback-text.pulse {
  animation: textPulse 0.3s ease;
}
@keyframes textPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ---------- Hot/Cold thermometer ---------- */
.hotcold-track {
  width: clamp(200px, 60vw, 360px);
  height: 16px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(245, 240, 225, 0.12);
  position: relative;
  overflow: hidden;
}
.hotcold-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6eb5ff, var(--gold), var(--coral));
  transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hotcold-fill.glowing {
  box-shadow: 0 0 20px rgba(245, 179, 66, 0.5);
}
.hotcold-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--surface);
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ---------- Star preview ---------- */
.star-preview {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.star-icon {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  color: var(--star-empty);
  transition: all 0.3s ease;
}
.star-icon.filled {
  color: var(--star-fill);
  text-shadow: 0 0 16px rgba(241, 196, 15, 0.5);
}
.star-icon.bump {
  animation: starBump 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes starBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.star-icon.earned {
  animation: starFlyIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
@keyframes starFlyIn {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ---------- Keypad ---------- */
.keypad {
  width: 100%;
  max-width: 480px;
  padding: 10px 12px 16px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.keypad-row {
  display: flex;
  gap: 8px;
}
.key-btn {
  flex: 1;
  height: 52px;
  border: var(--border-med) solid rgba(245, 240, 225, 0.15);
  border-radius: var(--radius-key);
  background: rgba(245, 240, 225, 0.08);
  color: var(--surface);
  font-family: var(--font-hud);
  font-size: 1.4rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.08s ease;
  box-shadow: var(--shadow-key);
  display: flex;
  align-items: center;
  justify-content: center;
}
.key-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(15, 13, 30, 0.25);
  background: rgba(245, 240, 225, 0.15);
}
.key-del { font-size: 0.9rem; color: rgba(245, 240, 225, 0.6); }
.key-submit {
  background: linear-gradient(180deg, var(--green-dark), var(--green));
  border-color: var(--green-dark);
  color: #fff;
  font-size: 1rem;
  box-shadow: 0 4px 0 var(--green-dark);
}
.key-submit:active {
  background: var(--green-dark);
}

/* ---------- Win scene ---------- */
#scene-win {
  background: rgba(15, 13, 30, 0.7);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.win-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.win-card {
  position: relative;
  background: var(--surface);
  border: var(--border-thick) solid rgba(15, 13, 30, 0.2);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  animation: cardSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardSlideUp {
  0% { transform: translateY(40px) scale(0.92); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.win-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--ink);
}
.win-number {
  font-size: 3.2rem;
  font-weight: 900;
  color: var(--green);
  text-shadow: 0 2px 0 rgba(46, 204, 113, 0.3);
}
.win-stars {
  display: flex;
  gap: 6px;
  margin: 4px 0;
}
.win-star {
  color: var(--star-fill);
  font-size: 2.4rem;
}
.win-stats {
  font-size: 0.85rem;
  color: var(--ink-muted);
  display: flex;
  gap: 6px;
  align-items: center;
}
.win-bullet { opacity: 0.4; }
.win-buttons {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

/* ---------- Tutorial ---------- */
#scene-tutorial {
  background: rgba(15, 13, 30, 0.75);
  backdrop-filter: blur(4px);
  z-index: 20;
}
.tutorial-card {
  background: var(--surface);
  border: var(--border-thick) solid rgba(15, 13, 30, 0.15);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px 30px;
  max-width: 420px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: cardSlideUp 0.35s ease;
}
.tutorial-title {
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--ink);
  text-align: center;
}
.tutorial-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}
.tutorial-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.tutorial-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-felt);
  color: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  margin-top: 2px;
}
.tutorial-thresholds {
  margin-top: 4px;
  padding: 10px 12px;
  background: rgba(26, 29, 54, 0.06);
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--ink-muted);
}
#scene-tutorial .game-btn {
  align-self: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .mode-grid { gap: 8px; }
  .mode-btn { min-width: 90px; padding: 10px 14px; }
  .key-btn { height: 48px; font-size: 1.2rem; }
  .key-submit { font-size: 0.9rem; }
  .win-card { padding: 24px 20px; min-width: 220px; }
  .tutorial-card { padding: 20px; }
}

/* Landscape phone adjustments */
@media (max-height: 480px) and (orientation: landscape) {
  .play-body { gap: 4px; padding: 4px 16px; }
  .guess-digits { font-size: clamp(2rem, 8vw, 3rem); }
  .guess-display { min-height: 50px; }
  .key-btn { height: 38px; font-size: 1rem; }
  .keypad { padding: 6px 12px 8px; gap: 5px; }
  .hud-chip { font-size: 0.7rem; padding: 4px 10px; }
}
