/* ============================================
   PULSAR V2 — Teenage Engineering Style
   Flat, white, grid-based, modular
   ============================================ */

/* --- Fonts --- */
@font-face {
  font-family: "Century Old Style";
  src:
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Bold.woff2") format("woff2"),
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Bold.woff") format("woff"),
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "Century Old Style";
  src:
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Regular.woff2") format("woff2"),
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Regular.woff") format("woff"),
    url("../assets/fonts/century-old-style/CenturyOldStyleStd-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

/* --- Design Tokens --- */
:root {
  --te-white: #FFFFFF;
  --te-bg: #F5F5F3;
  --te-grid-line: #E0E0DC;
  --te-border: #1A1A1A;
  --te-border-light: #CCCCCC;
  --te-black: #1A1A1A;
  --te-grey: #999999;
  --te-grey-light: #E8E8E4;

  --te-orange: #FF6600;
  --te-blue: #0066FF;
  --te-green: #00CC66;
  --te-pink: #FF3366;
  --te-purple: #9933FF;
  --te-yellow: #FFCC00;

  --te-font-brand: "Century Old Style", Georgia, serif;
  --te-font-ui: "Inter", -apple-system, system-ui, sans-serif;
  --te-font-mono: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;

  --te-radius: 3px;
  --te-border-width: 1.5px;

  --te-header-height: 10svh;
  --te-main-height: 90svh;
  --te-pad: 5svh;

  --te-grid-cols: 16;
  --te-grid-rows: 8;
  --te-grid-gap: 0px;
}

/* --- Reset --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--te-white);
  color: var(--te-black);
  font-family: var(--te-font-ui);
  font-size: 13px;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  height: var(--te-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--te-pad);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  font-family: var(--te-font-brand);
  font-weight: 700;
  font-size: 4svh;
  color: var(--te-black);
  letter-spacing: -0.5px;
  text-decoration: none;
}

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

/* --- Sheet Tabs --- */
.sheet-tabs-wrap {
  width: 30svw;
  height: 36px;
  display: flex;
  align-items: center;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  padding: 4px;
  gap: 8px;
  overflow: hidden;
}

.sheet-tabs {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sheet-tabs::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.sheet-tab {
  flex: 1;
  min-width: 100px;
  height: 100%;
  padding: 0;
  background: var(--te-white);
  border: var(--te-border-width) solid var(--sheet-color, var(--te-border-light));
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  transition: all 80ms;
  flex-shrink: 0;
}

.sheet-tab:hover {
  background: color-mix(in srgb, var(--sheet-color) 15%, var(--te-white));
}

.sheet-tab.active {
  background: var(--sheet-color, var(--te-orange));
  color: var(--te-white);
}

.sheet-tab-remove {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: none;
  border: none;
  color: var(--sheet-color, var(--te-black));
  font-family: var(--te-font-mono);
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 80ms;
  z-index: 5;
}

.sheet-tab:hover .sheet-tab-remove {
  opacity: 1;
}

.sheet-tab.active .sheet-tab-remove {
  color: var(--te-white);
}

.sheet-tab-add {
  width: 28px;
  min-width: 28px;
  height: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) dashed var(--te-border-light);
  border-radius: 2px;
  font-family: var(--te-font-mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--te-grey);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 80ms;
  flex-shrink: 0;
}

.sheet-tab-add:hover {
  border-color: var(--te-black);
  color: var(--te-black);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* --- Transport Controls --- */
.transport {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--te-white);
}

.transport-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: var(--te-border-width) solid var(--te-orange);
  border-radius: var(--te-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--te-orange);
  transition: background 80ms;
}

.transport-btn:active {
  background: var(--te-black);
  color: var(--te-white);
}

.transport-btn.playing {
  background: var(--te-orange);
  border-color: var(--te-orange);
  color: var(--te-white);
}

.transport-input {
  width: 38px;
  height: 28px;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--te-black);
  outline: none;
}

.transport-input:focus {
  border-color: var(--te-black);
}

.transport-label {
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
  letter-spacing: 0.5px;
}

.transport-sep {
  font-family: var(--te-font-mono);
  font-size: 13px;
  color: var(--te-grey);
}

/* Beat bar — continuous rounded progress */
.beat-bar-wrap {
  width: 80px;
  height: 10px;
  background: var(--te-bg);
  border: 1px solid var(--te-border-light);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
  margin: 0 2px;
}

.beat-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: var(--te-orange);
  border-radius: 5px;
  transition: width 60ms linear;
}

/* --- Header Grid Label --- */
.header-grid-label {
  font-family: var(--te-font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
  letter-spacing: 0.5px;
}

/* --- Header Settings Button & Panel --- */
.header-settings-wrap {
  position: relative;
}

.header-settings-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--te-grey);
  transition: all 80ms;
}

.header-settings-btn:hover {
  border-color: var(--te-black);
  color: var(--te-black);
}

.header-settings-btn.active {
  background: var(--te-black);
  border-color: var(--te-black);
  color: var(--te-white);
}

.header-settings-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 220px;
  background: var(--te-white);
  border: var(--te-border-width) solid var(--te-black);
  border-radius: var(--te-radius);
  padding: 10px;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  flex-direction: column;
  gap: 6px;
}

.header-settings-panel.open {
  display: flex;
}

.settings-section-title {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--te-grey);
  margin-bottom: 2px;
}

.settings-row-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-btn-action {
  flex: 1;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--te-black);
  padding: 4px;
  cursor: pointer;
  transition: all 80ms;
  text-transform: uppercase;
}

.settings-btn-action:hover {
  background: var(--te-black);
  color: var(--te-white);
  border-color: var(--te-black);
}

.settings-divider {
  height: 1px;
  background: var(--te-grid-line);
  margin: 4px 0;
}

.settings-select {
  flex: 1;
  max-width: none;
}

/* --- MIDI Selectors (shared) --- */
.midi-sel {
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 11px;
  color: var(--te-black);
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}

.midi-sel:hover {
  border-color: var(--te-black);
}

/* --- Main Area --- */
.main {
  flex: 1;
  min-height: 0;
  padding: 0 var(--te-pad) var(--te-pad) var(--te-pad);
}

.workspace {
  width: 100%;
  height: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  position: relative;
  overflow: hidden;
}

/* --- Grid System --- */
.grid-container {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--te-grid-cols), 1fr);
  grid-template-rows: repeat(var(--te-grid-rows), 1fr);
  gap: var(--te-grid-gap);
  position: relative;
}

/* Visible grid lines rendered as background */
.grid-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--te-grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--te-grid-line) 1px, transparent 1px);
  background-size:
    calc(100% / var(--te-grid-cols)) calc(100% / var(--te-grid-rows));
}

/* Drop zone highlight when dragging */
.grid-drop-preview {
  position: absolute;
  background: rgba(0, 102, 255, 0.08);
  border: 2px dashed var(--te-blue);
  border-radius: var(--te-radius);
  pointer-events: none;
  z-index: 5;
  display: none;
}

.grid-drop-preview.visible {
  display: block;
}

/* --- Floating Add Button --- */
.fab {
  position: absolute;
  bottom: 36px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: var(--te-black);
  color: var(--te-white);
  border: none;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: transform 100ms;
}

.fab:hover {
  transform: scale(1.08);
}

.fab:active {
  transform: scale(0.95);
}

/* --- Widget Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.3);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.visible {
  display: flex;
}

.modal-box {
  background: var(--te-white);
  border: var(--te-border-width) solid var(--te-black);
  border-radius: var(--te-radius);
  padding: 24px;
  min-width: 400px;
  max-width: 600px;
  height: 70svh;
  display: flex;
  flex-direction: column;
}

.modal-title {
  font-family: var(--te-font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--te-grey);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--te-grey);
  padding: 4px;
}

.modal-close:hover {
  color: var(--te-black);
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  cursor: pointer;
  transition: border-color 80ms;
}

.modal-option:hover {
  border-color: var(--te-black);
}

.modal-option:active {
  background: var(--te-black);
  color: var(--te-white);
}

.modal-option-icon {
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.modal-option-name {
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================
   WIDGET MODULE — Shared Base
   ============================================ */
.module {
  position: absolute;
  background: var(--te-white);
  border: var(--te-border-width) solid var(--te-black);
  border-radius: var(--te-radius);
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: visible;
  cursor: grab;
  container-type: inline-size;
}

.module:hover {
  z-index: 20;
}

.module.dragging {
  cursor: grabbing;
  opacity: 0.85;
  z-index: 100;
}

.module.resizing {
  z-index: 100;
}

/* Module Header */
.module-header {
  min-height: 26px;
  background: var(--te-bg);
  border-bottom: var(--te-border-width) solid var(--te-black);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  gap: 4px;
  overflow: hidden;
}

@container (max-width: 140px) {
  .module-header {
    flex-direction: column-reverse;
    justify-content: center;
    padding: 6px 4px;
  }
}

.module-header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.module-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.module-label {
  font-family: var(--te-font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--te-black);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-sub {
  font-family: var(--te-font-mono);
  font-size: 8px;
  color: var(--te-grey);
  white-space: nowrap;
  font-weight: 700;
  text-transform: uppercase;
}

.module-settings-btn {
  width: 20px;
  height: 20px;
  background: none;
  border: 1px solid var(--te-border-light);
  border-radius: var(--te-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--te-grey);
  flex-shrink: 0;
  transition: all 80ms;
}

.module-settings-btn:hover {
  border-color: var(--te-black);
  color: var(--te-black);
}

.module-settings-btn.active {
  background: var(--te-black);
  border-color: var(--te-black);
  color: var(--te-white);
}

/* Module Body */
.module-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1svh;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* Module Settings Panel (hidden by default) */
.module-settings {
  display: none;
  background: var(--te-bg);
  border-top: var(--te-border-width) solid var(--te-black);
  padding: 8px;
}

.module-settings.open {
  display: block;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
}

.settings-label {
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
}

.settings-input {
  width: 48px;
  height: 22px;
  background: var(--te-white);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 11px;
  text-align: center;
  color: var(--te-black);
  outline: none;
}

.settings-input:focus {
  border-color: var(--te-black);
}

.settings-close-btn {
  width: 100%;
  height: 22px;
  margin-top: 6px;
  background: none;
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
  cursor: pointer;
}

.settings-close-btn:hover {
  border-color: var(--te-pink);
  color: var(--te-pink);
}

/* Module Resize Handle */
.module-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  z-index: 15;
}

.module-resize::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--te-border-light);
  border-bottom: 2px solid var(--te-border-light);
}

.module:hover .module-resize::after {
  border-color: var(--te-black);
}

/* Module header with subtitle layout */
.module-header-left {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  overflow: hidden;
}

.module-sub {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 400;
  color: var(--te-grey);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

/* Floating Settings Popover */
.module-settings-float {
  position: absolute;
  top: 100%;
  left: 0;
  width: 180px;
  z-index: 50;
  background: var(--te-white);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: none;
  flex-direction: column;
  gap: 6px;
}

.module-settings-float.open {
  display: flex;
}

/* ============================================
   FADER MODULE
   ============================================ */

.fader-value {
  display: none;
}

/* Spring fader center line */
.fader-center-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--te-border-light);
  pointer-events: none;
  z-index: 1;
}

.fader-track-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
  min-height: 40px;
  touch-action: none;
}

.fader-track {
  width: 100%;
  height: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.fader-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--te-blue);
  pointer-events: none;
}

.fader-thumb {
  position: absolute;
  left: 0;
  right: 0;
  height: 10px;
  background: var(--te-blue);
  cursor: grab;
  z-index: 2;
  transition: none;
}

.fader-thumb:active {
  cursor: grabbing;
}

.fader-thumb::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 2px;
  background: var(--te-white);
  border-radius: 1px;
}

/* ============================================
   KNOB MODULE
   ============================================ */
.knob-area {
  width: 100%;
  height: 100%;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.knob-visual {
  width: 80cqmin;
  height: 80cqmin;
  border: var(--te-border-width) solid var(--te-black);
  border-radius: 50%;
  background: var(--te-white);
  position: relative;
  cursor: crosshair;
}

.knob-indicator {
  position: absolute;
  top: 8%;
  left: 50%;
  width: 3px;
  height: 22%;
  background: var(--te-orange);
  border-radius: 2px;
  transform-origin: bottom center;
  transform: translateX(-50%);
}

.knob-visual.interacting {
  border-color: var(--te-orange);
}

/* ============================================
   TRIGGER MODULE
   ============================================ */
.trigger-pad {
  flex: 1;
  width: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 50ms;
  position: relative;
}

.trigger-pad:active,
.trigger-pad.active {
  background: var(--te-orange);
  border-color: var(--te-orange);
}

/* ============================================
   TOGGLE MODULE
   ============================================ */
.toggle-pad {
  flex: 1;
  width: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  cursor: pointer;
  transition: all 80ms;
}

.toggle-pad.active {
  background: var(--te-green);
  border-color: var(--te-green);
}

.toggle-pad.active .toggle-pad-label {
  color: var(--te-green);
}

/* ============================================
   STATUS BAR
   ============================================ */
.status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22px;
  background: var(--te-white);
  border-top: 1px solid var(--te-grid-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-family: var(--te-font-mono);
  font-size: 9px;
  color: var(--te-grey);
  z-index: 50;
}

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--te-green);
  display: inline-block;
}

/* ============================================
   UTILITY
   ============================================ */
/* Remove number spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--te-border-light);
  border-radius: 2px;
}

/* ============================================
   XY PAD MODULE
   ============================================ */

.xypad-area {
  flex: 1;
  width: 100%;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  position: relative;
  cursor: crosshair;
  overflow: hidden;
}

.xypad-crosshair-v,
.xypad-crosshair-h {
  position: absolute;
  background: var(--te-grid-line);
  pointer-events: none;
}

.xypad-crosshair-v {
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
}

.xypad-crosshair-h {
  left: 0; right: 0;
  top: 50%;
  height: 1px;
}

.xypad-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--te-purple);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: none;
}

/* ============================================
   STEPPER MODULE
   ============================================ */
.module-stepper .module-body {
  gap: 8px;
}

.stepper-display {
  width: 100%;
  background: transparent;
  border: none;
  font-family: var(--te-font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--te-orange);
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
  cursor: text;
}

/* Hide number spinner */
.stepper-display::-webkit-inner-spin-button,
.stepper-display::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper-display {
  -moz-appearance: textfield;
}

.stepper-btns {
  display: flex;
  gap: 6px;
  width: 100%;
}

.stepper-btn {
  flex: 1;
  height: 32px;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--te-black);
  cursor: pointer;
  transition: all 50ms;
}

.stepper-btn:active {
  background: var(--te-orange);
  color: var(--te-white);
  border-color: var(--te-orange);
}

/* ============================================
   RADIO MODULE
   ============================================ */
.radio-group {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.radio-opt {
  flex: 1;
  width: 100%;
  padding: 2px 10px;
  background: var(--te-bg);
  border: var(--te-border-width) solid var(--opt-color);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  transition: all 50ms;
}

.radio-opt:hover {
  border-color: var(--te-black);
}

.radio-opt.active {
  background: var(--opt-color);
  border-color: var(--opt-color);
}

/* ============================================
   LIVECODER MODULE
   ============================================ */
.module-livecoder .module-body {
  flex: 1;
  min-height: 0;
}

.lc-editor-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  border-radius: var(--te-radius);
  transition: box-shadow 200ms;
}

.lc-editor-wrap.flash-blue {
  box-shadow: inset 0 0 0 2px var(--te-blue);
}

.lc-editor-wrap.flash-green {
  box-shadow: inset 0 0 0 2px var(--te-green);
}

.lc-editor-wrap.flash-red {
  box-shadow: inset 0 0 0 2px var(--te-pink);
}

/* Track highlight overlay — mirrors textarea text, highlights played ranges */
.lc-flash-bg {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  padding: 8px;
  font-family: var(--te-font-mono);
  font-size: 11px;
  line-height: 1.6;
  tab-size: 3;
  white-space: pre;
  overflow: hidden;
  color: transparent;
  opacity: 0;
  transition: opacity 0.12s ease-out;
}

.lc-flash-bg.lc-flash-active {
  opacity: 1;
  animation: lc-hl-fade 0.9s ease-out forwards;
}

.lc-track-hl {
  color: transparent;
  border-radius: 2px;
  animation: lc-hl-pulse 0.9s ease-out forwards;
}

@keyframes lc-hl-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes lc-hl-pulse {
  0% { outline: 2px solid rgba(0,0,0,0.15); }
  50% { outline: 2px solid rgba(0,0,0,0.08); }
  100% { outline: none; }
}

/* Floating toast label */
.lc-toast {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  padding: 3px 8px;
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
}

.lc-toast-show {
  opacity: 1;
  transform: translateY(0);
  animation: lc-toast-in 0.9s ease-out forwards;
}

.lc-toast-blue { background: var(--te-blue); color: #fff; }
.lc-toast-green { background: var(--te-green); color: #fff; }
.lc-toast-red { background: var(--te-pink); color: #fff; }

@keyframes lc-toast-in {
  0% { opacity: 0; transform: translateY(-6px) scale(0.95); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  75% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-2px) scale(0.98); }
}

/* Footer pulse */
.lc-footer-blue { background: var(--te-blue) !important; }
.lc-footer-blue .lc-status-text,
.lc-footer-blue .lc-status-dot { color: #fff !important; }
.lc-footer-blue .lc-status-dot { background: #fff !important; animation: lc-dot-pulse 0.4s ease 2; }

.lc-footer-green { background: var(--te-green) !important; }
.lc-footer-green .lc-status-text,
.lc-footer-green .lc-status-dot { color: #fff !important; }
.lc-footer-green .lc-status-dot { background: #fff !important; animation: lc-dot-pulse 0.4s ease 2; }

.lc-footer-red { background: var(--te-pink) !important; }
.lc-footer-red .lc-status-text,
.lc-footer-red .lc-status-dot { color: #fff !important; }
.lc-footer-red .lc-status-dot { background: #fff !important; animation: lc-dot-pulse 0.4s ease 2; }

.lc-footer {
  transition: background 0.15s ease;
}

@keyframes lc-dot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.8); }
}


.lc-overlay,
.lc-textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 8px;
  font-family: var(--te-font-mono);
  font-size: 11px;
  line-height: 1.6;
  tab-size: 3;
  white-space: pre;
  overflow: auto;
  border: none;
  outline: none;
}

.lc-overlay {
  color: transparent;
  pointer-events: none;
  z-index: 2;
}

.lc-textarea {
  background: var(--te-bg);
  color: var(--te-black);
  caret-color: var(--te-orange);
  resize: none;
  z-index: 1;
}

.lc-textarea::placeholder {
  color: var(--te-border-light);
}

.lc-footer {
  height: 22px;
  min-height: 22px;
  background: var(--te-bg);
  border-top: 1px solid var(--te-grid-line);
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.lc-status {
  display: flex;
  align-items: center;
  gap: 5px;
}

.lc-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--te-green);
}

.lc-status-text {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-grey);
}

/* Syntax highlighting */
.lc-comment { color: var(--te-border-light); }
.lc-track { color: #ff6b6b; font-weight: 700; }
.lc-track-mod { color: var(--te-orange); font-weight: 700; }
.lc-note { color: var(--te-blue); font-weight: 700; }
.lc-seq-mod { color: var(--te-purple); }
.lc-bracket-sq { color: var(--te-green); font-weight: 700; }
.lc-chord { color: #ff9ff3; font-weight: 700; }
.lc-random { color: var(--te-orange); font-style: italic; }

/* Help section */
.lc-help-section { display: flex; flex-direction: column; gap: 2px; }
.lc-help-title {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  color: var(--te-black);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

/* ============================================
   SEQUENCER MODULE
   ============================================ */
.module-sequencer .module-body {
  padding: 1svh;
  display: block;
  overflow-y: auto;
}

.seq-track-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.seq-track {
  background: var(--te-white);
  border: 1px solid var(--te-border-light);
  border-radius: var(--te-radius);
  padding: 8px;
}

.seq-track-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--te-bg);
  padding-bottom: 6px;
}

.seq-track-name {
  flex: 1;
  background: none;
  border: none;
  font-family: var(--te-font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--te-black);
  outline: none;
}

.seq-track-params {
  display: flex;
  align-items: center;
  gap: 4px;
}

.seq-param-lbl {
  font-family: var(--te-font-mono);
  font-size: 8px;
  color: var(--te-grey);
}

.seq-bpm-in, .seq-sn-in, .seq-sd-in {
  width: 32px;
  background: var(--te-bg);
  border: 1px solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  text-align: center;
  color: var(--te-black);
  outline: none;
  padding: 2px;
}

.seq-bpm-in { width: 38px; }

.seq-param-sep {
  font-family: var(--te-font-mono);
  font-size: 9px;
  color: var(--te-border-light);
}

.seq-sequences-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seq-group {
  background: var(--te-bg);
  border-radius: var(--te-radius);
  padding: 6px;
  border-left: 3px solid var(--te-orange);
}

.seq-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.seq-label {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  color: var(--te-grey);
}

.seq-midi-info {
  font-family: var(--te-font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--te-black);
  letter-spacing: -0.2px;
}

.seq-actions {
  display: flex;
  gap: 4px;
}

.seq-edit-btn, .seq-del-btn, .seq-del-track {
  background: none;
  border: 1px solid var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  color: var(--te-grey);
  cursor: pointer;
  padding: 1px 4px;
}

.seq-edit-btn:hover { background: var(--te-black); color: var(--te-white); }
.seq-del-btn:hover, .seq-del-track:hover { color: var(--te-pink); border-color: var(--te-pink); }

.seq-steps {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.seq-step {
  flex: 0 0 calc(6.25% - 4px); /* roughly 16 per row */
  aspect-ratio: 1;
  min-width: 14px;
  background: var(--te-white);
  border: 1px solid var(--te-border-light);
  border-radius: 2px;
  cursor: pointer;
}

.seq-step.active {
  background: var(--te-green);
  border-color: var(--te-green);
}

.seq-step.playing {
  outline: 2px solid var(--te-orange);
  outline-offset: -1px;
}

.seq-add-seq-btn, .seq-add-track-btn {
  width: 100%;
  padding: 6px;
  background: none;
  border: 1px dashed var(--te-border-light);
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--te-grey);
  cursor: pointer;
  margin-top: 4px;
}

.seq-add-track-btn {
  padding: 10px;
  font-size: 11px;
}

.settings-title {
  font-family: var(--te-font-mono);
  font-size: 8px;
  font-weight: 700;
  color: var(--te-grey);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--te-bg);
  text-transform: uppercase;
}

.settings-done-btn {
  width: 100%;
  padding: 6px;
  margin-top: 8px;
  background: var(--te-black);
  color: var(--te-white);
  border: none;
  border-radius: var(--te-radius);
  font-family: var(--te-font-mono);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
}

.module-label[contenteditable="true"] {
  outline: none;
  cursor: text;
  padding: 0 4px;
  border-radius: 2px;
}

.module-label[contenteditable="true"]:hover {
  background: var(--te-bg);
}

/* --- Responsive Header (Mobile) --- */
@media (max-width: 800px) {
  :root {
    --te-pad: 12px;
  }

  .header {
    height: auto;
    flex-direction: column;
    padding: 12px var(--te-pad);
    gap: 12px;
  }

  .header-left {
    width: 100%;
    justify-content: center;
    order: 1;
  }

  .logo {
    font-size: 3svh;
    margin: 0;
  }

  .header-right {
    width: 100%;
    order: 2;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 6px;
    align-items: center;
    background: var(--te-bg);
    padding: 4px 8px;
    border-radius: var(--te-radius);
    border: 1px solid var(--te-border-light);
  }

  .transport {
    flex: 1;
    width: auto;
    background: none;
    border: none;
    padding: 0;
    justify-content: flex-start;
    gap: 6px;
  }

  .beat-bar-wrap {
    flex: 1;
    min-width: 40px;
    margin: 0;
  }

  .header-grid-label {
    order: 2;
    font-size: 9px;
    white-space: nowrap;
  }

  .header-settings-wrap {
    order: 3;
  }

  .header-center {
    width: 100%;
    order: 3;
    justify-content: center;
  }

  .sheet-tabs-wrap {
    width: 100%;
    max-width: none;
  }

  .sheet-tabs {
    width: 100%;
    max-width: none;
  }

  /* Make header items slightly smaller on mobile */
  .transport-btn {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .transport-input {
    width: 32px;
    height: 24px;
    font-size: 11px;
  }

  .header-settings-btn {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .header-grid-label {
    letter-spacing: 0;
  }

  .transport-label, .transport-sep {
    font-size: 8px;
    margin: 0 -2px;
  }

  .sheet-tab-remove {
    opacity: 1;
    right: 2px;
    width: 16px;
    height: 16px;
    font-size: 12px;
    background: none;
  }
}

/* ============================================
   PIANO KEYS MODULE
   ============================================ */
.module-pianokeys .module-body {
  padding: 0;
  overflow: visible;
}

.piano-container {
  width: 100%;
  height: 100%;
  position: relative;
  background: var(--te-bg);
}

.piano-key {
  position: absolute;
  top: 0;
  height: 100%;
  border: 1px solid var(--te-black);
  box-sizing: border-box;
  cursor: pointer;
  transition: background 50ms, transform 50ms, border-bottom-width 50ms;
}

.white-key {
  background: linear-gradient(to bottom, #fff 0%, #f0f0f0 100%);
  z-index: 1;
  border-bottom: 4px solid var(--te-grey-light);
  border-radius: 0 0 3px 3px;
}

.white-key.active {
  background: linear-gradient(to bottom, var(--te-orange) 0%, #ff8c40 100%);
  border-bottom-width: 1px;
  transform: translateY(3px);
  z-index: 5;
}

.black-key {
  background: linear-gradient(to bottom, #444 0%, #1a1a1a 100%);
  height: 60%;
  z-index: 10;
  border: 1px solid #000;
  border-radius: 0 0 2px 2px;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}

.black-key.active {
  background: linear-gradient(to bottom, var(--te-blue) 0%, #408cff 100%);
  box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  transform: translateX(-50%) translateY(2px);
}

.black-key::after {
  content: "";
  position: absolute;
  top: 0;
  left: 15%;
  right: 15%;
  height: 20%;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0 0 1px 1px;
}
