/* ==========================================================================
   Osasu — Stylesheet
   Palette: bright sunny-day sky blue, sunshine yellow, and cheerful red
   accents — vivid and kid-friendly, still flat and clean (no neon glow,
   no purple).
   ========================================================================== */

:root {
  /* Core palette */
  --color-bg-deep:      #0d47a1;
  --color-bg-sky-top:   #29b6f6;
  --color-bg-sky-mid:   #4fc3f7;
  --color-bg-sky-low:   #ffe082;
  --color-ember:        #ff5252;
  --color-ember-light:  #ff8a80;
  --color-gold:         #ffd93d;
  --color-teal:         #2f80ed;
  --color-teal-dark:    #1565c0;
  --color-cream:        #ffffff;
  --color-cream-dim:    #dbe9fb;
  --color-danger:       #e53935;
  --color-panel:        rgba(13, 33, 74, 0.88);
  --color-panel-border: rgba(255, 217, 61, 0.35);

  /* Typography */
  --font-display: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Consolas', 'SFMono-Regular', Menlo, monospace;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;

  --shadow-panel: 0 20px 60px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-bg-deep);
  font-family: var(--font-body);
  color: var(--color-cream);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

img { -webkit-user-drag: none; user-select: none; }

/* ==========================================================================
   Screens & layout
   ========================================================================== */

.screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#app { position: fixed; inset: 0; width: 100%; height: 100%; }

#game-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, var(--color-bg-sky-top) 0%, var(--color-bg-sky-mid) 55%, var(--color-bg-sky-low) 100%);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,16,30,0.55) 0%, rgba(6,10,20,0.86) 100%);
  backdrop-filter: blur(3px);
  z-index: 50;
  animation: fadeIn 0.25s ease;
  padding: 20px;
}

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

/* ==========================================================================
   Loading screen
   ========================================================================== */

#loading-screen {
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, var(--color-bg-sky-mid) 0%, var(--color-bg-deep) 75%);
  transition: opacity 0.5s ease;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: min(320px, 84vw);
}

.brand-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.brand-mark.small { gap: 6px; }

.lantern-icon {
  filter: drop-shadow(0 0 14px rgba(255, 217, 61, 0.55));
  animation: swing 2.6s ease-in-out infinite;
  transform-origin: 32px 12px;
}

@keyframes swing {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

.game-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: clamp(28px, 6vw, 40px);
  background: linear-gradient(180deg, var(--color-gold) 0%, var(--color-ember) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
}

.brand-mark.small .game-title { font-size: clamp(22px, 5vw, 28px); }

.loading-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--color-ember), var(--color-gold));
  transition: width 0.2s ease;
  box-shadow: 0 0 10px rgba(255,217,61,0.6);
}

.loading-label {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.4px;
  color: var(--color-cream-dim);
}

/* ==========================================================================
   Y8 logo — untouched, clickable, gracefully hides if missing
   ========================================================================== */

.y8-logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
  opacity: 0.9;
  transition: opacity 0.2s ease, transform 0.2s ease;
  line-height: 0;
}
.y8-logo-link:hover { opacity: 1; transform: translateY(-1px); }

.y8-logo {
  height: 28px;
  width: auto;
  display: block;
  object-fit: contain;
}
.y8-logo.small { height: 22px; }

/* Hide the link entirely if the image fails to load */
.y8-logo-link:has(img.y8-broken) { display: none; }

.y8-logo-link.corner {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 30;
  background: rgba(12,18,32,0.55);
  padding: 6px 10px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
}

/* ==========================================================================
   Menu panels
   ========================================================================== */

.menu-panel {
  width: min(420px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--color-panel);
  border: 1px solid var(--color-panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  padding: 32px 28px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  animation: panelIn 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}

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

.tagline {
  margin: -6px 0 4px;
  color: var(--color-cream-dim);
  font-size: 14px;
  letter-spacing: 0.3px;
}

.panel-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  color: var(--color-gold);
}

.menu-best {
  font-size: 13px;
  color: var(--color-cream-dim);
  background: rgba(255,255,255,0.05);
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid rgba(255,255,255,0.08);
}
.menu-best strong { color: var(--color-gold); font-weight: 700; }

.menu-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* Buttons */
.btn {
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  position: relative;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, var(--color-ember-light), var(--color-ember));
  color: #24140a;
  box-shadow: 0 8px 20px rgba(255, 82, 82, 0.35), inset 0 1px 0 rgba(255,255,255,0.35);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 26px rgba(255, 82, 82, 0.48); }

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--color-cream);
  border: 1px solid rgba(255,255,255,0.14);
}
.btn-secondary:hover { background: rgba(255,255,255,0.11); }

.btn-danger-outline {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid rgba(224, 85, 63, 0.5);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
}
.btn-danger-outline:hover { background: rgba(224, 85, 63, 0.12); }

/* How To Play */
.howto-list {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.howto-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.4;
  color: var(--color-cream-dim);
}
.howto-list strong { color: var(--color-cream); }
.howto-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 217, 61, 0.15);
  border-radius: 8px;
  font-size: 15px;
}

/* Settings */
.settings-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 14px;
}
.settings-row.column { flex-direction: row; }

.toggle-btn {
  width: 46px;
  height: 26px;
  border-radius: 99px;
  background: rgba(255,255,255,0.12);
  position: relative;
  transition: background 0.2s ease;
  flex: 0 0 auto;
}
.toggle-btn[aria-checked="true"] { background: var(--color-teal); }
.toggle-knob {
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-btn[aria-checked="true"] .toggle-knob { transform: translateX(20px); }

/* Game over */
.final-score-block { margin: 6px 0 2px; }
.final-score {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 800;
  color: var(--color-gold);
  line-height: 1;
  text-shadow: 0 0 24px rgba(255, 217, 61, 0.4);
}
.final-score-label {
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--color-cream-dim);
  margin-top: 4px;
}
.stats-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.stat-chip {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 13px;
  color: var(--color-cream-dim);
}
.stat-chip strong { color: var(--color-cream); }
#new-best-chip {
  color: #241a08;
  background: linear-gradient(180deg, var(--color-gold), var(--color-ember-light));
  border: none;
  font-weight: 700;
}

/* ==========================================================================
   HUD
   ========================================================================== */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  pointer-events: none;
}

.hud-score {
  display: flex;
  flex-direction: column;
  background: rgba(12,18,32,0.5);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  pointer-events: auto;
}
.hud-score-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--color-cream-dim);
}
.hud-score-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--color-gold);
  line-height: 1.1;
}

.hud-combo {
  background: linear-gradient(180deg, var(--color-ember-light), var(--color-ember));
  color: #291608;
  font-weight: 800;
  font-size: 14px;
  padding: 5px 12px;
  border-radius: 99px;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.hud-combo.show { opacity: 1; transform: scale(1); }
.hud-combo.pulse { animation: comboPulse 0.25s ease; }
@keyframes comboPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(12,18,32,0.5);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--color-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  backdrop-filter: blur(4px);
  transition: background 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.14); }

.hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding: 10px;
}
.hud-best {
  font-size: 12px;
  color: var(--color-cream-dim);
  background: rgba(12,18,32,0.45);
  padding: 4px 12px;
  border-radius: 99px;
}
.hud-best span { color: var(--color-gold); font-weight: 700; }

/* Tutorial hint */
#tutorial-hint {
  position: absolute;
  bottom: 90px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  z-index: 21;
  pointer-events: none;
  animation: hintFloat 2s ease-in-out infinite;
}
.hint-bubble {
  background: rgba(12,18,32,0.7);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 13px;
  color: var(--color-cream);
  backdrop-filter: blur(4px);
}
kbd {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
}
@keyframes hintFloat {
  0%, 100% { transform: translateY(0); opacity: 0.9; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* ==========================================================================
   Touch controls
   ========================================================================== */

#touch-controls {
  position: absolute;
  bottom: 18px;
  right: 16px;
  left: auto;
  display: flex;
  gap: 12px;
  z-index: 25;
}

.touch-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(12,18,32,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--color-cream);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  backdrop-filter: blur(4px);
  transition: transform 0.1s ease, background 0.1s ease;
}
.touch-btn span { font-size: 9px; letter-spacing: 1px; font-weight: 700; }
.touch-btn.primary {
  background: linear-gradient(180deg, var(--color-ember-light), var(--color-ember));
  color: #291608;
  border: none;
  width: 76px;
  height: 76px;
}
.touch-btn:active { transform: scale(0.9); }

/* ==========================================================================
   Responsive tweaks
   ========================================================================== */

@media (min-width: 900px) {
  #touch-controls { display: none !important; }
}

@media (max-width: 480px) {
  .menu-panel { padding: 26px 20px 20px; border-radius: 18px; }
  .final-score { font-size: 44px; }
  .hud-score-value { font-size: 20px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .menu-panel { padding: 16px 22px; gap: 8px; max-height: 94vh; }
  .lantern-icon { width: 36px; height: 36px; }
  .game-title { font-size: 22px; }
  .howto-list { gap: 8px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .lantern-icon, #tutorial-hint, .overlay, .menu-panel { animation: none !important; }
}
