/* Aesthetic theme for 3D Dino Game landing and HUD */
/* Fonts */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800;900&display=swap');

:root {
  /* Dark navy palette */
  --bg-0: #090e1b;   /* deepest background */
  --bg-1: #0c1326;   /* base navy */
  --bg-2: #101a33;   /* elevated navy */
  --text: #e8ecf6;
  --muted: #aab3c8;
  --brand-1: #7c6df2; /* violet-leaning indigo */
  --brand-2: #5b6cf5; /* primary indigo */
  --brand-3: #2ac7f0; /* accent cyan */
  --success: #1fc86e;
  --danger: #ef4a4a;
  --glass: rgba(12,18,40,0.55);
  --glass-strong: rgba(10,16,36,0.75);
  --ring: rgba(255,255,255,0.16);
  --shadow-1: 0 10px 30px rgba(0,0,0,0.35);
  --inner-1: inset 0 0 0 1px rgba(255,255,255,0.06);
}

/* Fixed top-center controls (prevents layout shift when HUD content changes) */
.top-center-controls {
  position: absolute;
  /* Push slightly below the HUD so it never covers the difficulty bar */
  top: calc(max(16px, env(safe-area-inset-top)) + 48px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20; /* above HUD */
  pointer-events: none; /* pass through by default */
}
.top-center-controls > * { pointer-events: auto; }

/* On very small phones, nudge a bit less to preserve vertical space */
@media (max-width: 480px) {
  .top-center-controls { top: calc(max(12px, env(safe-area-inset-top)) + 42px); }
}
.top-center-controls > * { pointer-events: auto; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Poppins, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial;
  /* Deep navy layered gradients for premium look */
  background:
    radial-gradient(1200px 900px at 15% -10%, #1a2448 0%, var(--bg-2) 35%, var(--bg-1) 60%, var(--bg-0) 85%),
    radial-gradient(1200px 900px at 110% 120%, #0c1533 0%, #0a1228 55%, var(--bg-0) 85%);
  background-attachment: fixed;
  position: relative;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Global vignette for cinematic focus */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(140% 110% at 50% 20%, transparent 40%, rgba(0,0,0,0.20) 80%, rgba(0,0,0,0.35));
}

/* Slow ambient orb adding depth */
body::after {
  content: ""; position: fixed; width: 60vmax; height: 60vmax; left: -10vmax; top: -10vmax; z-index: 0; pointer-events: none;
  background: radial-gradient(closest-side, rgba(46,113,255,0.12), rgba(42,199,240,0.07), transparent 70%);
  filter: blur(12px) saturate(1.2);
  animation: orbFloat 24s ease-in-out infinite alternate;
}
@keyframes orbFloat {
  0% { transform: translate(0,0) scale(1) rotate(0deg); opacity: .8; }
  50% { transform: translate(10vmax, 8vmax) scale(1.1) rotate(180deg); opacity: 1; }
  100% { transform: translate(0,0) scale(1) rotate(360deg); opacity: .8; }
}

/* Canvas container */
#game-container {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  background-color: #0b1220; /* match renderer clear to avoid flashes */
}

canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  background-color: #0b1220; /* ensure opaque even before GL paints */
  transform: translateZ(0); /* stabilize compositing on some GPUs */
}

/* HUD: glass bar */
.hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap; /* allow wrapping on narrow screens */
  background: var(--glass);
  padding: 8px 12px;
  border-radius: 14px;
  backdrop-filter: blur(10px) saturate(1.1);
  box-shadow: var(--shadow-1), var(--inner-1);
  border: 1px solid rgba(255,255,255,0.06);
}
.hud:hover { box-shadow: 0 14px 36px rgba(0,0,0,0.4), var(--inner-1); }
.hud .hint { opacity: 0.8; font-size: 12px; filter: drop-shadow(0 1px 0 rgba(0,0,0,0.25)); }

.hud .score::before, .hud .diff::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  vertical-align: text-bottom;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

.hud .score[data-label="Score"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23eab308'%3E%3Cpath fill-rule='evenodd' d='M12 2.25c-5.385 0-9.75 4.365-9.75 9.75s4.365 9.75 9.75 9.75 9.75-4.365 9.75-9.75S17.385 2.25 12 2.25zm.255 3.86a.75.75 0 00-1.06 1.06l1.97 1.97a.75.75 0 101.06-1.06l-1.97-1.97zM10.5 12a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0z' clip-rule='evenodd' /%3E%3C/svg%3E");
}

.hud .score[data-label="High"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f59e0b'%3E%3Cpath fill-rule='evenodd' d='M12.75 2.25a.75.75 0 00-1.5 0v2.25h-1.5a.75.75 0 000 1.5h1.5v2.25a.75.75 0 001.5 0v-2.25h1.5a.75.75 0 000-1.5h-1.5V2.25zM12 6a.75.75 0 00-1.5 0v2.25h-1.5a.75.75 0 000 1.5h1.5v2.25a.75.75 0 001.5 0V9.75h1.5a.75.75 0 000-1.5H12V6zM12 18a.75.75 0 00-1.5 0v2.25H9a.75.75 0 000 1.5h1.5v.75a.75.75 0 001.5 0v-.75h1.5a.75.75 0 000-1.5h-1.5V18z' clip-rule='evenodd' /%3E%3C/svg%3E");
}

.hud .diff::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a855f7'%3E%3Cpath fill-rule='evenodd' d='M12 2.25c-5.385 0-9.75 4.365-9.75 9.75s4.365 9.75 9.75 9.75 9.75-4.365 9.75-9.75S17.385 2.25 12 2.25zm0 1.5a8.25 8.25 0 100 16.5 8.25 8.25 0 000-16.5zm-.75 5.25a.75.75 0 00-1.5 0v.09c-1.121.23-2.074.87-2.775 1.717a.75.75 0 001.14.975 3.23 3.23 0 012.385-1.04v-.09a.75.75 0 00-.75-.75zm2.25.75a.75.75 0 00.75-.75v-.09a3.23 3.23 0 012.385 1.04.75.75 0 101.14-.975c-.701-.847-1.654-1.487-2.775-1.717v-.09a.75.75 0 00-.75-.75z' clip-rule='evenodd' /%3E%3C/svg%3E");
}

.hud .score { font-weight: 800; letter-spacing: 0.3px; font-size: clamp(12px, 3.2vw, 16px); }
.hud .hint  { opacity: 0.8; font-size: 12px; }
.hud .diff  { display:flex; align-items:center; gap:8px; }

/* Small HUD badges: magnet timer + combo */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: var(--inner-1);
}
.badge .icon {
  width: 16px; height: 16px; flex: 0 0 16px;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

/* Magnet badge */
.badge.magnet .icon {
  /* horseshoe magnet icon */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='%232ac7f0'%3E%3Cpath d='M6 4a6 6 0 00-6 6v4a2 2 0 002 2h2v-4H2v-2a4 4 0 018 0v2H8v4h2a2 2 0 002-2v-4A6 6 0 006 4zm16 0a6 6 0 00-6 6v4a2 2 0 002 2h2v-4h-2v-2a4 4 0 118 0v2h-2v4h2a2 2 0 002-2v-4a6 6 0 00-6-6z'/%3E%3C/svg%3E");
}
.badge.magnet .timer {
  position: relative;
  width: 64px; height: 6px; border-radius: 999px; overflow: hidden;
  background: rgba(255,255,255,0.14);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.badge.magnet .timer-fill {
  position: absolute; inset: 0; width: 0%;
  background: linear-gradient(90deg, #22d3ee, #60a5fa);
  border-radius: inherit;
  transition: width 120ms linear;
}

/* Combo badge */
.badge.combo .icon {
  /* lightning/star chain icon */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fbbf24'%3E%3Cpath d='M13 2l-7 10h5l-1 10 7-10h-5l1-10z'/%3E%3C/svg%3E");
}
.badge.combo .value { font-weight: 800; font-size: 12px; letter-spacing: 0.3px; }

.diff-bar {
  width: 140px;
  height: 6px;
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.diff-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--danger));
  border-radius: inherit;
  transition: width 160ms ease;
}

/* Buttons */
button {
  appearance: none;
  border: none;
  padding: 12px 20px;
  border-radius: 12px;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--brand-2), #4f46e5);
  box-shadow: 0 8px 22px rgba(79,70,229,0.35), 0 0 0 1px var(--ring) inset;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
  position: relative; overflow: hidden;
}
button:hover { transform: translateY(-1px); filter: brightness(1.04); }
button:active { transform: translateY(0); filter: brightness(0.98); }
button.secondary {
  background: linear-gradient(180deg, #94a3b8, #64748b);
  box-shadow: 0 6px 18px rgba(100,116,139,0.35), 0 0 0 1px var(--ring) inset;
}

/* Button shine microinteraction */
button::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,0.25), transparent);
  transform: translateX(-120%);
}
button:hover::after { transition: transform 600ms ease; transform: translateX(120%); }

/* Focus-visible accessibility */
button:focus-visible, .owner-badge:focus-visible, .hud:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.25), 0 0 0 4px rgba(99,102,241,0.35);
}

/* Center overlays */
.center { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 20; }
.center .overlay {
  pointer-events: auto;
  text-align: center;
  width: min(92vw, 680px);
  /* Navy-tuned glass panel */
  background: linear-gradient(180deg, rgba(16,24,48,0.72), rgba(12,19,40,0.58));
  padding: 34px 38px;
  border-radius: 18px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.45), var(--inner-1);
  border: 1px solid rgba(255,255,255,0.06);
  opacity: 0; transform: translateY(8px) scale(0.98);
  backdrop-filter: blur(12px) saturate(1.2);
  transition: opacity 240ms ease, transform 240ms ease;
  position: relative;
}
.center .overlay > * { position: relative; z-index: 1; }
/* Inner vignette and subtle texture */
.center .overlay::marker { content: none; }
.center .overlay::selection { background: rgba(124,109,242,0.3); }
.center .overlay .texture {
  display: none; /* placeholder for future */
}
.center .overlay {
  background-image:
    radial-gradient(120% 120% at 50% 0%, rgba(255,255,255,0.04), transparent 60%),
    repeating-conic-gradient(from 0deg, rgba(255,255,255,0.012) 0 10deg, transparent 10deg 20deg);
  background-blend-mode: screen, normal;
  /* inner highlight + vignette */
  box-shadow:
    0 25px 60px rgba(0,0,0,0.45),
    var(--inner-1),
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -30px 60px rgba(0,0,0,0.25);
}
.center .overlay.visible { opacity: 1; transform: translateY(0) scale(1); }
.btns { display:flex; gap:14px; justify-content:center; }

/* Loading overlay */
#loading-screen .loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}
#loading-screen .loader-text { color: var(--muted); font-size: 13px; }
#loading-screen .spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--brand-3);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 10px rgba(42,199,240,0.3);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Share grid for fallback share menu */
.share-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 16px 0 8px;
}
.share-grid a {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  padding: 10px 12px;
  border-radius: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(180deg, #64748b, #475569);
  box-shadow: 0 6px 18px rgba(100,116,139,0.35), 0 0 0 1px var(--ring) inset;
}
.share-grid a:hover { filter: brightness(1.05); transform: translateY(-1px); transition: all 120ms ease; }

.title {
  font-size: clamp(34px, 5vw, 52px);
  font-weight: 900;
  letter-spacing: 0.2px;
  margin: 0 0 14px;
  color: transparent;
  background: linear-gradient(180deg, #f7f9ff, #b8c3ff 60%, #9aa8ff);
  -webkit-background-clip: text; background-clip: text;
  text-shadow: 0 10px 30px rgba(0,0,0,0.35);
  position: relative;
}
.title::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -10px; width: 120px; height: 2px; border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(99,102,241,0.7), rgba(42,199,240,0.7), transparent);
  box-shadow: 0 0 18px rgba(42,199,240,0.35);
}
.subtitle { margin: 0 0 22px; opacity: 0.9; color: var(--muted); letter-spacing: 0.2px; }

.how-to-play {
  margin: 24px 0;
  padding: 16px;
  background: rgba(0,0,0,0.1);
  border-radius: 12px;
}

.how-to-play-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 12px;
  text-align: center;
  color: var(--text);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.control-item {
  text-align: center;
}

.control-key {
  display: inline-block;
  padding: 6px 10px;
  background: var(--bg-1);
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

.control-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.scores {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 24px 0;
}

.score-item {
  text-align: center;
}

.score-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 4px;
}

.score-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.hidden { display: none !important; }

/* Overlay gradient border and animated ambient glow */
.center .overlay::before {
  content: "";
  position: absolute; inset: 0; border-radius: 18px;
  padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, rgba(139,92,246,0.45), rgba(34,211,238,0.35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.center .overlay::after {
  content: ""; position: absolute; inset: -30px -40px -40px -40px; z-index: -1; border-radius: 40px;
  background: radial-gradient(40% 60% at 50% 0%, rgba(99,102,241,0.18), rgba(34,211,238,0.05) 60%, transparent 70%);
  filter: blur(24px);
  animation: ambient 6s ease-in-out infinite alternate;
}
@keyframes ambient {
  0% { transform: translateY(0) scale(1); opacity: 0.9; }
  100% { transform: translateY(-6px) scale(1.02); opacity: 1; }
}

/* Score pop animation */
.pop { position: absolute; z-index: 20; font-weight: 800; color: #ffd166; text-shadow: 0 2px 8px rgba(0,0,0,0.4); opacity: 0; transform: translateY(8px) scale(0.98); transition: opacity 300ms ease, transform 300ms ease; pointer-events: none; }
.pop.show { opacity: 1; transform: translateY(-12px) scale(1); }

/* Screen flash */
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 15; transition: opacity 180ms ease; mix-blend-mode: screen; }
#flash.show { opacity: var(--flash-alpha, 0.25); }

/* Owner badge */
.owner-badge {
  position: fixed; top: 16px; right: 16px; z-index: 50;
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; letter-spacing: 0.5px; color: #0b0f1a;
  background: radial-gradient(120% 120% at 30% 20%, #a5b4fc 0%, #c4b5fd 45%, #fde68a 100%);
  box-shadow: 0 12px 28px rgba(0,0,0,0.35), inset 0 0 0 2px rgba(255,255,255,0.6);
  user-select: none; cursor: default;
}
.owner-badge::after {
  content: attr(data-tip);
  position: absolute; top: 54px; right: 0; transform: translateX(10%);
  white-space: nowrap; background: rgba(0,0,0,0.65); color: #e5e7eb; font-weight: 700; font-size: 11px;
  padding: 6px 8px; border-radius: 8px; box-shadow: 0 8px 18px rgba(0,0,0,0.35);
  opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 150ms ease;
}
.owner-badge:hover::after { opacity: 1; transform: translateX(10%) translateY(0); }
.owner-badge span { transform: translateY(1px); text-shadow: 0 1px 0 rgba(255,255,255,0.6); }

/* Helpers button as pill */
#helpers-btn { border-radius: 999px; padding-inline: 18px; }

/* Compact icon button (used for mobile pause/resume) */
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
}
#mobile-pause-btn {
  position: relative;
  min-width: 38px;
}
#mobile-pause-btn::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
/* Show pause (two bars) icon when game is running */
#mobile-pause-btn[data-state="pause"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M6 4h4v16H6zM14 4h4v16h-4z'/%3E%3C/svg%3E");
}
/* Show play (triangle) icon when paused */
#mobile-pause-btn[data-state="resume"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}

/* Responsive tweaks */
@media (max-width: 720px) {
  .hud { gap: 10px; padding: 8px 10px; border-radius: 12px; }
  .diff-bar { width: 110px; }
  .badge.magnet .timer { width: 52px; }
  .title { font-size: clamp(26px, 6vw, 34px); }
  .subtitle { font-size: 14px; }
  .btns { gap: 10px; }
  button { padding: 12px 16px; font-size: 15px; }
  /* De-emphasize hint on smaller screens */
  .hud .hint { font-size: 11px; opacity: 0.7; }
}

/* Phone width */
@media (max-width: 480px) {
  .hud { gap: 8px; padding: 8px 10px; }
  .hud .score { font-size: clamp(11px, 3.6vw, 14px); }
  .hud .hint { display: none; } /* hide long hint to avoid overlap */
  .diff-bar { width: 92px; height: 5px; }
  .owner-badge { width: 40px; height: 40px; top: 12px; right: 12px; }
  .center .overlay { width: min(94vw, 600px); padding: 24px 22px; }
  .subtitle { font-size: 13px; }
  button { padding: 11px 14px; font-size: 14px; }
}

/* Very narrow phones */
@media (max-width: 360px) {
  .hud { gap: 6px; }
  .hud .score { font-size: 12px; }
  .diff-bar { width: 80px; }
  .center .overlay { padding: 20px 18px; }
  .title { font-size: clamp(22px, 7vw, 30px); }
}

/* Motion accessibility */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
