@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,700&family=Barlow:wght@400;500;700;900&family=Rajdhani:wght@400;600;700&display=swap');

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

:root {
  --berry: #EE0C5D;
  --grey: #41273C;
  --bg: #0a0a1a;
  --text: #ffffff;
  --gold: #FCB117;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  color: var(--text);
  /* Mobile: prevent browser scroll/zoom/long-press menu during gameplay */
  overscroll-behavior: contain;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* Header is 42px + iOS notch safe-area inset */
  padding-top: calc(42px + env(safe-area-inset-top, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── Page header ─────────────────────────────────────────────────────────── */
#game-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(42px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
  background: rgba(7, 7, 22, 0.97);
  border-bottom: 1px solid #1a1a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10002;
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  user-select: none;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

#header-logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#header-logo {
  height: 22px;
  width: auto;
  display: block;
  vertical-align: middle;
}

#header-em {
  font-size: 14px;
  font-weight: 500;
  color: #d7dbe8;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#header-sep {
  color: #3a3a5c;
  font-size: 15px;
}

#header-game-title {
  font-size: 17px;
  font-weight: 700;
  color: #EE0C5D;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

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

#game-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  /* No browser gestures (pan/zoom/double-tap-zoom) while playing */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Page footer — copyright (low-profile, bottom-left; mirrors fullscreen btn) */
#game-footer {
  position: fixed;
  bottom: 14px;
  left: max(16px, env(safe-area-inset-left, 0px));
  z-index: 100;
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 0.04em;
  user-select: none;
}

#game-footer a {
  color: #555555;
  text-decoration: none;
  transition: color 0.2s;
}

#game-footer a:hover {
  color: #EE0C5D;
  text-decoration: underline;
}

/* Hide on small portrait phones — would overlap Phaser-drawn buttons,
   matching the fullscreen button's behaviour. */
@media screen and (orientation: portrait) and (max-width: 900px) {
  #game-footer { display: none; }
}

/* Fullscreen toggle button */
#fullscreen-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  background: rgba(238, 12, 93, 0.15);
  border: 1px solid var(--berry);
  border-radius: 6px;
  color: var(--berry);
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 16px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background 0.2s, color 0.2s;
  user-select: none;
}

#fullscreen-btn:hover {
  background: var(--berry);
  color: #fff;
}

/* Hide the fullscreen button on small portrait phones — it overlaps
   Phaser-drawn buttons (Play Now, START LEVEL N, etc.) in the
   bottom-right area, and iOS Safari doesn't honour Fullscreen API anyway. */
@media screen and (orientation: portrait) and (max-width: 900px) {
  #fullscreen-btn { display: none; }
}

/* Modal overlay for nickname submission */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.82);
  align-items: center;
  justify-content: center;
}

#modal-overlay.active {
  display: flex;
}

#modal-box {
  background: #12102a;
  border: 2px solid var(--berry);
  border-radius: 12px;
  padding: 40px 48px;
  width: min(480px, 92vw);
  text-align: center;
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

#modal-box h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--berry);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#modal-box p {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 24px;
}

#nickname-input {
  width: 100%;
  padding: 12px 16px;
  background: #1e1b3a;
  border: 2px solid #41273c;
  border-radius: 8px;
  color: #fff;
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 8px;
}

#nickname-input:focus {
  border-color: var(--berry);
}

#nickname-error {
  font-size: 14px;
  color: #ff6b6b;
  min-height: 20px;
  margin-bottom: 16px;
}

#modal-submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--berry);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#modal-submit-btn:hover  { background: #c80a4e; }
#modal-submit-btn:active { transform: scale(0.98); }

#modal-cancel-btn {
  display: block;
  margin-top: 14px;
  background: none;
  border: none;
  color: #666;
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 15px;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-decoration: underline;
}

#modal-cancel-btn:hover { color: #999; }

/* Leaderboard page styles */
.lb-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px;
}

.lb-page .lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 900px;
  margin-bottom: 40px;
}

.lb-page h1 {
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--berry);
}

.lb-page .lb-logo {
  font-size: 14px;
  color: #aaa;
  text-align: right;
  line-height: 1.4;
}

.lb-page .lb-logo strong {
  color: #fff;
  display: block;
  font-size: 16px;
}

.lb-table {
  width: 100%;
  max-width: 900px;
  border-collapse: collapse;
}

.lb-table thead tr {
  border-bottom: 2px solid var(--berry);
}

.lb-table th {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--berry);
  text-align: left;
}

.lb-table th:last-child,
.lb-table td:last-child {
  text-align: right;
}

.lb-table tbody tr {
  border-bottom: 1px solid #1e1b3a;
  transition: background 0.15s;
}

.lb-table tbody tr:hover {
  background: rgba(238, 12, 93, 0.06);
}

.lb-table td {
  padding: 16px 20px;
  font-size: clamp(18px, 2.5vw, 26px);
  font-weight: 600;
}

.lb-table td.rank {
  color: #666;
  font-size: clamp(14px, 2vw, 20px);
  width: 60px;
}

.lb-table tbody tr:nth-child(1) td.rank { color: var(--gold); }
.lb-table tbody tr:nth-child(2) td.rank { color: #c0c0c0; }
.lb-table tbody tr:nth-child(3) td.rank { color: #cd7f32; }

.lb-table td.score {
  color: var(--berry);
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.lb-table td.nickname {
  letter-spacing: 0.06em;
}

.lb-refresh {
  margin-top: 32px;
  font-size: 14px;
  color: #444;
}

.lb-event-tag {
  margin-top: 8px;
  padding: 4px 14px;
  background: rgba(238, 12, 93, 0.12);
  border: 1px solid var(--berry);
  border-radius: 20px;
  font-size: 13px;
  color: var(--berry);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lb-empty {
  padding: 80px 0;
  font-size: 22px;
  color: #333;
  letter-spacing: 0.06em;
}

/* Landscape advisory bar — pinned to the BOTTOM of the viewport on portrait
   phones so it doesn't cover the canvas's top-of-screen content (titles,
   leaderboard headers). Dismissable via the X button. */
#rotate-prompt {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10001;
  background: rgba(10,10,26,0.93);
  border-top: 1px solid #333;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#rotate-prompt-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}

#rotate-icon {
  font-size: 20px;
  color: #EE0C5D;
  line-height: 1;
}

#rotate-title {
  font-family: 'DIN Pro', 'Barlow Condensed', 'Rajdhani', Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #aaaaaa;
  letter-spacing: 0.06em;
}

#rotate-dismiss {
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  font-family: Arial, sans-serif;
}
#rotate-dismiss:hover { color: #aaa; }

@media screen and (orientation: portrait) and (max-width: 900px) {
  #rotate-prompt { display: flex; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
