/* style.css */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

:root{
  --card-w: clamp(240px, 32vw, 400px);
  --card-ratio: 7 / 10;
  --lane-gap: 27px;
  --meta-h: 44px;             /* space reserved above each card for symmetry */
}

body {
  background: url('../images/bck_img.png') no-repeat center center fixed;
  background-size: cover;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  color: #f0f0f0;
}
/* Safety: ensure something always paints immediately */
html, body { opacity: 1 !important; visibility: visible !important; }

/* If you animate fades, never start at 0 exactly */
@keyframes fadeInSafe { from { opacity: 0.01; } to { opacity: 1; } }

/* ========= Container & Title ========= */
.game-container {
  background: rgba(0,0,0,0.7);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  width: 100%;
  max-width: 1250px;          /* widened */
  padding: 30px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.game-title {
  font-size: 2.8rem;
  margin-bottom: 20px;
  color: #ffcc00;
  text-shadow: 0 0 10px rgba(255,204,0,.7);
  letter-spacing: 2px;
}

/* ========= Round / Score Rail ========= */
.stats-rail{
  display:flex;
  align-items:stretch;
  justify-content:center;
  gap:16px;
  padding:12px 16px;
  background:rgba(30,30,50,.8);
  border:2px solid #444;
  border-radius:15px;
  box-shadow:0 4px 8px rgba(0,0,0,.4);
  width:max-content;
  margin:0 auto;
  z-index:1;
}
.stats-rail .stat-box{ min-width:160px; max-width:240px; }
.stat-title{ font-size:.95rem; color:#aaa; }
.stat-value{ font-size:1.6rem; color:#ffcc00; font-weight:700; }

/* ========= ARENA: Player vs Monster ========= */
.arena{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--lane-gap);
  align-items:start;           /* top-align both columns */
  justify-items:center;        /* center contents within each column */
  margin:18px 0 10px;
}
.side{ display:flex; flex-direction:column; gap:14px; align-items:center; }

/* Card frames (player + monster) */
.card-frame{
  width: var(--card-w);
  aspect-ratio: var(--card-ratio); /* trading-card look */
  border:3px solid #ffcc00;
  border-radius:12px;
  background: rgba(0,0,0,.25);
  box-shadow:0 8px 16px rgba(0,0,0,.45);
  position:relative;
  overflow:hidden;
  perspective:1000px;
}

/* Player image fills left frame — SYMMETRICAL */
#player-portrait{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:cover;          /* was contain — fill like monster card */
  object-position:center;
  display:block;
  border-radius:inherit;     /* match frame radius */
}

/* Monster card fills right frame */
.monster-display{
  /* IMPORTANT: do NOT override sizing of .card-frame here */
  position: relative;
  margin:0;
}
.monster-card{
  position:absolute; inset:0;
  background-size:contain;
  background-repeat:no-repeat;
  background-position:center bottom; /* anchor feet near bottom */
  border-radius:inherit;             /* match frame radius (was 10px) */
  box-shadow:0 8px 16px rgba(0,0,0,.5);
  transform-style:preserve-3d;
  transition: transform .5s ease, box-shadow .3s ease;
}
.monster-card:hover{ transform: translateY(-10px) rotateY(5deg); box-shadow:0 12px 24px rgba(255,204,0,.4); }

/* Titles above monster; reserve same space on player side for symmetry */
.monster-meta{
  min-height: var(--meta-h);
  display:flex; align-items:center; justify-content:center;
  text-align:center; margin-bottom:6px;
}
.player-side::before{
  content:""; display:block; height: var(--meta-h); margin-bottom:6px;
}

.monster-name{ font-size:1.8rem; font-weight:bold; color:#ff6b6b; text-shadow:0 0 8px rgba(255,107,107,.7); }
.monster-level{ font-size:1.1rem; color:#4ecdc4; }

/* ========= Health Bars (under each card) ========= */
.health-container{ width: var(--card-w); max-width:none; margin:0; }
.health-bar{
  height:30px; background:#333; border-radius:15px;
  overflow:hidden; margin:10px 0; position:relative; border:2px solid #555;
}
.health-fill{ height:100%; border-radius:15px; transition: width .5s ease; }
#player-health{ background: linear-gradient(to right, #4CAF50, #8BC34A); }
#monster-health{ background: linear-gradient(to right, #F44336, #FF9800); }
.health-label{ display:flex; justify-content:space-between; font-size:.9rem; margin-top:5px; }

/* ========= Controls & Buttons ========= */
.controls{ display:flex; justify-content:center; gap:15px; margin:20px 0 25px; }
.control-btn{
  padding:12px 25px; font-size:1.1rem; font-weight:bold; border:none; border-radius:50px; cursor:pointer; transition: all .3s ease;
  background: linear-gradient(to right, #3498db, #2980b9); color:#fff; box-shadow:0 4px 8px rgba(0,0,0,.3);
}
.control-btn:hover{ transform: translateY(-3px); box-shadow:0 6px 12px rgba(0,0,0,.4); }
.control-btn:active{ transform: translateY(1px); }
#start-btn{ background: linear-gradient(to right, #2ecc71, #27ae60); }
#redo-btn{  background: linear-gradient(to right, #f39c12, #d35400); }

.game-buttons{
  display:grid; grid-template-columns: repeat(2, 1fr);
  gap:20px; margin:0 auto 25px; max-width:500px;
}
.game-button{
  height:100px; border:none; border-radius:15px; cursor:pointer; font-size:1.3rem; font-weight:bold;
  display:flex; flex-direction:column; justify-content:center; align-items:center; transition: all .2s ease;
  box-shadow:0 6px 12px rgba(0,0,0,.3); position:relative; overflow:hidden;
}
/* Static highlight using each button's --glow */
.game-button.cue{
  box-shadow: 0 0 22px var(--glow);
  transform: scale(1.03);
}

/* Gold highlight specifically for the second-in-a-row cue */
.game-button.cue-gold{
  box-shadow:
    0 0 24px rgba(241,196,15,.95),
    0 0 8px rgba(241,196,15,.6) inset;
  transform: scale(1.03);
}

.game-button:hover{ transform: translateY(-5px); box-shadow:0 8px 16px rgba(0,0,0,.4); }
.game-button:active{ transform: translateY(2px); }
.game-button.active{ transform: scale(.95); box-shadow:0 0 20px rgba(255,255,255,.8); }
.button-icon{ font-size:2.5rem; margin-bottom:10px; }
#archer{  background: linear-gradient(to bottom right, #8e44ad, #9b59b6); }
#mage{    background: linear-gradient(to bottom right, #3498db, #2980b9); }
#warrior{ background: linear-gradient(to bottom right, #e74c3c, #c0392b); }
#healer{  background: linear-gradient(to bottom right, #2ecc71, #27ae60); }
/* === Top-right action icons === */
.top-actions{
  position: fixed; top: 16px; right: 16px;
  display: flex; gap: 10px; z-index: 1200;
}
.icon-btn{
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.6); border: 2px solid #ffcc00; color: #ffcc00;
  cursor: pointer; transition: transform .15s ease, background .15s ease;
}
.icon-btn:hover{ transform: translateY(-2px); background: rgba(0,0,0,0.75); }
.icon-btn i{ font-size: 18px; }

/* Music "off" slash overlay */
#music-toggle{ position: relative; overflow: hidden; }
#music-toggle .slash{
  display: none; position: absolute; width: 2px; height: 140%;
  background: #ffcc00; top: -20%; left: 50%; transform: rotate(45deg);
}
#music-toggle.off .slash{ display: block; }
/* Reserve space for portraits/monster */
#player-portrait, #monster-portrait {
  width: 100%;
  aspect-ratio: 7 / 10;   /* match your card ratio */
  object-fit: cover;
  display: block;
}

/* Ensure stat bars and headers don’t resize on first paint */
.stats-bar, .meta-row, .level-round-score {
  min-height: 44px; /* matches your --meta-h if you use it */
}

/* Prevent large reflows while sections render */
.game-container {
  content-visibility: auto;
}

/* Make How-to overlay instead of pushing layout (optional but smoothest) */
.howto-panel.is-modal {
  position: fixed; inset: 0; 
  display: none; /* or flex when visible */
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.6);
  z-index: 9999;
}
.howto-panel.is-modal .box {
  max-width: 640px; width: calc(100% - 40px);
  background: #111; border: 2px solid #ffcc00; border-radius: 12px; padding: 20px;
}

/* Small screens: keep icons reachable */
@media (max-width: 480px){
  .top-actions{ top: 10px; right: 10px; }
  .icon-btn{ width: 40px; height: 40px; }
}

.key-hint{
  position:absolute; bottom:8px; right:8px;
  background: rgba(0,0,0,.4); border-radius:50%; width:25px; height:25px;
  display:flex; justify-content:center; align-items:center; font-size:.9rem;
}

/* ========= Feedback ========= */
#feedback{
  min-height:60px; font-size:1.4rem; font-weight:bold; padding:15px; border-radius:12px;
  background: rgba(0,0,0,.4); margin:20px auto; max-width:800px; display:flex; align-items:center; justify-content:center; border:2px solid #444;
}

/* ========= Side Instructions ========= */
.instructions-side{
  position: fixed;
  top: 100px;
  right: 20px;
  width: 280px;
  background: rgba(40,40,60,.85);
  padding: 20px;
  border-radius: 15px;
  font-size: 1rem;
  line-height: 1.7;
  text-align: left;
  z-index: 500;
}
.instructions-side h3{ color:#ffcc00; margin-bottom:10px; }
.instructions ul{ padding-left:20px; margin-bottom:15px; }

/* ========= Level + Mode Circle ========= */
.level-indicator{
  position:absolute; top:20px; right:20px;
  width:110px; height:110px; border-radius:50%;
  background: rgba(255,204,0,.18);
  border:2px solid #ffcc00;
  box-shadow: 0 4px 10px rgba(0,0,0,.35);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:2px; text-align:center; padding:6px 4px; z-index:2;
}
.level-indicator .label{ font-size:.65rem; color:#aaa; letter-spacing:.06em; line-height:1; }
.level-indicator .value{ font-size:2rem; font-weight:800; color:#ffcc00; line-height:1.05; }
.level-indicator .mode-label{ font-size:.6rem; color:#aaa; letter-spacing:.06em; margin-top:2px; line-height:1; }
.level-indicator .mode{ font-size:.9rem; font-weight:700; color:#ffcc00; line-height:1.05; }

/* ========= Animations ========= */
@keyframes cardAppear { 0% { transform: scale(2) rotateY(90deg); opacity:0; } 100% { transform: scale(1) rotateY(0); opacity:1; } }
.monster-card.appear{ animation: cardAppear .8s ease-out forwards; }

@keyframes cardDefeat { 0% { transform: translateY(0) rotate(0); opacity:1; } 100% { transform: translateY(-100px) rotate(-30deg); opacity:0; } }
.monster-card.defeat{ animation: cardDefeat 1s ease-in forwards; }

/* ========= Story Modal ========= */
#story-modal{
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; justify-content: center; align-items: center; z-index: 1000;
}
#story-modal.hidden{ display:none; }
.story-card{
  background:#222; padding:20px; border-radius:12px;
  max-width:640px; width:92%; text-align:center; color:#fff; border:3px solid #ffcc00;
}
#story-image{ width:100%; max-height:340px; object-fit:contain; border-radius:10px; margin-bottom:16px; }
#story-text{ margin-bottom:20px; line-height:1.5; }
#story-buttons{ display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
#story-buttons button{
  padding:10px 20px; background: linear-gradient(to right, #2ecc71, #27ae60);
  border:none; border-radius:8px; color:#fff; cursor:pointer; font-size:1rem; transition:.3s;
}
#story-buttons button:hover{ background: linear-gradient(to right, #27ae60, #2ecc71); }

/* ========= Contact Button ========= */
.contact-btn{
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #ffcc00, #d4a017);
  color: #000;
  padding: 12px 18px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0,0,0,.4);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all .3s ease;
  z-index: 1001;
}
.contact-btn i{ font-size:1.2rem; }
.contact-btn:hover{ transform: translateY(-3px); box-shadow:0 6px 12px rgba(0,0,0,.5); }
.notfound-image img {
  max-width: 280px;
  border-radius: 12px;
  box-shadow: 0 6px 14px rgba(0,0,0,.6);
}
/* --- Inline notice (index) --- */
.notice-pop {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  background: #1e1e1e;
  color: #fff;
  border: 2px solid #ffcc00;
  border-radius: 10px;
  padding: 12px 16px;
  z-index: 3000;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
  font-weight: 600;
}
.notice-pop.fade-out {
  opacity: 0;
  transition: opacity .35s ease;
}

/* ========= Responsive ========= */
@media (max-width: 1024px){
  /* Avoid overlap on tablets */
  .instructions-side{ position: static; width:auto; margin-top:16px; }
}

@media (max-width: 900px){
  .arena{ grid-template-columns: 1fr; gap:20px; }
  .health-container{ width: 100%; }
  .card-frame{ width: 100%; }
}
@media (max-width: 850px){
  /* The main wrapper should be nearly full width */
  .game-container{
    max-width: none !important;
    width: min(96vw, 1250px) !important;   /* much wider than before */
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
  }

  /* Stack to avoid side-by-side squish */
  .arena{
    grid-template-columns: 1fr !important;
    justify-items: center;
  }

  /* (Will be overridden by targeted breakpoints below when applicable) */
  :root{ --card-w: min(92vw, 560px); }

  .card-frame{
    width: var(--card-w) !important;
    aspect-ratio: 7 / 10;
  }

  .health-container{
    width: var(--card-w) !important;
  }

  .stats-rail{
    width: 100% !important;
    justify-content: space-around;
  }

  .game-buttons{
    grid-template-columns: repeat(2, minmax(0,1fr)) !important;
    max-width: none !important;
    width: var(--card-w);
    margin-left: auto;
    margin-right: auto;
  }
}
@media (max-width: 600px){
  .game-title{ font-size:2rem; }
  .game-buttons{ grid-template-columns:1fr; }
  .level-indicator{
    top:12px; right:12px; width:90px; height:90px; padding:4px 3px; gap:1px;
  }
  .level-indicator .value{ font-size:1.6rem; }
  .level-indicator .mode{ font-size:.8rem; }
}
/* ===========================
   RESPONSIVE FIXES YOU ASKED FOR
   =========================== */

/* --- Phone-tight rules (≤350px width) --- */
@media (max-width: 450px){
  .game-container{
    width: 92vw !important;
    max-width: none !important;
  }

  :root{ --mobile-card: 80vw; }

  .arena .card-frame{
    width: var(--mobile-card) !important;
    height: var(--mobile-card) !important;
    max-width: none !important;
    aspect-ratio: 1 / 1;
    margin-inline: auto;
  }

  .monster-display .monster-card{
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
  }

  .health-container{ margin-top: 10px; }
  .health-label{ font-size: 14px; }
  .health-bar{ height: 12px; border-radius: 12px; }

  .game-buttons{ grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .controls{ gap: 10px; }
  .control-btn{ width: 100%; }
}
/* ===============================
   iPhone SE / very small phones fix
   =============================== */

@media (max-width: 420px){
  .game-container{
    box-sizing: border-box;
    max-width: none !important;
    width: calc(100vw - 16px) !important;
    margin-inline: auto;
    padding-left: 14px;
    padding-right: 14px;
  }

  .instructions-side{ display:none !important; }

  .level-indicator{
    position: static !important;
    width: 78px; height: 78px;
    margin: 6px auto 12px;
  }
  .level-indicator .value{ font-size: 1.4rem; }
  .level-indicator .mode{ font-size: .75rem; }

  :root{ --card-w: min(92vw, 320px); }
  .arena{
    grid-template-columns: 1fr !important;
    gap: 14px;
    justify-items: center;
  }
  .card-frame{
    width: var(--card-w) !important;
    aspect-ratio: 4 / 5;
    height: auto !important;
  }
  .health-container{ width: var(--card-w) !important; }
  .health-bar{ height: 12px; border-radius: 12px; }
  .health-label{ font-size: 14px; }

  .stats-rail{
    width: var(--card-w) !important;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
  }
  .stats-rail .stat-box{ min-width: 0; max-width: none; }
  .stat-title{ font-size: .85rem; }
  .stat-value{ font-size: 1.2rem; }

  .controls{
    display: grid;
    grid-auto-flow: row;
    gap: 10px;
    width: var(--card-w);
    margin: 14px auto;
  }
  .control-btn{ width: 100%; padding: 10px 12px; font-size: 1rem; }

  .game-buttons{
    width: var(--card-w);
    grid-template-columns: 1fr;
    gap: 10px;
    margin-left: auto; margin-right: auto;
  }
  .game-button{ height: 84px; font-size: 1.05rem; }
  .button-icon{ font-size: 2rem; }

  #feedback{
    max-width: none;
    width: var(--card-w);
    font-size: 1rem;
    padding: 10px;
    margin: 12px auto;
  }

  html, body{ overflow-x: hidden; }
}

/* Optional: if height is short too (e.g. SE in landscape), tighten more */
@media (max-width: 360px) and (max-height: 640px){
  :root{ --card-w: min(88vw, 300px); }
  .card-frame{ aspect-ratio: 3.9 / 5; }
  .game-button{ height: 76px; }
  .health-bar{ height: 10px; }
}
/* Invisible to sighted users, visible to SRs */
.sr-only {
  position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden;
  clip:rect(0 0 0 0); white-space:nowrap; border:0;
}

/* Reduced motion: damp animations/transitions */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* Ensure the game fits on small screens without scrolling */
.game-container {
  width: min(100%, 1100px);
  margin: 12px auto;
  padding: clamp(12px, 2.5vw, 24px);
}

/* Buttons: minimum touch target */
.game-button, .control-btn, button {
  min-width: 44px;
  min-height: 44px;
}

/* Tighten grid on very small screens */
@media (max-width: 480px) {
  .game-container { width: 85vw; }
  .game-buttons   { gap: 12px; }
  .controls      { gap: 10px; flex-wrap: wrap; }
}

/* Phone portrait up to 800px */
@media (max-width: 800px) {
  .status-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .monster-card, .player-card {
    max-height: 42vh; /* keep both cards on screen with controls */
  }
  .howto-side { display: none; } /* keep modal for small screens */
}

/* Tablets 768–1024 */
@media (min-width: 768px) and (max-width: 1024px) {
  .game-buttons { max-width: 520px; margin-inline: auto; }
}

/* Desktop & up */
@media (min-width: 1025px) {
  .layout {
    display: grid;
    grid-template-columns: 1fr minmax(640px, 760px) 1fr; /* center game lane */
    gap: 20px;
    align-items: start;
  }
  .howto-side { display: block; position: sticky; top: 12px; }
}

/* ==========================================
   TARGETED CARD-SIZE OVERRIDES (final wins)
   Ensures .monster-card.appear matches portrait
   at your exact breakpoints.
   ========================================== */

/* 1600×992 (large laptop-ish) */
@media (min-width: 1400px){
  :root{ --card-w: min(28vw, 420px); }
}

/* 1280×802 (standard laptop range) */
@media (max-width: 1399.98px) and (min-width: 1025px){
  :root{ --card-w: min(32vw, 380px); }
}

/* 768×1024 (tablet portrait) */
@media (max-width: 1024px){
  :root{ --card-w: min(60vw, 360px); }
}

/* 320×480 (small mobile) */
@media (max-width: 480px){
  :root{ --card-w: 85vw; } /* both frames = 85% viewport width */
}
