/* css/ui.css — piano-magic v0.1.8. Sin fuentes ni CDN. */
:root {
  --bg0: #10243f;
  --bg1: #1c3d68;
  --fg: #f6f1e6;
  --dim: #c5d4ea;
  --gold: #e2c27a;
  --gold-deep: #a67c32;
  --ink: #2a2118;
  --parchment: #efe6d2;
  --danger: #e15b5b;
  --setup: #7ec8ff;
  --defend: #8ddeaf;
  --hole: #d7b4f5;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

html {
  background:
    radial-gradient(90% 55% at 50% 8%, rgba(186, 214, 242, 0.55), transparent 58%),
    radial-gradient(70% 40% at 50% 22%, #3d6ea8 0%, transparent 62%),
    linear-gradient(180deg, #8eafd4 0%, #2a4f86 28%, #17325c 62%, #0c1c36 100%);
}

body {
  color: var(--fg);
  font-family: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#frame {
  max-width: 960px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

#scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-bottom: 6px;
}

.utility {
  grid-area: util;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 0 0;
}

.wordmark {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(246, 241, 230, 0.72);
  margin-right: auto;
}

#btnKeyboard, #btnMic, #btnHelp, #btnPause {
  appearance: none;
  border: 1px solid rgba(226, 194, 122, 0.85);
  background: rgba(8, 18, 36, 0.35);
  color: var(--fg);
  border-radius: 999px;
  font-family: Georgia, serif;
  font-weight: 700;
  cursor: pointer;
}

#btnKeyboard, #btnMic {
  font-size: 13px;
  padding: 6px 12px;
  min-height: 36px;
}

#btnKeyboard.on {
  background: rgba(226, 194, 122, 0.28);
  color: #fff8e6;
}

#btnMic.on {
  background: rgba(126, 200, 255, 0.32);
  color: #f4fbff;
}

#btnHelp {
  width: 36px;
  height: 36px;
  font-size: 18px;
  line-height: 1;
}

#stageTop {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.3fr) auto;
  grid-template-areas:
    "util util util"
    "room boss bpm";
  align-items: start;
  gap: 2px 12px;
  padding: 2px 12px 0;
}

.room-card { grid-area: room; display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.boss-card {
  grid-area: boss;
  text-align: center;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bpm-orb { grid-area: bpm; justify-self: end; padding-top: 2px; }

#roomIcon {
  width: 68px;
  height: auto;
  flex: 0 0 auto;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.room-emoji {
  font-size: 32px;
  width: 68px;
  text-align: center;
}

.room-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

#roomName {
  font-size: 26px;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#roomKeyTag {
  font-size: 13px;
  color: var(--dim);
}

.player-hp {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  min-width: 150px;
}

.hp-k {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.player-hp .track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(6, 16, 32, 0.35);
  border: 1px solid rgba(226, 194, 122, 0.75);
  overflow: hidden;
  min-width: 64px;
}

#playerHpBar {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #b9dcff, #2f6fdd);
}

.player-hp .val, .boss-hp-num, #bpmVal, #version, #midiStatus, .key, #phaseBadge {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.player-hp .val {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 52px;
}

#songTitle {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  margin-bottom: 2px;
}

.boss-hp {
  position: relative;
  z-index: 2;
  width: min(280px, 74%);
  margin: 0 auto 2px;
}

.boss-hp img {
  display: block;
  width: 100%;
  height: auto;
}

.boss-hp-num {
  position: absolute;
  right: 8%;
  top: 11%;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.boss-hp-mask {
  position: absolute;
  top: 14%;
  height: 22%;
  right: 5%;
  width: 0;
  background: rgba(6, 12, 28, 0.55);
  border-radius: 3px;
  pointer-events: none;
}

#bossPortrait {
  width: min(460px, 96%);
  height: auto;
  max-height: 168px;
  object-fit: contain;
  object-position: center top;
  display: block;
  margin: 0 auto;
  background: transparent;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.35));
  position: relative;
  z-index: 1;
}

.bpm-orb {
  width: 86px;
  text-align: center;
}

.bpm-k {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: #e7f2ff;
  margin-bottom: 2px;
}

.orb-face {
  position: relative;
  transition: transform 80ms linear;
}

.bpm-orb.pulse .orb-face { transform: scale(1.08); }

.orb-face img {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 0 10px rgba(140, 200, 255, 0.65));
}

#bpmVal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 8px #9ad0ff, 0 1px 2px #021018;
}

.beats {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 4px;
}

.beats i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  display: block;
}

.beats i.on { background: var(--gold); }
.beats i.pulse { background: #fff; transform: scale(1.2); }

#tapeFrame {
  position: relative;
  height: 176px;
  margin: 6px 12px 8px;
  overflow: hidden;
  background: transparent;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

#tape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#pauseBanner {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  align-items: center;
  justify-content: center;
  background: rgba(12, 24, 44, 0.18);
  pointer-events: none;
}

#pauseBanner.visible { display: flex; }

#pauseBanner span {
  background: #f6edd9;
  color: #2a2118;
  border: 2px solid #c6a15a;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 15px;
}

#btnPause, #btnPauseRestart {
  font-size: 17px;
  padding: 12px 36px;
  min-width: 180px;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid #f8e7b8;
  background: linear-gradient(#f6e2ad, #d7a84a);
  color: var(--ink);
}

#btnPause[hidden], #btnPauseRestart[hidden] { display: none !important; }
#btnPauseRestart { background: transparent; color: #f8e7b8; min-width: 140px; }

#btnPause.on {
  background: linear-gradient(#f4f8ff, #9ec0ea);
  border-color: #d5e4f8;
}

.gesture-legend, .buff-live {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 10px;
}

.buff-live:empty { display: none; }
.buff-live { padding-top: 6px; }

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(8, 18, 36, 0.38);
  border: 1px solid rgba(226, 194, 122, 0.55);
  border-radius: 999px;
  padding: 2px 12px 2px 2px;
  color: var(--fg);
  font-size: 12px;
  line-height: 1.15;
  text-align: left;
}

.chip img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.chip.live {
  background: rgba(226, 194, 122, 0.22);
}

#statusRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px 0;
}

#phaseBadge {
  border: 1px solid rgba(226, 194, 122, 0.7);
  background: rgba(8, 18, 36, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 auto;
}

#phaseBadge.setup { color: var(--setup); }
#phaseBadge.defend { color: var(--defend); }
#phaseBadge.hole { color: var(--hole); }

#feedback {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: #f3e2b0;
  min-height: 1.2em;
}

#feedback.miss { color: #ffb4b4; }
#feedback.partial { color: #ffd27a; }
#feedback.setup { color: var(--setup); }

#hint {
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  padding: 4px 16px 8px;
  line-height: 1.35;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

footer {
  flex: 0 0 auto;
  padding: 4px 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#btnStart, #btnRestart, #tutNext {
  appearance: none;
  border: 1px solid #f8e7b8;
  border-radius: 999px;
  background: linear-gradient(#f6e2ad, #d7a84a);
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  padding: 12px 36px;
  min-width: 180px;
  min-height: 46px;
  cursor: pointer;
}

#btnStart:active, #btnRestart:active, #tutNext:active { filter: brightness(0.95); }
#btnStart.hidden { display: none; }

#midiStatus, #micStatus, #version {
  font-size: 11px;
  color: var(--dim);
  text-align: center;
}

#micStatus:empty { display: none; }

#speakerUnlock {
  position: absolute;
  width: 1px;
  height: 1px;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

#keys {
  flex: 0 0 auto;
  padding: 6px 8px calc(8px + var(--safe-bottom));
  background: rgba(7, 14, 28, 0.78);
  border-top: 1px solid rgba(226, 194, 122, 0.45);
}

#keys[hidden] { display: none !important; }

.piano {
  position: relative;
  display: flex;
  height: 118px;
  max-width: 720px;
  margin: 0 auto;
  touch-action: none;
}

.key {
  appearance: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  padding-bottom: 6px;
  touch-action: none;
}

.key.white {
  flex: 1 1 0;
  height: 100%;
  margin: 0 1px;
  background: linear-gradient(#fffdf8, #e7dcc6);
  color: #1c2430;
  border-radius: 0 0 8px 8px;
  border: 1px solid #b7a88a;
  box-shadow: inset 0 -3px 0 rgba(90, 70, 40, 0.15);
  z-index: 1;
  min-width: 0;
}

.key.black {
  position: absolute;
  z-index: 2;
  top: 0;
  width: 10.5%;
  height: 62%;
  background: linear-gradient(#3a4458, #121722);
  color: #f6f1e6;
  border-radius: 0 0 7px 7px;
  border: 1px solid #0a0d14;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  padding-bottom: 4px;
}


.key .k { font-size: 13px; font-weight: 800; line-height: 1; }
.key .p { font-size: 10px; font-weight: 700; opacity: 0.8; line-height: 1.1; }
.key.black .k { font-size: 12px; }
.key.black .p { font-size: 9px; }

.key.white.down, .key.white:active {
  background: linear-gradient(#fff4cc, #e7c56a);
}
.key.black.down, .key.black:active {
  background: linear-gradient(#6a5430, #2a2114);
}

#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.82);
  z-index: 20;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

#overlay.visible { display: flex; }

#overlayMsg {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
}

#overlayMsg.win { color: #b6f0c8; }
#overlayMsg.lose { color: #ffb4b4; }

#error {
  display: none;
  margin: 12px;
  padding: 12px;
  background: rgba(8, 16, 32, 0.85);
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: #ffb4b4;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#error.visible { display: block; }

#tutorial[hidden] { display: none !important; }

.tut-blocker {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
}

.tut-spot {
  position: fixed;
  z-index: 41;
  border-radius: 16px;
  pointer-events: none;
  box-shadow:
    0 0 0 2px rgba(242, 214, 140, 0.95),
    0 0 22px rgba(150, 210, 255, 0.45),
    0 0 0 9999px rgba(6, 12, 28, 0.62);
}

.tut-card {
  position: fixed;
  z-index: 42;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px));
  background: #f6edd9;
  color: var(--ink);
  border: 2px solid #c6a15a;
  border-radius: 16px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.tut-kicker {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a6230;
  font-weight: 700;
}

#tutText {
  font-size: 18px;
  line-height: 1.35;
  margin-top: 4px;
}

.tut-progress {
  margin-top: 8px;
  font-size: 12px;
  color: #7a6548;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.tut-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

#tutSkip {
  appearance: none;
  background: transparent;
  border: none;
  color: #6d5436;
  font-family: Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 6px;
  text-decoration: underline;
}

#tutNext {
  min-width: 120px;
  font-size: 16px;
  padding: 8px 18px;
  min-height: 42px;
}

@media (max-width: 640px) {
  #stageTop {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "util util"
      "room bpm"
      "boss boss";
  }
  #roomName { font-size: 22px; }
  #roomIcon { width: 56px; }
  #bossPortrait { max-height: 132px; }
  #songTitle { font-size: 16px; }
  #tapeFrame { height: 156px; }
  .piano { height: 124px; }
  .boss-hp-num { font-size: 12px; top: 14%; }
}

@media (max-height: 700px) {
  #bossPortrait { max-height: 96px; }
  #tapeFrame { height: 140px; }
  #hint { display: none; }
  .chip img { width: 32px; height: 32px; }
}

/* v0.1.9: selector de rival, Modo libre y encaje iPad mini sin scroll. */
.rival-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.rival-picker[hidden] { display: none; }
.rival-picker::before {
  content: "Rival";
  align-self: center;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  margin-right: 2px;
}
.rival-opt {
  appearance: none;
  font-family: Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(226, 194, 122, 0.6);
  background: rgba(8, 18, 36, 0.4);
  color: var(--fg);
  cursor: pointer;
}
.rival-opt[aria-checked="true"] {
  background: rgba(226, 194, 122, 0.9);
  color: var(--ink);
  border-color: #f8e7b8;
}
.pause-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.pause-actions:not(:has(button:not([hidden]))) { display: none; }
#btnPauseRival, .ghost-btn {
  appearance: none;
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
  padding: 12px 28px;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid #f8e7b8;
  background: transparent;
  color: #f8e7b8;
  cursor: pointer;
}
#btnPauseRival[hidden] { display: none !important; }
.dmg-stats {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: #ffe6a6;
  margin: 2px 0;
}
.dmg-stats[hidden] { display: none; }
#overlay .dmg-stats { font-size: 17px; }
.dmg-pops { position: absolute; left: 0; right: 0; top: 62%; height: 0; pointer-events: none; z-index: 3; }
.dmg-pop {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 34px;
  font-weight: 800;
  color: #fff1c2;
  text-shadow: 0 2px 0 #7a3b00, 0 0 14px rgba(255, 190, 80, 0.9);
  animation: dmgRise 1.1s ease-out forwards;
  white-space: nowrap;
}
.dmg-pop.big { font-size: 44px; color: #ffd0a0; }
@keyframes dmgRise {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -60px) scale(1); }
}

/* v0.1.10: layout que llena la pantalla sin scroll en iPad/iPhone (Safari).
   El cuerpo nunca hace scroll; #scroll es una columna flex y la cinta crece
   para ocupar el alto libre. Los tamaños escalan con la ventana (dvh/vw)
   en vez de encoger todo con media queries fijas. */
html, body { position: fixed; inset: 0; width: 100%; height: 100%; overflow: hidden; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#frame { height: 100vh; height: 100dvh; max-width: min(1180px, 100vw); overflow: hidden; padding-bottom: var(--safe-bottom); }
#scroll { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
#stageTop, #gestureLegend, #buffs, #statusRow, #hint { flex: 0 0 auto; }
#tapeFrame { flex: 1 1 auto; height: auto; min-height: 110px; max-height: 340px; }
#bossPortrait { max-height: clamp(64px, 15dvh, 200px); }
#hint { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
footer { flex: 0 0 auto; }
#keys { flex: 0 0 auto; }
.piano { height: clamp(96px, 16dvh, 190px); max-width: 900px; }
.key .k { font-size: clamp(13px, 1.9dvh, 18px); }
.key .p { font-size: clamp(10px, 1.4dvh, 14px); }
@media (min-width: 700px) {
  #songTitle { font-size: clamp(18px, 2.6dvh, 28px); }
  .rival-opt { font-size: clamp(15px, 2dvh, 19px); }
}
/* Horizontal con poco alto (iPad mini apaisado ≈ 1133×~650 útil). */
@media (orientation: landscape) and (max-height: 820px) {
  #hint { display: none; }
  #bossPortrait { max-height: clamp(56px, 12dvh, 120px); }
  .chip img { width: 30px; height: 30px; }
  footer { flex-direction: row; flex-wrap: wrap; justify-content: center; column-gap: 12px; row-gap: 2px; padding-top: 4px; padding-bottom: 4px; }
  #midiStatus, #micStatus, #version { flex-basis: 100%; }
  .piano { height: clamp(90px, 17dvh, 150px); }
}

/* v0.1.11: retrato teñido por rival (sin arte nuevo). */
body[data-rival="bosque-de-sol"] #bossPortrait { filter: hue-rotate(95deg) saturate(1.2); }
body[data-rival="torre-de-escalas"] #bossPortrait { filter: hue-rotate(220deg) saturate(1.3); }
/* v0.1.11: iOS ignora user-scalable=no; sin doble toque-zoom ni rebote que parezcan scroll. */
html, body { overscroll-behavior: none; touch-action: manipulation; }
#frame, #scroll, footer, #keys { overscroll-behavior: none; }
button { touch-action: manipulation; }
