:root {
  --bg: #0a0a0f;
  --bg-card: #0d0d18;
  --fg: #e2e8f0;
  --muted: #7c8496;
  --border: rgba(148, 163, 184, 0.16);
  --accent: #d97706;
  --accent-bright: #f59e0b;
  --accent-soft: rgba(217, 119, 6, 0.14);
  --danger: #ef4444;
  --success: #10b981;
  --cold: #3b82f6;
  --radius: 18px;
  --font-display: "Sora", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body.no-scroll { overflow: hidden; }

::selection { background: var(--accent); color: #000; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #92400e; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Splash screen ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #14141f, var(--bg) 70%);
  cursor: pointer;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px;
  max-width: 380px;
}

.splash-door {
  font-size: 3.6rem;
  display: inline-block;
  animation: splashDoorSwing 1.6s ease-in-out infinite;
  transform-origin: left center;
  filter: drop-shadow(0 0 24px rgba(217, 119, 6, 0.45));
}

@keyframes splashDoorSwing {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(35deg); }
}

.splash-title {
  margin: 14px 0 6px;
  font-size: 2.4rem;
  font-weight: 800;
  background: linear-gradient(100deg, var(--accent-bright), #fbbf24 45%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
  animation-delay: 0.1s;
}

.splash-tagline {
  margin: 0 0 20px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
  animation-delay: 0.22s;
}

.splash-tagline .dots span {
  animation: dotBlink 1.4s infinite;
  opacity: 0;
}
.splash-tagline .dots span:nth-child(2) { animation-delay: 0.2s; }
.splash-tagline .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBlink {
  0%, 20% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.splash-bar {
  width: 180px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
  animation-delay: 0.3s;
}

.splash-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  animation: splashLoad 2.2s ease forwards 0.4s;
}

@keyframes splashLoad {
  to { width: 100%; }
}

.splash-credit {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  width: 100%;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
  animation-delay: 0.5s;
}

.splash-by {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.splash-by strong { color: var(--fg); }

.splash-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.splash-links a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

.splash-links a:hover { color: var(--accent); text-decoration: underline; }
.splash-links .dot { color: var(--border); }

.splash-skip {
  margin: 26px 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  animation: splashSkipIn 0.6s ease forwards 1.4s;
}

@keyframes splashSkipIn {
  from { opacity: 0; }
  to { opacity: 0.5; }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(16px, 5vw, 48px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.brand-icon {
  font-size: 1.4rem;
  display: inline-block;
  animation: doorSway 4s ease-in-out infinite;
  transform-origin: left center;
}

@keyframes doorSway {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(25deg); }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn, .lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.icon-btn { padding: 8px 10px; }

.icon-btn:hover, .lang-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.icon-btn:active, .lang-btn:active { transform: translateY(0); }

.flag { font-size: 1rem; }

/* ---------- Stage / Hero ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px 40px;
  gap: 34px;
}

.hero {
  text-align: center;
  max-width: 620px;
  margin-top: clamp(6px, 3vh, 24px);
}

.eyebrow {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: 0.25em;
  font-size: 0.72rem;
  margin: 0 0 10px;
  text-transform: uppercase;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards;
}

.title {
  margin: 0 0 14px;
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.08;
  font-weight: 800;
}

.title-line {
  display: block;
  opacity: 0;
  transform: translateY(16px);
  animation: fadeUp 0.7s ease forwards;
}

.title-line.accent {
  background: linear-gradient(100deg, var(--accent-bright), #fbbf24 45%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation-delay: 0.12s;
}

.tagline {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 auto;
  max-width: 520px;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.24s;
}

@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Difficulty picker ---------- */
.difficulty-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards;
  animation-delay: 0.32s;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.2s ease;
  font-family: var(--font-display);
}

.diff-btn:hover { border-color: var(--accent); transform: translateY(-2px); }

.diff-btn.is-active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), rgba(217, 119, 6, 0.04));
  box-shadow: 0 0 0 1px var(--accent-soft), 0 8px 24px -8px rgba(217, 119, 6, 0.5);
}

.diff-name { font-weight: 700; font-size: 0.95rem; }
.diff-meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.diff-btn.is-active .diff-meta { color: var(--accent-bright); }

/* ---------- Game Card ---------- */
.game-card {
  position: relative;
  width: min(520px, 92vw);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px clamp(18px, 4vw, 30px) 22px;
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
  opacity: 0;
  animation: cardIn 0.7s cubic-bezier(.16,1,.3,1) forwards;
  animation-delay: 0.4s;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.game-card.shake { animation: shakeCard 0.4s ease; }
@keyframes shakeCard {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.game-card-glow {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: radial-gradient(600px circle at var(--mx, 50%) var(--my, 0%), rgba(217,119,6,0.12), transparent 60%);
  pointer-events: none;
  z-index: -1;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat:last-child { align-items: flex-end; }

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
}

.doors {
  display: flex;
  gap: 4px;
}

.door-pip {
  width: 12px;
  height: 16px;
  border-radius: 3px 3px 2px 2px;
  background: var(--accent-soft);
  border: 1px solid rgba(217, 119, 6, 0.4);
  transition: all 0.3s ease;
}

.door-pip.used {
  background: transparent;
  border-color: rgba(148, 163, 184, 0.25);
  transform: scaleY(0.85);
  opacity: 0.5;
}

/* ---------- Proximity meter ---------- */
.proximity { margin-bottom: 20px; }

.proximity-track {
  height: 10px;
  border-radius: 99px;
  background: rgba(255,255,255,0.05);
  overflow: hidden;
  border: 1px solid var(--border);
}

.proximity-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cold), #a855f7 50%, var(--danger));
  transition: width 0.5s cubic-bezier(.16,1,.3,1);
}

.proximity-label {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
}

/* ---------- Guess form ---------- */
.guess-form {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.input-wrap {
  position: relative;
  flex: 1;
}

#guess-input {
  width: 100%;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  padding: 14px 16px;
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  text-align: center;
  -moz-appearance: textfield;
}

#guess-input::-webkit-outer-spin-button,
#guess-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#guess-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: rgba(217, 119, 6, 0.06);
}

#guess-input.invalid { animation: inputShake 0.35s ease; border-color: var(--danger); }
@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.input-range {
  position: absolute;
  right: 14px;
  bottom: -20px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  color: #0a0a0f;
  border: none;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 0 24px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.98rem;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 8px 20px -8px rgba(217, 119, 6, 0.7);
}

.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  transition: all 0.2s ease;
}

.ghost-btn:hover { color: var(--accent-bright); border-color: var(--accent); }

.feedback {
  min-height: 1.4em;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 600;
  margin: 18px 0 6px;
  transition: color 0.2s ease;
}

.feedback.up { color: var(--cold); }
.feedback.down { color: var(--accent-bright); }
.feedback.correct { color: var(--success); }
.feedback.over { color: var(--danger); }

/* ---------- History ---------- */
.history-wrap { margin-top: 10px; }

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  animation: slideIn 0.3s cubic-bezier(.16,1,.3,1);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-item .h-num { color: var(--muted); }
.history-item .h-guess { font-weight: 700; }
.history-item .h-hint { display: flex; align-items: center; gap: 5px; }

.history-item.h-up .h-hint { color: var(--cold); }
.history-item.h-down .h-hint { color: var(--accent-bright); }
.history-item.h-correct { border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.08); }
.history-item.h-correct .h-hint { color: var(--success); }

.hint-note {
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.6;
  text-align: center;
  font-family: var(--font-mono);
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 24px 20px 30px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p { margin: 0 0 8px; }
.site-footer strong { color: var(--fg); }

.footer-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.footer-links a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover { color: var(--accent); text-decoration: underline; }
.footer-links .dot { color: var(--border); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 10, 0.75);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
}

.modal-overlay.is-open { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.modal {
  position: relative;
  width: min(420px, 88vw);
  background: linear-gradient(180deg, #14141f, #0d0d18);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 26px 26px;
  text-align: center;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7);
  animation: modalIn 0.4s cubic-bezier(.16,1,.3,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 10px;
  animation: pop 0.5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.modal-title {
  font-size: 1.5rem;
  margin: 0 0 8px;
  font-weight: 800;
}

.modal-text {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 22px;
  font-family: var(--font-mono);
}

.modal-stats .m-stat { display: flex; flex-direction: column; gap: 2px; }
.modal-stats .m-stat-value { font-weight: 800; font-size: 1.2rem; color: var(--accent-bright); }
.modal-stats .m-stat-label { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .guess-form { flex-direction: column; }
  .primary-btn { padding: 14px; }
  .modal-stats { gap: 12px; }
}
