:root {
    --panel-grad-top: #8e24aa;
    --panel-grad-bot: #4a148c;
    --accent: #ec407a;
    --accent-2: #43a047;
    --pill-bg: rgba(255, 255, 255, 0.18);
    --glass: rgba(255, 255, 255, 0.12);
    --glass-strong: rgba(255, 255, 255, 0.22);
    --text: #ffffff;
  }
  
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  
  body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    color: var(--text);
    background: radial-gradient(1200px 900px at 10% 10%, #b3e5fc 0%, #e0f7fa 35%, #b3e5fc 100%);
    display: grid;
    place-items: center;
    overflow: hidden;
  }
  
  #container {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    padding: max(2vh, env(safe-area-inset-top)) 2vw 2vh;
  }
  
  /* Panels */
  .panel {
    background: linear-gradient(180deg, var(--panel-grad-top), var(--panel-grad-bot));
    width: min(92vw, 640px);
    border-radius: 24px;
    padding: 14px 14px 16px;
    box-shadow:
      0 24px 60px rgba(0,0,0,0.35),
      inset 0 1px 0 rgba(255,255,255,0.15);
    display: grid;
    gap: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    position: relative;
  }
  
  #menu h1 {
    margin: 6px 0 12px;
    font-size: clamp(24px, 3.8vw, 32px);
    letter-spacing: 0.5px;
    text-shadow: 0 1px 0 rgba(0,0,0,0.25);
  }
  
  button {
    appearance: none;
    border: 0;
    outline: 0;
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
    font-size: 1rem;
    padding: 10px 14px;
    border-radius: 14px;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.06)) padding-box,
      linear-gradient(180deg, rgba(255,255,255,0.4), rgba(255,255,255,0)) border-box;
    border: 1px solid transparent;
    box-shadow: 0 10px 24px rgba(0,0,0,0.25);
    transition: transform .15s ease, box-shadow .2s ease, filter .2s ease;
  }
  
  button:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(0,0,0,0.3); filter: brightness(1.03); }
  button:active { transform: translateY(0); box-shadow: 0 10px 20px rgba(0,0,0,0.26); }
  
  /* Stage */
  #stage {
    width: 100%;
    display: grid;
    place-items: center;
    padding: 8px;
    border-radius: 18px;
    background: var(--glass);
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    position: relative;
  }
  
  #canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 18px;
    background: #ffffff;
    box-shadow:
      0 16px 40px rgba(0,0,0,0.25),
      inset 0 1px 0 rgba(0,0,0,0.06);
    transition: box-shadow .3s ease;
    position: relative;
    z-index: 1; /* below overlays */
  }
  
  #canvas:hover {
    box-shadow:
      0 20px 50px rgba(0,0,0,0.28),
      inset 0 1px 0 rgba(0,0,0,0.06);
  }
  
  /* HUD overlay */
  #hud.overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: grid;
    gap: 8px;
    pointer-events: none;
    z-index: 3; /* above canvas */
  }
  
  .hud-metrics {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
  }
  
  .pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--pill-bg);
    font-weight: 700;
    letter-spacing: .2px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.18);
    text-shadow: 0 1px 0 rgba(0,0,0,0.18);
    font-size: .9rem;
  }
  
  .hud-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    pointer-events: auto; /* buttons clickable */
  }
  
  #pause { background: linear-gradient(180deg, #43a047, #2e7d32); }
  #hint { background: linear-gradient(180deg, #0288d1, #0277bd); }
  #extend { background: linear-gradient(180deg, #ef5350, #d32f2f); }
  
  /* Modals */
  .modal {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0,0,0,0.45);
    border-radius: 18px;
    z-index: 10;
  }
  
  .modal-card {
    width: min(86%, 420px);
    background: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0.1));
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 18px;
    padding: 18px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 24px 60px rgba(0,0,0,0.35);
    text-align: center;
  }
  
  .modal-card h2 { margin: 4px 0 6px; }
  .modal-card p.muted { opacity: 0.8; font-size: .95rem; margin-top: 8px; }
  
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 12px;
  }
  
  .modal-actions #watchAdReplay { background: linear-gradient(180deg, #ffb300, #f57c00); color: #111; font-weight: 800; }
  .modal-actions #plainReplay { background: linear-gradient(180deg, #4caf50, #2e7d32); }
  .modal-actions #backToMenu { background: linear-gradient(180deg, #9e9e9e, #616161); }
  
  .progress {
    height: 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.2);
    overflow: hidden;
    margin-top: 8px;
  }
  .bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ffeb3b, #ff9800);
  }
  
  /* Utils */
  .hidden { display: none !important; }
  audio { display: none; }
  
  /* Rotate overlay */
  #rotateOverlay {
    position: fixed;
    inset: 0;
    background: rgba(10,10,10,0.7);
    display: grid;
    place-items: center;
    z-index: 20;
  }
  
  .rotate-card {
    background: var(--glass-strong);
    padding: 18px 22px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.2);
    text-align: center;
    box-shadow: 0 18px 40px rgba(0,0,0,0.35);
  }
  
  .rotate-card .phone {
    width: 28px;
    height: 44px;
    margin: 0 auto 8px;
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 6px;
    position: relative;
    animation: tilt 1.6s ease-in-out infinite;
  }
  
  .rotate-card .text { font-weight: 700; letter-spacing: .3px; }
  @keyframes tilt { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(90deg); } }
  
  @media (max-width: 380px) {
    .panel { width: 94vw; }
  }
  