/* ── Reset ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

/* ── Canvas ── */
canvas#main {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Top bar: stylus HUD ── */
#top-bar {
  position: fixed;
  top: 8px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 20;
  pointer-events: none;
  font-family: 'SF Mono', ui-monospace, monospace;
  font-size: 12px;
  color: #999;
}

.hud-item {
  white-space: nowrap;
}

.hud-title {
  color: #ccc;
  font-weight: 600;
}

#top-bar .hl {
  color: #666;
  margin-right: 5px;
}

#top-bar .hv {
  color: #ccc;
  font-variant-numeric: tabular-nums;
}

.hbar {
  display: inline-block;
  width: 50px;
  height: 4px;
  background: #333;
  border-radius: 2px;
  vertical-align: middle;
  margin-left: 5px;
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  background: #aaa;
  border-radius: 2px;
  transition: width 0.06s;
}

/* ── Sidebar: 2-column grid ── */
#sidebar {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 140px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 6px;
  align-content: center;
  z-index: 20;
  pointer-events: none;
  transition: transform 0.25s ease;
}

#sidebar > * {
  pointer-events: auto;
}

/* ── Brush type buttons (2×2 grid) ── */
.brush-types {
  grid-column: span 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.bt-btn {
  width: 100%;
  height: 30px;
  border-radius: 7px;
  background: #333;
  border: 1px solid #555;
  color: #aaa;
  font-family: -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  cursor: pointer;
  touch-action: none;
}

.bt-btn:active {
  background: #555;
}

.bt-btn.active {
  background: #fff;
  color: #000;
  border-color: #fff;
}

/* ── Sidebar buttons ── */
#btn-brush-panel {
  grid-column: span 2;
  width: 100%;
  height: 30px;
  border-radius: 7px;
  background: #333;
  border: 1px solid #555;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-brush-panel:active {
  background: #555;
}

/* ── Button groups: transparent in grid ── */
.btn-group {
  display: contents;
}

/* ── Slider row: 3 sliders side by side ── */
.slider-row {
  grid-column: span 2;
  display: flex;
  gap: 4px;
  justify-content: center;
}

.slider-row .vslider {
  flex: 1;
  width: auto;
}

/* ── Color palette ── */
#color-palette {
  grid-column: span 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.cp-swatch {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
}

.cp-swatch.active {
  border-color: #fff;
}

/* ── Vertical slider ── */
.vslider {
  position: relative;
  width: 34px;
  height: 80px;
  background: #333;
  border-radius: 17px;
  border: 1px solid #555;
  overflow: hidden;
  cursor: ns-resize;
  touch-action: none;
  justify-self: center;
}

.vslider-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 17px;
  pointer-events: none;
}

.vslider-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  font-family: -apple-system, sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* ── Brush preview ── */
#brush-preview {
  display: none;
}

#brush-dot {
  border-radius: 50%;
  background: #fff;
}

/* ── Pause spans full width ── */
#btn-pause {
  grid-column: span 2;
}

/* ── Brush settings panel ── */
#brush-panel {
  position: fixed;
  right: 140px;
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  opacity: 0;
  pointer-events: none;
  width: calc((100vw - 140px) * 0.25);
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 18px;
  font-family: -apple-system, sans-serif;
  font-size: 13px;
  color: #ccc;
  z-index: 25;
  transition: opacity 0.2s, transform 0.2s;
}

#brush-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) scale(1);
}

.bp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
  color: #eee;
}

.bp-close {
  background: none;
  border: none;
  color: #999;
  font-size: 20px;
  cursor: pointer;
  padding: 0 2px;
}

.bp-close:active {
  color: #fff;
}

.bp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.bp-row:last-child {
  margin-bottom: 0;
}

.bp-row label {
  flex: 0 0 90px;
  font-size: 13px;
  color: #aaa;
}

.bp-row input[type="range"] {
  flex: 1;
  accent-color: #888;
  height: 20px;
}

.bp-row .bp-val {
  flex: 0 0 30px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #ccc;
}

/* ── Mobile: smaller UI ── */
@media (max-width: 768px) {
  #sidebar {
    width: 80px;
    gap: 3px;
    padding: 4px;
  }

  .bt-btn {
    height: 26px;
    font-size: 10px;
    border-radius: 6px;
  }

  .brush-types {
    gap: 2px;
    grid-template-columns: 1fr 1fr;
  }

  .vslider {
    width: 28px;
    height: 60px;
    border-radius: 14px;
  }

  .vslider-fill {
    border-radius: 14px;
  }

  .vslider-label {
    font-size: 8px;
  }

  #btn-brush-panel {
    height: 26px;
    font-size: 14px;
    border-radius: 6px;
  }

  #top-bar {
    font-size: 9px;
    gap: 10px;
  }

  #brush-panel {
    right: 80px;
    width: calc((100vw - 80px) * 0.45);
    padding: 12px;
    font-size: 11px;
    border-radius: 10px;
  }

  .bp-header {
    font-size: 13px;
    margin-bottom: 10px;
  }

  .bp-row {
    gap: 6px;
    margin-bottom: 8px;
  }

  .bp-row label {
    flex: 0 0 65px;
    font-size: 11px;
  }

  .bp-row .bp-val {
    font-size: 10px;
  }
}

/* ── Short screens: even more compact ── */
@media (max-height: 500px) {
  #sidebar {
    gap: 2px;
    padding: 3px;
  }

  .bt-btn {
    height: 22px;
    font-size: 9px;
    border-radius: 5px;
  }

  #btn-brush-panel {
    height: 22px;
    font-size: 12px;
    border-radius: 5px;
  }

  .vslider {
    width: 26px;
    height: 44px;
    border-radius: 13px;
  }

  .vslider-fill {
    border-radius: 13px;
  }

  .vslider-label {
    font-size: 7px;
  }
}
