/* =========================
   Font (Lyon)
========================= */
@font-face {
  font-family: "Lyon";
  src: url("./CIS26/Lyon.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
}

/* =========================
   Vars
========================= */
:root {
  --stroke: 2px;
  --piano-h: clamp(260px, 32vh, 360px); /* keeps piano higher on tall screens */
  --press-depth: 2px;
}

/* =========================
   Base
========================= */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  height: 100%;
  width: 100%;
  min-height: -webkit-fill-available;
}

body {
  margin: 0;
  font-family: "Lyon", serif;
  background: #fff;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: none;
}

/* =========================
   Layout
========================= */
.app {
  height: 100vh;
  height: 100dvh;
  height: -webkit-fill-available;
  width: 100%;
  display: grid;
  grid-template-rows: 1fr var(--piano-h);
}

#stage {
  position: relative;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#activeLayer {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#piano {
  position: relative;
  border-top: var(--stroke) solid #000;
  border-bottom: var(--stroke) solid #000;
  background: #fff;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* =========================
   Word boxes
========================= */
.wordBox {
  position: absolute;
  transform: translate(-50%, 0);

  width: 160px;
  height: var(--word-box-h, 44px);
  display: grid;
  place-items: center;

  padding: 0;
  border: 2px solid #000;
  background: #fff;

  font-size: 26px;
  font-family: "Lyon", serif;
  line-height: 1;
  white-space: nowrap;

  opacity: 0;
  transition: opacity 220ms ease;
}

.wordBox.show { opacity: 1; }

.wordBox.fadeOut {
  opacity: 0;
  filter: blur(1px);
  transition: opacity 520ms ease, filter 520ms ease;
}

/* make sure the i button never gets covered */
#infoBtn { z-index: 1000; }
.wordBox { z-index: 10; }

/* =========================
   Emoji rain ("spice" → "girl")
========================= */
#emojiRain{
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 500; /* above word boxes */
}

.emojiDrop{
  position: absolute;
  top: -10vh;
  left: 50%;
  transform: translate3d(0, -10vh, 0);
  will-change: transform;
  animation: emojiFall var(--dur, 1.6s) linear forwards;
}

@keyframes emojiFall{
  from{
    transform: translate3d(0, -10vh, 0) rotate(0deg);
    opacity: 0.95;
  }
  to{
    transform: translate3d(var(--drift, 0px), 110vh, 0) rotate(360deg);
    opacity: 1;
  }
}

/* =========================
   Piano keys
========================= */
.keyboard {
  position: relative;
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(21, 1fr);
}

.whiteKey {
  appearance: none;
  border: 0;
  background: #fff;
  padding: 0;
  margin: 0;
  cursor: pointer;

  border-right: var(--stroke) solid #000;
  transition: transform 60ms ease, background 60ms ease;
}

.whiteKey:first-child {
  border-left: var(--stroke) solid #000;
}

.whiteKey.pressed {
  transform: none;
  height: 100%;
  margin-top: 0;
}

.whiteKey.pressed[data-octave="1"] { background: #0C8CE9; }
.whiteKey.pressed[data-octave="2"] { background: #F1ED4C; }
.whiteKey.pressed[data-octave="3"] { background: #F316B0; }

.blackKey {
  position: absolute;
  top: 0;
  height: 62%;
  width: calc(100% / 24 * 0.58);
  transform: translateX(-50%);
  background: #000;
  border: var(--stroke) solid #000;
  border-top: none;
  cursor: pointer;
  z-index: 3;
  padding: 0;
}

.blackKey.pressed[data-octave="1"] { background: #0C8CE9; }
.blackKey.pressed[data-octave="2"] { background: #F1ED4C; }
.blackKey.pressed[data-octave="3"] { background: #F316B0; }

/* =========================
   Emoji Rain
========================= */
#emojiRain{
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 500;
}
.emojiDrop{
  position: absolute;
  top: -10vh;
  left: 50%;
  transform: translate3d(0, -10vh, 0);
  will-change: transform;
  animation: emojiFall var(--dur, 1.6s) linear forwards;
}
@keyframes emojiFall{
  from{ transform: translate3d(0, -10vh, 0) rotate(0deg); opacity: 0.95; }
  to{ transform: translate3d(var(--drift, 0px), 110vh, 0) rotate(360deg); opacity: 1; }
}
   
/* =========================
   Info button (prototype style)
========================= */
#infoBtn {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 56px;
  height: 56px;
  border: 0;
  background: #000;
  color: #fff;
  cursor: pointer;

  display: grid;
  place-items: center;

  z-index: 99;
  opacity: 0;
  pointer-events: none;
}

#infoBtn .infoGlyph{
  font-family: "Lyon", serif;
  font-size: 28px;
  line-height: 1;
  transform: translateY(-1px); /* optical center */
} 

body.started #infoBtn {
  opacity: 1;
  pointer-events: auto;
}

/* =========================
   Octave controls (hidden on desktop, only show on mobile after started)
========================= */
#octaveControls {
  display: none !important;
}

/* =========================
   Overlays
========================= */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.72); /* slightly lighter so piano shows */
  z-index: 100;

  opacity: 0;
  pointer-events: none;
  transition: opacity 650ms ease; /* slow fade */
}

.overlay--show {
  opacity: 1;
  pointer-events: auto;
}

/* Start card position */
.startCard {
  text-align: center;
  transform: translateY(-130px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  font-weight: 400;
  font-size: 38px;
  line-height: 1.15;
  margin: 0 0 46px 0;
}

.playBtn {
  width: 120px;
  height: 120px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.playIcon {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 46px solid transparent;
  border-bottom: 46px solid transparent;
  border-left: 80px solid #000;
  transform: translateX(6px);
}

@media (max-width: 600px) {
  .startCard {
    transform: translateY(-140px);
  }

  .title {
    font-size: 34px;
    margin: 0 0 40px 0;
  }

  .playBtn {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* =========================
   Help image modal (matches prototype)
========================= */
.helpPanel {
  position: relative;
  padding: 0;
  border: 0;
  background: transparent;

  /* start slightly higher + invisible */
  transform: translateY(-140px) scale(0.98);
  opacity: 0;

  transition: transform 650ms ease, opacity 650ms ease;
}

/* when overlay is visible, panel animates in */
.overlay--show .helpPanel {
  transform: translateY(-120px) scale(1);
  opacity: 1;
}

/* scale image DOWN so piano stays visible */
.helpImg {
  display: block;
  width: min(820px, 86vw);
  max-height: 48vh;
  height: auto;
  object-fit: contain;
}

.helpImg--phone {
  display: none;
}

@media (max-width: 600px) {
  .helpImg--desktop {
    display: none;
  }

  .helpImg--phone {
    display: block;
    width: 70vw;
    max-height: 40vh;
  }

  .helpPanel {
    transform: translateY(-160px) scale(0.98);
  }

  .overlay--show .helpPanel {
    transform: translateY(-140px) scale(1);
  }

}

/* X button pinned to top-right of the image */
.closeBtn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 52px;
  height: 52px;
  border: 0;
  background: #000;
  color: #fff;
  font-size: 45px;
  font-weight: 200;
  font-family: "Lyon", serif;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================================================
   FINAL PHONE OVERRIDES (keeps laptop/desktop unchanged)
   - shows -1/+1 buttons
   - makes -1/+1 and i the same SQUARE size
   - forces 1 octave keyboard grid (C–C) styling
========================================================= */
@media (max-width: 600px){
  :root{
    --pianoH: 320px;
    --ctl: 52px;
  }

  /* make the top area actually fill the space above the piano */
  .app{
    height: 100dvh !important;
    height: -webkit-fill-available !important;
    width: 100vw !important;
    grid-template-rows: 1fr var(--pianoH) !important;
  }
  #stage{
    height: 100% !important;
  }

  /* 1 octave (C–B) keyboard - 7 white keys */
  .keyboard{
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    width: 100% !important;
  }
  .blackKey{
    width: calc(100% / 7 * 0.58) !important;
  }

  /* -1 / +1 octave buttons (SQUARE) */
  #octaveControls{
    display: none !important;
    gap: 0;
    position: absolute;
    left: 18px;
    bottom: 16px;
    border: 2px solid #000;
    background: #fff;
    z-index: 90;
  }

  #octaveControls button{
    width: var(--ctl);
    height: var(--ctl);
    aspect-ratio: 1 / 1;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
    color: #000;
    font-family: "Lyon", serif;
    font-size: 22px;
    display: grid;
    place-items: center;
    -webkit-appearance: none;
  }
  
  #octaveControls button + button{
    border-left: 2px solid #000;
  }
  
/* Octave button states */
  body.started #octaveControls{
    display: flex !important;
  }
  
  #octaveControls button{
    transition: background-color 0.1s ease;
    background: #fff;
  }
  
/* PRESSED STATES - color shows destination octave */

  /* From yellow (2) pressing -1 → going to blue (1) */
  body.started.octave-2 #octDown:active,
  body.started.octave-2 #octDown.btn-pressed{
    background: #3BACFF;
  }

  /* From blue (1) pressing +1 → going to yellow (2) */
  body.started.octave-1 #octUp:active,
  body.started.octave-1 #octUp.btn-pressed{
    background: #FFDD00;
  }

  /* From yellow (2) pressing +1 → going to pink (3) */
  body.started.octave-2 #octUp:active,
  body.started.octave-2 #octUp.btn-pressed{
    background: #FF56CF;
  }

  /* From pink (3) pressing -1 → going to yellow (2) */
  body.started.octave-3 #octDown:active,
  body.started.octave-3 #octDown.btn-pressed{
    background: #FFDD00;
  }
  
  /* info button (SQUARE, same size as octave buttons) */
  #infoBtn{
    position: fixed;
    top: 18px;
    right: 18px;
    width: var(--ctl) !important;
    height: var(--ctl) !important;
    min-width: var(--ctl);
    min-height: var(--ctl);
    aspect-ratio: 1 / 1;
    padding: 0 !important;
    border-radius: 0 !important;
    display: grid;
    place-items: center;
  }

  #infoBtn .infoGlyph{
    font-size: 26px;
    line-height: 1;
  }

  .wordBox{
    width: 150px;
    font-size: 24px;
  }
}

/* =========================================================
   LANDSCAPE PHONE OVERRIDES
========================================================= */
@media (max-width: 900px) and (orientation: landscape) {
  :root{
    --piano-h: clamp(160px, 35vh, 220px);
  }

  .app{
    grid-template-rows: 1fr var(--piano-h) !important;
  }

  #stage{
    height: 100% !important;
  }

  /* 3 octaves like desktop but sized for landscape */
  .keyboard{
    display: grid !important;
    grid-template-columns: repeat(21, 1fr) !important;
  }
  .blackKey{
    width: calc(100% / 21 * 0.58) !important;
  }

  /* Show octave controls in landscape, same position as portrait */
  body.started #octaveControls{
    display: flex !important;
    gap: 0;
    position: absolute;
    left: 18px;
    bottom: 16px;
    border: 2px solid #000;
    background: #fff;
    z-index: 90;
  }

  #octaveControls button{
    width: 52px;
    height: 52px;
    aspect-ratio: 1 / 1;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
    color: #000;
    font-family: "Lyon", serif;
    font-size: 20px;
    display: grid;
    place-items: center;
    -webkit-appearance: none;
  }

  #octaveControls button + button{
    border-left: 2px solid #000;
  }

  /* Start card */
  .startCard{
    transform: translateY(0px);
  }

  .title{
    font-size: 32px;
    margin: 0 0 30px 0;
  }

  .playBtn{
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .playIcon {
    border-top: 36px solid transparent;
    border-bottom: 36px solid transparent;
    border-left: 62px solid #000;
  }

  /* Info button fixed top right */
  #infoBtn{
    position: fixed !important;
    top: 18px !important;
    right: 18px !important;
    width: 44px !important;
    height: 44px !important;
  }

  .helpImg--phone {
    display: block;
    width: 50vw;
    max-height: 70vh;
  }

  .helpImg--desktop {
    display: none;
  }

  .helpPanel {
    transform: translateY(-40px) scale(0.98);
  }

  .overlay--show .helpPanel {
    transform: translateY(-20px) scale(1);
  }
}