:root {
  --bg: #16100e;
  --bg-panel: #211714;
  --bg-inset: #180f0c;
  --line: #3a2822;
  --ink: #f3e6d8;
  --ink-dim: #a8907f;
  --accent: #ff9d5c;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  background:
    radial-gradient(1200px 700px at 50% 120%, #2a1a12 0%, transparent 60%),
    radial-gradient(900px 500px at 85% -10%, #241420 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  display: flex;
  flex-direction: column;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px 10px;
  flex-wrap: wrap;
}
h1 {
  font-family: "Unbounded", sans-serif;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #ffb36b, #ff6d9c, #b58cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
h1 span { font-weight: 400; opacity: 0.85; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.group {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 8px;
}
/* The class `.groupTag` gives the same appearance as a `.group label`. The
   code uses it where a caption applies to more than one control, such as the
   octave buttons and the view buttons. */
.group label, .group .groupTag, .setRow > label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
select, button.ctl {
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 4px;
  outline-offset: 2px;
}
select:disabled { color: var(--ink-dim); cursor: default; }
select:focus-visible, button.ctl:focus-visible, input:focus-visible, button.cell:focus-visible {
  outline: 2px solid var(--accent);
  border-radius: 6px;
}
select option, select optgroup { background: var(--bg-panel); color: var(--ink); }
button.ctl {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 26px;
  transition: background 0.15s, border-color 0.15s;
}
button.ctl:hover { background: #2e201a; border-color: #55392e; }
button.ctl.on {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(255, 157, 92, 0.35);
}
#octLabel { min-width: 3ch; text-align: center; font-size: 12px; }
#zoomLabel { min-width: 4ch; text-align: center; font-size: 12px; color: var(--ink-dim); }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 90px; height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #ff9d5c, #ff5c8a);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 8px rgba(255, 157, 92, 0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: none; border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 8px rgba(255, 157, 92, 0.6);
}

#stage { flex: 1; position: relative; outline: none; }
/* A border that shows that the instrument holds the keyboard. */
#stage.capturing::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 157, 92, 0.5);
}
svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#stage.panning svg { cursor: grab; }
#stage.panning.dragging svg { cursor: grabbing; }

.hex { cursor: pointer; }
#stage.panning .hex { cursor: grab; }
/* A hex outside the scale that is silent, or a grey copy of a note that is
   already on the screen. */
.hex.muted, .hex.duplicate { pointer-events: none; }
.hex .halo {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease-out;
}
.hex polygon { transition: fill 0.2s ease-out, stroke 0.2s ease-out; }
.hex text {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  fill: var(--ink-dim);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  transition: fill 0.2s;
}
.hex.root text { font-weight: 500; fill: var(--ink); }
.hex.out text { opacity: 0.32; }
.hex.duplicate text { opacity: 0.4; }
.hex.active polygon { transition: none; }
.hex.active text { fill: #fff; opacity: 1; transition: none; }

/* The rows have a fixed height. The display line fills and empties while the
   user holds notes. A footer with a variable height changes the size of the
   stage and moves the board. */
footer {
  padding: 8px 20px 12px;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.03em;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 3px 16px;
}
#boardInfo {
  grid-area: 1 / 1;
  color: var(--ink);
  opacity: 0.75;
}
#readout {
  grid-area: 2 / 1;
  color: var(--accent);
  min-height: 15px;
}
#boardInfo, #readout, #hints {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#hints { grid-area: 1 / 2 / span 2 / 2; text-align: right; }
@media (max-width: 900px) {
  /* There is not sufficient width for two columns. The hints line moves
     below the other lines. Its row keeps a fixed height. */
  footer { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; }
  #hints { grid-area: 3 / 1; text-align: left; white-space: normal; }
}

/* ---------- The settings dialog ---------- */
#modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 6, 5, 0.65);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#modal[hidden] { display: none; }
#modalPanel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(760px, 96vw);
  max-height: 88vh;
  overflow: auto;
  padding: 18px 22px 22px;
  box-shadow: 0 0 44px rgba(255, 140, 80, 0.12);
}
.modalHead { display: flex; align-items: center; justify-content: space-between; }
.modalHead h2 {
  font-family: "Unbounded", sans-serif;
  font-size: 14px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--accent);
}
#modalPanel section {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
#modalPanel h3 {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-dim); margin-bottom: 10px; font-weight: 500;
}
.setRow { display: flex; align-items: center; gap: 12px; margin: 9px 0; flex-wrap: wrap; }
.setRow > label { width: 150px; }
#modalPanel select, #modalPanel input[type="number"] {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  padding: 4px 7px;
  font-family: inherit; font-size: 12px;
}
#modalPanel input[type="number"] { width: 86px; }
#modalPanel input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
#modalPanel input[type="checkbox"]:disabled { opacity: 0.4; }
button.ctl:disabled { opacity: 0.45; cursor: default; }
.hint { font-size: 11px; color: var(--ink-dim); line-height: 1.5; margin: 6px 0 12px; }
#tuningError:empty { display: none; }
#tuningError { color: #ff8b6b; }
#modalPanel input[type="file"] {
  font-family: inherit; font-size: 11px; color: var(--ink-dim);
  max-width: 240px;
}
#modalPanel input[type="file"]::file-selector-button {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-family: inherit; font-size: 11px;
  padding: 4px 9px; margin-right: 8px;
  cursor: pointer;
}
#modalPanel input[type="file"]::file-selector-button:hover { border-color: #55392e; }
#mosGroup[hidden] { display: none; }
.hint b { color: var(--ink); font-weight: 500; }

#degreeDetails { margin: 10px 0 4px; }
#degreeDetails summary {
  font-size: 11px; color: var(--ink-dim); cursor: pointer; letter-spacing: 0.04em;
}
#degreeDetails summary:hover { color: var(--ink); }
#degreeEditor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 5px 12px;
  margin: 10px 0 4px;
  max-height: 220px;
  overflow: auto;
}
.degreeRow { display: flex; align-items: center; gap: 8px; }
.degreeRow .degreeTag {
  width: 68px; font-size: 10px; color: var(--ink-dim); letter-spacing: 0.04em;
}
.degreeRow input[type="number"] { width: 84px; }
.degreeRow input:disabled { opacity: 0.45; }

.mapRow { display: flex; gap: 4px; margin: 5px 0; align-items: center; }
.mapRow .rowTag { width: 66px; font-size: 10px; color: var(--ink-dim); letter-spacing: 0.06em; }
#mapEditor { overflow-x: auto; }
button.cell {
  width: 38px; height: 34px; flex: none;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-family: inherit; font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
button.cell:hover { border-color: #55392e; }
button.cell.empty { color: #5a463c; }
/* This key plays a note that the main area also plays. */
button.cell.echo { opacity: 0.42; border-style: dashed; }
button.cell.arming {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 9px rgba(255, 157, 92, 0.55);
}
#captureHint { min-height: 16px; font-size: 11px; color: var(--accent); margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .hex, .hex polygon, .hex text { transition: none !important; }
}
