/* Nitrided steel instrument panel.
   A handpan is hammered steel, nitrided until the surface carries temper
   colours over graphite. The console borrows them: straw for a struck field,
   blue for the ding and the playhead, violet for what is selected, patina for
   the beds that hold everything up. */

:root {
  --ground: #0d1012;
  --etch: #161b1e;
  --ridge: #232a2e;
  --ink: #dfe6e9;
  --steel: #8fa3ac;
  --faint: #5d6a70;
  --straw: #d6a03c;
  --blue: #4e7fd8;
  --violet: #8a6bd1;
  --patina: #4fa391;
  --ui: Archivo, "Helvetica Neue", Arial, sans-serif;
  --mono: "Azeret Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "Instrument Serif", Georgia, serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #dde3e5;
    --etch: #eef2f3;
    --ridge: #b4c0c4;
    --ink: #161b1d;
    --steel: #3f4c52;
    --faint: #6d7c82;
    --straw: #a4701a;
    --blue: #2f5fbb;
    --violet: #6a4cb5;
    --patina: #2f7a6b;
  }
}

* { box-sizing: border-box; }

/* Anything given a display value here would otherwise outrank the browser's
   own [hidden] rule, so hiding it in JS would silently do nothing. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom, 0px));
  max-width: 1440px;
  margin: 0 auto;
}

/* --- head ---------------------------------------------------------------- */

.panel-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 0 12px;
  /* Solid, not a fade: a gradient to transparent let the page scroll through
     the gap between the buttons and the rule below them. */
  background: var(--ground);
  border-bottom: 1px solid var(--ridge);
  box-shadow: 0 10px 22px -18px rgba(0, 0, 0, .9);
}

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(24px, 4vw, 32px);
  letter-spacing: .01em;
  margin: 0;
  color: var(--ink);
}

.transport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.key {
  font: 500 12px/1 var(--ui);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--steel);
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-radius: 3px;
  padding: 9px 14px;
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.key:hover { color: var(--ink); border-color: var(--steel); }
.key:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.key-primary {
  color: var(--ground);
  background: var(--straw);
  border-color: var(--straw);
  font-weight: 600;
}
.key-primary:hover { color: var(--ground); filter: brightness(1.07); }
.key.key-primary kbd {
  /* On the filled button the chip has to sit *in* the surface, not draw a box
     on top of it: a bordered grey chip on straw reads as disabled. The extra
     class is load-bearing: the generic `.key kbd` rule sits further down the
     file and would otherwise win on source order. */
  color: var(--ground);
  background: rgba(0, 0, 0, .16);
  border-color: transparent;
  opacity: .85;
}
.head-right { margin-left: auto; position: relative; }
.key-icon { padding: 8px 10px; line-height: 0; }
.key-icon svg { display: block; }
.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 240px;
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-radius: 4px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .35);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--steel);
  font-size: 13px;
}
.seg { display: flex; }
.seg .tog { border-radius: 0; margin-left: -1px; }
.seg .tog:first-child { border-radius: 2px 0 0 2px; margin-left: 0; }
.seg .tog:last-child { border-radius: 0 2px 2px 0; }
.tog[aria-current="true"] { color: var(--ground); background: var(--straw); border-color: var(--straw); }
.key kbd {
  font: 400 9px/1 var(--mono);
  border: 1px solid var(--ridge);
  border-radius: 2px;
  padding: 2px 3px;
  margin-left: 6px;
  color: var(--faint);
  vertical-align: 1px;
}
.key.is-working { color: var(--straw); border-color: var(--straw); }
.key.is-working::after {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  margin-left: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.key[disabled] { opacity: .4; cursor: not-allowed; }
.key[aria-pressed="true"] { color: var(--ground); background: var(--straw); border-color: var(--straw); }

.readout {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--steel);
  padding-left: 4px;
}

.status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .03em;
  color: var(--faint);
  border-left: 1px solid var(--ridge);
  padding-left: 12px;
  min-width: 15ch;
}
.status[data-state="work"] { color: var(--straw); }
.status[data-state="bad"] { color: var(--violet); }

.guide-close {
  position: absolute;
  top: 10px;
  right: 12px;
  font: 500 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  background: transparent;
  border: 1px solid var(--ridge);
  border-radius: 2px;
  padding: 6px 8px;
  cursor: pointer;
}
.guide-close:hover { color: var(--ink); border-color: var(--steel); }

.guide {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px 22px;
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-radius: 4px;
  padding: 16px 18px;
  margin-top: 14px;
}
.guide h2 {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 4px;
}
.guide p { margin: 0; color: var(--steel); font-size: 13px; max-width: 52ch; }
.guide b { color: var(--ink); font-weight: 500; }

/* --- wells --------------------------------------------------------------- */

main {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
  padding-block: 14px;
}
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } }

.well {
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-radius: 4px;
  padding: 10px 12px 12px;
  min-width: 0;
}

.well-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
}
.hint { text-transform: none; letter-spacing: .02em; font-family: var(--ui); font-size: 11px; }
.well-label .stats {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  text-transform: none;
  letter-spacing: .02em;
}
.well-label .stats b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--steel);
  font-weight: 500;
}
.pan-keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--ridge);
}

.pan-well { display: flex; flex-direction: column; align-items: center; }
#pan { width: 100%; max-width: 320px; height: auto; touch-action: manipulation; cursor: pointer; }
.pan-meta {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 320px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  padding-top: 8px;
}

.roll-wrap { position: relative; }
/* The pattern is usually wider than its panel; this says so at the edge. */
.roll-wrap::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 9px;
  width: 34px;
  pointer-events: none;
  background: linear-gradient(to right, transparent, var(--etch));
  opacity: var(--edge, 1);
  transition: opacity .15s;
}
.zoom { display: flex; gap: 4px; margin-left: 10px; }
.zoom .tog { padding: 3px 7px; }

.roll-scroll { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; scrollbar-color: var(--ridge) transparent; }
.roll-scroll::-webkit-scrollbar { height: 9px; }
.roll-scroll::-webkit-scrollbar-track { background: transparent; }
.roll-scroll::-webkit-scrollbar-thumb { background: var(--ridge); border-radius: 5px; }
#roll { display: block; touch-action: pan-x pan-y; cursor: crosshair; }

/* --- layer strips -------------------------------------------------------- */

.strips { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 14px; }

.strip {
  flex: 1 1 230px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-left: 3px solid var(--kind, var(--steel));
  border-radius: 3px;
  padding: 9px 10px;
  cursor: pointer;
}
.strip[aria-selected="true"] {
  border-color: var(--violet);
  border-left-color: var(--kind, var(--violet));
  background: color-mix(in srgb, var(--violet) 9%, var(--etch));
}
.strip .lvl {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--faint);
  min-width: 4ch;
  text-align: right;
}
.strip[data-edited="true"] .sub::after {
  content: " · edited";
  color: var(--straw);
}
.strip .nm { font-size: 13px; color: var(--ink); }
.strip .sub { font-family: var(--mono); font-size: 10px; color: var(--faint); letter-spacing: .05em; }
.strip input[type="range"] { width: 100%; accent-color: var(--kind, var(--straw)); }
.tog {
  font: 500 10px/1 var(--mono);
  color: var(--faint);
  background: transparent;
  border: 1px solid var(--ridge);
  border-radius: 2px;
  padding: 5px 6px;
  cursor: pointer;
}
.tog[aria-pressed="true"] { color: var(--ground); background: var(--straw); border-color: var(--straw); }

/* --- racks --------------------------------------------------------------- */

.racks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

.rack {
  background: var(--etch);
  border: 1px solid var(--ridge);
  border-radius: 4px;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.rack h2 {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0;
}

.knob { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; align-items: baseline; }
.knob label { color: var(--steel); font-size: 13px; }
.knob output {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink);
}
.knob input[type="range"], .knob select, .knob input[type="text"] { grid-column: 1 / -1; width: 100%; }
.knob .note { grid-column: 1 / -1; margin: 0; font-size: 11px; color: var(--faint); }

input[type="range"] { accent-color: var(--straw); height: 22px; }
select, input[type="text"] {
  font: 400 13px/1.2 var(--ui);
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--ridge);
  border-radius: 3px;
  padding: 8px 9px;
}
select:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.switches { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.switches label { display: flex; align-items: center; gap: 7px; color: var(--steel); font-size: 13px; }
input[type="checkbox"] { accent-color: var(--straw); width: 15px; height: 15px; }

.row { display: flex; gap: 8px; align-items: center; }
.row select { flex: 1 1 auto; min-width: 0; }

.history { display: flex; flex-direction: column; gap: 2px; }
.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--ridge);
  padding: 7px 0;
}
.history-item:first-child { border-top: 0; }
.history-item .h-name { font-size: 13px; color: var(--ink); }
.history-item .h-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: .04em;
}
.history-item .tog { padding: 4px 8px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 500; }
.stats span { font-size: 10px; color: var(--faint); letter-spacing: .04em; }

footer {
  padding-block: 16px;
  margin-top: 14px;
  border-top: 1px solid var(--ridge);
  font-size: 12px;
  color: var(--faint);
}
#engineLine { font-family: var(--mono); }

@media (max-width: 560px) {
  .panel-head { gap: 8px 10px; padding-bottom: 10px; }
  .head-right { margin-left: 0; width: 100%; }
  .head-right .key { flex: 1 1 auto; }
  h1 { font-size: 22px; width: 100%; }
  .transport { width: 100%; gap: 6px; }
  .key { padding: 10px 11px; flex: 1 1 auto; }
  .key kbd { display: none; }
  .key-ghost { margin-left: 0; }
  .readout { width: 100%; padding-left: 0; }
  .status { width: 100%; border-left: 0; padding-left: 0; min-width: 0; }
  .well-label .stats { margin-left: 0; width: 100%; }
  .pan-keys { grid-template-columns: 1fr; }
  .strip { grid-template-columns: 1fr auto auto auto; }
  .strip .lvl { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
