:root {
  --bg:    #111;
  --panel: #1a1a1a;
  --fg:    #eee;
  --muted: #888;
  --line:  #2a2a2a;
  --hot:   #6cd06c;
  --warn:  #ff7a7a;
  --admin: #ffb84d;
  --blue:  #6cd0ff;
  --pink:  #ff6cb0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none; touch-action: manipulation;
}
body { display: flex; flex-direction: column; min-height: 100vh; }

header {
  padding: 12px 16px 8px;
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px solid var(--line);
}
header .who   { font-size: 16px; font-weight: 600; }
header .meta-group { display: flex; gap: 8px; align-items: center; }
header .meta  { color: var(--muted); font-size: 12px; }
header .meta.started { color: var(--hot); }
header .meta.warn    { color: var(--warn); }
header .reload {
  padding: 2px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer; line-height: 1;
}
header .reload:hover, header .reload:active {
  color: var(--fg); border-color: var(--fg);
}

main {
  flex: 1; padding: 14px 16px 24px;
  display: flex; flex-direction: column; gap: 14px;
  max-width: 720px; width: 100%; margin: 0 auto;
}

h1 { margin: 0; font-size: 22px; letter-spacing: 0.04em; }
h2 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; }
h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
p  { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.4; }

input, select, button {
  font-family: inherit; font-size: 16px;
}
input[type=text], input[type=password], input[type=number], textarea {
  padding: 12px 14px; border-radius: 10px;
  background: #1a1a1a; color: var(--fg); border: 1px solid var(--line);
  width: 100%;
}
textarea { min-height: 80px; resize: vertical; font-family: inherit; font-size: 14px; }
button {
  padding: 12px 16px; border-radius: 10px; border: 0;
  background: var(--fg); color: var(--bg); font-weight: 600; cursor: pointer;
}
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
button.hot   { background: #1f3a1f; color: var(--hot); border: 2px solid var(--hot); }
button.warn  { background: #3a1f1f; color: var(--warn); border: 1px solid var(--warn); }
button:disabled { opacity: 0.4; cursor: default; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.err { color: var(--warn); font-size: 12px; padding: 4px 0; min-height: 14px; }
.footer-note { color: var(--muted); font-size: 11px; padding: 8px 0; text-align: center; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

/* roster chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; padding: 4px; }
.chip {
  padding: 4px 10px; border-radius: 999px;
  background: #1a1a1a; border: 1px solid var(--line);
  font-size: 13px; display: inline-flex; gap: 6px; align-items: center;
}
.chip.me    { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip.admin { border-color: var(--admin); color: var(--admin); }
.chip.offline { opacity: 0.5; font-style: italic; }
.chip-name { font-weight: 600; }
.chip .role-tag {
  padding: 1px 6px; border-radius: 6px;
  background: rgba(108, 208, 108, 0.18); color: var(--hot);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  border: 1px solid rgba(108, 208, 108, 0.35);
}
.chip .role-tag.admin {
  background: rgba(255, 184, 77, 0.18); color: var(--admin);
  border-color: rgba(255, 184, 77, 0.45);
}
.chip.me .role-tag {
  background: rgba(255,255,255,0.85); color: #1a4a1a; border-color: #1a4a1a;
}
.chip.me .role-tag.admin { color: #5a3a14; border-color: #5a3a14; }
.roster-empty { color: var(--muted); font-style: italic; font-size: 13px; padding: 4px 8px; }

/* join-screen role tiles */
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.role-tile {
  padding: 14px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #1a1a1a;
  text-align: center; font-weight: 600; font-size: 15px;
  cursor: pointer; user-select: none;
}
.role-tile.on        { border-color: var(--hot); color: var(--hot); background: #1f3a1f; }
.role-tile.admin     { border-color: var(--admin); }
.role-tile.admin.on  { background: #3a2a14; color: var(--admin); border-color: var(--admin); }

/* lobby banner */
.lobby-banner {
  text-align: center; padding: 14px; border-radius: 10px;
  background: #2a2a1a; border: 1px solid var(--line); color: var(--muted);
}
.lobby-banner.admin-can-start { background: #1a2a1a; border-color: var(--hot); color: var(--hot); }

/* ── tab bar ── */
.tabbar {
  display: flex; gap: 4px; overflow-x: auto; padding: 6px 4px;
  border-bottom: 1px solid var(--line); margin: -8px -16px 6px;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar .tab {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none;
  white-space: nowrap;
}
.tabbar .tab.active { background: var(--panel); color: var(--fg); border: 1px solid var(--line); }

/* ── sensor card (generic) ── */
.sensor {
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); padding: 10px 12px;
}
.sensor.on   { border-color: var(--hot); }
.sensor h3   { display: flex; justify-content: space-between; align-items: center; }
.sensor .v   { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-all; }
.sensor .toggle {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  cursor: pointer;
}
.sensor.on .toggle { color: var(--hot); border-color: var(--hot); }

.cards { display: grid; gap: 10px; grid-template-columns: 1fr; }

/* ── touchpad / multitouch ── */
.touchpad {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  background: repeating-linear-gradient(45deg, #181818 0 10px, #1a1a1a 10px 20px);
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; touch-action: none;
}
.touchpad .dot {
  position: absolute; width: 36px; height: 36px;
  border: 2px solid var(--hot); border-radius: 50%;
  transform: translate(-50%, -50%); pointer-events: none;
}
.touchpad .dot span {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--hot);
}

/* ── video preview ── */
.video-prev {
  width: 100%; max-height: 240px; border-radius: 8px; background: #000;
  object-fit: cover;
}

/* ── buttons grid ── */
.pad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pad {
  aspect-ratio: 1 / 1; border-radius: 12px;
  border: 1px solid var(--line); background: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: var(--muted);
  user-select: none; touch-action: manipulation;
}
.pad.down { background: var(--hot); color: var(--bg); border-color: var(--hot); transform: scale(0.97); }

/* ── sliders + dials ── */
.slider-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.slider-row label { min-width: 60px; font-size: 12px; color: var(--muted); }
.slider-row input[type=range] { flex: 1; }
.slider-row .v { min-width: 60px; text-align: right; font-variant-numeric: tabular-nums; color: var(--fg); font-size: 12px; }

.dial-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dial-cell { text-align: center; }
.dial {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: 50%; border: 2px solid var(--line); background: #1a1a1a;
  touch-action: none; user-select: none;
}
.dial .indicator {
  position: absolute; left: 50%; top: 10%; width: 4px; height: 40%;
  background: var(--hot); transform-origin: 50% 100%;
  transform: translateX(-50%);
  border-radius: 2px;
}
.dial-label { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── text keyboard ── */
.text-keyboard textarea { font-size: 18px; }

/* ── MIDI keyboard ── */
.midi-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.midi-keys {
  position: relative; width: 100%; height: 220px;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #0a0a0a; touch-action: none; user-select: none;
}
/* In landscape on a phone, stretch the keyboard to occupy almost all
   vertical space so individual keys are big enough to hit cleanly. */
@media (orientation: landscape) and (max-height: 500px) {
  .midi-keys { height: 75vh; }
}
.midi-key {
  position: absolute; top: 0; bottom: 0;
  border-right: 1px solid #999;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 10px; font-size: 11px; color: var(--muted);
  box-sizing: border-box;
}
/* White keys: subtle vertical gradient + a thin bottom shadow to give
   the keyboard a hint of depth. Border-right separates adjacent whites. */
.midi-key.white {
  background: linear-gradient(to bottom, #fdfdfd 0%, #ebebeb 100%);
  color: #555;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.08);
}
/* Black keys: rounded bottom edges + soft gradient + a small bottom
   highlight, so each looks like a 3-D piano key from above instead of
   a flat rectangle. */
.midi-key.black {
  background: linear-gradient(to bottom, #2a2a2a 0%, #0a0a0a 90%, #1a1a1a 100%);
  color: #aaa;
  z-index: 2;
  border-radius: 0 0 4px 4px;
  border-right: none;
  box-shadow: inset 0 -3px 0 rgba(255,255,255,0.06), 0 2px 4px rgba(0,0,0,0.6);
}
.midi-key.down.white {
  background: linear-gradient(to bottom, #8de08d 0%, var(--hot) 100%);
  color: var(--bg);
}
.midi-key.down.black {
  background: linear-gradient(to bottom, #4a8c4a 0%, #2f6c2f 100%);
  color: var(--bg);
}

/* ── output tab ── */
.output-display {
  min-height: 120px; padding: 14px; border-radius: 10px;
  background: #0a0a0a; border: 1px solid var(--line);
  font-size: 18px; line-height: 1.4;
}
.output-display.flash { background: var(--hot); color: var(--bg); }

/* ── responsive ── */
@media (min-width: 560px) {
  .cards { grid-template-columns: 1fr 1fr; }
}
