@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@600;700&display=swap");

:root {
  --paper: #fffdf5;
  --ink: #121212;
  --muted: #646464;
  --highlight: #ffd84d;
  --highlight-dark: #e0aa00;
  --try: #b33a2f;
  --frame-max-width: 1180px;
  --display-font: "Fredoka", "Nunito", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

@font-face {
  font-family: "NotoMusicLocal";
  src: url("./NotoMusic-Regular.ttf") format("truetype");
  font-display: block;
}

* { box-sizing: border-box; }

html,
body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: #f2f0e9;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

.app-shell {
  --app-fit-scale: 1;
  width: min(var(--frame-max-width), calc(100vw - 24px));
  margin: 0;
  padding: 18px 0 20px;
  flex: 0 0 auto;
  transform: scale(var(--app-fit-scale));
  transform-origin: center;
  will-change: transform;
}

header { text-align: center; }

h1 {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(2.2rem, 5vw, 4.25rem);
  font-weight: 700;
  line-height: 1.05;
}

header p {
  margin: 10px 0 16px;
  font-family: var(--display-font);
  font-size: clamp(1rem, 2.1vw, 1.4rem);
  font-weight: 600;
}

.sound-control {
  position: absolute;
  z-index: 4;
  top: 10px;
  right: 18px;
  display: inline-grid;
  justify-items: center;
  gap: 4px;
}

.sound-toggle {
  min-height: 34px;
  padding: 5px 15px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  font-family: var(--display-font);
  font-size: .82rem;
  font-weight: 800;
  line-height: 1.05;
  cursor: pointer;
}

.sound-toggle:hover,
.sound-toggle:focus-visible { background: #fff3b5; outline: none; }
.sound-toggle[aria-pressed="true"] { background: var(--highlight); }

.sound-status {
  min-height: 1.2em;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 500;
  text-align: center;
}

.sound-status:empty { visibility: hidden; }
.sound-status.error { color: var(--try); }

.guide-controls {
  position: absolute;
  z-index: 4;
  /* F5 is at 27.94% of the SVG height; align the stack's top edge to it. */
  top: 27.94%;
  left: 7px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 7px;
}

.guide-button {
  min-width: 44px;
  height: 142px;
  padding: 8px 5px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  font-family: var(--display-font);
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.05;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  cursor: pointer;
}

.guide-button:hover,
.guide-button:focus-visible { background: #fff3b5; outline: none; }
.guide-button[aria-pressed="true"] { background: var(--highlight); }
.guide-button:disabled { cursor: default; opacity: .4; }
.guide-button:disabled:hover { background: #fff; }
.guide-reset { height: 76px; }
.visual-notes-toggle {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  background-color: #fffdf5;
  background-image:
    linear-gradient(rgba(255, 253, 245, .48), rgba(255, 253, 245, .48)),
    url("src/assets/visual-notes-island-button.png");
  background-position: center;
  background-size: cover;
  transform: none;
  writing-mode: horizontal-tb;
}

.visual-notes-toggle[aria-pressed="true"] {
  background-image:
    linear-gradient(rgba(255, 216, 77, .28), rgba(255, 216, 77, .28)),
    url("src/assets/visual-notes-island-button.png");
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 2px var(--highlight-dark);
}

.test-button {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 18px;
  min-height: 34px;
  padding: 5px 11px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  color: var(--ink);
  background: #fff;
  font-family: var(--display-font);
  font-size: .82rem;
  font-weight: 800;
  line-height: 1.05;
  cursor: pointer;
}

.test-button:hover,
.test-button:focus-visible { background: #fff3b5; outline: none; }
.test-button[aria-pressed="true"] { background: var(--highlight); }

.creator-credit {
  margin: 14px 0 8px;
  color: #9a9a9a;
  font-size: .78rem;
  font-weight: 400;
  opacity: .7;
  text-align: center;
}

.selected-label {
  position: absolute;
  z-index: 2;
  top: 20px;
  left: 50%;
  min-width: 190px;
  min-height: 54px;
  font-family: var(--display-font);
  font-size: clamp(2.25rem, 5vw, 4.4rem);
  font-weight: 700;
  line-height: .95;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
}

.selected-label.is-hidden { visibility: hidden; }

.board-stage {
  width: 100%;
  margin-top: 18px;
}

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 825;
  min-height: 440px;
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
  touch-action: none;
  overscroll-behavior: contain;
}

#musicBoard { width: 100%; height: 100%; display: block; user-select: none; }
.white-key, .slider-hit { cursor: pointer; }
.staff-click-zone { cursor: pointer; touch-action: none; }
.white-key:focus-visible { stroke: var(--try); stroke-width: 5; outline: none; }
.slider-thumb { filter: drop-shadow(2px 3px 0 rgba(0,0,0,.25)); will-change: transform; }
.staff-note-hit { cursor: grab; touch-action: none; }
.staff-note-hit:active { cursor: grabbing; }
.staff-note.dragging { stroke: var(--highlight); stroke-width: 7; }
.guide-note-hit { cursor: pointer; touch-action: manipulation; }
.guide-note-hit:focus-visible { outline: none; stroke: var(--highlight-dark); stroke-width: 2; }
.visual-notes-overlay,
.visual-note-art { pointer-events: none; }
.visual-note-art { filter: saturate(.92); }
.visual-note-image { image-rendering: auto; }
.visual-note-descriptor { letter-spacing: .15px; }

/* Desktop frames are height-aware so the 825:1000 board never forces scroll. */
@media (min-width: 901px) {
  :root { --frame-max-width: min(1180px, 95vh); }
  .selected-label {
    top: 12px;
    min-height: 44px;
    font-size: clamp(2.5rem, 5.5vh, 3.25rem);
  }
}

@media (min-width: 901px) and (max-height: 800px) {
  :root { --frame-max-width: min(1180px, 103vh); }
  .app-shell { padding: 6px 0 8px; }
  h1 { font-size: 2.5rem; }
  header p { margin: 4px 0 8px; font-size: 1rem; }
  .board-stage { margin-top: 6px; }
  .creator-credit { margin: 6px 0 2px; font-size: .7rem; }
}

@media (max-width: 900px) {
  .app-shell { width: min(calc(100vw - 12px), 900px); padding: 10px 0 14px; }
  h1 { font-size: clamp(1.9rem, 5vw, 3rem); }
  header p { margin: 6px 0 10px; font-size: clamp(.88rem, 2.2vw, 1.1rem); }
  .board-stage { margin-top: 10px; }
  .board-frame { min-height: 0; border-width: 4px; box-shadow: 5px 5px 0 var(--ink); }
}

@media (max-width: 600px) {
  .app-shell { width: calc(100vw - 8px); padding: 6px 0 10px; }
  h1 { font-size: clamp(1.55rem, 7vw, 2rem); white-space: nowrap; }
  header p { margin: 4px 0 7px; font-size: clamp(.72rem, 3.3vw, .9rem); }
  .board-stage { margin-top: 7px; }
  .board-frame { border-width: 3px; border-radius: 15px; box-shadow: 3px 4px 0 var(--ink); }
  .guide-controls { top: 27.94%; left: 3px; gap: 4px; }
  .guide-button { min-width: 32px; height: 76px; padding: 3px 2px; font-size: .5rem; border-width: 1.5px; border-radius: 7px; }
  .guide-reset { height: 44px; }
  .visual-notes-toggle { width: 32px; min-width: 32px; height: 32px; }
  .guide-notes text[x="17"] { transform: translateX(2px); }
  .guide-notes text[x="38"] { transform: translateX(-3px); }
  .visual-notes-overlay { opacity: .82; }
  .selected-label { top: 8px; left: 50%; min-width: 92px; min-height: 32px; font-size: clamp(1.35rem, 6vw, 1.8rem); }
  .test-button { top: 6px; left: 4px; min-height: 23px; padding: 1px 6px; border-width: 1.5px; border-radius: 6px; font-size: .54rem; line-height: 1.05; }
  .sound-control { top: 5px; right: 4px; gap: 1px; }
  .sound-toggle { min-height: 23px; padding: 1px 7px; font-size: .54rem; border-width: 1.5px; border-radius: 6px; line-height: 1.05; }
  .sound-status { min-height: 1em; max-width: 92px; font-size: .5rem; }
  .sound-status:not(.error) { visibility: hidden; }
  .creator-credit { margin: 7px 0 2px; font-size: .64rem; }
}

@media (max-width: 420px) {
  .app-shell { width: calc(100vw - 6px); }
  h1 { font-size: clamp(1.4rem, 6.5vw, 1.7rem); }
  header p { font-size: clamp(.66rem, 3.1vw, .8rem); }
  .guide-button { min-width: 25px; height: 70px; font-size: .46rem; }
  .guide-reset { height: 40px; }
  .visual-notes-toggle { width: 25px; min-width: 25px; height: 25px; }
  .selected-label { min-width: 82px; font-size: clamp(1.2rem, 5.5vw, 1.55rem); }
  .test-button { font-size: .49rem; }
  .sound-toggle { padding-inline: 5px; font-size: .49rem; }
}
