/* =========================
   Product Sans font faces
   ========================= */
@font-face {
  font-family: 'Product Sans';
  src: url('assets/fonts/ProductSans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Product Sans';
  src: url('assets/fonts/ProductSans-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Product Sans';
  src: url('assets/fonts/ProductSans-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* =========================
   Theme variables
   ========================= */
:root{
  --glass: rgba(21, 32, 56, 0.86);
  --panel: rgba(21, 32, 56, 0.86);
  --panel-strong: rgba(21, 32, 56, 0.86);
  --text: #eefcff;
  --muted: #ffffff;
  --brand: #163381;
  --brand-2: #070303;
  --ghost: rgba(255,255,255,0.12);
  --card-radius: 16px;
  --btn-radius: 12px;
  --shadow: 0 12px 40px rgba(0,0,0,0.28);
  --max-stage: 520px;
}

/* =========================
   Base
   ========================= */
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body{
  color: var(--text);
  font-family: 'Product Sans', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #20180b url('assets/bg.jpg') center/cover fixed no-repeat;
  font-weight: 400; /* Regular default */
}
[hidden] { display: none !important; }

/* =========================
   Layout
   ========================= */
.page-wrap{
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: linear-gradient(180deg, rgba(25, 41, 88, 0.86), rgba(69, 68, 120, 0));
  backdrop-filter: blur(4px);
}
.site-header{ padding: 12px 16px; text-align: center; }
.brand-title{
  margin: 0;
  font-size: 22px;
  font-weight: 700; /* Bold */
  letter-spacing: .3px;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.45);
}
.site-footer{
  color:#cbd5e1;
  text-align:center;
  padding:12px;
  text-shadow:0 1px 8px rgba(0,0,0,0.4);
  font-weight: 400; /* Regular */
}
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button:focus-visible, input[type="range"]:focus-visible, label.btn:focus-visible {
  outline: 2px solid var(--brand-2); outline-offset: 2px; border-radius: 12px;
}

/* =========================
   Main
   ========================= */
.content.two-col{
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  padding: 12px 16px 24px;
  min-height: 0;
}

/* =========================
   Stage
   ========================= */
.stage-card{
  background: rgba(21, 32, 56, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.292);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding:14px;
}
.canvas-wrap{
  position:relative;
  width:min(100%,var(--max-stage));
  margin:0 auto;
  aspect-ratio:calc(1080/1350);
  border-radius:14px;
  overflow:hidden;
  background:#0b1220;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,0.09);
  overscroll-behavior: contain;
  transform: translateZ(0);
  min-height: 0;
  contain: layout paint size;
  backface-visibility: hidden;
  -webkit-tap-highlight-color: transparent;
}
#photoCanvas{
  position:absolute; inset:0; width:100%; height:100%;
  cursor:grab; z-index:1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#photoCanvas:active { cursor: grabbing; }
#frame{
  position:absolute; inset:0; width:100%; height:100%;
  object-fit:cover; z-index:2; pointer-events: none;
}
.frame-hint{
  position:absolute; top:8px; left:8px;
  background:rgba(0,0,0,0.55); color:#fff;
  font-size:12px; padding:4px 8px; border-radius:8px;
  z-index:3; display:none; pointer-events: none;
}
#sourceImage { display:none; }

/* =========================
   Controls
   ========================= */
.controls{
  background:var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.292);
  border-radius:14px;
  padding:12px;
}
.sliders{ display:grid; gap:10px; margin-bottom:10px; }
.slider-row{
  display:grid; grid-template-columns:72px 1fr; gap:12px;
  align-items:center; color:var(--muted);
  font-weight:600; /* SemiBold labels */
}
input[type="range"]{
  width:100%; accent-color:var(--brand);
  -webkit-appearance: none; appearance: none;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
  margin-top: -7px;
}
input[type="range"]::-moz-range-thumb{
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
}

.rotate-row{ display:flex; gap:8px; justify-content:center; margin:6px 0 12px; }
.rotate-row.one{ justify-content:center; margin:6px 0 10px; }

.btn-ghost{ background:var(--ghost); color:var(--text); }
.btn-ghost:hover{ background:rgba(255,255,255,0.18); }

.actions{
  display:flex; flex-wrap:wrap; gap:10px; justify-content:center;
}
.btn{
  border:0; padding:10px 16px; border-radius:var(--btn-radius);
  font-size:15px;
  font-weight:600; /* SemiBold for buttons */
  cursor:pointer;
  transition:transform .08s ease,box-shadow .2s ease,opacity .2s;
  display:inline-flex; align-items:center; gap:8px;
  box-shadow:0 4px 14px rgba(0,0,0,0.25);
}
.btn:hover, .joy-btn:hover { filter: brightness(1.06); }
.btn:focus-visible, .joy-btn:focus-visible { box-shadow: 0 0 0 3px rgba(79,127,255,0.35); }
.btn:active{ transform:translateY(1px) scale(0.99); }
.btn-primary{
  background:linear-gradient(135deg,var(--brand),#072edb);
  color:#fff;
  font-weight:700; /* Bold for primary CTA */
}
.btn-upload{
  background:linear-gradient(135deg,var(--brand-2),#072edb);
  color:#ffffff; position:relative; overflow:hidden;
  font-weight:600; /* SemiBold */
}
.btn-upload input[type="file"]{
  position:absolute; inset:0; opacity:0; cursor:pointer;
}

.msg{
  margin:10px 0 0; min-height:18px;
  color:#a5defc; font-size:13px; text-align:center;
  font-weight:400; /* Regular */
}

/* =========================
   Tips
   ========================= */
.tips{
  background: var(--glass);
  margin-top: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--card-radius);
  padding: 16px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.tips h3{
  margin: 0 0 8px;
  color: #fff;
  font-weight:700; /* Bold section title (optional) */
}
.tips ul{ margin: 0; padding-left: 18px; }
.tips li{ margin: 6px 0; color: var(--muted); font-weight:400; /* Regular */ }

/* =========================
   Joystick
   ========================= */
.joystick{
  display:grid;
  grid-template-rows:auto auto auto;
  justify-items:center;
  gap:6px;
  margin:8px 0 12px;
}
.joy-mid{
  display:grid;
  grid-template-columns:auto auto auto;
  gap:6px;
}
.joy-btn{
  width:44px; height:44px;
  border:0;
  border-radius:10px;
  background:var(--ghost);
  color:#fff;
  font-size:18px;
  font-weight:600; /* SemiBold */
  box-shadow:0 4px 12px rgba(0,0,0,0.25);
  cursor:pointer;
  transition:transform .05s ease, background .15s ease, opacity .15s ease;
}
.joy-btn:active{ transform:translateY(1px) scale(0.98); }
#joy-center{
  font-size:14px;
  background:linear-gradient(135deg, var(--brand), #072edb);
  color:#fff;
  font-weight:600; /* SemiBold */
}
#btn-rotate{ min-width:160px; }

/* =========================
   Desktop
   ========================= */
@media (min-width: 1024px){
  .page-wrap { overflow: hidden; }

  .content.two-col{
    grid-template-columns: minmax(400px, 520px) minmax(420px, 1fr);
    gap: 40px; padding: 24px 24px; max-width: 1200px; width: 100%; margin: 0 auto;
    height: 100%; min-height: 0; overflow: auto;
  }

  .stage-card{
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 74vh;
    min-height: 0;
    overflow: hidden;
  }

  .canvas-wrap{
    aspect-ratio: calc(1080/1350);
    height: 100%;
    max-height: 74vh;
    width: auto;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
  }

  #photoCanvas, #frame{
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
  }

  .right-rail{
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: auto;
    overflow: visible;
    min-width: 0;
    min-height: 0;
    max-height: 74vh;
  }

  .controls{ flex: 0 0 auto; }

  .tips{
    flex: 0 0 auto;
    overflow: auto;
    max-width: 520px;
    padding: 14px;
    max-height: 40vh;
  }

  .site-footer{
    position: static;
    padding: 10px 16px;
  }
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 1023.98px){
  .controls{ transform-origin: top center; padding: 10px; }
  .joystick{ gap: 4px; margin: 6px 0 10px; }
  .joy-btn{ width: 40px; height: 40px; font-size: 16px; }
  #joy-center{ font-size: 13px; }
  .rotate-row.one{ margin: 6px 0 8px; }
  #btn-rotate{ min-width: 0; padding: 8px 12px; }
  .slider-row{ grid-template-columns: 64px 1fr; gap: 10px; }
  input[type="range"]{ height: 4px; }
  .actions{ gap: 8px; }
  .btn{ padding: 8px 12px; font-size: 14px; }
}

/* =========================
   Touch
   ========================= */
@media (hover: none) and (pointer: coarse){
  .joy-btn { width: 48px; height: 48px; font-size: 18px; }
  #btn-rotate { padding: 10px 14px; }
  input[type="range"] { height: 6px; }
}

/* =========================
   Reduced motion
   ========================= */
@media (prefers-reduced-motion: reduce){
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* =========================
   Visual polish
   ========================= */
.canvas-wrap.glow #frame {
  filter: drop-shadow(0 0 14px rgba(79,127,255,0.35))
          drop-shadow(0 0 24px rgba(38,210,255,0.25));
}

.joy-btn.is-active {
  transform: translateY(1px) scale(0.98);
  filter: brightness(1.12);
}
/* Particles background behind the main canvas */
.fx-wrap {
  position: absolute;
  inset: 0;
  z-index: 0; /* photoCanvas z:1, frame z:2 */
  pointer-events: none;
}
#particlesCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
