/* style.css */
@font-face {
    font-family: 'zabars';
    src: url('./fonts/zabars.ttf') format('truetype');
}

body {
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url('img/10_ai_images_by_tay/game_design_bg/DALLE2_2.png');
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    min-height: 100vh;
    font-family: 'zabars', Arial, Helvetica, sans-serif;
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Darken background so the canvas stays in focus */
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 0;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    /* Place container above the dark body overlay layer */
    z-index: 1;
    height: 800px;
}

h1 {
    font-size: 80px;
    letter-spacing: 3px;
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 2;
    color: #F2D4A2;
    /* Spacing between title and canvas */
    margin-bottom: 16px;
}

canvas {
    background-color: black;
    border-radius: 16px;
    display: block;
    /* Slight shadow to emphasize the canvas focus */
    box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
}

/* Stage wraps the canvas and acts as fullscreen root */
.stage{
  position: relative;
  display: inline-block;
}

/* No whitespace gap around the canvas */
.stage > canvas{ display:block; }


/* === UI-Bar (Language & Controls) – aligned with game style === */
.ui-bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  width:100%;
  max-width: 720px;          /* visually matches the canvas width */
  padding: 8px 0px;
  margin-bottom: 16px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(242,212,162,0.35);
  border-radius: 12px;
  position: relative;
  /* Keeps the bar above the dark body overlay */
  z-index: 3;
}

.ui-bar h1{
  color: #F2D4A2;
  font-size: 48px;
  letter-spacing: 2px;
  margin: 0;
}

.ui-right{
  display:flex;
  align-items:center;
  gap: 12px;
}

.btn-row{
  display:flex;
  align-items:center;
  gap: 8px;
  padding-left: 12px;
}

.ui-btn{
  background: transparent;
  color: #F2D4A2;
  border: 1px solid #F2D4A2;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: 'zabars', Arial, Helvetica, sans-serif;
  font-size: 20px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 120ms ease;
}

.ui-btn:hover{
  background: rgba(242,212,162,0.12);
}

#btn-mute{
  padding: 1px;
}

.lang-switch{
  display:flex;
  align-items:center;
  gap: 8px;
  color: #F2D4A2;
  padding-right: 12px;
  font-size: 22px;
}

.lang-label{ opacity: 0.9; }

.lang-btn{
  background: transparent;
  color: #F2D4A2;
  border: 1px solid #F2D4A2;
  padding: 4px 8px;
  border-radius: 8px;
  font-family: 'zabars', Arial, Helvetica, sans-serif;
  font-size: 22px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.lang-btn.active{
  background: #F2D4A2;
  color: #1a1a1a;
}

/* === Scroll-to-Top Button (DA-style, adapted to this theme) === */
.to-top{
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(242,212,162,0.6);
  color: #F2D4A2;
  box-shadow: 4px 4px 8px rgba(0,0,0,0.5);
  font-family: 'zabars', Arial, Helvetica, sans-serif;
  font-size: 28px;
  line-height: 1;
  /* Flexbox only used for centering the arrow */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 160ms ease, transform 160ms ease, background 120ms ease;
  /* Above body overlay (0), game container (1), UI bar (2) */
  z-index: 3;
  opacity: 0;
  transform: translateY(8px);
  /* When hidden it should not be clickable */
  pointer-events: none;
}

.to-top:hover{
  background: rgba(242,212,162,0.12);
}

.to-top.show{
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Startscreen overlay – exact positioning handled via JS (see ui-frame.js) */
.start-screen {
  position: absolute;          /* JS positions it exactly over the canvas */
  inset: 0;
  width: 100%;                /* set via JS */
  height: 100%;               /* set via JS */
  border-radius: 16px;
  box-shadow: 4px 4px 8px rgba(0,0,0,0.5);
  background-size: cover;
  background-position: center;
  display: none;              /* visibility controlled via JS */
  align-items: center;
  justify-content: center;
  /* Above mobile controls */
  z-index: 1000;
}

/* Fallback button if no "go-btn" class is injected from Game Over screen */
.game-primary-btn{
  background: #f2d5a280;
  color: #1a1a1a;
  border: 1px solid #F2D4A2;
  padding: 10px 18px;
  border-radius: 12px;
  font-family: 'zabars', Arial, Helvetica, sans-serif;
  letter-spacing: 1px;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 4px 4px 8px rgba(0,0,0,0.5);
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
  min-width: 220px;
  /* Same height as the Try-Again button */
  min-height: 56px;
}
.game-primary-btn:hover{ transform: translateY(-1px); opacity: 0.95; }

.pause-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  /* Above canvas & UI bar, below start screen (z=1000) */
  z-index: 890;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pause-overlay.hidden { display: none; }

.pause-overlay > button {
  position: relative;
  min-width: 220px;
  min-height: 56px;
  z-index: 891;
}

/***************************** Mobile / Responsive Design *********************************/

@media only screen and (max-width: 720px) {
  .to-top{
    right: 12px;
    bottom: 12px;
    width: 44px;
    height: 44px;
    font-size: 24px;
  }
}

/****************************** Header and Footer section *********************************/

:root{ --header-h:44px; --footer-h:36px; --ui-gap:12px; }

/* Single-page layout: no global scrollbars (content fits between header & footer) */
html, body { overflow:hidden; }

/* Header (fixed, compact) */
.header-bar{
  position:fixed; 
  inset:auto 0 auto 0; 
  top:0; 
  height:var(--header-h);
  display:flex; 
  align-items:center; 
  justify-content:space-between;
  padding:20px 16px; 
  background:rgba(0,0,0,0.35);
  border-bottom:1px solid rgba(242,212,162,0.35); 
  backdrop-filter: blur(4px);
  z-index:5;
}
.brand-logo{ height:88px; width:auto; display:block; cursor: pointer; }
.header-right{ display:flex; gap:16px; align-items:center }

.hdr-btn{
  border:1px solid #F2D4A2; 
  color:#F2D4A2; 
  background:transparent;
  border-radius:10px; 
  padding:12px 20px; 
  cursor:pointer;
  transition:transform .22s ease, opacity .22s ease, background .22s ease;
  font-family:'zabars', Arial, Helvetica, sans-serif;
  font-size: 22px; 
  letter-spacing:1px;
  text-decoration: none;
}
.hdr-btn:hover{ transform:translateY(-1px); opacity:.95 }
.hdr-btn.glass{ background:rgba(242,213,162,.08); backdrop-filter: blur(3px); }
.hdr-btn.cta{ padding:12px 48px; background:#068F42; color:#fff; border-color:#068F42; animation:pulse 2.8s ease-in-out infinite }
.hdr-btn.cta:hover{ background-color: #A6D82F; border-color: #A6D82F; color: #571413; }
@keyframes pulse { 0%,100%{ box-shadow:0 0 0 0 rgba(6,143,66,.35) } 50%{ box-shadow:0 0 18px 3px rgba(6,143,66,.45) } }

.icon-link img{ height:32px; width:32px; display:block }
.icon-link{ display:inline-flex; align-items:center; justify-content:center; padding:8px; border-radius:8px; transition:transform .22s, filter .22s, opacity .22s }
.icon-link:hover{ transform:translateY(-1px) scale(1.03); filter: drop-shadow(0 0 8px rgba(242,212,162,.4)) }

/* Footer (fixed, compact) */
.footer-bar{
  position:fixed; 
  inset:auto 0 0 0; 
  height:var(--footer-h);
  display:flex; 
  align-items:center; 
  justify-content:space-between;
  padding:20px 24px; 
  background:rgba(0,0,0,0.35);
  border-top:1px solid rgba(242,212,162,0.35); 
  backdrop-filter: blur(4px);
  z-index:5;
  color:#F2D4A2;
}

.foot-left,.foot-mid,.foot-right{ 
  display:flex; 
  align-items:center; 
  gap:8px; 
  font-size:22px; 
  letter-spacing: 1px; 
}

/* "Made by Taironman" middle badge */
.foot-mid{ flex:1; justify-content:center; margin-right: 96px; font-family: 'Courier New', Courier, monospace; font-size: 18px;}

.ftr-link{ 
  background:transparent; 
  border:none; 
  color:#F2D4A2; 
  cursor:pointer; 
  padding:0 2px; 
  font-family:'zabars', Arial, Helvetica, sans-serif; 
  font-size: 22px; 
  letter-spacing: 1px; 
  transition:opacity .22s 
}

.ftr-link:hover{ opacity:.85 }
.sep{ opacity:.6 }
.green-heart{ filter: drop-shadow(0 0 6px rgba(6, 143, 66, .6)) }

/* Offset for game content because of header/footer */
.game-container{ margin-top:calc(var(--header-h) + var(--ui-gap)); margin-bottom:calc(var(--footer-h) + var(--ui-gap)); }

/* Overlays (aligned to the canvas area) */
.overlay{ 
  position:fixed; 
  inset:0; 
  display:none; 
  z-index:10 
}

.overlay[hidden]{ display:none }
.overlay.show{ display:block }
.overlay-mask{ position:absolute; inset:0; background:rgba(0,0,0,.65) }

/* Position & size of the overlay-card are synced to the canvas via JS */
.overlay-card{
  position:absolute;
  width:720px; 
  height:480px; 
  border-radius:16px; 
  background:#111;
  border:1px solid rgba(242,212,162,.35); 
  color:#eaeaea; 
  box-shadow:0 10px 30px rgba(0,0,0,.6);
  display:flex; 
  flex-direction:column; 
  overflow:hidden;
}

.overlay-close{ 
  position:absolute; 
  top:8px; 
  right:10px; 
  background:transparent; 
  border:none; 
  color:#fff; 
  font-size:28px; 
  line-height:1; 
  cursor:pointer 
}

.overlay-body{ 
  font-family: 'Courier New', Courier, monospace;
  flex:1; 
  overflow:auto; 
  padding:16px;
}

.overlay h2{ 
  margin:14px 16px;
  font-family: 'Courier New', Courier, monospace; 
  font-size:20px;
}

.to-top-in{ 
  position:absolute; 
  right:12px; 
  bottom:12px; 
  width:40px; 
  height:40px; 
  border-radius:50%; 
  border:1px solid rgba(242,212,162,.6); 
  background:rgba(0,0,0,.35); 
  color:#F2D4A2; 
  cursor:pointer; 
  display:none 
}

.to-top-in.show{ display:block }

/* Custom scrollbar styling for overlay text areas */
.overlay-body{
  scrollbar-width: thin;
  scrollbar-color: #F2D4A2 #1b1b1b;
}
.overlay-body::-webkit-scrollbar { width: 10px; }
.overlay-body::-webkit-scrollbar-track { background: #1b1b1b; }
.overlay-body::-webkit-scrollbar-thumb { background: #19d16b; border-radius: 8px; }
.overlay-body::-webkit-scrollbar-thumb:hover { background: #18b85f; }

/* Keycaps in rules overlay */
.overlay-body kbd{
  display:inline-block;
  padding:2px 6px;
  border:1px solid rgba(242,212,162,.35);
  border-radius:6px;
  background:rgba(0,0,0,.35);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  line-height: 1.2;
  color:#F2D4A2;
}

/*********************************************************************************************************/

/* Mobile: hide title, make controls more compact – keep canvas as main focus */
@media only screen and (max-width: 720px) {
  .ui-bar h1{ display:none; }
  .ui-btn{ padding: 6px 8px; }
  .lang-switch{ padding-right: 0px;}
}


/* ----- Smartphones portrait ----- */
@media only screen and (max-width: 720px) {
    canvas {
        width: 100%;
    }

    h1 {
        padding-top: 32px;
        font-size: 40px;
    }

    .footer-bar{
      display: flex;
      flex-direction: column-reverse;
      gap: 8px;
    }

    .foot-left,.foot-mid,.foot-right{ 
      font-size: 16px; 
      letter-spacing: 1px;
    }

    .foot-left {
      display: none;
    }
}


/* ----- Smartphones landscape height constraints ----- */
@media only screen and (max-height: 480px) {
    canvas {
        height: 100vh;
    }

    h1 {
        font-size: 32px;
    }
}


/* Mobile landscape: hide header/footer and title, use full height for the canvas */
body.is-mobile-ui.is-landscape .header-bar,
body.is-mobile-ui.is-landscape .footer-bar,
body.is-mobile-ui.is-landscape #lbl-title {
  display: none !important;
}

/* In landscape no extra outside margins from header/footer */
body.is-mobile-ui.is-landscape .game-container{
  margin-top: var(--ui-gap);
  margin-bottom: var(--ui-gap);
}

/* Canvas size: scales with fixed aspect ratio and respects safe areas */
body.is-mobile-ui.is-landscape canvas{
  width: min(100vw - (env(safe-area-inset-left) + env(safe-area-inset-right)), 720px);
  height: inherit;
  aspect-ratio: 4 / 2.0;
  width: 100%;
}

/* Portrait: canvas fills width, height follows 3:2 ratio */
body.is-mobile-ui.is-portrait canvas{
  width: min(100vw - (env(safe-area-inset-left) + env(safe-area-inset-right)), 720px);
  height: auto;
  aspect-ratio: 3 / 2;
}

/* =========================================================
   Galaxy S9+ / 320px – PORTRAIT tuning
   Goal: start-screen + game area fully visible, nothing outside the viewport.
   Applied only to very narrow devices (≤ 360px width).
   ========================================================= */
@media only screen and (max-width: 360px) {

  :root{
    /* more compact header/footer + game-container spacing */
    --header-h: 32px;
    --footer-h: 30px;
    --ui-gap: 8px;
  }

  /* Body aligns at top for more vertical space */
  body{
    align-items: flex-start;
  }

  /* Compact header/footer */
  .header-bar{
    padding: 8px 10px;
  }

  .footer-bar{
    padding: 8px 12px;
    flex-direction: column-reverse;
    gap: 4px;
  }

  .foot-left{ 
    display:none; 
  }

  .foot-mid,
  .foot-right{
    font-size: 14px;
  }

  /* Game container height adapts to available space */
  .game-container{
    height: auto;
    margin-top: calc(var(--header-h) + var(--ui-gap));
    margin-bottom: calc(var(--footer-h) + var(--ui-gap));
    align-items: center;
  }

  /* Smaller, compact title */
  #lbl-title{
    font-size: 32px;
    margin-bottom: 8px;
    padding-top: 8px;
  }

  /* UI bar uses full width, compact padding */
  .ui-bar{
    max-width: 100%;
    padding: 6px 4px;
    margin-bottom: 8px;
  }

  .btn-row{
    gap: 4px;
    padding-left: 4px;
    flex-wrap: wrap;
  }

  .hdr-btn{
    padding:4px 8px; 
    font-size: 18px;
  }

  .brand-logo{
    height: 64px;
  }

  .ui-btn{
    padding: 4px 6px;
    font-size: 16px;
  }

  .ui-right{
    gap: 8px;
  }

  .lang-switch{
    font-size: 16px;
    gap: 4px;
    padding-right: 0;
  }

  /* Canvas: fitted to width, 3:2 aspect ratio */
  canvas{
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
  }

  /* Rules/Imprint/Privacy overlays match canvas width on small screens */
  .overlay-card{
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
  }

  .footer-bar{
    padding: 20px 12px;
  }

  .foot-right{ 
    font-size:32px;
  }

}


/* =========================================================
   Galaxy S9+ / 320px – LANDSCAPE tuning
   Goal: game area visible without cutting off pixels at the bottom.
   Applied only to very low viewports (≤ 360px height).
   ========================================================= */
@media only screen and (max-height: 360px) {

  body.is-mobile-ui.is-landscape canvas{
    /* Keep aspect ratio and ensure the canvas height stays within viewport. */
    height: auto;
    aspect-ratio: 4.2 / 2;
  }

  .stage{
    max-width: 100vw;
  }
}
