/* =============================
   PIXEL RPG LOVE LETTER — CSS
   ============================= */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --bg:        #0d0005;
  --panel:     #1a000a;
  --panel2:    #2a0015;
  --border:    #ff3366;
  --border2:   #ff88aa;
  --gold:      #ffd700;
  --gold2:     #ffaa00;
  --text:      #ffe0ea;
  --text2:     #ff99bb;
  --red:       #cc0033;
  --rose:      #ff3366;
  --cream:     #fff5f0;
  --shadow:    #600020;
  --glow:      rgba(255,51,102,0.35);

  /* dialog transparency */
  --dialog-bg: rgba(5, 0, 10, 0.58);
  --dialog-bg-carta: rgba(5, 0, 10, 0.72);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  image-rendering: pixelated;
}

/* ========================
   VIDEO BG
   ======================== */
.video-bg {
  position: fixed; inset: 0; z-index: 0;
  /* fallback image while video loads / iOS blocks autoplay */
  background: url('../assets/bg-poster.jpg') center center / cover no-repeat;
}

#bg-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  pointer-events: none;
  -webkit-media-controls: none;
}

/* Hide iOS/Safari native video play button overlay */
#bg-video::-webkit-media-controls,
#bg-video::-webkit-media-controls-panel,
#bg-video::-webkit-media-controls-play-button,
#bg-video::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none;
  appearance: none;
  opacity: 0 !important;
  visibility: hidden !important;
}

.overlay {
  position: absolute; inset: 0;
  background: rgba(8, 0, 5, 0.35);
}

/* ========================
   PIXEL HEARTS CANVAS
   ======================== */
#canvas {
  position: fixed; inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* ========================
   SCREENS
   ======================== */
.screen {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ========================
   RPG BUTTON
   ======================== */
.rpg-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  color: var(--gold);
  background: rgba(30, 0, 15, 0.85);
  border: 3px solid var(--gold2);
  padding: 12px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.06em;
  line-height: 1.6;
  position: relative;
  box-shadow:
    0 0 0 2px var(--shadow),
    0 4px 0 #3a2000,
    0 0 20px rgba(255,215,0,0.2);
  transition: all 0.1s;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.rpg-btn:hover {
  background: rgba(60, 0, 25, 0.9);
  box-shadow:
    0 0 0 2px var(--shadow),
    0 4px 0 #3a2000,
    0 0 30px rgba(255,215,0,0.4);
  transform: translateY(-2px);
}
.rpg-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 2px var(--shadow), 0 1px 0 #3a2000;
}
.rpg-btn-arrow {
  color: var(--rose);
  animation: arrow-blink 0.8s infinite;
}
@keyframes arrow-blink {
  0%,100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ========================
   SCREEN 1 — INTRO
   ======================== */
.intro-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px;
}

.sprite-hearts {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}
.ph {
  position: relative;
  width: 16px; height: 14px;
}
.ph::before, .ph::after {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  background: var(--rose);
  border-radius: 50% 50% 0 0;
  box-shadow: 0 0 8px var(--glow);
}
.ph::before { left: 0; top: 0; transform: rotate(-45deg); transform-origin: 0% 100%; }
.ph::after  { right: 0; top: 0; transform: rotate(45deg); transform-origin: 100% 100%; }
.ph1::before, .ph1::after { animation: ph-beat 1s 0s infinite; }
.ph2::before, .ph2::after { background: #ff6688; animation: ph-beat 1s 0.2s infinite; }
.ph3::before, .ph3::after { background: #ff99aa; animation: ph-beat 1s 0.4s infinite; }
@keyframes ph-beat {
  0%,100% { transform: scale(1) rotate(-45deg); }
  50% { transform: scale(1.3) rotate(-45deg); }
}
.ph::after { transform: scale(1) rotate(45deg) !important; }
.ph1::after { animation: ph-beat-r 1s 0s infinite; }
.ph2::after { animation: ph-beat-r 1s 0.2s infinite; }
.ph3::after { animation: ph-beat-r 1s 0.4s infinite; }
@keyframes ph-beat-r {
  0%,100% { transform: scale(1) rotate(45deg); }
  50% { transform: scale(1.3) rotate(45deg); }
}

.title-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.title-blink {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45rem;
  color: var(--text2);
  letter-spacing: 0.15em;
  animation: blink 1.2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.game-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(1.6rem, 7vw, 3rem);
  color: var(--border2);
  line-height: 1.5;
  text-shadow:
    4px 4px 0 var(--shadow),
    0 0 30px var(--glow),
    0 0 60px rgba(255,51,102,0.2);
}
.title-sub {
  font-family: 'VT323', monospace;
  font-size: 1.2rem;
  color: var(--text);
  opacity: 0.6;
  letter-spacing: 0.05em;
}
.press-start {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.4rem;
  color: var(--text2);
  opacity: 0.5;
  letter-spacing: 0.1em;
  animation: blink 1.5s infinite;
}

/* ========================
   HUD BAR
   ======================== */
.hud-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: rgba(15, 0, 8, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--border);
  box-shadow: 0 0 20px var(--glow);
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}
.hud-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  color: var(--gold);
  letter-spacing: 0.1em;
}
.hud-orbs { display: flex; gap: 6px; }
.orb {
  width: 14px; height: 14px;
  border: 2px solid var(--border2);
  background: rgba(30,0,15,0.6);
  transition: background 0.4s;
  clip-path: polygon(20% 0%,80% 0%,100% 20%,100% 80%,80% 100%,20% 100%,0% 80%,0% 20%);
}
.orb.filled {
  background: var(--rose);
  box-shadow: 0 0 8px var(--glow);
}

/* ========================
   SCREEN 2 — DIALOG
   ======================== */
.scene-space { flex: 1; }

.dialog-box {
  width: min(600px, 94vw);
  /* TRANSPARENT background - can see video behind */
  background: var(--dialog-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 4px solid var(--border);
  box-shadow:
    0 0 0 2px var(--shadow),
    0 0 0 6px var(--border),
    0 0 40px var(--glow),
    inset 0 0 30px rgba(0,0,0,0.3);
  padding: 20px 24px 16px;
  position: relative;
  margin-bottom: 16px;
}

/* pixel corners */
.dialog-corner {
  position: absolute;
  width: 10px; height: 10px;
  background: var(--gold);
}
.dialog-corner.tl { top: -1px; left: -1px; }
.dialog-corner.tr { top: -1px; right: -1px; }
.dialog-corner.bl { bottom: -1px; left: -1px; }
.dialog-corner.br { bottom: -1px; right: -1px; }

.dialog-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  position: relative;
}

.dialog-portrait {
  width: 36px; height: 36px;
  background: rgba(30,0,15,0.7);
  border: 3px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--glow);
  color: var(--rose);
}

.dialog-speaker {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  color: var(--gold);
  letter-spacing: 0.1em;
}

.dialog-text {
  font-family: 'VT323', monospace;
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  color: var(--text);
  line-height: 1.65;
  min-height: 70px;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
}

.dialog-cursor {
  text-align: right;
  color: var(--rose);
  font-size: 0.9rem;
  animation: blink 0.7s infinite;
  margin-top: 6px;
}

.dialog-next-btn { margin-bottom: 16px; }

/* ========================
   SCREEN 3 — CHEST
   ======================== */
.carta-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  padding: 60px 16px 16px;
  position: relative;
}

.chest-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transition: opacity 0.4s;
}
.chest-scene.hidden {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.chest-glow {
  position: absolute;
  width: 120px; height: 60px;
  background: radial-gradient(ellipse, rgba(255,215,0,0.4), transparent 70%);
  bottom: 40px;
  animation: glow-pulse 1.5s infinite;
}
@keyframes glow-pulse { 0%,100%{opacity:0.6} 50%{opacity:1} }

.pixel-chest {
  width: 96px;
  position: relative;
  filter: drop-shadow(0 0 16px rgba(255,215,0,0.5));
}

.chest-lid {
  width: 96px; height: 38px;
  background: linear-gradient(180deg, #8B4513, #6B3410);
  border: 4px solid #5a2d0c;
  border-bottom: none;
  position: relative;
  transform-origin: bottom center;
  transition: transform 0.6s cubic-bezier(0.4,0,0.2,1);
  box-shadow: inset 0 4px 0 rgba(255,200,100,0.2);
}
.chest-lid::before {
  content: '';
  position: absolute;
  top: 6px; left: 4px; right: 4px; height: 4px;
  background: rgba(255,200,100,0.25);
}

.pixel-chest.open .chest-lid {
  transform: rotateX(-130deg);
}

.chest-lock {
  position: absolute;
  bottom: -14px; left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 24px;
  background: var(--gold);
  border: 3px solid #8B6914;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem;
  color: var(--red);
  z-index: 5;
  clip-path: polygon(20% 0%,80% 0%,100% 20%,100% 80%,80% 100%,20% 100%,0% 80%,0% 20%);
  transition: opacity 0.3s;
}
.pixel-chest.open .chest-lock { opacity: 0; }

.chest-body {
  width: 96px; height: 56px;
  background: linear-gradient(180deg, #6B3410, #4a2008);
  border: 4px solid #5a2d0c;
  border-top: 3px solid #8B4513;
  position: relative;
}
.chest-stripe {
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 8px;
  background: #5a2d0c;
  transform: translateY(-50%);
}

.chest-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.4rem;
  color: var(--gold2);
  letter-spacing: 0.1em;
  animation: blink 1.2s infinite;
}

.chest-sparkle {
  position: absolute;
  font-size: 1.2rem;
  pointer-events: none;
  animation: sparkle-out 0.8s ease-out forwards;
}
@keyframes sparkle-out {
  0% { transform: translate(0,0) scale(0.5); opacity:1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(1.5); opacity:0; }
}

/* ========================
   RPG CARTA
   ======================== */
.rpg-carta {
  display: none;
  width: min(500px, 92vw);
  max-height: 75vh;
  overflow-y: auto;
  /* TRANSPARENT - matches dialog style */
  background: var(--dialog-bg-carta);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 4px solid var(--gold);
  box-shadow:
    0 0 0 2px #5a3a00,
    0 0 0 6px var(--gold2),
    0 0 50px rgba(255,215,0,0.3),
    inset 0 0 40px rgba(0,0,0,0.3);
  position: relative;
  animation: carta-appear 0.6s cubic-bezier(0.22,1,0.36,1) forwards;
  scrollbar-width: thin;
  scrollbar-color: var(--rose) transparent;
}
.rpg-carta.visible { display: block; }

@keyframes carta-appear {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.rpg-carta-inner { padding: 28px 24px; position: relative; }

.rc-corner {
  position: absolute;
  width: 16px; height: 16px;
  background: var(--gold);
}
.rc-corner::before {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  background: transparent;
}
.rc-tl { top: 0; left: 0; }
.rc-tl::before { bottom: 0; right: 0; }
.rc-tr { top: 0; right: 0; }
.rc-tr::before { bottom: 0; left: 0; }
.rc-bl { bottom: 0; left: 0; }
.rc-bl::before { top: 0; right: 0; }
.rc-br { bottom: 0; right: 0; }
.rc-br::before { top: 0; left: 0; }

.rc-header {
  text-align: center;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rc-ornament {
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: var(--gold2);
  letter-spacing: 0.4em;
  opacity: 0.7;
}
.rc-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.6rem, 3vw, 0.85rem);
  color: var(--gold);
  letter-spacing: 0.1em;
  text-shadow: 0 0 20px rgba(255,215,0,0.5);
}

.rc-body {
  font-family: 'VT323', monospace;
  font-size: clamp(1.3rem, 4vw, 1.75rem);
  color: var(--text);
  line-height: 1.8;
  text-align: center;
  border-top: 2px solid rgba(255,215,0,0.2);
  border-bottom: 2px solid rgba(255,215,0,0.2);
  padding: 16px 0;
  min-height: 60px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9);
}

.rc-footer {
  text-align: right;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.rc-sign {
  font-family: 'VT323', monospace;
  font-size: 1.2rem;
  color: var(--text2);
  line-height: 1.5;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
}
.rc-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  color: var(--rose);
  text-shadow: 0 0 12px var(--glow);
}

.rc-sparkles {
  position: absolute; inset: 0;
  pointer-events: none; overflow: hidden;
}
.sparkle-dot {
  position: absolute;
  width: 4px; height: 4px;
  background: var(--gold);
  animation: sparkle-float 2s ease-in-out infinite;
}
@keyframes sparkle-float {
  0%,100% { transform: translateY(0) scale(1); opacity: 0.8; }
  50%      { transform: translateY(-12px) scale(1.5); opacity: 0.3; }
}

/* ========================
   SCANLINES
   ======================== */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent 2px,
    rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px
  );
  pointer-events: none;
  z-index: 999;
}

/* ========================
   SCROLLBAR
   ======================== */
.rpg-carta::-webkit-scrollbar { width: 6px; }
.rpg-carta::-webkit-scrollbar-track { background: transparent; }
.rpg-carta::-webkit-scrollbar-thumb { background: var(--rose); }

/* ========================
   RESPONSIVE — iPhone XR +
   ======================== */
@media (max-width: 430px) {
  .rpg-btn { font-size: 0.42rem; padding: 10px 14px; }
  .game-title { font-size: 1.4rem; }
  .dialog-box { padding: 14px 16px 12px; }
  .dialog-text { font-size: 1.25rem; }
  .hud-name { font-size: 0.42rem; }
}

@media (max-height: 750px) {
  .dialog-box { margin-bottom: 10px; }
  .scene-space { flex: 0.4; }
}
