/* Retro console UI: one pixel font, hard edges, four colours. No blur, no gradients, no radii. */
:root {
  --ink: #14141a;
  --ink-2: #2a2a35;
  --paper: #efe6d6;
  --paper-2: #a89f8c;
  --lime: #c6f24e;
  --lime-2: #86a82c;
  --hot: #ff5c39;
  --u: 2px;                                   /* the pixel: borders and shadows are multiples of it */
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--ink); color: var(--paper);
  font: 16px/1.25 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', sans-serif;
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-font-smoothing: none;
}
button, input, output { font: inherit; color: inherit; border-radius: 0; }
[hidden] { display: none !important; }

#app {
  height: 100vh; height: 100dvh; display: grid;
  grid-template: "stage" minmax(0, 1fr) "bar" auto "dock" auto / minmax(0, 1fr);
}

/* ---------- stage ---------- */
#stage { grid-area: stage; position: relative; overflow: hidden; background: var(--paper); color: var(--ink); }
#view { position: absolute; left: 0; top: 0; image-rendering: pixelated; }

#hud {
  position: absolute; inset: 0 0 auto 0; display: flex; align-items: flex-start; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 0; pointer-events: none; transition: opacity .3s steps(3);
}
#hud.away { opacity: 0; }
#now { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
#title { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tag { padding: 2px 6px; background: var(--ink); color: var(--paper); font-size: 12px; letter-spacing: 1px; white-space: nowrap; }
.tag.lime { background: var(--lime); color: var(--ink); outline: var(--u) solid var(--ink); outline-offset: calc(-1 * var(--u)); }
.tag.lime.hot { background: var(--hot); }                 /* the chorus */
.tag.busy { animation: blink 1.1s steps(1) infinite; }

#prompt { position: absolute; inset: auto 0 14px 0; text-align: center; pointer-events: none; animation: blink 1.1s steps(1) infinite; }
#prompt.away { display: none; }
@keyframes blink { 50% { opacity: 0; } }

#toast {
  position: absolute; left: 50%; top: calc(56px + env(safe-area-inset-top)); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); padding: 8px 12px; z-index: 3;
  background: var(--ink); color: var(--paper); border: var(--u) solid var(--hot); display: none;
}
#toast.show { display: block; }

/* ---------- buttons: keys with a lip that sinks when pressed ---------- */
.btn {
  min-height: 48px; margin-bottom: 4px; padding: 0 14px; cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
  border: var(--u) solid var(--ink); background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--paper-2);
}
.btn:active, .btn.down { transform: translateY(4px); box-shadow: none; }
.btn.lime { background: var(--lime); box-shadow: 0 4px 0 var(--lime-2); }
.btn small { font-size: 12px; opacity: .7; }

/* ---------- control bar ---------- */
#bar {
  grid-area: bar; position: relative; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 6px; background: var(--ink); border-top: var(--u) solid var(--paper);
}
#bar .btn { padding: 0 10px; }
#pips { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; }
#pips i { width: 8px; height: 12px; background: var(--ink-2); }
#pips i:nth-child(4n+1) { height: 22px; }                 /* the first beat of each bar stands taller */
#pips i.on { background: var(--lime); }
#pips.hot i.on { background: var(--hot); }
#open-tempo { flex-direction: row; align-items: baseline; gap: 6px; }
#open-tempo b { font-size: 32px; font-weight: 400; line-height: 44px; }
#open-tempo.unset b { color: var(--paper-2); }            /* no tempo for this song yet */
#open-help { width: 44px; padding: 0; }

/* ---------- sheets: open over the bottom of the stage, never over the player ---------- */
#sheets {
  grid-area: stage; align-self: end; position: relative; z-index: 2; max-height: 100%; overflow-y: auto;
  padding: 0 8px 8px; pointer-events: none;
}
.sheet {
  display: none; gap: 8px; padding: 10px; pointer-events: auto;
  background: var(--ink); color: var(--paper); border: var(--u) solid var(--paper); box-shadow: 4px 4px 0 rgba(20, 20, 26, .45);
}
.sheet.open { display: grid; animation: rise .16s steps(4) both; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet header { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.sheet h2 { padding: 2px 6px; background: var(--lime); color: var(--ink); font-size: 12px; font-weight: 400; letter-spacing: 2px; }
.sheet h3 { color: var(--paper-2); font-size: 12px; font-weight: 400; letter-spacing: 2px; }
.x { margin-left: auto; width: 44px; height: 44px; border: var(--u) solid var(--paper-2); background: none; font-size: 16px; cursor: pointer; }
.x:active { background: var(--ink-2); }
.row { display: grid; gap: 8px; }
.note { color: var(--paper-2); font-size: 12px; }

#bpm { margin-left: 6px; font-size: 48px; line-height: 48px; }
.unit { align-self: flex-end; padding-bottom: 6px; color: var(--paper-2); font-size: 12px; }
.pads { grid-template-columns: 2fr 1fr; }
.pads .btn { min-height: 84px; }
#tap { font-size: 32px; gap: 4px; }
.keys { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.keys .btn, .timing .btn { padding: 0 4px; }
.auto [data-manual] { display: none; }                    /* following the heard beat: nothing to fine-tune */
.timing { grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1fr); align-items: center; }
#timing { text-align: center; padding-bottom: 4px; }

#sheet-help dl { display: grid; gap: 3px; }
#sheet-help dt { justify-self: start; margin-top: 5px; padding: 0 6px; background: var(--paper); color: var(--ink); font-size: 12px; letter-spacing: 1px; }
#sheet-help dd { margin: 0; font-size: 14px; line-height: 1.45; }
.phone .pc { display: none; }

#track-form { grid-template-columns: minmax(0, 1fr) auto; }
#url {
  height: 48px; padding: 0 10px; outline: none; -webkit-user-select: text; user-select: text;
  border: var(--u) solid var(--paper-2); background: var(--ink-2);
}
#url:focus { border-color: var(--lime); }
#url::placeholder { color: var(--paper-2); }
#recent { list-style: none; padding: 0; display: grid; gap: 6px; max-height: 174px; overflow-y: auto; scrollbar-width: none; }
#recent::-webkit-scrollbar { display: none; }
#recent button {
  width: 100%; min-height: 52px; padding: 4px; display: grid; grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center; gap: 10px; text-align: left; cursor: pointer;
  border: var(--u) solid var(--ink-2); background: var(--ink-2);
}
#recent button.cur { border-color: var(--lime); }
#recent img { display: block; width: 64px; height: 36px; object-fit: cover; }
#recent .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#recent .b { padding-right: 6px; color: var(--lime); }
#recent .empty { color: var(--paper-2); font-size: 12px; }

#qr { justify-self: center; width: 200px; height: 200px; image-rendering: pixelated; border: 8px solid var(--paper); }
#lan-url { text-align: center; -webkit-user-select: text; user-select: text; overflow-wrap: anywhere; }
#lan { grid-auto-flow: column; }
#lan:empty { display: none; }

/* ---------- player ---------- */
#dock { grid-area: dock; display: grid; justify-content: center; background: #000; padding-bottom: env(safe-area-inset-bottom); }
#screen { width: min(100vw, 36dvh * 16 / 9); aspect-ratio: 16 / 9; }
#screen iframe { display: block; width: 100%; height: 100%; border: 0; }

/* ---------- wide screens: player and controls in a column beside the stage ---------- */
#side { display: none; }
@media (min-aspect-ratio: 1/1) and (min-width: 720px) {
  #app { grid-template: "stage side" minmax(0, 1fr) "stage bar" auto "stage dock" auto / minmax(0, 1fr) 380px; }
  #side {
    grid-area: side; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 12px;
    padding: 20px 16px; border-left: var(--u) solid var(--paper);
  }
  .logo { color: var(--lime); font-size: 48px; font-weight: 400; line-height: 1; }
  #bar, #dock { border-left: var(--u) solid var(--paper); }
  #screen { width: 378px; }
  #sheets { justify-self: end; width: 372px; }             /* short window: a corner of the stage */
}
@media (min-aspect-ratio: 1/1) and (min-width: 720px) and (max-height: 639px) {
  #side { padding: 12px 16px; }
  #side p, .logo br { display: none; }                     /* a phone on its side: one line of logo is all that fits */
  .logo { font-size: 32px; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 720px) and (min-height: 640px) {
  #sheets { grid-area: side; width: auto; justify-self: stretch; padding-top: 8px; }     /* room beside the stage */
}

@media (prefers-reduced-motion: reduce) {
  #prompt, .tag.busy { animation: none; }
}
