/* Xylophone Basics Play-Along — the Rainbow Xylophone's look: wood table, brown frame, rainbow bars.
   Sizes and places of the video and the xylophone are set by app.js (layout) as pixels and --vars. */

*, *::before, *::after { box-sizing: border-box; -webkit-touch-callout: none; }

html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  font-family: "Fredoka", sans-serif;
  color: #3e2723;
  background-color: #d4a373;
  background-image: url("assets/wood-pattern.png");   /* kept on our own site: school filters block the texture site */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid #fbbf24; outline-offset: 2px; }

/* ---------- top bar: tabs + gear ---------- */

.topbar {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
}

/* the way back to the hub and the app's name, as in the Rainbow Xylophone (no way back inside a frame) */
.home-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 42px;
  margin-top: 2px;
  padding: 0 14px 0 9px;
  border-radius: 999px;
  color: #3e2723;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
}
.home-btn svg { width: 20px; height: 20px; }
.in-iframe .home-btn { display: none; }
.app-title {
  flex: 0 0 auto;
  margin: 0;
  line-height: 46px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(20px, 2.2vw, 30px);
  letter-spacing: 0.025em;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.07)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
}
@media (max-width: 1279px) {   /* the word only on wide screens, so the tabs stay on one row */
  .home-btn { width: 42px; padding: 0; justify-content: center; }
  .home-btn span { display: none; }
}
@media (max-width: 639px) {
  html:not(.in-iframe) .app-title { display: none; }
}

.tabs { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; padding: 2px; }

.tab, .gear, .home-btn {
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.tab:hover, .gear:hover, .home-btn:hover { background: rgba(255, 255, 255, 0.38); }
.tab:active, .gear:active, .home-btn:active { transform: scale(0.95); }
.topbar .home-btn { border-radius: 999px; }

.tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 42px;
  padding: 0 8px;
  border-width: 2px;
}
.tab[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.72);
  border-color: #fbbf24;
  cursor: default;
}
.chip {
  width: 24px;
  height: 26px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  border-bottom: 2px solid rgba(0, 0, 0, 0.12);
  border-right: 2px solid rgba(0, 0, 0, 0.12);
  transition: opacity 0.2s;
}
.tab:not([aria-selected="true"]) .chip { opacity: 0.7; }
.tab:not([aria-selected="true"]):hover .chip { opacity: 1; }
/* phones: smaller tabs, and they wrap onto a second row */
@media (max-width: 640px) {
  .tabs { gap: 6px; }
  .tab { height: 36px; padding: 0 5px; gap: 2px; }
  .chip { width: 18px; height: 22px; font-size: 13px; border-radius: 4px; }
}

.gear {
  flex: 0 0 auto;
  margin-left: auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
}
.gear svg { width: 22px; height: 22px; transition: transform 0.3s; }
.gear[aria-expanded="true"] { background: rgba(255, 255, 255, 0.5); }
.gear[aria-expanded="true"] svg { transform: rotate(60deg); }

/* ---------- settings ---------- */

.panel {
  position: absolute;
  top: calc(100% + 4px);
  right: max(12px, env(safe-area-inset-right));
  width: min(370px, calc(100vw - 24px));
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  padding: 6px 16px 10px;
  border-radius: 16px;
  color: #fff;
  background: rgba(62, 39, 35, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.panel[hidden] { display: none; }

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;   /* a long control (Instrument's three choices) drops under its label on a phone */
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 52px;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.row:first-child { border-top: 0; }
.row[hidden] { display: none; }
.label { font-weight: 600; font-size: 15px; }
.names { margin-left: 4px; font-weight: 700; letter-spacing: 0.08em; color: #fcd34d; }
.hint { margin: -4px 0 8px; font-size: 12.5px; line-height: 1.35; color: rgba(255, 255, 255, 0.65); }
.hint[hidden] { display: none; }

.seg { display: flex; gap: 2px; margin-left: auto; padding: 3px; border-radius: 9px; background: rgba(0, 0, 0, 0.28); }
.seg button {
  border: 0;
  padding: 7px 10px;
  border-radius: 7px;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.seg button:hover { color: #fff; }
.seg button.on { background: #fbbf24; color: #3e2723; font-weight: 700; }
.seg.disabled { opacity: 0.45; pointer-events: none; }

.slider { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.slider input { width: 128px; accent-color: #fbbf24; cursor: pointer; }
.slider output { min-width: 2.4em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 28px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.22);
  cursor: pointer;
  transition: background 0.2s;
}
.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}
.switch[aria-checked="true"] { background: #fbbf24; }
.switch[aria-checked="true"] span { transform: translateX(22px); }

/* ---------- the stage: video + xylophone ---------- */

.stage { position: relative; flex: 1 1 auto; min-height: 0; outline: none; }

.video-box {
  position: absolute;
  overflow: hidden;
  background: #000;
  border: 4px solid #3e2723;
  border-radius: 18px;
  box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.5);
}
.video-box iframe { display: block; width: 100%; height: 100%; border: 0; }

.video-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  color: #fff;
  font-size: 17px;
  background: #3e2723;
}
.video-msg[hidden] { display: none; }
.video-msg p { margin: 0; max-width: 24em; }
.video-msg a { color: #3e2723; background: #fbbf24; font-weight: 700; text-decoration: none; padding: 8px 14px; border-radius: 8px; }

/* the xylophone (sizes from app.js: --bw bar width, --bh longest bar, --gap, --px/--py padding,
   --bolt, --bolt-at, --letter, --keyfs, --hl/--hr handle heights) */
.frame {
  position: absolute;
  background: #5d4037;
  border: 4px solid #3e2723;
  border-radius: 24px;
  box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.rails {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: multiply;
}

.handle {
  position: absolute;
  top: 50%;
  width: 16px;
  transform: translateY(-50%);
  background: #4e342e;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}
.handle.left { left: -12px; height: var(--hl); border-radius: 4px 0 0 4px; }
.handle.right { right: -12px; height: var(--hr); border-radius: 0 4px 4px 0; }

.bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  padding: 0 var(--px);
}

.bar {
  position: relative;
  flex: 0 0 var(--bw);
  width: var(--bw);
  height: calc(var(--bh) * var(--pct));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--letter) * 0.35);
  background: var(--c);
  border-radius: 6px;
  border-bottom: 4px solid rgba(0, 0, 0, 0.1);
  border-right: 4px solid rgba(0, 0, 0, 0.1);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: filter 75ms, translate 75ms, box-shadow 75ms;
}
@media (hover: hover) {
  .bar:not(.off):hover { filter: brightness(1.05); }
}
.bar.down {
  filter: brightness(1.1);
  translate: 0 2px;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}
.bar.off { background: #374151; cursor: default; }

.bolt {
  position: absolute;
  left: 50%;
  width: var(--bolt);
  height: var(--bolt);
  margin-left: calc(var(--bolt) / -2);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}
.bolt.top { top: var(--bolt-at); }
.bolt.bottom { bottom: var(--bolt-at); }
.bar.off .bolt { background: rgba(255, 255, 255, 0.4); box-shadow: none; }

.letter {
  font-weight: 700;
  font-size: var(--letter);
  line-height: 1;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.07)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
}

.key {
  display: none;
  min-width: 1.6em;
  padding: 0.12em 0.4em 0.08em;
  border-radius: 0.3em;
  border-bottom: 0.14em solid rgba(0, 0, 0, 0.28);
  background: rgba(255, 255, 255, 0.9);
  color: #3e2723;
  font-weight: 700;
  font-size: var(--keyfs);
  line-height: 1.1;
  text-align: center;
}
.show-keys .key { display: block; }
body:not(.show-names) .letter, body:not(.show-names) .pkey .name { display: none; }
.bar.off .letter, .bar.off .key { display: none; }

/* the piano: the Virtual Keyboard's (sizes from app.js: --p padding, --ww/--wh white keys, --kbw/--kbh black
   keys, --name/--bname note names, --keyfs key bindings) */
.piano {
  position: absolute;
  background: #111;
  border-radius: 10px;
  box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.5);
  touch-action: none;
}
.piano[hidden] { display: none; }
.frame.tray .bars, .frame.tray .rails { display: none; }
.pkeys { position: absolute; inset: var(--p); }

.pkey {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
}
.pkey.white {
  z-index: 1;
  width: var(--ww);
  height: var(--wh);
  gap: calc(var(--name) * 0.3);
  padding-bottom: calc(var(--name) * 0.6);
  background: linear-gradient(to bottom, var(--c) 50%, #fff 50%);   /* the colour on the top half */
  border: 1px solid #999;
  border-radius: 6px 6px 10px 10px;
}
.pkey.black {
  z-index: 3;
  width: var(--kbw);
  height: var(--kbh);
  padding-bottom: calc(var(--bname) * 0.6);
  background: linear-gradient(#111, #333);
  border: 1px solid #000;
  border-radius: 6px 6px 8px 8px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.6), inset 0 -2px 0 rgba(255, 255, 255, 0.05);
}
@media (hover: hover) {
  .pkey:not(.off):hover { filter: brightness(1.04); }
}
.pkey.down { background: var(--c); }   /* the whole key in its colour while held */
.pkey.white.off { background: #8f8f8f; border-color: #6e6e6e; cursor: default; }
.pkey.black.off { background: #4a4a4a; box-shadow: none; cursor: default; }

.pkey .name { font-weight: 700; line-height: 1.05; text-align: center; }
.pkey.white .name { font-size: var(--name); color: #1c1c1e; }
.pkey.black .name { font-size: var(--bname); color: #fff; }
.pkey .key { font-size: var(--keyfs); background: #3e2723; color: #fff; border-bottom-color: rgba(0, 0, 0, 0.45); }
.pkey.off .name, .pkey.off .key { display: none; }
