/* style.css - Responsive + mobile-friendly updates */

/* Global & Variables */
:root {
  --primary: #10b981;
  --primary-hover: #059669;
  --secondary: #64748b;
  --panel-bg: rgba(2, 6, 23, 0.6);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text-color: #f8fafc;
  --muted: #94a3b8;
  --canvas-bg: transparent;
  --glow-color: #34d399;
  --touch-size: 56px; /* comfortable touch target default */
}
html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-color);
  /* Allow page scrolling on small screens (so overlays/footer remain reachable) */
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(135deg, #10b981, #6366f1);
  background-size: 400% 400%;
  animation: movingGradient 30s linear infinite;
}
@keyframes movingGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
h1, h2, h3 { margin: 0; color: #fff; }
ul { list-style: none; padding: 0; }
li { margin-bottom: 8px; }

/* Game Wrapper (responsive) */
.game-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 60px rgba(0, 0, 0, 0.3);
  border-radius: 16px;
  overflow: hidden;
  /* Scale to viewport but cap at 1080px */
  width: min(1080px, 96vw);
  /* Use aspect-ratio so the canvas scales properly without distortion */
  aspect-ratio: 16 / 9;
  transition: all 0.22s ease;
  margin: 28px 0;
  background: transparent;
}

/* Game area covers the wrapper */
.game-area {
  position: relative;
  width: 100%;
  height: 100%;
  background: url('assets/bg.jpg') no-repeat center center;
  background-size: cover;
  overflow: hidden;
}
.game-area::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(rgba(15, 23, 42, 0.5), rgba(15, 23, 42, 0.2));
  pointer-events: none;
  z-index: 1;
}

.game-container {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 2;
  display: block;
}

/* Canvas should fill container, dpr handled in JS */
canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* better touch behavior */
}

/* HUD */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: none;
  user-select: none;
}
.hud > * { pointer-events: auto; }
.hud-left { display:flex; align-items:center; }
.hud-right { display:flex; align-items:center; }
.hud-controls { display:flex; gap:8px; margin-left:12px; }

.hud-item {
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 500;
  font-size: 1.1em;
  border: 1px solid var(--panel-border);
  transition: all 0.2s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 10;
}
.hud-item#score.glow {
  color: var(--glow-color);
  text-shadow: 0 0 10px var(--glow-color);
}
.hud-item#score.pulse {
  animation: pulse 0.4s ease-in-out;
}
@keyframes pulse {
  0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); }
}

/* Timer Bar */
.time-bar {
  width: 120px;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 5px;
  overflow: hidden;
}
.time-bar .fill {
  height: 100%;
  width: 100%;
  transition: width 0.1s linear, background-color 0.1s linear;
  background: linear-gradient(to right, #10b981, #f97316, #ef4444);
}

/* Overlays & Modals */
.overlay, .modal {
  position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: center;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 100;
}
.overlay.hidden, .modal.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 30px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: fadeUp 0.4s ease;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.end-panel { max-width: 480px; }
@keyframes fadeUp { from { transform: translateY(20px); opacity:0 } to { transform: translateY(0); opacity:1 } }
.small-notes { margin-top:10px; color:var(--muted); font-size:0.9em; }
.overlay-actions, .modes { margin-top:24px; display:flex; flex-direction:column; gap:12px; }
.modes { flex-direction:row; justify-content:center; }

/* Buttons */
.btn {
  padding: 12px 18px;
  font-size: 1em;
  font-weight: 500;
  border: none; border-radius: 12px; cursor: pointer;
  transition: all 0.18s ease; text-decoration: none;
}
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 15px rgba(16,185,129,0.3); }
.btn.primary:hover { background: var(--primary-hover); transform: translateY(-2px); }
.btn.ghost { background: rgba(255,255,255,0.06); color: var(--text-color); border: 1px solid var(--panel-border); }
.btn.icon { background: var(--panel-bg); width:44px; height:44px; padding:0; border-radius:50%; display:flex; align-items:center; justify-content:center; }
.btn.mode { flex:1; text-align:center; }

/* Guard Popup */
.guard-popup {
  position:absolute; top:50%; left:50%; transform: translate(-50%,-50%);
  display:flex; flex-direction:column; align-items:center; z-index:50;
  pointer-events:none; opacity:0; visibility:hidden; transition:opacity .3s;
}
.guard-popup.show { opacity:1; visibility:visible; pointer-events:none; }
.guard-popup img { width:120px; height:auto; animation: popIn 0.5s cubic-bezier(0.68,-0.55,0.27,1.55); }
@keyframes popIn { from { transform: scale(0.6); opacity:0 } to { transform: scale(1); opacity:1 } }
.guard-text { background:#dc2626; color:#fff; padding:8px 16px; border-radius:12px; margin-top:-10px; font-weight:600; }

/* End Tint & Footer */
.full-tint { position:absolute; inset:0; opacity:0; pointer-events:none; transition:background-color .8s ease; z-index:20; }
.full-tint.show { opacity:1; }
.full-tint.win { background: rgba(16,185,129,0.08); }
.full-tint.lose { background: rgba(239,68,68,0.08); }

.site-footer {
  width: 100%; text-align:center; font-size:0.85em; color:var(--muted);
  user-select:none; padding:10px 0; margin-top:6px;
  background: rgba(2,6,23,0.36); backdrop-filter: blur(4px); box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.site-footer a { color: var(--muted); transition:color .2s ease; }
.site-footer a:hover { color: var(--text-color); }

/* MOBILE-CONTROLS (hidden by default; shown in media queries) */
.mobile-controls {
  display: flex; /* desktop: hidden */
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  gap: 24px;
  z-index: 40;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}
.mobile-controls .control {
  width: var(--touch-size);
  height: var(--touch-size);
  min-width: 48px;
  min-height: 48px;
  border-radius: 12px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: var(--text-color);
  font-size: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.12s ease;
  touch-action: none;
}
.mobile-controls .control:active { transform: translateY(1px) scale(0.98); }
.mobile-controls .control:focus { outline: 2px solid rgba(255,255,255,0.12); }

/* Desktop hint */
.hint.desktop-only { display: none; }

/* Media queries */
/* Tablet / small-desktop down to mobile */
@media (max-width: 1100px) {
  .game-wrapper { width: min(960px, 96vw); aspect-ratio: 16/9; }
  .hud { padding: 12px; }
}

/* Mobile layout: change aspect ratio and show mobile nav */
@media (max-width: 900px) {
  /* Use a taller aspect ratio on narrow screens so UI and footer fit better */
  .game-wrapper { width: min(96vw, 720px); aspect-ratio: 4 / 5; margin: 18px 0; border-radius: 12px; }
  .panel { max-width: 92%; padding: 18px; }
  .overlay-actions, .modes { gap: 10px; }
  .hud { padding: 10px; }
  .hud-item { padding: 8px 10px; font-size: 0.98rem; }
  .time-bar { width: 90px; }
  .btn.icon { width: 40px; height: 40px; font-size: 1rem; }
  .mobile-controls { display: flex; }
  .hint.desktop-only { display: none; }
  .site-footer { font-size: 0.82rem; padding: 8px 6px; }
}

/* Very narrow phones - compact adjustments */
@media (max-width: 420px) {
  :root { --touch-size: 48px; }
  .game-wrapper { aspect-ratio: 4 / 6; border-radius: 8px; }
  .hud-item { font-size: 0.95rem; padding: 6px 8px; }
  .mobile-controls { gap: 10px; bottom: 10px; }
}

/* Accessibility helper: reduce motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
