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

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

:root {
  --red: #FF2D55;
  --pink: #FF6B9D;
  --gold: #FFD700;
  --dark: #080014;
  --card: rgba(8, 0, 25, 0.92);
  --border: rgba(255, 45, 85, 0.7);
  --glow: 0 0 24px rgba(255,45,85,0.5), 0 0 60px rgba(255,45,85,0.18);
  --font: 'Press Start 2P', 'Courier New', monospace;
  /* Safe-area insets for iPhone notch / home bar */
  --sai-b: env(safe-area-inset-bottom, 0px);
  --sai-l: env(safe-area-inset-left,   0px);
  --sai-r: env(safe-area-inset-right,  0px);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--dark);
  font-family: var(--font);
  color: #fff;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* Prevent all iOS scroll-bounce and zoom */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* Fill the screen including the notch area */
  position: fixed;
  inset: 0;
}

/* Scanline overlay */
body::after {
  content: "";
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.055) 2px, rgba(0,0,0,0.055) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

#root {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(80,0,120,0.35) 0%, transparent 70%),
    radial-gradient(ellipse 100% 100% at 50% 100%, rgba(200,0,60,0.12) 0%, transparent 60%),
    #080014;
}

#gameWrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  position: relative;
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: 3px solid rgba(255,45,85,0.7);
  box-shadow: var(--glow), inset 0 0 0 1px rgba(255,255,255,0.04);
  position: relative;
  z-index: 1;
  /* Prevent tap highlight flash on iOS */
  -webkit-tap-highlight-color: transparent;
}

/* Corner decorations */
#gameWrapper::before, #gameWrapper::after {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  border-color: var(--gold);
  border-style: solid;
  z-index: 2;
  pointer-events: none;
}
#gameWrapper::before { top: -2px; left: -2px;  border-width: 2px 0 0 2px; }
#gameWrapper::after  { top: -2px; right: -2px; border-width: 2px 2px 0 0; }

#mobileControls {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  /* Safe area: moves buttons above the home bar on iPhone X+ */
  padding-bottom: max(20px, calc(var(--sai-b) + 10px));
  padding-left:  max(18px, var(--sai-l));
  padding-right: max(18px, var(--sai-r));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 200;
}

.ctrl-group {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  pointer-events: auto;
}

.ctrl-btn {
  width: 88px; height: 88px;
  background: transparent;
  border: 2px solid rgba(255,255,255,0.32);
  border-radius: 18px;
  color: rgba(255,255,255,0.90);
  font-size: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  /* Smooth press feel */
  transition: background 0.07s, transform 0.07s, border-color 0.07s;
  /*box-shadow: 0 6px 20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);/*
  touch-action: none;
  outline: none;
  /* Larger invisible hit area so fingers don't miss */
  padding: 8px;
}
.ctrl-btn:active {
  border-color: var(--red);
  transform: scale(0.86);
  box-shadow: 0 0 24px rgba(255,45,85,0.7);
}

/*Desktop: hide mobile controls*/
@media (hover: hover) and (pointer: fine) {
  #mobileControls { display: none !important; }
}

/*Landscape phone: slightly smaller buttons*/
@media (max-height: 500px) and (orientation: landscape) {
  .ctrl-btn      { width: 60px; height: 60px; font-size: 24px; }
  .ctrl-btn.jump { width: 72px; height: 72px; font-size: 28px; }
  #mobileControls {
    padding-bottom: max(10px, var(--sai-b));
    padding-left:   max(10px, var(--sai-l));
    padding-right:  max(10px, var(--sai-r));
  }
}

#rotateHint {
  display: none; /* hidden by default */
  position: fixed; inset: 0;
  background: rgba(8,0,20,0.97);
  z-index: 10000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
}

.rotate-icon {
  font-size: 48px;
  animation: rotateWiggle 1.5s ease-in-out infinite;
}
@keyframes rotateWiggle {
  0%, 100% { transform: rotate(-15deg); }
  50%       { transform: rotate(15deg); }
}
.rotate-text {
  font-family: var(--font);
  font-size: 14px;
  color: var(--gold);
  line-height: 1.8;
  text-shadow: 0 0 12px rgba(255,215,0,0.5);
}
.rotate-sub {
  font-family: var(--font);
  font-size: 9px;
  color: rgba(255,255,255,0.45);
}

/* Show rotate hint ONLY on touch devices in portrait */
@media (max-width: 600px) and (orientation: portrait) and (hover: none) {
  #rotateHint { display: flex; }
}

#resetBtn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 10px));
  right: max(10px, var(--sai-r));
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 7px;
  color: rgba(255,255,255,0.45);
  font-family: var(--font);
  font-size: 7px;
  padding: 6px 10px;
  cursor: pointer;
  z-index: 1000;
  letter-spacing: 0.5px;
  transition: color 0.2s, border-color 0.2s;
}
#resetBtn:hover { color: #fff; border-color: var(--red); }

#lockScreen {
  display: none;
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(80,0,120,0.5) 0%, transparent 70%),
    #080014;
  z-index: 500;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: max(16px, calc(var(--sai-b) + 16px));
  overflow-y: auto;
}

.lock-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 36px 40px 28px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 50px rgba(255,45,85,0.25), 0 0 100px rgba(100,0,200,0.15);
  position: relative;
}

.lock-card::before, .lock-card::after {
  content: "♥"; position: absolute;
  font-size: 10px; color: rgba(255,45,85,0.5);
}
.lock-card::before { top: 12px; left: 16px; }
.lock-card::after  { top: 12px; right: 16px; }

.lock-title {
  font-size: 14px; color: var(--gold);
  margin-bottom: 6px; letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(255,215,0,0.5);
}
.lock-sub {
  font-size: 8px; color: rgba(255,255,255,0.5);
  line-height: 2; margin-bottom: 26px;
}

.lock-hints { display: flex; gap: 10px; justify-content: center; margin-bottom: 22px; }
.hint-badge {
  flex: 1;
  background: rgba(255,45,85,0.08);
  border: 1px solid rgba(255,45,85,0.35);
  border-radius: 10px; padding: 10px 8px;
  font-size: 7px; color: rgba(255,255,255,0.55); line-height: 2;
}
.hint-badge .digit {
  display: block; font-size: 26px; color: var(--gold);
  margin-top: 4px; text-shadow: 0 0 10px rgba(255,215,0,0.6);
}

.code-inputs { display: flex; gap: 12px; justify-content: center; margin-bottom: 22px; }
.code-input {
  width: 66px; height: 76px;
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(255,255,255,0.18);
  border-radius: 12px; color: var(--gold);
  font-family: var(--font); font-size: 30px;
  text-align: center; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--red);
}
.code-input:focus { border-color: var(--red); box-shadow: 0 0 16px rgba(255,45,85,0.45); }

.open-btn {
  background: linear-gradient(135deg, #FF2D55, #c0004a);
  border: none; border-radius: 12px; color: #fff;
  font-family: var(--font); font-size: 10px;
  padding: 14px 28px; cursor: pointer; letter-spacing: 1px;
  box-shadow: 0 5px 22px rgba(255,45,85,0.5);
  transition: transform 0.12s, box-shadow 0.12s;
}
.open-btn:hover  { transform: translateY(-2px); box-shadow: 0 9px 30px rgba(255,45,85,0.65); }
.open-btn:active { transform: translateY(0); }

#lockError {
  display: none; color: #FF6B6B; font-size: 8px;
  margin-top: 12px; animation: shake 0.3s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

.lock-reset-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 7px; color: rgba(255,255,255,0.3);
  font-family: var(--font); font-size: 6px;
  padding: 8px 14px; cursor: pointer; margin-top: 12px;
  transition: color 0.2s, border-color 0.2s;
}
.lock-reset-btn:hover { color: #fff; border-color: var(--red); }

/*Responsive*/
@media (max-width: 840px) { canvas { outline-width: 2px; } }

@media (max-width: 540px) {
  .lock-card  { padding: 24px 16px 20px; }
  .lock-title { font-size: 11px; }
  .code-input { width: 54px; height: 64px; font-size: 24px; }
  .hint-badge .digit { font-size: 20px; }
}
