:root{
  /* layout + scaling */
  --footer-h: 28px;           /* updated by JS */
  --overlay-lift: -4vh;       /* updated by JS for short screens */

  /* card sizing */
  --card-wvw: 98vw;
  --card-max-w: 1280px;

  /* image sizing (tablet/desktop defaults) */
  --img-max-w-vw: 30vw;
  --img-max-w-px: 420px;
  --img-max-h: 72vh;

  /* transparency controls */
  --card-rgb: 255,255,255;    /* 255,255,255 = light glass | 0,0,0 = dark glass */
  --card-alpha: 0.5;         /* 0 = transparent, 0.5 = medium, 0.9 = solid */
  --card-blur: 6px;           /* set 0px to remove blur */
}

*{ box-sizing:border-box; }
html,body{
  margin:0; padding:0; height:100%;
  overflow:hidden; background:#000; color:#000;
  -webkit-tap-highlight-color:transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
}

/* Fullscreen container */
#video-container{
  position:fixed; inset:0;
  width:100vw; height:100dvh; height:100svh; min-height:100vh;
}

/* Camera feed */
#qr-reader, #qr-reader video{
  position:absolute; inset:0; width:100%; height:100%;
  object-fit:cover; z-index:1; background:#000;
}

/* Slide overlay wrapper (deprecated - using story container now) */
#info-overlay{
  display: none !important;
}

/* Card */
.info-content{
  width:min(var(--card-wvw), var(--card-max-w));
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:min(5vw, 36px);
  padding:clamp(12px, 3.2vw, 24px);
  border-radius:20px;
  background: rgba(var(--card-rgb), var(--card-alpha));
  backdrop-filter: blur(var(--card-blur)) saturate(1.05);
  border:none;
  box-shadow:0 10px 28px rgba(0,0,0,.25);
}

.info-text{
  flex:1 1 72%;
  min-width:0;
  color:#111;
}
.info-image{
  flex:0 0 28%;
  display:flex; justify-content:center; align-items:flex-start;
}
.info-image img{
  width:auto; height:auto;
  max-width:min(var(--img-max-w-vw), var(--img-max-w-px));
  max-height:var(--img-max-h);
  border-radius:12px;
  box-shadow:0 8px 24px rgba(0,0,0,.25);
  object-fit:cover;
}

/* Plain black text (no outlines) */
.outlined{
  color:#111 !important;
  -webkit-text-stroke: 0 !important;
  text-shadow:none !important;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
  -webkit-hyphens: none;
  letter-spacing:.01em;
}
.outlined.h1{ -webkit-text-stroke: 0 !important; }

/* Base type */
#slide-title{
  margin:0 0 .55rem 0;
  font-weight:900;
  font-size: clamp(1.45rem, 4vw, 3.2rem);
  line-height:1.16;
  text-wrap: balance;
}
.info-text p{
  margin:.55rem 0;
  font-weight:800;
  font-size: clamp(1.05rem, 1.8vw, 1.6rem);
  line-height:1.44;
}
.info-text .label{
  text-transform:uppercase;
  font-weight:900;
}

/* ---------- Tablet up ---------- */
@media (min-width: 768px){
  .info-content{
    padding:clamp(16px, 2.6vw, 28px);
    gap:min(4vw, 40px);
    --card-max-w: 1400px;
  }
}

/* ---------- Desktop/Laptop ---------- */
@media (min-width: 1200px){
  .info-text{ flex:1 1 74%; }
  .info-image{ flex:0 0 26%; }
  .info-image img{ max-width:min(26vw, 440px); max-height:74vh; }
  .info-content{ --card-max-w: 1500px; gap:min(3.6vw, 44px); }
}

/* ---------- PHONE FIXES: fit above footer & avoid overlap ---------- */
@media (max-width: 600px){
  /* put card near the top so full content fits */
  #info-overlay{
    align-items:flex-start;
    padding-top: calc(env(safe-area-inset-top) + 10px);
  }

  /* stack content; image below text to save vertical space */
  .info-content{
    width:96vw;
    max-height: calc(100dvh - var(--footer-h) - env(safe-area-inset-bottom) - 22px);
    overflow:hidden; /* no internal scroll; everything sized to fit */
    flex-direction: column;
    gap:10px;
    border-radius:16px;
  }
  .info-text{ flex:0 0 auto; }
  .info-image{ flex:0 0 auto; }
  .info-image img{
    max-width: 100%;
    max-height: 26vh;   /* small, so text has room */
  }

  /* compact, readable type */
  #slide-title{
    font-size: 1.35rem;
    line-height:1.18;
    margin-bottom:.4rem;
  }
  .info-text p{
    font-size: 0.98rem;
    line-height:1.35;
    margin:.4rem 0;
  }
}

/* Error banner */
#scan-result{
  position:absolute; top: env(safe-area-inset-top, 8px); left:50%;
  transform:translateX(-50%);
  padding:.5rem .75rem;
  background:rgba(255,210,210,.95); color:#D8000C;
  border-radius:10px; font-weight:700; z-index:6;
}
.hidden{ display:none !important; }

/* Loader */
#loader{
  position:absolute; top:50%; left:50%;
  width:56px; height:56px;
  border:5px solid rgba(255,255,255,.35); border-top:5px solid #E4572E;
  border-radius:50%; transform:translate(-50%,-50%);
  animation:spin 1s linear infinite; z-index:7;
}
@keyframes spin{ 100%{ transform:translate(-50%,-50%) rotate(360deg); } }

/* Start overlay (logo and button) */
#start-logo{
  position:absolute; left:50%; top:38%;
  transform:translate(-50%,-50%);
  width:min(240px, 50vw); max-height:20vh;
  z-index:8; user-select:none; pointer-events:none;
}
.primary{
  position:absolute; left:50%; top:66%;
  transform:translateX(-50%);
  border:0; border-radius:14px; padding:1rem 1.25rem;
  background:rgba(0,0,0,.55); color:#fff;
  font-weight:800; font-size:1.1rem; letter-spacing:.3px;
  z-index:8; cursor:pointer; backdrop-filter: blur(4px);
}
.primary:active{ transform:translateX(-50%) scale(.98); }

/* Footer */
.footer{
  position:fixed; bottom:max(6px, env(safe-area-inset-bottom));
  left:0; right:0; text-align:center; z-index:2;
  font-weight:600; color:#ffffff; line-height:1; font-size:.92rem;
  padding:.25rem 0;
}
.footer a{ color:inherit; text-decoration:underline; }
/* --- MOBILE: push the card lower; avoid overlap with the top UI --- */
:root{
  --mobile-top-gap: 32px; /* tweak this: bigger = farther down */
}

@media (max-width: 600px){
  #info-overlay{
    align-items: flex-start;
    transform: none !important; /* cancel the negative lift from desktop */
    padding-top: calc(env(safe-area-inset-top) + var(--mobile-top-gap));
    padding-bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 10px);
  }

  /* keep the card tight, no extra top margin needed */
  .info-content{
    margin-top: 0;
  }
}

/* ---------- Avatar Container ---------- */
#avatar-container {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 10px);
  left: 10px;
  width: 140px;
  height: 180px;
  z-index: 10;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

#avatar-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#avatar-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
}

/* Tablet and up: larger avatar */
@media (min-width: 768px) {
  #avatar-container {
    width: 180px;
    height: 220px;
    bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 16px);
    left: 16px;
  }
}

/* Desktop: even larger */
@media (min-width: 1200px) {
  #avatar-container {
    width: 220px;
    height: 280px;
    bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 20px);
    left: 24px;
  }
}

/* ---------- Ask Question Button ---------- */
.ask-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #ff4521 0%, #d42f10 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 4px 15px rgba(255, 69, 33, 0.4);
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ask-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 69, 33, 0.5);
}

.ask-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(255, 69, 33, 0.4);
}

.ask-btn:disabled {
  background: linear-gradient(135deg, #a0a0a0 0%, #808080 100%);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Listening state animation */
.ask-btn:disabled {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Phone adjustments */
@media (max-width: 600px) {
  .ask-btn {
    padding: 10px 16px;
    font-size: 0.9rem;
    margin-top: 8px;
  }
}

/* ---------- Story Container (Main Content Display) ---------- */
#story-container {
  position: fixed;
  top: 3%;
  right: 3%;
  bottom: auto;
  transform: none;
  z-index: 15;
  pointer-events: auto;
  animation: storyFadeIn 0.5s ease-out;
}

@keyframes storyFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------- EDGE Group brand theme ---------- */
:root {
  --edge-orange: #ff4521;
  --edge-orange-dark: #d42f10;
  --edge-charcoal: #1c1f24;
  --edge-charcoal-2: #2a2e35;
  --edge-ink: #1c1f24;
}

.story-frame {
  position: relative;
  width: min(42vw, 480px);
  background: linear-gradient(160deg, #25292f 0%, #1c1f24 100%);
  border-radius: 16px;
  padding: 6px;
  box-shadow:
    0 14px 44px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.story-frame::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 11px;
  pointer-events: none;
}

/* EDGE accent bar (the signature orange block) */
.story-frame::after {
  content: '';
  position: absolute;
  top: 0;
  left: 24px;
  width: 64px;
  height: 5px;
  background: var(--edge-orange);
  border-radius: 0 0 4px 4px;
  pointer-events: none;
}

.story-header {
  position: relative;
  z-index: 2;
  background: linear-gradient(135deg, var(--edge-orange) 0%, var(--edge-orange-dark) 100%);
  color: #fff;
  text-align: center;
  padding: 14px 24px;
  margin: 18px 18px 14px 18px;
  border-radius: 8px;
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  box-shadow:
    0 6px 18px rgba(255, 69, 33, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.story-content {
  position: relative;
  z-index: 2;
  padding: 20px 26px 24px 26px;
  margin: 0 10px 12px 10px;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-left: 4px solid var(--edge-orange);
  max-height: 50vh;
  overflow-y: auto;
}

#story-text {
  color: var(--edge-ink);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.7;
  text-align: left;
}

#story-text p {
  margin: 0 0 12px 0;
}

#story-text p:last-child {
  margin-bottom: 0;
}

#story-text strong {
  color: var(--edge-orange-dark);
}

#story-text .label {
  color: var(--edge-orange-dark);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.95rem;
}

/* Ask button inside story frame */
.story-frame .ask-btn {
  position: relative;
  z-index: 2;
  display: block;
  margin: 0 20px 16px 20px;
  width: calc(100% - 40px);
}

/* ---------- Slide Image Container ---------- */
#slide-image-container {
  position: fixed;
  top: 3%;
  left: 10px;
  right: auto;
  bottom: auto;
  transform: none;
  z-index: 14;
  animation: imageFadeIn 0.5s ease-out;
  padding-top: 55px; /* Space for mute button */
}

@keyframes imageFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#slide-image-container img {
  max-width: min(30vw, 320px);
  max-height: 45vh;
  border-radius: 20px;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.5),
    0 0 0 6px rgba(255, 255, 255, 0.3);
  object-fit: cover;
}

/* Desktop: larger image on left */
@media (min-width: 1200px) {
  #slide-image-container {
    top: 3%;
    left: 20px;
    bottom: auto;
  }

  #slide-image-container img {
    max-width: min(28vw, 380px);
    max-height: 42vh;
  }
}

/* ---------- Tablet Layout (768px - 1199px) ---------- */
@media (min-width: 768px) and (max-width: 1199px) {
  /* Story container on right */
  #story-container {
    top: 3%;
    right: 2%;
  }

  .story-frame {
    width: min(45vw, 420px);
  }

  /* Image on left side, at top */
  #slide-image-container {
    top: 3%;
    left: 10px;
    right: auto;
    bottom: auto;
    transform: none;
  }

  #slide-image-container img {
    max-width: min(32vw, 260px);
    max-height: 38vh;
  }

  /* Avatar smaller on tablet */
  #avatar-container {
    width: 160px;
    height: 200px;
  }
}

/* ---------- Phone Layout (under 768px) ---------- */
@media (max-width: 767px) {
  /* Avatar stays bottom-left */
  #avatar-container {
    width: 100px;
    height: 130px;
    left: 8px;
    bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 8px);
  }

  /* Story container top-right */
  #story-container {
    top: calc(env(safe-area-inset-top) + 10px);
    right: 8px;
    bottom: auto;
    left: auto;
    transform: none;
  }

  .story-frame {
    width: min(55vw, 280px);
    max-width: none;
  }

  .story-header {
    font-size: 0.9rem;
    padding: 8px 12px;
    margin: 8px 10px 6px 10px;
    letter-spacing: 1.5px;
  }

  .story-content {
    padding: 10px 12px 12px 12px;
    margin: 0 6px 6px 6px;
    max-height: 32vh;
  }

  #story-text {
    font-size: 0.8rem;
    line-height: 1.4;
  }

  .story-frame .ask-btn {
    margin: 0 10px 8px 10px;
    width: calc(100% - 20px);
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  /* Image top-left, below story container level */
  #slide-image-container {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 150px);
    left: 8px;
    right: auto;
    transform: none;
    padding-top: 42px;
  }

  #slide-image-container img {
    max-width: min(28vw, 110px);
    max-height: 15vh;
    border-radius: 10px;
  }
}

/* Extra small phones (under 600px) */
@media (max-width: 600px) {
  #avatar-container {
    width: 80px;
    height: 100px;
  }

  .story-frame {
    width: min(56vw, 240px);
  }

  .story-content {
    max-height: 26vh;
  }

  #slide-image-container {
    bottom: calc(env(safe-area-inset-bottom) + var(--footer-h) + 120px);
    padding-top: 36px;
  }

  #slide-image-container img {
    max-width: min(26vw, 100px);
    max-height: 14vh;
  }

  .story-header {
    font-size: 0.8rem;
    padding: 6px 10px;
    margin: 6px 8px 4px 8px;
  }

  #story-text {
    font-size: 0.7rem;
  }
}

/* Landscape mode (any device) */
@media (max-height: 500px) {
  #avatar-container {
    width: 70px;
    height: 90px;
  }

  .story-frame {
    width: min(45vw, 320px);
  }

  .story-content {
    max-height: 50vh;
    padding: 8px 12px;
  }

  .story-header {
    padding: 6px 12px;
    margin: 6px 10px 4px 10px;
    font-size: 0.9rem;
  }

  /* Image on left, at top in landscape */
  #slide-image-container {
    top: 5%;
    bottom: auto;
    left: 3%;
    right: auto;
    transform: none;
    padding-top: 40px;
  }

  #slide-image-container img {
    max-width: 20vw;
    max-height: 50vh;
  }
}

/* ---------- Mute Button ---------- */
.mute-btn {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #e53935, #c62828);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(229, 57, 53, 0.5);
  transition: all 0.2s ease;
  z-index: 20;
}

.mute-btn:hover {
  transform: translateX(-50%) scale(1.1);
  box-shadow: 0 6px 20px rgba(229, 57, 53, 0.6);
}

.mute-btn:active {
  transform: translateX(-50%) scale(0.95);
}

.mute-btn svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.mute-btn.muted {
  background: linear-gradient(145deg, #757575, #616161);
  box-shadow: 0 4px 15px rgba(97, 97, 97, 0.5);
}

/* Phone mute button */
@media (max-width: 767px) {
  .mute-btn {
    width: 36px;
    height: 36px;
    top: 0;
  }

  .mute-btn svg {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 600px) {
  .mute-btn {
    width: 30px;
    height: 30px;
    top: 0;
  }

  .mute-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* ---------- Fullscreen Image Overlay ---------- */
#fullscreen-image-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  animation: fadeIn 0.3s ease-out;
}

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

#fullscreen-image-overlay img {
  max-width: 95%;
  max-height: 90vh;
  border-radius: 16px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.8);
  object-fit: contain;
}

.close-fullscreen-btn {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.close-fullscreen-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.close-fullscreen-btn svg {
  width: 28px;
  height: 28px;
  color: #fff;
}

/* Clickable image indicator */
#slide-image-container img {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#slide-image-container img:hover {
  transform: scale(1.02);
}

#slide-image-container img:active {
  transform: scale(0.98);
}
