/* ============================================================
   Pico 2 Synth Workshop -- Combined Styles
   Playable synth + Config generator, mobile-responsive
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #6C3CE1;
  --primary-light: #8B5CF6;
  --primary-bg: #F3F0FF;
  --text: #1E293B;
  --text-muted: #64748B;
  --bg: #0F0F1A;
  --card-bg: #1A1A2E;
  --card-border: #2A2A40;
  --border: #2A2A40;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);

  --code-bg: #12121E;
  --code-text: #CDD6F4;
  --code-string: #A6E3A1;
  --code-comment: #6C7086;
  --code-number: #FAB387;
  --code-keyword: #CBA6F7;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: #E2E8F0;
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Header --- */
.site-header {
  background: linear-gradient(135deg, #1a0533 0%, #2d1b69 50%, #1a1a2e 100%);
  border-bottom: 1px solid var(--primary);
  padding: 1.25rem 1rem 1rem;
  text-align: center;
}

.site-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 0 20px rgba(139, 92, 246, 0.5);
}

.subtitle {
  font-size: 0.9rem;
  color: #A0A0C0;
  margin-top: 0.25rem;
}

/* --- Serial controls in header --- */
.serial-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-serial {
  padding: 0.4rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #B0B0C8;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-serial:hover {
  border-color: var(--primary-light);
  background: rgba(139, 92, 246, 0.1);
}

.btn-serial.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.btn-mute.active {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.serial-status {
  font-size: 0.75rem;
  color: #666;
}

/* --- Tab bar --- */
.tab-bar {
  display: flex;
  justify-content: center;
  gap: 0;
  background: #12121E;
  border-bottom: 1px solid var(--border);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.tab {
  flex: 1;
  max-width: 280px;
  padding: 0.85rem 1.5rem;
  border: none;
  background: transparent;
  color: #8888AA;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border-bottom: 3px solid transparent;
}

.tab:hover {
  color: #C0C0E0;
  background: rgba(139, 92, 246, 0.05);
}

.tab.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary-light);
  background: rgba(139, 92, 246, 0.08);
}

/* --- Tab panels --- */
.tab-panel {
  display: none;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.tab-panel.active { display: block; }

/* --- Cards --- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: #E8E8F0;
}

.card h2 .hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* --- Voice buttons --- */
.voice-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.voice-btn {
  padding: 0.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: #C0C0D0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.voice-btn:hover {
  border-color: var(--primary-light);
  background: rgba(139, 92, 246, 0.1);
}

.voice-btn.active {
  border-color: var(--voice-color, var(--primary));
  background: var(--voice-color, var(--primary));
  color: #fff;
  box-shadow: 0 0 12px color-mix(in srgb, var(--voice-color, var(--primary)) 40%, transparent);
}

/* --- Keyboard with key columns --- */
.keyboard {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.key-column {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 1;
  min-width: 52px;
  gap: 4px;
}

.key {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, #22223A 0%, #1A1A2E 100%);
  color: #B0B0C8;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.08s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.key:hover {
  border-color: var(--primary-light);
  background: linear-gradient(180deg, #2A2A48 0%, #22223A 100%);
}

.key.pressed {
  border-color: var(--primary-light);
  background: linear-gradient(180deg, var(--primary) 0%, #4C1D95 100%);
  color: #fff;
  transform: translateY(2px);
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

.key-note { font-size: 0.75rem; font-weight: 700; }
.key-bind { font-size: 0.6rem; color: #666; font-weight: 500; }
.key.pressed .key-bind { color: rgba(255,255,255,0.6); }

/* --- Key assignment dropdown (below each key) --- */
.key-assign {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.key-assign select {
  width: 100%;
  padding: 0.2rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #12121E;
  color: #A0A0C0;
  font-size: 0.65rem;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.key-assign-type { font-weight: 600; }

.key-assign select:focus {
  outline: none;
  border-color: var(--primary);
}

/* --- Keyboard settings --- */
.keyboard-settings {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  padding-top: 0.5rem;
  flex-wrap: wrap;
}

.keyboard-settings label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #A0A0C0;
}

.keyboard-settings select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: #E0E0F0;
  font-family: inherit;
  font-size: 0.85rem;
}

/* --- FX grid --- */
.fx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.fx-group {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.fx-group h3 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fx-group label {
  display: block;
  font-size: 0.78rem;
  color: #A0A0C0;
  margin-bottom: 0.15rem;
}

.fx-group label span {
  color: var(--primary-light);
  font-weight: 600;
}

/* --- FX assignment inline dropdown --- */
.fx-assign-inline {
  margin-bottom: 0.5rem;
}

.fx-assign-inline select {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #12121E;
  color: #8888AA;
  font-size: 0.7rem;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.fx-assign-inline select:focus {
  outline: none;
  border-color: var(--primary);
  color: #C0C0E0;
}

.fx-assign-source {
  min-width: 80px;
}

/* --- Sliders --- */
input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #2A2A40;
  border-radius: 999px;
  outline: none;
  margin: 0.25rem 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #1A1A2E;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #1A1A2E;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

/* --- Transport buttons (loop, arp) --- */
.transport-buttons {
  display: flex;
  gap: 0.5rem;
}

/* Tonality toggle (Major/Minor) */
.btn-tonality {
  min-width: 60px;
  text-align: center;
}

.btn-tonality.disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.btn-tonality.active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

/* Update Pico button */
.btn-update-pico {
  background: #059669;
  color: #fff;
}

.btn-update-pico:hover:not(:disabled) {
  background: #10b981;
}

.btn-update-pico:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-update-pico.sending {
  background: #f59e0b;
  color: #000;
  animation: pulse-recording 1s ease-in-out infinite;
}

.speed-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #A0A0C0;
  flex: 1;
  min-width: 180px;
}

.speed-label input[type="range"] { flex: 1; min-width: 80px; }
.speed-label span { color: var(--primary-light); font-weight: 600; min-width: 32px; }

.btn-transport {
  padding: 0.4rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: #B0B0C8;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-transport:hover {
  border-color: var(--primary-light);
  background: rgba(139, 92, 246, 0.1);
}

.btn-transport.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.btn-transport.recording {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  animation: pulse-recording 1s ease-in-out infinite;
}

@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- Form elements (config tab) --- */
select, input[type="number"], input[type="text"] {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  color: #E0E0F0;
  background: #12121E;
  transition: border-color 0.12s ease;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888AA' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

select:focus, input[type="number"]:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.input-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #8888AA;
}

/* --- System pins grid --- */
.system-pins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.system-pins-grid input[type="number"] { width: 100%; }
.system-pins-grid select { width: 100%; }

/* --- Setup steps --- */
.setup-steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.setup-step {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.setup-step h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 0.4rem;
}

.setup-step p {
  font-size: 0.82rem;
  color: #A0A0C0;
  margin-bottom: 0.5rem;
}

.setup-step code {
  background: rgba(139, 92, 246, 0.1);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.8rem;
  color: #CDD6F4;
}

.setup-step .btn-download {
  display: inline-block;
  text-decoration: none;
}

/* --- Wiring guide --- */
.wiring-ref { font-size: 0.85rem; color: #B0B0C8; }
.wiring-ref h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #E0E0F0;
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.wiring-ref p { margin-bottom: 0.5rem; }

.wiring-note {
  background: rgba(239, 68, 68, 0.08);
  border-left: 3px solid #ef4444;
  padding: 0.5rem 0.75rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  color: #f87171;
  margin-bottom: 0.5rem;
}

.wiring-diagram {
  background: #12121E;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.8rem;
  color: #CDD6F4;
  margin-bottom: 0.75rem;
  line-height: 1.8;
}

.wiring-diagram span {
  color: var(--primary-light);
  font-weight: 600;
}

.wiring-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
}

.wiring-table th, .wiring-table td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.wiring-table th {
  color: var(--primary-light);
  font-weight: 700;
}

.wiring-tips {
  list-style: none;
  padding: 0;
}

.wiring-tips li {
  padding: 0.3rem 0 0.3rem 1.2rem;
  position: relative;
  font-size: 0.82rem;
}

.wiring-tips li::before {
  content: "\2022";
  color: var(--primary-light);
  position: absolute;
  left: 0;
}

/* --- Code output --- */
.code-output {
  border: 1px solid #2A2A40;
  border-radius: var(--radius);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0A0A14;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #2A2A40;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.code-header .filename {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.8rem;
  color: #6C7086;
}

.code-format-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.btn-fmt {
  padding: 0.3rem 0.7rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #8888AA;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-fmt:hover {
  background: rgba(139, 92, 246, 0.1);
  color: #C0C0E0;
}

.btn-fmt.active {
  background: var(--primary);
  color: #fff;
}

.code-format-desc {
  font-size: 0.78rem;
  color: #8888AA;
  padding: 0.5rem 1rem 0;
  margin: 0;
}

.code-actions { display: flex; gap: 0.5rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-copy { background: var(--primary); color: #fff; }
.btn-copy:hover { background: var(--primary-light); }
.btn-copy.copied { background: #059669; }

.btn-download {
  background: #2A2A40;
  color: #CDD6F4;
}

.btn-download:hover { background: #3A3A50; }

.code-body {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code-body pre {
  font-family: "SF Mono", "Fira Code", "Consolas", "Courier New", monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--code-text);
  white-space: pre;
  margin: 0;
}

.syn-comment { color: var(--code-comment); font-style: italic; }
.syn-string  { color: var(--code-string); }
.syn-number  { color: var(--code-number); }
.syn-keyword { color: var(--code-keyword); }
.syn-key     { color: #89B4FA; }
.syn-punct   { color: #9399B2; }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #2A2A40;
  color: #fff;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  border: 1px solid var(--primary);
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .site-header h1 { font-size: 1.2rem; }
  .fx-grid { grid-template-columns: 1fr; }
  .setup-steps { grid-template-columns: 1fr; }
  .system-pins-grid { grid-template-columns: 1fr 1fr; }

  .keyboard { gap: 3px; }
  .key-column { min-width: 42px; }
  .key { min-height: 56px; }
  .key-note { font-size: 0.65rem; }
  .key-bind { font-size: 0.5rem; }
  .key-assign select { font-size: 0.6rem; }

  .voice-btn { padding: 0.4rem 0.7rem; font-size: 0.78rem; }

  .code-header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }
}

/* --- Print --- */
@media print {
  .site-header, .tab-bar, #tab-play, .toast, .serial-controls {
    display: none !important;
  }
  body { background: #fff; color: #000; }
  .card { background: #fff; border: 1px solid #ccc; box-shadow: none; }
  .code-body { background: #fff !important; border: 1px solid #ccc; }
  .code-body pre { color: #000 !important; }
  .syn-comment, .syn-string, .syn-number, .syn-keyword, .syn-key, .syn-punct { color: #000 !important; }
  .code-actions { display: none !important; }
}
