/* Jazz Keys. One screen, no page scroll: bar on top, the chord in the middle, keys at the bottom.
   The look borrows from 1960s jazz record sleeves: one flat blue, heavy condensed type. */

@font-face {
  font-family: 'Big Shoulders Display';
  src: url('../fonts/big-shoulders-display.woff2') format('woff2');
  font-weight: 500 900;
  font-display: swap;
}

:root {
  --ground: #14248a;  /* the page */
  --well: #0b1560;    /* the tray the keys sit in */
  --paper: #f6f3ea;   /* white keys and text */
  --ink: #0a0f33;     /* black keys and text on light fills */
  --root: #ffc62e;    /* the root of a chord */
  --tone: #8fd3ff;    /* its other chord tones */
  --tension: #ff8a73; /* tensions */
  --dim: rgb(246 243 234 / 0.68);
  --line: rgb(246 243 234 / 0.26);

  --display: 'Big Shoulders Display', 'Arial Narrow', sans-serif;
  --text: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', sans-serif;

  --gutter: clamp(16px, 3.6vw, 44px);
  --pad-left: max(var(--gutter), env(safe-area-inset-left));
  --pad-right: max(var(--gutter), env(safe-area-inset-right));
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--paper);
  font: 500 15px/1.5 var(--text);
  /* This is an instrument: no text selection, long-press menus or double-tap zoom under the fingers. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--root); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Flat and sharp signs are drawn, not typed, so they match the weight of any text around them. */
.acc {
  display: inline-block;
  height: 0.8em;
  margin: 0 0.035em;
  vertical-align: -0.02em;
  background: currentColor;
  -webkit-mask: var(--glyph) center / contain no-repeat;
  mask: var(--glyph) center / contain no-repeat;
}
.acc.flat {
  width: 0.3em;
  --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 24'%3E%3Cpath fill-rule='evenodd' d='M.6 0h2.8v12.4C6 10.2 9.8 10.9 9.8 14.6c0 3.4-3.6 6.5-6.4 8.9H.6ZM3.4 15v5.2c1.7-1.5 3.6-3.300 3.600-5.100 0-1.700-2.100-1.500-3.600-.1Z'/%3E%3C/svg%3E");
}
.acc.sharp {
  width: 0.38em;
  --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 24'%3E%3Cpath d='M2.600 3.500h2v19.500h-2zM7.400 1h2v19.500h-2zM0 9.600l12-3.100v3.500L0 13.100zM0 16.400l12-3.100v3.500L0 19.900z'/%3E%3C/svg%3E");
}

/* ---------- top bar ---------- */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 22px;
  padding: calc(6px + env(safe-area-inset-top)) var(--pad-right) 0 var(--pad-left);
}
.brand {
  margin: 0;
  font: 800 25px/1 var(--display);
  letter-spacing: 0.025em;
}
.bar-end { display: flex; margin-left: auto; }

.tabs { display: flex; flex-wrap: wrap; gap: 0 2px; }
.tabs button {
  min-height: 44px;
  padding: 0 11px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--dim);
  font: 600 15px/1 var(--text);
}
.tabs button[aria-pressed='true'] { color: var(--paper); border-bottom-color: var(--paper); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  font: 500 14px/1 var(--text);
  white-space: nowrap;
}
.status .dot {
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--dim);
  border-radius: 50%;
}
.status.is-on .dot { border-color: var(--root); background: var(--root); }
/* Notes are arriving but the browser has not been allowed to make sound yet. */
.status.needs-tap { border-radius: 6px; background: var(--root); color: var(--ink); }
.status.needs-tap .dot { border-color: var(--ink); }

/* ---------- the view above the keys ---------- */

main {
  overflow-y: auto;
  padding: clamp(10px, 3dvh, 34px) var(--pad-right) clamp(8px, 2dvh, 20px) var(--pad-left);
}
.view {
  display: grid;
  gap: clamp(14px, 3dvh, 30px) 44px;
  align-content: start;
}
.hero { min-width: 0; }

.chord {
  margin: 0;
  font: 800 clamp(60px, min(21vw, 25dvh), 210px)/0.92 var(--display);
  white-space: nowrap;
}
.chord .suffix { margin-left: 0.03em; font-size: 0.6em; font-weight: 700; }
.chord .bass { margin-left: 0.05em; font-size: 0.6em; font-weight: 700; color: var(--dim); }
/* Korean phrases and loose note lists take the hero's place at a calmer size. */
.chord.is-words {
  font: 700 clamp(28px, min(8.5vw, 11dvh), 68px)/1.2 var(--text);
  letter-spacing: -0.02em;
  white-space: normal;
}
.chord.is-notes { font-size: clamp(38px, min(12vw, 15dvh), 110px); letter-spacing: 0.02em; white-space: normal; }

.spelled {
  min-height: 1.25em;
  margin: 0.4em 0 0;
  color: var(--dim);
  font: 600 clamp(20px, 3.4dvh, 32px)/1.25 var(--display);
  letter-spacing: 0.07em;
}
.spelled.is-words {
  max-width: 34em;
  font: 400 15px/1.6 var(--text);
  letter-spacing: 0;
}

/* Chord tones, tensions and substitutes. Each chip plays and shows its notes when pressed. */
.guide { display: grid; gap: 10px; align-content: start; }
.guide-row {
  display: grid;
  grid-template-columns: 4.3em minmax(0, 1fr);
  gap: 8px;
}
.guide-row h2 {
  margin: 0;
  padding-top: 12px;
  color: var(--dim);
  font: 600 13px/1.3 var(--text);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-height: 42px;
  padding: 9px 11px 6px;
  border: 1.5px solid var(--role, var(--line));
  border-radius: 4px;
  background: none;
  color: var(--paper);
}
.chip b { color: var(--role, var(--paper)); font: 800 22px/1 var(--display); letter-spacing: 0.01em; }
.chip > span { color: var(--dim); font: 600 17px/1 var(--display); letter-spacing: 0.03em; }
.chip.is-root { --role: var(--root); }
.chip.is-tone { --role: var(--tone); }
.chip.is-tension { --role: var(--tension); }
.chip.is-on { background: var(--role); }
.chip.is-on b, .chip.is-on > span { color: var(--ink); }
.chip.sub { padding-top: 7px; }
.chip.sub b { font-size: 26px; }
.chip.sub b .suffix { font-size: 0.72em; }
.chip.sub > span { font: 500 12.5px/1.2 var(--text); letter-spacing: 0; }
.chip:active { background: rgb(246 243 234 / 0.14); }

/* ---------- 2-5-1 ---------- */

.drill-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.drill-key { margin: 0; font: 700 clamp(17px, 3dvh, 24px)/1.2 var(--text); }
.ticks { display: flex; gap: 4px; }
.ticks span { width: 14px; height: 6px; background: var(--line); }
.ticks .done { background: var(--paper); }
.ticks .now { background: var(--root); }

.changes {
  display: flex;
  align-items: flex-end;
  gap: clamp(14px, 4.5vw, 56px);
  margin: clamp(10px, 2.4dvh, 26px) 0 0;
  padding: 0;
  list-style: none;
}
.changes li {
  display: grid;
  gap: 5px;
  padding-bottom: 7px;
  border-bottom: 5px solid transparent;
  color: var(--dim);
}
.changes li.now { border-bottom-color: var(--root); color: var(--paper); }
.changes .numeral { font: 600 clamp(14px, 2.2dvh, 19px)/1 var(--display); letter-spacing: 0.05em; }
.changes .sym { font: 800 clamp(38px, min(12vw, 17dvh), 124px)/0.92 var(--display); white-space: nowrap; }
.changes .sym .suffix { margin-left: 0.03em; font-size: 0.6em; font-weight: 700; }

.finish-title { margin: 0; font: 700 clamp(24px, min(7vw, 8dvh), 46px)/1.25 var(--text); letter-spacing: -0.02em; }
.finish-time { margin: 0.5em 0 1.1em; color: var(--dim); }

.options { display: grid; align-content: start; }
.option { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; min-height: 46px; }
.option-name { width: 4.6em; color: var(--dim); font: 600 13px/1.3 var(--text); }

/* ---------- 음 찾기 ---------- */

.ask { display: flex; flex-wrap: wrap; align-items: center; gap: 12px clamp(16px, 3.4vw, 40px); margin: 0; }
.ask-degree {
  padding: 0.14em 0.3em 0.07em;
  border: 3px solid currentColor;
  border-radius: 6px;
  font: 800 clamp(36px, min(12vw, 14dvh), 112px)/1 var(--display);
}
.ask-degree.is-tone { color: var(--tone); }
.ask-degree.is-tension { color: var(--tension); }
.feedback { min-height: 1.6em; margin: 0.9em 0 0; color: var(--dim); font-size: 16px; }
.feedback.right { color: var(--paper); font-weight: 700; }
.streak { font: 800 30px/1 var(--display); }

/* ---------- keys ---------- */

.deck {
  padding: 8px var(--pad-right) calc(10px + env(safe-area-inset-bottom)) var(--pad-left);
  background: var(--well);
}
.tools { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
.tools-gap { flex: 1; }
.tool {
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  font: 600 14px/1 var(--text);
  white-space: nowrap;
}
.tool:active { background: rgb(246 243 234 / 0.14); }
.tool[aria-pressed='true'] { border-color: var(--paper); background: var(--paper); color: var(--ink); }
.tool:disabled { opacity: 0.4; cursor: default; }
.octave { position: relative; min-width: 40px; padding: 0 0 3px; font-size: 22px; }
/* How many sounding notes are out of sight on that side. */
.octave[data-count]::after {
  content: attr(data-count);
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--root);
  color: var(--ink);
  font: 700 11px/18px var(--text);
}
.range {
  min-width: 4.4em;
  color: var(--dim);
  font: 600 16px/1 var(--display);
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
}

.keys {
  position: relative;
  display: flex;
  height: clamp(124px, 33dvh, 310px);
  touch-action: none; /* fingers play; they never scroll or zoom from here */
}
.key { position: relative; }
.key.white {
  flex: 1;
  border-radius: 0 0 5px 5px;
  background: var(--paper);
  box-shadow: inset -1px 0 0 rgb(10 15 51 / 0.3);
}
.key.black {
  position: absolute;
  z-index: 1;
  top: 0;
  height: 62%; /* keep in step with BLACK_HEIGHT in keyboard.js */
  border-radius: 0 0 4px 4px;
  background: var(--ink);
  box-shadow: inset 0 -6px 0 rgb(246 243 234 / 0.1);
}
.mark, .cname {
  position: absolute;
  right: 0;
  left: 0;
  text-align: center;
  pointer-events: none;
  font-family: var(--display);
  line-height: 1;
}
.cname { bottom: 8px; color: rgb(10 15 51 / 0.5); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.mark { bottom: 10px; color: var(--ink); font-size: clamp(14px, 2.3dvh, 19px); font-weight: 800; }
.key.black .mark { bottom: 9px; font-size: clamp(12px, 1.9dvh, 15px); }
.key[class*='is-'] .cname { display: none; }

.key.is-root { --fill: var(--root); }
.key.is-tone { --fill: var(--tone); }
.key.is-tension { --fill: var(--tension); }
.key.is-plain { --fill: #b6bad6; }
/* A held key takes its role's colour whole. */
.key[class*='is-']:not(.is-ghost) { background: var(--fill); }
.key.white[class*='is-']:not(.is-ghost) { box-shadow: inset -1px 0 0 rgb(10 15 51 / 0.3), inset 0 8px 12px -6px rgb(10 15 51 / 0.35); }
/* A ghost is a note being pointed at, not played: the key stays as it is and carries a badge. */
.key.is-ghost .mark {
  right: auto;
  left: 50%;
  min-width: 1.55em;
  padding: 0.24em 0.22em 0.14em;
  border-radius: 1em;
  background: var(--fill);
  box-shadow: 0 0 0 1.5px var(--ink);
  transform: translateX(-50%);
}
.key.black.is-ghost .mark { box-shadow: none; }

/* ---------- help dialog ---------- */

dialog {
  max-width: min(440px, calc(100vw - 32px));
  padding: 22px;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.65 var(--text);
  -webkit-user-select: text;
  user-select: text;
}
dialog::backdrop { background: rgb(5 9 40 / 0.62); }
dialog h2 { margin: 0 0 10px; font: 700 18px/1.4 var(--text); }
dialog p { margin: 0 0 10px; }
dialog ul { margin: 0 0 10px; padding-left: 1.2em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .tool { border-color: rgb(10 15 51 / 0.35); }
dialog .tool:active { background: rgb(10 15 51 / 0.08); }
#midi-connect { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* ---------- layouts ---------- */

/* Wide enough for two columns: the chord on the left, its breakdown or the options on the right. */
@media (min-width: 760px) {
  .view { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; }
  .guide, .options { padding-top: clamp(4px, 1.5dvh, 16px); }
}

/* Phones held upright: the three views get their own row under the name. */
@media (max-width: 620px) {
  .bar { gap: 0 8px; }
  #modes { order: 3; flex-basis: 100%; margin-left: -11px; }
  .status { padding: 0 6px; font-size: 13px; }
  #midi-label { max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; }
  .tools { gap: 5px; }
  .tool { padding: 0 8px; font-size: 13px; }
  .octave { min-width: 36px; }
  .range { min-width: 0; font-size: 14px; letter-spacing: 0.02em; }
}

/* Phones on their side: very little height, so everything tightens. */
@media (max-height: 470px) {
  .brand { font-size: 20px; }
  .tabs button, .status { min-height: 38px; }
  main { padding-top: 6px; padding-bottom: 4px; }
  .view { gap: 8px 28px; }
  .guide { gap: 4px; }
  .guide-row h2 { padding-top: 9px; }
  .chip { min-height: 34px; padding: 6px 8px 3px; }
  .chip b { font-size: 18px; }
  .chip > span { font-size: 14px; }
  .chip.sub b { font-size: 20px; }
  .option { min-height: 38px; }
  .deck { padding-top: 5px; }
  .tools { padding-bottom: 5px; }
  .tool { min-height: 34px; }
  .keys { height: clamp(112px, 38dvh, 200px); }
}

@media (prefers-reduced-motion: no-preference) {
  .chip, .tool, .tabs button { transition: background-color 0.12s, color 0.12s, border-color 0.12s; }
}
