
@font-face {
  font-family: 'Elementarz';
  src: url('./elementarz.ttf') format('truetype');
  font-display: swap;
}

@scope (.omni-generatory-pisanie-po-sladzie) {

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

  :scope {
    --primary: #4f883d;
    --primary-dark: #3f6e31;
    --primary-tint: #edf6ea;
    --page-line: #a6aaa8;
    --grid-line: #aeb4b1;
  }

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

  .app {
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: 1fr;
    min-height: 900px;
    width: 100%;
  }

  header {
    grid-column: 1 / -1;
    background: #ffffff;
    color: var(--primary);
    padding: 14px 24px;
    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 {
    background: #ffffff;
    border-right: 1px solid #e0e4ef;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .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;
  }

  .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: #ffffff;
  }

  .mode-card .mode-icon {
    font-size: 1.3rem;
    margin-bottom: 4px;
    display: block;
    line-height: 1;
    font-family: 'Elementarz', cursive;
  }

  .mode-card .mode-label {
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }

  .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;
    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);
  }

  .control-row input[type=color] {
    width: 44px;
    height: 30px;
    border: 1px solid #dde0ef;
    border-radius: 6px;
    background: #ffffff;
    padding: 1px;
    cursor: pointer;
  }

  .control-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
  }

  .control-col label {
    font-size: 0.8rem;
    color: #555;
  }

  .control-col textarea {
    width: 100%;
    min-height: 96px;
    resize: vertical;
    border: 1px solid #dde0ef;
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 0.8rem;
    font-family: inherit;
    outline: none;
    line-height: 1.35;
  }

  .control-col textarea:focus {
    border-color: var(--primary);
  }

  .control-col.emphasis-box {
    margin-top: 12px;
    padding: 10px;
    border: 2px solid #cfe2c8;
    border-radius: 12px;
    background: linear-gradient(180deg, #f7fbf5 0%, #edf6ea 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  }

  .control-col.emphasis-box label {
    font-weight: 700;
    color: var(--primary-dark);
  }

  .control-col.emphasis-box textarea {
    min-height: 124px;
    border: 2px dashed var(--primary);
    background: #ffffff;
    padding: 10px 12px;
    caret-color: var(--primary-dark);
  }

  .control-col.emphasis-box textarea:focus {
    border-style: solid;
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 4px rgba(79, 136, 61, 0.14);
  }

  .control-col.emphasis-box textarea::placeholder {
    color: #9ba39d;
    opacity: 1;
  }

  .control-col.emphasis-box textarea:placeholder-shown {
    background-image: linear-gradient(var(--primary), var(--primary));
    background-size: 3px 1.5em;
    background-position: 12px 12px;
    background-repeat: no-repeat;
  }

  .hint {
    font-size: .72rem;
    color: #8896a1;
    margin-top: 2px;
  }

  .hidden-file-input { display: none; }

  .image-items {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .image-item {
    border: 1px solid #e3e7f0;
    border-radius: 10px;
    padding: 9px;
    background: #fafbff;
  }

  .image-item-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .image-thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid #d8deec;
    background: #ffffff;
    object-fit: contain;
    flex-shrink: 0;
  }

  .image-remove {
    border: none;
    background: #ffecee;
    color: #9f2a2a;
    border-radius: 7px;
    font-size: 0.72rem;
    padding: 4px 8px;
    cursor: pointer;
    flex-shrink: 0;
  }

  .image-control {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
  }

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

  .image-control label {
    min-width: 78px;
    font-size: 0.72rem;
    color: #5f6473;
  }

  .image-control input[type=range] {
    flex: 1;
    min-width: 0;
    accent-color: var(--primary);
  }

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

  .btn-primary {
    display: block;
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #ffffff;
    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: .92; }
  .btn-primary:active { transform: scale(.98); }

  .btn-secondary {
    display: block;
    width: 100%;
    padding: 8px;
    background: #ffffff;
    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); }

  .preview-area {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    background: #e8eaf0;
    min-width: 0;
  }

  .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%;
  }

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

  .a4 {
    width: 794px;
    min-height: 1123px;
    background: #ffffff;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .2);
    padding: 44px 52px 32px;
    display: flex;
    flex-direction: column;
    /* Arial/Helvetica instead of -apple-system: html2canvas cannot resolve OS-specific
       font aliases and falls back to a cursive/script face, causing merged words in PDF. */
    font-family: Arial, Helvetica, sans-serif;
  }

  .a4.is-canvas-preview {
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }

  .a4-canvas-preview {
    display: block;
    width: 794px;
    height: auto;
  }

  .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: 14px;
  }

  .sheet-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
  }

  .trace-row {
    flex-shrink: 0;
    position: relative;
    z-index: 1;
  }

  .sheet-images {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
  }

  .sheet-image {
    position: absolute;
    left: 50%;
    top: 50%;
    transform-origin: center center;
    max-width: none;
    max-height: none;
    user-select: none;
    -webkit-user-drag: none;
  }

  .lineatura-row {
    overflow: visible;
    position: relative;
  }

  .lineatura-guides {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .lineatura-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--page-line);
  }

  .lineatura-text {
    font-family: 'Elementarz', cursive;
    white-space: pre;
    letter-spacing: 0.5px;
    line-height: 1;
    user-select: none;
    position: absolute;
    left: 8px;
  }

  .kratka-row {
    position: relative;
    overflow: hidden;
    background-image:
      linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
      linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size), var(--grid-size) var(--grid-size);
    border-right: 1px solid var(--grid-line);
  }

  .kratka-row.is-last {
    border-bottom: 1px solid var(--grid-line);
  }

  .kratka-text {
    position: absolute;
    left: 0;
    font-family: 'Elementarz', cursive;
    white-space: pre;
    letter-spacing: 0.5px;
    line-height: 1;
    user-select: none;
  }

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

  @media (max-width: 849px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
    .panel { border-right: none; border-bottom: 1px solid #e0e4ef; }
  }

  @media print {
    @page { size: A4; margin: 0; }
    *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    html, body { width: 210mm; height: 297mm; overflow: hidden; }
    .app { display: block; width: 210mm; }
    .panel, header { display: none !important; }
    .preview-area {
      display: block !important;
      padding: 0 !important;
      background: #ffffff !important;
      overflow: visible !important;
      width: 210mm !important;
    }
  .preview-label { display: none !important; }
    .a4-wrap {
      width: 210mm !important;
      height: auto !important;
      overflow: visible !important;
    }
    .a4-scale {
      transform: none !important;
      width: 210mm !important;
    }
    .a4 {
      box-shadow: none !important;
      width: 210mm !important;
      min-height: 297mm;
      padding: 14mm 16mm 10mm !important;
    }
  }

  @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;
    }
  }

}
