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

body {
  background: #000;
  overflow: hidden;
  height: 100dvh;
  font-family: 'Courier New', monospace;
}

/* ── Canvas — fixed; JS sets top/left/width/height to cover viewport ─── */
canvas {
  position: fixed;
  display: block;
}

/* ── Overlay (status + parameter value) ─────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: white;
  text-align: center;
  gap: 16px;
  transition: opacity 0.8s;
}

#status {
  font-size: 1.1rem;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  padding: 0.5rem 1.5rem;
  white-space: pre-line;
  letter-spacing: 0.04em;
}

#count {
  font-size: clamp(2.5rem, 14vw, 5rem);
  font-weight: bold;
  line-height: 1;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.4);
  letter-spacing: 0.04em;
}

/* ── REC indicator ───────────────────────────────────────────────────── */
#rec-dot {
  position: fixed;
  top: 1rem;
  left: 1.2rem;
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #ff3333;
  letter-spacing: 0.1em;
  pointer-events: none;
}

#rec-dot.active {
  display: flex;
}

#rec-dot .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3333;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.1; }
}

/* ── Keyboard shortcut bar (desktop only) ────────────────────────────── */
#tip {
  position: fixed;
  bottom: 1.2rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.28);
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.8s;
}

body.touch #tip {
  display: none;
}

/* ── Sidebar toggle button ───────────────────────────────────────────── */
#btn-sidebar-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 101;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: white;
  font-size: 1.1rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#btn-sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

body.sidebar-open #btn-sidebar-toggle {
  opacity: 0;
  pointer-events: none;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 100vw);
  background: rgba(8, 8, 8, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0 1.4rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

body.touch #sidebar {
  width: 100vw;
}

body.sidebar-open #sidebar {
  transform: translateX(0);
  pointer-events: all;
}

/* Sidebar header */
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1.4rem;
  padding-bottom: 0.4rem;
  position: sticky;
  top: 0;
  background: rgba(8, 8, 8, 0.96);
}

#sidebar-header span {
  font-size: 0.72rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#btn-sidebar-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  transition: color 0.15s;
  line-height: 1;
}

#btn-sidebar-close:hover {
  color: rgba(255, 255, 255, 0.9);
}

/* Action buttons row */
#sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

#sidebar-actions button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: white;
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  padding: 0.6rem 0.3rem;
  border-radius: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  letter-spacing: 0.04em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}

#sidebar-actions button:hover,
#sidebar-actions button:active {
  background: rgba(255, 255, 255, 0.18);
}

#btn-rec.recording {
  background: rgba(255, 50, 50, 0.32);
  border-color: #ff3333;
  color: #ff9999;
}

/* Touch: larger sidebar gaps for breathing room */
body.touch #sidebar {
  gap: 2rem;
  padding-bottom: env(safe-area-inset-bottom, 2rem);
}

/* Individual setting row */
.setting {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.setting-name {
  font-size: 0.9rem;
  font-weight: bold;
  color: #fff;
  letter-spacing: 0.02em;
}

.setting-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.03em;
}

/* Slider track */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

/* Slider thumb — WebKit */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}

/* Slider thumb — Firefox */
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}

/* Touch: larger slider thumbs and taller track hit area */
body.touch input[type="range"] {
  height: 28px;
  background: transparent;
  display: flex;
  align-items: center;
}

body.touch input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}

body.touch input[type="range"]::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
  margin-top: -12px;
}

body.touch input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
}

body.touch input[type="range"]::-moz-range-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}

/* Keyboard shortcuts reference */
#shortcuts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1.2rem;
  margin-top: 0.4rem;
}

body.touch #shortcuts {
  display: none;
}

.shortcut {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.03em;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  padding: 0.1rem 0.4rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.3rem;
  font-family: 'Courier New', monospace;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Reset button */
#btn-reset-settings {
  align-self: flex-start;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  transition: color 0.15s;
}

#btn-reset-settings:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ── Hide UI (H key) — hides everything, forces sidebar closed ───────── */
body.ui-hidden #overlay,
body.ui-hidden #tip,
body.ui-hidden #rec-dot,
body.ui-hidden #btn-sidebar-toggle {
  opacity: 0 !important;
  pointer-events: none !important;
}

body.ui-hidden #sidebar {
  transform: translateX(100%) !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

/* ── Portrait hint (mobile only) — non-blocking small banner ─────────── */
#portrait-warning {
  display: none;
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0);
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.65);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.72rem;
  text-align: center;
  padding: 0.5rem 1rem;
  z-index: 200;
  pointer-events: none;
  letter-spacing: 0.06em;
}

body.touch.portrait #portrait-warning {
  display: block;
}
