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

:root {
  --ink: #f2ecff;
  --dim: #a394c9;
  --accent: #c9a8ff;
  --good: #9dffc9;
}

html, body {
  height: 100%;
  background: #0c0718;
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: none;
}

#stage { position: fixed; inset: 0; }

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* --- Overlay UI --------------------------------------------------------- */
.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.hud {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity .5s ease;
}
/* The HUD arrives after the scene has settled, not with it. */
.hud.on { opacity: 1; transition-delay: .55s; }

.hud-label {
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--dim);
  text-transform: uppercase;
}

.meter {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 2px solid rgba(201, 168, 255, .35);
  background: rgba(10, 6, 20, .5);
}
.meter i {
  display: block;
  width: 7px;
  height: 14px;
  background: rgba(201, 168, 255, .13);
  transition: background .12s linear, box-shadow .12s linear;
}
.meter i.lit  { background: var(--accent); box-shadow: 0 0 8px rgba(201, 168, 255, .8); }
.meter i.full { background: var(--good);   box-shadow: 0 0 10px rgba(157, 255, 201, .9); }

/* --- Buttons ------------------------------------------------------------ */
.pbtn {
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  color: #150e26;
  background: var(--accent);
  border: 0;
  padding: 14px 22px;
  min-height: 48px;                     /* comfortable touch target */
  box-shadow: 0 4px 0 #7a5aa8, 0 0 24px rgba(201, 168, 255, .35);
  transition: transform .08s ease, box-shadow .08s ease, filter .2s ease;
}
.pbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 #7a5aa8; }
@media (hover: hover) {
  .pbtn:hover { filter: brightness(1.08); }
}

#startBtn {
  font-size: 17px;
  letter-spacing: 3px;
  padding: 20px 46px;
  min-height: 60px;
  box-shadow: 0 5px 0 #7a5aa8, 0 0 40px rgba(201, 168, 255, .45);
  animation: breathe 3.4s ease-in-out infinite;
}
#startBtn:active { transform: translateY(4px); box-shadow: 0 1px 0 #7a5aa8; }
@keyframes breathe {
  50% { box-shadow: 0 5px 0 #7a5aa8, 0 0 60px rgba(201, 168, 255, .75); }
}
.pbtn.ghost {
  color: var(--ink);
  background: transparent;
  border: 2px solid rgba(201, 168, 255, .5);
  box-shadow: none;
}
.pbtn.ghost:active { transform: translateY(2px); }

/* "Artık iyiyim" sits away from where the thumb rests, so reaching it means
   letting go of the feather on purpose. */
#okBtn {
  position: absolute;
  top: max(52px, calc(env(safe-area-inset-top) + 44px));
  right: max(16px, env(safe-area-inset-right));
  background: var(--good);
  box-shadow: 0 4px 0 #4e9b74, 0 0 26px rgba(157, 255, 201, .45);
  opacity: 0;
  transform: translateY(-10px) scale(.9);
  transition: opacity .6s ease, transform .6s cubic-bezier(.2, 1.4, .4, 1);
  pointer-events: none;
}
#okBtn.on {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-4px); } }

/* Sound toggle — opposite corner from "artık iyiyim" so they never collide. */
.iconbtn {
  position: absolute;
  top: max(52px, calc(env(safe-area-inset-top) + 44px));
  left: max(16px, env(safe-area-inset-left));
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 9px 11px;
  color: var(--ink);
  background: rgba(20, 12, 38, .6);
  border: 2px solid rgba(201, 168, 255, .3);
  opacity: .55;
  transition: opacity .25s ease, transform .08s ease;
}
.iconbtn:active { transform: translateY(2px); }
.iconbtn.muted { opacity: .3; }

/* --- Screens ------------------------------------------------------------ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 45%, rgba(30, 18, 54, .72), rgba(10, 6, 20, .94));
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  /* Leaving pulls the curtain toward the viewer: fade, push past, blur out. */
  transition: opacity .6s ease, transform .7s cubic-bezier(.35, 0, .2, 1), filter .6s ease;
  pointer-events: auto;
}
.screen.hide {
  opacity: 0;
  transform: scale(1.09);
  filter: blur(7px);
  pointer-events: none;
}

/* The intro hides the scene completely — the game is a reveal, not a backdrop. */
#titleScreen {
  background: radial-gradient(125% 95% at 50% 38%, #271748 0%, #170e2c 48%, #0a0514 100%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
#titleScreen .big { animation: floaty 4.5s ease-in-out infinite; }
@keyframes floaty {
  50% { transform: translateY(-12px) rotate(-5deg); }
}

/* Small "hold" diagram under the copy so the rule is obvious before starting. */
.holdhint {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--dim);
  opacity: .8;
}
.holdhint .dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: press 1.9s ease-in-out infinite;
}
@keyframes press {
  0%, 100% { transform: scale(1); opacity: .5; }
  40%      { transform: scale(.72); opacity: 1; box-shadow: 0 0 14px rgba(201, 168, 255, .8); }
}

.screen h1 { font-size: clamp(20px, 6.5vw, 30px); letter-spacing: 2px; font-weight: 700; }
.screen p  { font-size: clamp(12px, 3.6vw, 15px); line-height: 1.9; color: var(--dim); max-width: 36ch; white-space: pre-line; }
.screen .big { font-size: clamp(30px, 11vw, 52px); line-height: 1; }
.screen .warm { color: var(--ink); }

.hint {
  position: absolute;
  left: 0; right: 0;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px));
  text-align: center;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--dim);
  opacity: 0;
  transition: opacity .6s ease;
}
.hint.on { opacity: .85; animation: pulse 2.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* Off-screen haptic switch (iOS only trick) */
#hapticLabel {
  position: fixed;
  bottom: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  #okBtn.on { animation: none; }
  .hint.on { animation: none; }
}
