:root {
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg: 1.125rem;     /* 18px */

  --space-1: 0.25rem;      /* 4px */
  --space-2: 0.5rem;       /* 8px */
  --space-3: 0.75rem;      /* 12px */
  --space-4: 1rem;         /* 16px */
  --space-5: 1.25rem;      /* 20px */
  --space-6: 1.5rem;       /* 24px */
  --space-8: 2rem;         /* 32px */

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --font-body: 'Satoshi', 'Inter', sans-serif;
  --transition: 150ms cubic-bezier(0.16, 1, 0.3, 1);

  --ui-tap-min: 28px;
  --ui-control-h: 30px;
  --ui-input-h: 28px;
  --ui-panel-title-h: 24px;
}

[data-theme="dark"] {
  --bg: #111110;
  --surface: #1a1918;
  --surface-2: #222120;
  --surface-3: #2a2927;
  --surface-4: #32312f;
  --border: rgba(255,255,255,0.08);
  --divider: rgba(255,255,255,0.05);
  --text: #e2e0dc;
  --text-muted: #9b9892;
  --text-faint: #66635f;
  --accent: #4f98a3;
  --accent-hover: #3d8491;
  --accent-bg: rgba(79,152,163,0.14);
  --warn: #e07b40;
  --success: #6daa45;
  --wall-color: #c86a20;
  --cell-color: #4f98a3;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg: #f2f0ec;
  --surface: #faf9f6;
  --surface-2: #f0eee9;
  --surface-3: #e6e4df;
  --surface-4: #ddd9d2;
  --border: rgba(0,0,0,0.08);
  --divider: rgba(0,0,0,0.05);
  --text: #1a1916;
  --text-muted: #6a6864;
  --text-faint: #94918a;
  --accent: #016970;
  --accent-hover: #015a60;
  --accent-bg: rgba(1,105,112,0.08);
  --warn: #964219;
  --success: #437a22;
  --wall-color: #b55500;
  --cell-color: #016970;
  --shadow: 0 4px 20px rgba(0,0,0,0.12);
}

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

html {
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.25;
  background: var(--bg);
  color: var(--text);
  padding: 0;
  margin: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  min-height: 100vh;
  overflow: hidden;
}


button,
select,
input {
  font: inherit;
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button,
select,
input[type="number"],
input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
}



.cell.cell-key-focus {
  outline: 2px solid #ffd166;
  outline-offset: -2px;
  box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.35);
}

#app {
  width: 800px;
  height: 480px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  flex: 0 0 auto;
}

header {
  display: none !important;
}

#grid-canvas:focus,
#grid-canvas:focus-visible {
  outline: none;
}

/* ---------- TOP BAR ---------- */

#top-bar {
  height: 22px;
  flex: 0 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 8px;
  overflow: hidden;
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
}

.top-bar-left,
.top-bar-middle,
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.top-btn,
.top-select,
.top-bpm-input {
  min-height: var(--ui-control-h);
  height: var(--ui-control-h);
  padding: 0 4px;
  font-size: 12px;
}

.top-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  font-weight: 500;
}

.top-btn:hover {
  background: var(--surface-3);
}

.top-btn.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-size: 12px;
}

.top-btn.btn-primary:hover {
  background: var(--accent-hover);
}

.top-btn.btn-active {
  background: var(--accent-bg);
  color: var(--accent);
}

.top-btn.btn-warn {
  background: var(--warn);
  color: #fff;
  border-color: transparent;
  font-size: 12px;
}

.top-select {
  min-width: 38px;
}

.midi-port-select {
  min-width: 96px;
  max-width: 96px;
}

.top-icon-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}

.top-icon-btn:hover {
  background: var(--surface-3);
}

.top-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.top-bpm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface-2);
  padding: 0 8px;
  height: 28px;
  min-width: 72px;
  justify-content: center;
  flex-shrink: 0;
}

.top-bpm-input::-webkit-outer-spin-button,
.top-bpm-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.top-bpm-input {
  width: 58px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.bpm-label-mini {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

/* ---------- MAIN PANELS ---------- */

#panels-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

#left-panel {
  flex: 0 0 435px;
  width: 435px;
  min-width: 430px;
  height: 448px;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg);
  overflow: hidden;
  flex-shrink: 0;
}

#right-panel {
  flex: 0 0 365px;
  width: 365px;
  min-width: 365px;
  height: 449px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
  overflow: hidden;
  flex-shrink: 0;
  padding: 4px 4px 4px 0;
}

#left-panel .card:nth-child(2),
#left-panel .card:nth-child(3),
#left-panel .card:nth-child(4),
#btn-start, #btn-wall-mode, #btn-clear-walls, #btn-clear-sounds,
#bpm-slider, #bpm-val, #scale-menu, #octave-shift, #octave-range, #grid-size,
#btn-save, #btn-load {
  display: none !important;
}

#right-panel > .card:first-child {
  display: none !important;
}

#left-panel .card:first-child {
  padding: var(--space-2) !important;
  margin: 0;
  border: none;
  border-radius: 0;
  background: var(--bg);
  box-shadow: none;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---------- GRID ---------- */
/* A gridet nem bántottam, csak a környező spacinget minimálisan. */

.cell.cell-wall-5 {
  background: #e84040;
  color: #fff;
}

.cell.cell-wall-5::after {
  content: '✕';
  font-size: 18px;
}

.cell.cell-wall-5:hover {
   background: #e84040;
}

#note-labels {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  margin-bottom: var(--space-1);
  flex-shrink: 0;
  min-height: 14px;
}

#note-labels div {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
}

#grid-canvas {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(16, 1fr);
  gap: 1px;
  background: var(--divider);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.cell {
  background: var(--surface-3);
  transition: background var(--transition), box-shadow var(--transition);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.3rem;
  color: var(--text-faint);
  border-radius: 1px;
  position: relative;
  min-width: 0;
}

.cell:hover {
  background: var(--surface-2);
}

.cell.cell-active {
  background: var(--surface-3);
  color: #fff;
}

.cell.cell-active::before {
  content: '';
  position: absolute;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: var(--cell-color);
  box-shadow: 0 0 8px rgba(79,152,163,0.5);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.cell-active.cell-playing::before {
  box-shadow: 0 0 14px 4px rgba(79,152,163,0.7);
}

.cell.cell-wall-0,
.cell.cell-wall-1,
.cell.cell-wall-2,
.cell.cell-wall-3 {
  background: var(--wall-color);
  color: #fff;
}

.cell.cell-wall-0 { opacity: 0.7; }
.cell.cell-wall-3 { background: #e84040; color: #fff; }

.cell.cell-wall-0::after { content: '■'; font-size: 18px; }
.cell.cell-wall-1::after { content: '/'; font-size: 18px; }
.cell.cell-wall-2::after { content: '\\'; font-size: 18px; }
.cell.cell-wall-3::after { content: '✕'; font-size: 18px; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79,152,163,0.7); transform: translate(-50%,-50%) scale(1); }
  100% { box-shadow: 0 0 16px 6px rgba(79,152,163,0); transform: translate(-50%,-50%) scale(1.15); }
}

.cell.cell-playing::before {
  animation: pulse 0.25s ease-out;
}

.grid-help {
  display: none;
}

/* ---------- CARDS ---------- */

.card {
  background: var(--surface);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  min-height: var(--ui-panel-title-h);
}

.card-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 10px;
  background: var(--accent);
  border-radius: var(--radius-full);
}

#right-panel .card {
  display: flex;
  flex-direction: column;
  margin: 0;
  border-radius: var(--radius-md);
  border-left: none;
  border-right: none;
  padding: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
  margin-top: 0;
  background: var(--surface);
}

#right-panel .card-title {
  font-size: 11px;
  padding: 6px 10px;
  margin-bottom: 0;
  flex-shrink: 0;
  background: var(--surface);
}

/* ---------- SCROLL PANELS ---------- */

#param-panel,
#wall-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  background: var(--surface);
}

#param-panel::-webkit-scrollbar,
#wall-panel::-webkit-scrollbar {
  width: 6px;
}

#param-panel::-webkit-scrollbar-track,
#wall-panel::-webkit-scrollbar-track {
  background: var(--surface-2);
}

#param-panel::-webkit-scrollbar-thumb,
#wall-panel::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: var(--radius-full);
}

#param-panel::-webkit-scrollbar-thumb:hover,
#wall-panel::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* ---------- CELL CARD / INSPECTOR ---------- */

.cell-card {
  overflow: hidden;
  margin-right: 4px;
  margin-left: 4px;
  margin-bottom: 6px;
  background: var(--surface-2);
}

.cell-card:last-child {
  margin-bottom: 0;
}

.cell-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  min-height: 24px;
  height: 24px;
  padding: 1px 6px;
  gap: 4px;
}

.cell-card-header:hover {
  background: var(--surface-3);
}

.cell-active-badge {
  margin-left: 0.25rem;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #ffd166;
  text-transform: uppercase;
}

.cell-card-title {
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  line-height: 1;
}

.cell-card-arrow {
  color: var(--text-faint);
  transition: transform 0.2s;
  font-size: 9px;
  flex-shrink: 0;
}

.cell-card.expanded .cell-card-arrow {
  transform: rotate(90deg);
}

.cell-card-actions {
  gap: var(--space-1);
}

.cell-card-body {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-top: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--surface-2);
}

.cell-pos-badge {
  width: 30px;
  min-width: 30px;
  text-align: center;
  font-size: 13px;
  font-weight: 400;
  background: var(--accent-bg);
  color: var(--accent);
  padding: 1px 3px;
  line-height: 1;
  height: 16px;
}

/* ---------- HEADER ROW / MINI INPUTS ---------- */

.cell-header-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 8px;
}

.cell-name-input-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cell-name-input,
.midi-select-mini {
  min-height: var(--ui-input-h);
  height: var(--ui-input-h);
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}

.cell-name-input {
  width: 74px;
  font-weight: 700;
  text-align: left;
  color: var(--accent);
}

.midi-select-mini {
  min-width: 82px;
  max-width: 82px;
}

.midi-select-mini:focus,
.cell-name-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- PARAM CONTROLS ---------- */

.param-section-title {
  display: none;
}

.param-row {
  display: grid;
  grid-template-columns: 56px 1fr 46px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  font-size: 12px;
  padding: 3px 0;
}

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

.param-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 48px;
  font-weight: 700;
}

.param-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  min-width: 0;
  text-align: right;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.param-slider {
  width: 100%;
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--surface-4);
  outline: none;
  border: 1px solid var(--border);
}

.param-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

.param-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

.param-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

/* ---------- MINI KNOBS ---------- */

.param-knob-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: nowrap;
  margin-top: 6px;
}

.param-knob-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.param-knob-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  min-width: 0;
  text-align: center;
}

.param-knob {
  -webkit-appearance: none;
  appearance: none;
  width: 64px;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-4);
  outline: none;
  border: 1px solid var(--border);
}

.param-knob::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.param-knob::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ---------- EMPTY STATE ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-4) var(--space-3);
  color: var(--text-muted);
  gap: 8px;
}

.empty-state svg {
  color: var(--text-faint);
}

.empty-state p {
  font-size: 12px;
  max-width: 28ch;
  line-height: 1.3;
}

/* ---------- IGNORE / TOGGLES ---------- */

.ignore-row {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.ignore-btn {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-muted);
  font-weight: 700;
  transition: all var(--transition);
}

.ignore-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.theme-btn {
  min-height: 28px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.theme-btn:hover {
  background: var(--surface-3);
}

.controls-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  color: var(--text);
  font-size: 12px;
  padding: 0 10px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
 
  background: var(--surface-2);
  font-weight: 700;
}

.btn:hover {
  background: var(--surface-3);
  border-color: rgba(255,255,255,0.15);
}

.btn.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn.btn-primary:hover {
  background: var(--accent-hover);
}

.btn.btn-active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.btn.btn-danger {
  background: rgba(168,44,60,0.15);
  border-color: rgba(168,44,60,0.3);
  color: #e06070;
}

.btn.btn-danger:hover {
  background: rgba(168,44,60,0.25);
}

.btn.btn-warn {
  background: rgba(200,106,32,0.15);
  border-color: rgba(200,106,32,0.3);
  color: var(--warn);
}

.btn.btn-warn:hover {
  background: rgba(200,106,32,0.25);
}

.btn-start {
  padding: 0 var(--space-6);
  min-height: 32px;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 800;
  letter-spacing: 0.04em;
  transition: background var(--transition), transform var(--transition);
}

.btn-start:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-start.running {
  background: #8a2030;
}

.btn-start.running:hover {
  background: #6e1828;
}

/* ---------- FOCUS CLEANUP ---------- */

#param-panel select:focus,
#param-panel input:focus,
#param-panel button:focus {
  outline: none;
  box-shadow: none;
}

#wall-panel select:focus,
#wall-panel select:focus-visible,
#wall-panel input:focus,
#wall-panel input:focus-visible,
#wall-panel button:focus,
#wall-panel button:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

#top-bar select:focus,
#top-bar select:focus-visible {
  outline: none;
  box-shadow: none;
}

/* ---------- GLOBAL SCROLLBAR ---------- */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: 3px;
}

/* ---------- OPTIONAL SYNTH DISPLAY POLISH ---------- */

#right-panel .card,
.cell-card,
.top-bpm,
.top-btn,
.top-select,
.top-bpm-input,
.cell-name-input,
.midi-select-mini,
.btn,
.ignore-btn,
.theme-btn {
  box-shadow: none;
}

#right-panel .card {
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--surface) 92%, white 8%),
      var(--surface)
    );
}

.cell-card-header,
#right-panel .card-title {
 
    );
}

#right-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

#right-panel .card.panel-sound,
#right-panel .card.panel-wall {
  flex: 1 1 0;
  min-height: 0;
  transition:
    opacity 180ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 180ms cubic-bezier(0.16, 1, 0, 0.3, 1);
}

#right-panel.sound-expanded .panel-sound,
#right-panel.wall-expanded .panel-wall {
  flex: 1 1 100%;
}

#right-panel.sound-expanded .panel-wall,
#right-panel.wall-expanded .panel-sound {
  display: none;
}

#right-panel .card.panel-sound,
#right-panel .card.panel-wall {
  overflow: hidden;
}

/* fejléc kattinthatóbb */
#right-panel .card-title {
  cursor: pointer;
  user-select: none;
}

/* opcionális vizuális állapot */
#right-panel.sound-expanded .panel-sound .card-title,
#right-panel.wall-expanded .panel-wall .card-title {
  color: var(--accent);
  background: var(--accent-bg);
}

/* opcionális kis nyíl */
#right-panel .card-title::after {
  content: '▾';
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

#right-panel.sound-expanded .panel-sound .card-title::after,
#right-panel.wall-expanded .panel-wall .card-title::after {
  transform: rotate(180deg);
  color: var(--accent);
}

.panel-heading {
  margin: 0;
}

.panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.panel-toggle span {
  pointer-events: none;
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}