*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #f7f7f7;
  font-family: 'Courier New', monospace;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  color: #535353;
}

/* ============ LOADING ============ */
#loading-screen {
  position: fixed; inset: 0;
  background: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}
#loading-screen.fade-out { opacity: 0; pointer-events: none; }

#loading-title {
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: 900;
  letter-spacing: clamp(6px, 3vw, 14px);
  margin-bottom: 28px;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.65; transform: scale(1.03); }
}

#loading-dino-canvas {
  image-rendering: pixelated;
  margin-bottom: 32px;
  max-width: 60vw;
  height: auto;
}

#loading-bar-wrap {
  width: clamp(200px, 55vw, 340px);
  height: 5px;
  background: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
#loading-bar {
  height: 100%; width: 0%;
  background: #535353;
  transition: width 0.25s ease;
}
#loading-label {
  font-size: 0.8rem;
  color: #aaa;
  letter-spacing: 2px;
}

/* ============ ROTATE PROMPT ============ */
#rotate-prompt {
  position: fixed; inset: 0;
  background: #fff;
  flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 10000;
  display: none;
  gap: 20px;
  padding: 40px;
  text-align: center;
}
#rotate-prompt.show { display: flex; }
#rotate-icon {
  font-size: 72px;
  line-height: 1;
  filter: grayscale(1) brightness(0);
  animation: rotateAnim 2s ease-in-out infinite;
}
@keyframes rotateAnim {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(90deg); }
}
#rotate-prompt h2 { font-size: 1.3rem; letter-spacing: 2px; }
#rotate-prompt p { color: #888; max-width: 320px; line-height: 1.6; }
#rotate-fs-btn {
  margin-top: 8px;
  padding: 14px 28px;
  background: #535353;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 1px;
}
#rotate-fs-btn:hover { background: #333; }

/* ============ AUTH SCREEN ============ */
#auth-screen, #google-setup-screen {
  position: fixed; inset: 0;
  background: #fff;
  display: none;
  align-items: center; justify-content: center;
  z-index: 8000;
  padding: 20px;
  overflow-y: auto;
}
#auth-screen.show, #google-setup-screen.show { display: flex; }

.auth-card {
  width: 100%; max-width: 400px;
  text-align: center;
  padding: 20px 0;
}
.auth-title {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  letter-spacing: 8px;
  margin-bottom: 6px;
}
.auth-sub {
  font-size: 0.75rem;
  color: #bbb;
  letter-spacing: 3px;
  margin-bottom: 30px;
}
.auth-tabs {
  display: flex; gap: 4px;
  margin-bottom: 20px;
  background: #f0f0f0;
  padding: 4px;
  border-radius: 8px;
}
.auth-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: bold;
  color: #888;
  cursor: pointer;
  border-radius: 6px;
  letter-spacing: 1px;
}
.auth-tab.active { background: #535353; color: #fff; }

.auth-card input, .field-input {
  width: 100%;
  padding: 14px;
  font-family: inherit;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 6px;
  outline: none;
  color: #535353;
  background: #fff;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}
.auth-card input:focus, .field-input:focus { border-color: #535353; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px !important; }
.pw-eye {
  position: absolute;
  right: 6px; top: 6px;
  background: none;
  border: none;
  cursor: pointer;
  width: 38px; height: 38px;
  font-size: 1.2rem;
  padding: 0;
  opacity: 0.45;
  transition: opacity 0.15s;
  line-height: 1;
}
.pw-eye:hover { opacity: 1; }
.pw-eye.shown { opacity: 1; }

#auth-status, #setup-status {
  font-size: 0.85rem;
  min-height: 1.3em;
  margin: 8px 0;
  font-weight: bold;
}

.btn-primary, .btn-secondary, .btn-danger, .btn-google {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 1px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary { background: #535353; color: #fff; }
.btn-primary:hover { background: #333; }
.btn-primary:disabled { background: #bbb; cursor: not-allowed; }
.btn-primary.small { width: auto; padding: 10px 22px; font-size: 0.85rem; }
.btn-secondary { background: #eee; color: #535353; }
.btn-secondary:hover { background: #ddd; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-google { background: #fff; color: #535353; border: 1px solid #ddd; }
.btn-google:hover { background: #f5f5f5; }
.btn-primary:active, .btn-secondary:active, .btn-danger:active, .btn-google:active { transform: scale(0.97); }

.auth-divider {
  text-align: center;
  margin: 16px 0;
  color: #bbb;
  font-size: 0.75rem;
  position: relative;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 35%;
  height: 1px;
  background: #ddd;
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

.auth-credits { margin-top: 20px; font-size: 0.65rem; color: #ccc; letter-spacing: 1px; }
.setup-info { font-size: 0.85rem; color: #888; margin-bottom: 16px; line-height: 1.5; }

/* ============ GAME ============ */
#game-wrap {
  position: fixed;
  inset: 0;
  display: none;
  overflow: hidden;
  background: #f7f7f7;
  transition: background 0.8s ease;
  will-change: background;
}
#game-wrap.show { display: block; }
#game-wrap.night-bg { background: #1a1a2e; }
#game-wrap.hardcore-bg { background: #2d0a0a; }
#game-wrap.hardcore-night-bg { background: #0d0010; }

canvas#game {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #f7f7f7;
  transition: background 0.8s ease;
  will-change: transform;
}
canvas#game.night-canvas { background: #222244; }
canvas#game.hardcore-canvas { background: #3d1010; }
canvas#game.hardcore-night-canvas { background: #1a0020; }

#menu-btns {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
#menu-btns.show { opacity: 1; pointer-events: auto; }

.top-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #535353;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 13px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: bold;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.top-btn:hover { background: #333; }
.top-btn:active { transform: scale(0.94); }

@media (max-width: 560px) {
  .top-btn .btn-label { display: none; }
  .top-btn { padding: 9px 11px; font-size: 0.95rem; }
}

#menu-coins-display {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 20;
  background: #535353;
  color: #f0c030;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  font-weight: bold;
  padding: 9px 13px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}
#menu-coins-display.show { display: block; opacity: 1; }

#menu-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.menu-el {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.menu-el.show { opacity: 1; }

#menu-title-text {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 900;
  letter-spacing: clamp(4px, 2vw, 12px);
}
#menu-sub-text {
  font-size: clamp(0.55rem, 1.4vw, 0.75rem);
  color: #bbb;
  letter-spacing: 3px;
  margin-top: 4px;
  transition-delay: 0.05s;
}
#menu-greet {
  font-size: clamp(0.7rem, 1.6vw, 0.9rem);
  color: #888;
  margin-top: 28px;
  transition-delay: 0.1s;
}
#menu-start {
  font-size: clamp(0.8rem, 2vw, 1.1rem);
  font-weight: bold;
  letter-spacing: 2px;
  margin-top: 8px;
  animation: blink 1.2s step-end infinite;
  transition-delay: 0.15s;
}
#menu-made-by {
  font-size: clamp(0.55rem, 1.2vw, 0.7rem);
  color: #ccc;
  letter-spacing: 2px;
  margin-top: 20px;
  transition-delay: 0.2s;
}

/* Sleeping dino Z's */
#menu-zs {
  position: absolute;
  pointer-events: none;
  font-weight: bold;
  color: #535353;
  z-index: 11;
  display: none;
}
.z-letter {
  position: absolute;
  animation: floatZ 2s ease-out forwards;
  font-family: 'Courier New', monospace;
}
@keyframes floatZ {
  0% { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(-20px,-40px) scale(1.5); }
}

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

#menu-tap {
  position: absolute;
  inset: 0;
  z-index: 9;
  cursor: pointer;
  display: none;
}

#hud {
  position: absolute;
  top: 14px;
  right: 14px;
  text-align: right;
  z-index: 15;
  display: none;
}
#hud-mode {
  font-size: clamp(0.6rem, 1.2vw, 0.75rem);
  font-weight: bold;
  color: #cc3333;
  margin-bottom: 2px;
  letter-spacing: 1px;
}
#hud-coins {
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  font-weight: bold;
  color: #d4a017;
  margin-bottom: 4px;
}
#hud-score {
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  font-weight: bold;
}
#hud-hi {
  font-size: clamp(0.65rem, 1.4vw, 0.85rem);
  color: #bbb;
  margin-top: 2px;
}

#gameover-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 15;
  background: rgba(255,255,255,0.6);
}
#gameover-screen.show { display: flex; }

#go-title {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 900;
  letter-spacing: clamp(2px, 1vw, 6px);
  margin-bottom: 10px;
}
#go-scores {
  font-size: 1rem;
  color: #777;
  margin-bottom: 6px;
}
#go-coins-earned {
  font-size: 0.95rem;
  color: #d4a017;
  font-weight: bold;
  margin-bottom: 22px;
}
#go-restart {
  font-size: 0.95rem;
  font-weight: bold;
  letter-spacing: 1px;
  animation: blink 1.2s step-end infinite;
  margin-bottom: 22px;
}
#go-menu-btn {
  background: #535353;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 1px;
}
#go-menu-btn:hover { background: #333; }

/* PAUSE SCREEN */
#pause-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 16;
  background: rgba(255,255,255,0.75);
  gap: 16px;
}
#pause-screen.show { display: flex; }
#pause-title {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 4px;
}
#pause-resume-btn, #pause-menu-btn {
  padding: 12px 28px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 1px;
}
#pause-resume-btn { background: #535353; color: #fff; }
#pause-resume-btn:hover { background: #333; }
#pause-menu-btn { background: #eee; color: #535353; margin-top: 4px; }
#pause-menu-btn:hover { background: #ddd; }

.touch-zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 50%;
  z-index: 12;
  display: none;
}
#tz-left { left: 0; }
#tz-right { right: 0; }

#credits {
  position: absolute;
  bottom: 8px;
  left: 0; right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: #ccc;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.5s ease 0.25s;
}
#credits.show { opacity: 1; }

/* ============ MODALS ============ */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-bg.show { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 26px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 12px 48px rgba(0,0,0,0.28);
}
.modal-box.lb-wide { max-width: 820px; }
.modal-box.small { max-width: 380px; text-align: center; }
.modal-box h2 { font-size: 1.2rem; letter-spacing: 3px; margin-bottom: 16px; }
.modal-box p { font-size: 0.9rem; color: #777; line-height: 1.5; margin-bottom: 18px; }

.modal-close-btn {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  width: 30px; height: 30px;
  font-size: 1.2rem;
  color: #888;
  border-radius: 50%;
}
.modal-close-btn:hover { background: #eee; }

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}
.setting-row small { color: #bbb; font-size: 0.72rem; }

.toggle {
  width: 48px; height: 25px;
  background: #ddd;
  border-radius: 13px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.25s;
}
.toggle.on { background: #535353; }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 19px; height: 19px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.25s;
}
.toggle.on::after { left: 26px; }

.section-divider {
  border-top: 2px solid #f0f0f0;
  margin-top: 14px;
  padding-top: 16px;
}
.section-divider label {
  display: block;
  font-size: 0.82rem;
  color: #777;
  font-weight: bold;
  margin-bottom: 10px;
}

.fps-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.fps-btn {
  background: #eee;
  border: 2px solid transparent;
  color: #535353;
  padding: 6px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: bold;
}
.fps-btn.active { background: #535353; color: #fff; border-color: #333; }
.fps-btn:hover { background: #ddd; }

.bind-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  font-size: 0.85rem;
}
.bind-row > span:first-child { width: 60px; }
.bind-keys { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.bind-key {
  background: #535353;
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bind-key .remove { cursor: pointer; opacity: 0.7; font-weight: bold; }
.bind-key .remove:hover { opacity: 1; }
.bind-add {
  background: #eee;
  border: none;
  color: #535353;
  padding: 6px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: bold;
}
.bind-add:hover { background: #ddd; }

.field-status {
  font-size: 0.78rem;
  min-height: 1.1em;
  margin: 8px 0;
  font-weight: bold;
}
.field-note { font-size: 0.73rem; color: #bbb; margin-bottom: 10px; }

#account-info { padding: 8px 0 12px; font-size: 0.85rem; color: #777; }

/* ============ LEADERBOARD ============ */
.lb-columns {
  display: flex;
  gap: 0;
  align-items: flex-start;
}
.lb-col { flex: 1; min-width: 0; }
.lb-col-divider {
  width: 2px;
  background: #f0f0f0;
  align-self: stretch;
  margin: 0 16px;
  flex-shrink: 0;
}
.lb-col-title {
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 2px;
  margin-bottom: 10px;
  text-align: center;
  color: #535353;
}
.lb-col-title.hc-title { color: #cc3333; }

.lb-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: #f0f0f0;
  padding: 3px;
  border-radius: 8px;
}
.lb-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: bold;
  color: #888;
  cursor: pointer;
  border-radius: 6px;
}
.lb-tab.active { background: #535353; color: #fff; }

.lb-list { list-style: none; }
.lb-item {
  display: flex;
  align-items: center;
  padding: 8px 4px;
  gap: 8px;
  border-bottom: 1px solid #f5f5f5;
  font-size: 0.82rem;
}
.lb-item.lb-self { background: #f7f7f7; border-radius: 4px; }
.lb-rank { width: 26px; font-weight: bold; color: #aaa; text-align: center; flex-shrink: 0; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: bold; font-size: 0.78rem; flex-shrink: 0; }
.lb-empty { text-align: center; padding: 20px; color: #bbb; font-size: 0.85rem; list-style: none; }

#lb-guest-notice {
  text-align: center;
  padding: 16px;
  border-top: 1px solid #f0f0f0;
  margin-top: 12px;
}
#lb-guest-notice p { margin-bottom: 12px; color: #777; }

@media (max-width: 600px) {
  .lb-columns { flex-direction: column; }
  .lb-col-divider { width: auto; height: 2px; margin: 16px 0; }
}

/* ============ NIGHT MODE ============ */
html.night-mode body { background: #1a1a2e; }
html.night-mode #game-wrap { background: #1a1a2e !important; }
html.night-mode canvas#game { background: #222244 !important; }
