/* Sky Island — game.css. Self-contained: no external fonts/icons, so the
   game never has an unstyled-flash or broken-glyph moment on a slow link. */

:root {
  --sky-blue: #4aa8ff;
  --sky-blue-dark: #2f7fd6;
  --accent-pink: #ff6fa5;
  --accent-yellow: #ffd23f;
  --ink: #1c2a4a;
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-border: rgba(255, 255, 255, 0.6);
  --radius-lg: 22px;
  --radius-md: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0c1445;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#game-root {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1c2a5e 0%, #070c22 100%);
  touch-action: none;
  user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-canvas {
  aspect-ratio: 480 / 800;
  height: 100%;
  max-height: 100dvh;
  max-width: 100%;
  width: auto;
  display: block;
  border-radius: 0;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.45);
  background: #8fd7ff;
}

@media (min-aspect-ratio: 480/800) {
  #game-canvas { width: auto; height: 100%; }
}
@media (max-aspect-ratio: 480/800) {
  #game-canvas { width: 100%; height: auto; }
}

/* ---------------- HUD ---------------- */
#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  padding: 0 14px;
  pointer-events: none;
  z-index: 20;
}
.hud-top {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}
.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: rgba(12, 20, 45, 0.55);
  backdrop-filter: blur(4px);
  border-radius: var(--radius-md);
  padding: 5px 12px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
}
.hud-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  opacity: 0.75;
  font-weight: 600;
}
.hud-label svg { vertical-align: -2px; }
.shop-title svg, .trail-btn svg { vertical-align: -2px; }
#btn-mute,
#btn-fullscreen,
#btn-pause {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(12, 20, 45, 0.55);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#btn-mute {
  margin-left: auto;
}
#btn-mute svg {
  width: 16px;
  height: 16px;
}
#btn-fullscreen svg {
  width: 16px;
  height: 16px;
}
.hud-combo {
  margin-top: 6px;
  text-align: center;
  font-weight: 800;
  font-size: 18px;
  color: var(--accent-yellow);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  animation: combo-pop 0.25s ease;
}
@keyframes combo-pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------------- Banners (event popups) ---------------- */
#banner-container {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  pointer-events: none;
  text-align: center;
}
.banner {
  font-weight: 800;
  font-size: 26px;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.7) translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}
.banner.show { opacity: 1; transform: scale(1) translateY(0); }
.banner-perfect { color: var(--accent-yellow); }
.banner-good { color: #b8ffcf; font-size: 20px; }
.banner-close { color: #ffb3b3; font-size: 20px; }
.banner-nearmiss { color: #ff9ecb; font-size: 24px; }
.banner-milestone { color: #cdeaff; font-size: 22px; }

/* ---------------- Toasts ---------------- */
#toast-container {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 20, 45, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon { font-size: 15px; }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 30;
  padding: 16px;
  text-align: center;
}
.screen-overlay {
  background: rgba(7, 12, 34, 0.55);
  backdrop-filter: blur(2px);
}

#screen-boot { background: linear-gradient(180deg, #8fd7ff, #dff6ff); gap: 20px; }
.boot-logo {
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.08em;
  text-shadow: 0 4px 14px rgba(0, 40, 90, 0.35);
}
.boot-spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#screen-menu { background: linear-gradient(180deg, #8fd7ff 0%, #cdeeff 55%, #eaf8ff 100%); }

.menu-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  width: min(340px, 100%);
  box-shadow: 0 18px 40px rgba(20, 40, 90, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.menu-card-tall { max-height: 82vh; overflow-y: auto; }

.game-title {
  font-size: 34px;
  font-weight: 900;
  margin: 0;
  background: linear-gradient(180deg, #4aa8ff, #2f7fd6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 0.03em;
}
.game-tagline {
  margin: 0 0 4px;
  font-weight: 600;
  color: #4a5a80;
  font-size: 14px;
}
.menu-best {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--sky-blue-dark);
}
.menu-daily-code { font-weight: 800; margin-left: 4px; }
.menu-daily-streak { margin: -4px 0 4px; font-size: 12px; font-weight: 700; color: #ff8a3d; }

.btn-primary, .btn-secondary, .btn-tertiary, .toggle-btn, .trail-btn, .lb-tab {
  font-family: var(--font);
  border: none;
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn-primary:active, .btn-secondary:active, .btn-tertiary:active { transform: scale(0.96); }

.btn-primary {
  width: 100%;
  padding: 16px;
  font-size: 20px;
  color: #fff;
  background: linear-gradient(180deg, #ff8fb3, #ff5f9e);
  border-radius: 999px;
  box-shadow: 0 8px 0 #d63e7e, 0 14px 22px rgba(214, 62, 126, 0.35);
}
.btn-primary.btn-small { width: auto; padding: 10px 18px; font-size: 14px; box-shadow: 0 5px 0 #d63e7e; }

.btn-secondary {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  color: var(--sky-blue-dark);
  background: #eaf6ff;
  border: 2px solid #bfe3ff;
  border-radius: 999px;
}

.menu-row { display: flex; gap: 8px; width: 100%; margin-top: 4px; flex-wrap: wrap; justify-content: center; }
.btn-tertiary {
  flex: 1 1 auto;
  padding: 10px 12px;
  font-size: 12px;
  color: #4a5a80;
  background: #f2f6fb;
  border-radius: 999px;
}

.link-btn {
  background: none;
  border: none;
  color: #8a97b8;
  text-decoration: underline;
  font-size: 12px;
  cursor: pointer;
}

/* Tutorial overlay */
.tutorial-card {
  background: rgba(12, 20, 45, 0.85);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  max-width: 300px;
}
.tutorial-hint { font-size: 18px; font-weight: 800; margin: 0 0 6px; }
.tutorial-sub { font-size: 13px; opacity: 0.85; margin: 0 0 14px; }

/* Game over */
.go-title { margin: 0; font-size: 20px; letter-spacing: 0.08em; color: #8a97b8; }
.go-new-best {
  font-weight: 900;
  color: #ff8a3d;
  font-size: 16px;
  animation: combo-pop 0.3s ease;
}
.go-score { font-size: 44px; font-weight: 900; color: var(--sky-blue-dark); line-height: 1; }
.go-stats-row {
  display: flex;
  gap: 16px;
  font-size: 13px;
  font-weight: 700;
  color: #4a5a80;
}
.go-stats-row b { color: var(--ink); }
.go-rank { font-size: 13px; font-weight: 800; color: var(--accent-pink); min-height: 16px; }

.go-nickname-wrap { display: flex; gap: 6px; align-items: center; width: 100%; flex-wrap: wrap; justify-content: center; }
.go-nickname-wrap input {
  flex: 1 1 150px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 2px solid #bfe3ff;
  font-size: 14px;
  font-family: var(--font);
  min-width: 0;
}
.go-saved-msg { font-size: 13px; font-weight: 700; color: #2fbf6e; }

/* Leaderboard */
.lb-tabs { display: flex; gap: 6px; width: 100%; }
.lb-tab {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  border-radius: 999px;
  background: #f2f6fb;
  color: #4a5a80;
}
.lb-tab.active { background: var(--sky-blue); color: #fff; }
.lb-list { width: 100%; max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.lb-loading { font-size: 13px; color: #8a97b8; padding: 20px 0; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f7fafc;
  border-radius: var(--radius-md);
  font-size: 13px;
}
.lb-row-you { background: #fff3d6; font-weight: 800; }
.lb-rank { width: 30px; text-align: center; font-weight: 800; }
.lb-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--sky-blue-dark); }
.lb-personal {
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  background: #eaf6ff;
  font-weight: 800;
  font-size: 13px;
  color: var(--sky-blue-dark);
}

/* Settings */
.settings-row { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 14px; font-weight: 700; }
.toggle-btn {
  padding: 6px 16px;
  border-radius: 999px;
  background: #dff0ff;
  color: var(--sky-blue-dark);
  font-size: 12px;
}
.toggle-btn.on { background: var(--sky-blue); color: #fff; }
.shop-title { width: 100%; text-align: left; font-size: 13px; margin: 8px 0 2px; color: #4a5a80; }
.trail-shop { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.trail-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #f7fafc; border-radius: var(--radius-md); }
.trail-item.equipped { background: #eaf6ff; }
.trail-swatch { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.trail-none { background: #d8dde6; }
.trail-cloud { background: linear-gradient(135deg, #bfe9ff, #ffffff); }
.trail-star { background: linear-gradient(135deg, #ffe27a, #fff7cf); }
.trail-lightning { background: linear-gradient(135deg, #c9a2ff, #7ee8ff); }
.trail-rainbow { background: linear-gradient(135deg, #ff8fa3, #ffd97a, #8fffb0, #8fd7ff); }
.trail-name { flex: 1; text-align: left; font-size: 12px; font-weight: 700; }
.trail-btn { padding: 6px 10px; font-size: 11px; border-radius: 999px; background: var(--sky-blue); color: #fff; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.ach-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  background: #f7fafc;
}
.ach-card.unlocked { background: #fff3d6; }
.ach-icon { font-size: 24px; }
.ach-name { font-size: 11px; font-weight: 800; }
.ach-desc { font-size: 9px; color: #8a97b8; text-align: center; }

/* Ad slots — placeholders only; wire real AdSense per HUONG-DAN-TRIEN-KHAI.md */
.ad-slot {
  width: min(320px, 100%);
  min-height: 50px;
  border: 1px dashed rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
}
.ad-slot-gameover { margin-top: 6px; }
.ad-label { letter-spacing: 0.08em; }

@media (prefers-reduced-motion: reduce) {
  .banner, .toast, .go-new-best, .hud-combo { animation: none !important; transition: none !important; }
}
