@font-face {
  font-family: 'Gochi Hand';
  src: url(fonts/gochi-hand.woff2) format('woff2');
  font-display: swap;
}

:root {
  --paper: #fbfbf8;
  --grid: #c3c8d0;
  --ink: #1e1f25;
  --pencil: #6d717a;
  --hl: rgba(255, 224, 0, 0.62);
  --wood: #b98a5c;
  --hand: 'Gochi Hand', 'Comic Sans MS', 'Chalkboard SE', cursive;
  --cell: 30px;
  --offx: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

.paper {
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#scroller {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-width: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
#scroller::-webkit-scrollbar { display: none; }

#sheet {
  position: relative;
  width: 100%;
  background-position: var(--offx) 100%;
  cursor: crosshair;
}

#deck {
  flex: 0 0 auto;
  position: relative;
  background-position: var(--offx) 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

#kbwrap { position: relative; }
#kb { display: block; position: relative; overflow: visible; touch-action: none; cursor: pointer; }
#kb text { font-family: var(--hand); fill: var(--ink); stroke: var(--ink); stroke-width: 0.35px; pointer-events: none; }
#kb .hl { fill: var(--hl); opacity: 0; transition: opacity 0.08s; }
#kb .hl.on { opacity: 1; transition: none; }

/* Notes: pen boxes on the paper */
.note {
  position: absolute;
  touch-action: none;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
.note:active { cursor: grabbing; }
.note svg.ink { position: absolute; overflow: visible; pointer-events: none; }
.note .lbl {
  position: relative;
  line-height: 1;
  letter-spacing: -0.02em;
  pointer-events: none;
  white-space: nowrap;
  padding-top: 0.08em;
  -webkit-text-stroke: 0.3px var(--ink);
}
.note .hl {
  position: absolute;
  inset: -2px -3px;
  background: var(--hl);
  border-radius: 3px 7px 4px 6px;
  transform: rotate(-1.5deg);
  opacity: 0;
  pointer-events: none;
}
.note.black .hl { inset: -5px -6px; border-radius: 6px; }
.note.on .hl { opacity: 1; }
.note .handle {
  position: absolute;
  left: -2px; right: -2px; top: -5px;
  height: 11px;
  cursor: ns-resize;
}
.note.small .handle { display: none; }
.note.lift { z-index: 5; filter: drop-shadow(1px 3px 2px rgba(0, 0, 0, 0.18)); }
.note.gone { transition: opacity 0.18s, transform 0.18s; opacity: 0; transform: scale(0.6) rotate(8deg); }

.hole {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #c99d70, var(--wood) 60%, #9b6f45);
  box-shadow: inset 2px 3px 4px rgba(60, 35, 10, 0.45);
  pointer-events: none;
}

/* Controls written under the keyboard */
#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  margin: 14px auto 0;
  padding: 0 10px;
}
.btn {
  position: relative;
  font: inherit;
  font-size: 21px;
  line-height: 1;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 8px 12px 6px;
  min-height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn > svg.box { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.btn::before {
  content: '';
  position: absolute;
  inset: 4px 3px;
  background: var(--hl);
  border-radius: 3px 8px 4px 7px;
  transform: rotate(-1deg);
  opacity: 0;
  transition: opacity 0.12s;
}
.btn:hover::before, .btn:focus-visible::before { opacity: 0.55; }
.btn:active::before { opacity: 1; }
.btn:focus { outline: none; }
.btn > span, .btn > svg.ico { position: relative; }
.btn svg.ico { width: 18px; height: 18px; overflow: visible; }
.btn.big { font-size: 24px; padding: 8px 16px 6px 13px; }
.btn.big svg.ico { width: 20px; height: 20px; }
.btn.sq { width: 40px; justify-content: center; padding: 6px 0 4px; font-size: 24px; }
.btn[disabled] { opacity: 0.35; cursor: default; }
.btn[disabled]::before { display: none; }
.tempo { display: inline-flex; align-items: center; gap: 6px; font-size: 20px; }
#bpm { min-width: 5.2em; text-align: center; }

.hint, .credit {
  margin: 8px auto 0;
  padding: 0 12px;
  text-align: center;
  color: var(--pencil);
  font-size: 16px;
  line-height: 1.25;
  max-width: 60em;
}
.credit { font-size: 13px; margin-top: 4px; opacity: 0.8; }
.credit a { color: inherit; }

#toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translate(-50%, -8px) rotate(-1deg);
  background: #fff8b8;
  color: var(--ink);
  font-size: 19px;
  padding: 8px 14px 6px;
  box-shadow: 1px 3px 8px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0) rotate(-1deg); }

@media (max-width: 520px) {
  .btn { font-size: 19px; padding: 7px 9px 5px; }
  .btn.big { font-size: 21px; }
  .tempo { font-size: 18px; }
  #controls { gap: 6px 6px; margin-top: 10px; }
  .hint { font-size: 14px; }
  .credit { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .note.gone { transition: none; }
}

@media (max-height: 520px) {
  .hint { display: none; }
  #controls { margin-top: 8px; }
}
