
@scope (.omni-generatory-szlaczki) {

  /* ===== RESET & BASE ===== */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :scope {
    --primary: #4f883d;
    --primary-tint: #edf6ea;
    --primary-dark: #3f6e31;
  }

  :scope {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    min-height: 900px;
  }

  /* ===== LAYOUT ===== */
  .app {
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: 1fr;
    min-height: 900px;
  }

  header {
    grid-column: 1 / -1;
    background: white;
    color: var(--primary);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.2);
  }
  header h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.5px; }
  header p  { font-size: 0.82rem; opacity: .8; }

  /* ===== PANEL BOCZNY ===== */
  .panel {
    background: white;
    border-right: 1px solid #e0e4ef;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .section {
    padding: 14px 18px;
    border-bottom: 1px solid #eef0f7;
  }

  .section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    margin-bottom: 10px;
  }

  /* ===== TRYB UKŁADU ===== */
  .mode-picker {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .mode-card {
    border: 2px solid #e0e4ef;
    border-radius: 10px;
    padding: 10px 8px;
    cursor: pointer;
    text-align: center;
    transition: all .15s;
    background: #fafbff;
  }

  .mode-card:hover { border-color: var(--primary); background: var(--primary-tint); }

  .mode-card.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
  }

  .mode-card .mode-icon {
    font-size: 1.4rem;
    margin-bottom: 4px;
    display: block;
    line-height: 1;
  }

  .mode-card .mode-label {
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
  }

  /* ===== SIATKA KSZTAŁTÓW ===== */
  .shapes-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }

  .shape-btn {
    aspect-ratio: 1;
    border: 2px solid #e0e4ef;
    border-radius: 8px;
    background: #fafbff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s ease;
    position: relative;
    overflow: hidden;
  }

  .shape-btn img {
    width: 80%;
    height: 80%;
    object-fit: contain;
    filter: grayscale(1);
    opacity: .72;
    pointer-events: none;
  }

  .shape-btn:hover {
    border-color: var(--primary);
    background: var(--primary-tint);
    transform: scale(1.08);
    z-index: 1;
  }

  /* ===== KOLEJKA ===== */
  .queue-area {
    min-height: 54px;
    border: 2px dashed #cdd0e3;
    border-radius: 10px;
    padding: 7px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-content: flex-start;
    background: #fafbff;
  }

  .queue-item {
    background: #edf6ea;
    color: var(--primary-dark);
    border: 1px solid #c5ddbc;
    border-radius: 6px;
    padding: 3px 6px 3px 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background .15s;
  }

  .queue-item:hover {
    background: #ffdede;
    border-color: #eaa;
    color: #8a1f1f;
  }

  .queue-item img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    filter: grayscale(1);
    pointer-events: none;
  }

  .queue-item .qi-x {
    font-family: sans-serif;
    font-size: 0.6rem;
    opacity: .8;
  }

  .queue-hint {
    font-family: sans-serif;
    font-size: 0.75rem;
    color: #aaa;
    align-self: center;
    margin-left: 4px;
  }

  /* ===== CONTROLS ===== */
  .control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 9px;
  }

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

  .control-row label {
    font-size: 0.8rem;
    color: #555;
    min-width: 82px;
    overflow-wrap: anywhere;
  }

  .control-row input[type=range] {
    flex: 1;
    min-width: 0;
    appearance: none;
    -webkit-appearance: none;
    height: 6px;
    border-radius: 999px;
    background: #e5f2e1;
    cursor: pointer;
  }

  .control-row input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: #e5f2e1; }
  .control-row input[type=range]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border: 0; border-radius: 50%; background: var(--primary); }
  .control-row input[type=range]::-moz-range-track { height: 6px; border-radius: 999px; background: #e5f2e1; }
  .control-row input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--primary); }
  }

  .control-row .val {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 38px;
    text-align: right;
  }

  .control-row input[type=text] {
    flex: 1;
    min-width: 0;
    border: 1px solid #dde0ef;
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 0.82rem;
    outline: none;
    transition: border .15s;
  }
  .control-row input[type=text]:focus { border-color: var(--primary); }

  /* ===== PRZYCISKI ===== */
  .btn-primary {
    display: block;
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    margin-top: 4px;
  }
  .btn-primary:hover  { opacity: .9; }
  .btn-primary:active { transform: scale(.98); }

  .btn-secondary {
    display: block;
    width: 100%;
    padding: 8px;
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    margin-top: 7px;
  }
  .btn-secondary:hover { background: var(--primary-tint); }

  /* ===== OBSZAR PODGLĄDU ===== */
  .preview-area {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    background: #e8eaf0;
  }

  .preview-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    margin-bottom: 14px;
    align-self: stretch;
    width: 100%;
  }

  /* ===== KARTA A4 ===== */
  .a4-wrap {
    width: 794px;
  }

  .a4-scale {
    width: 794px;
    transform-origin: top left;
  }

  .a4 {
    width: 794px;
    min-height: 1123px;
    background: white;
    box-shadow: 0 4px 24px rgba(0,0,0,.2);
    padding: 44px 52px 32px;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }

  .a4-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
    font-size: 0.76rem;
    color: #888;
    gap: 16px;
  }

  .a4-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 10px;
    text-align: center;
  }

  .a4-instruction {
    font-size: 0.8rem;
    color: #555;
    text-align: center;
    margin-bottom: 16px;
  }

  /* ===== WIERSZE – WSPÓLNE ===== */
  .szlaczek-rows {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  /* Odstęp pionowy między blokami */
  .row-spacer { flex-shrink: 0; }

  /* ===== BLOK LINIATURY =====
     Struktura pionowa jednego bloku:

     ━━━━━━━━━━━━━━━━━  linia górna   (.staff-zone.top)
     a b a b a b a b a  strefa szlaczka
     ━━━━━━━━━━━━━━━━━  linia środkowa (.staff-zone.bottom)
     [puste miejsce]    strefa ćwiczenia
     ━━━━━━━━━━━━━━━━━  linia dolna   (border-bottom na całym bloku)

     Blok = flex-column. Strefy mają jawne wysokości z JS.
  */
  .staff-block {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-bottom: 1px solid #aaa;  /* linia dolna */
  }

  /* Strefa górna (szlaczek) i dolna (ćwiczenie) */
  .staff-zone {
    border-top: 1px solid #aaa;     /* linia górna / środkowa */
    overflow: hidden;
    flex-shrink: 0;
  }

  /* Szlaczek w strefie górnej */
  .staff-pattern {
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    padding-left: 4px;
    gap: var(--shape-gap, 0px);
  }

  .staff-pattern img {
    height: 100%;
    width: auto;
    object-fit: contain;
    filter: grayscale(1);
    pointer-events: none;
  }

  /* ===== TRYB 2 – wzór po lewej + liniatura na całej szerokości ===== */
  .mode2-row {
    position: relative;
    flex-shrink: 0;
  }

  .mode2-lines-col {
    width: 100%;
    display: flex;
    flex-direction: column;
  }

  .mode2-sample {
    position: absolute;
    left: 12px;
    top: 0;
    height: calc(var(--line-h) * 2);
    width: var(--sample-w);
    pointer-events: none;
    overflow: hidden;
  }

  .mode2-sample img {
    display: block;
    height: 100%;
    width: auto;
    margin: 0 auto;
    object-fit: contain;
    filter: grayscale(1);
    pointer-events: none;
  }

  /* Zamknięcie liniatury na dole ostatniego bloku */
  .mode2-row.is-last .mode2-lines-col {
    border-bottom: 1px solid #aaa;
  }

  .mode2-placeholder {
    position: absolute;
    left: 10px;
    top: 0;
    height: calc(var(--line-h) * 2);
    display: flex;
    align-items: center;
    color: #ccc;
    font-size: .72rem;
    pointer-events: none;
  }

  /* Stopka */
  .a4-footer {
    margin-top: 14px;
    text-align: center;
    font-size: 0.58rem;
    color: #ccc;
    letter-spacing: 0.5px;
    flex-shrink: 0;
  }

  /* ===== PRINT ===== */
  @media print {
    .app { display: block; }
    .panel, header { display: none !important; }
    .preview-area { padding: 0; background: white; }
    .preview-label { display: none; }
    .a4-wrap { transform: none !important; }
    .a4 {
      box-shadow: none;
      width: 210mm;
      min-height: 297mm;
      padding: 14mm 16mm 10mm;
    }
  }

  @media screen {
    .preview-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .btn-download-top { width: auto; padding: 9px 14px; border-radius: 5px; }
  }

}
