:root {
    --ink: #3a3226;
    --muted: #8a7f6c;
    --line: #ece3d2;
    --paper: #dff0ff;
    --panel: #fffdf8;
    --primary: #ff5a5f;
    --primary-dark: #e0393e;
    --info: #4d9de0;
    --info-dark: #2f7ec4;
    --gold: #ffce45;
    --gold-dark: #e0a600;
    --green: #4caf6d;
    --danger: #d64545;
    --danger-dark: #b3362f;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
    margin: 0;
    padding: 1.5rem;
    font-family: 'Quicksand', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-weight: 600;
    color: var(--ink);
    background-color: var(--paper);
    background-image: radial-gradient(rgba(255, 255, 255, .6) 2px, transparent 2px);
    background-size: 26px 26px;
}

.page-header { text-align: left; }

.page-banner {
    display: inline-block;
    background: var(--panel);
    border-radius: 16px;
    padding: 0.85rem 1.5rem;
    transform: rotate(-1deg);
    box-shadow: 0 12px 22px rgba(58, 50, 38, .14);
    position: relative;
    margin-bottom: 0.6rem;
}

.page-banner::before,
.page-banner::after {
    content: '';
    position: absolute;
    top: -7px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
}
.page-banner::before { left: 20px; background: var(--primary); }
.page-banner::after { right: 24px; background: var(--info); }

.page-header h1 { margin: 0; font-size: 1.7rem; font-weight: 700; font-family: 'Baloo 2', cursive; color: var(--ink); }
.page-header p { margin: 0 0 1.5rem; color: #4a5a72; font-weight: 600; }

.flash {
    padding: 0.6rem 1rem;
    background: #eafaf0;
    border: 2px solid var(--green);
    border-radius: 10px;
    font-weight: 600;
}

.layout {
    display: grid;
    grid-template-columns: minmax(360px, 500px) 1fr;
    gap: 1.5rem;
    align-items: stretch;
    min-height: calc(100vh - 3rem);
}

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; min-height: 0; }
    .preview-panel { position: static; }
    .preview-panel .preview-sheet { overflow: visible; }
}

.panel {
    position: relative;
    background: var(--panel);
    border: none;
    border-radius: 22px;
    padding: 1.35rem 1.5rem;
    box-shadow: 0 16px 32px rgba(58, 50, 38, .12);
}

.panel::before {
    content: '';
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, .3), inset -2px -2px 0 rgba(0, 0, 0, .1);
}

.preview-panel::before { background: var(--info); }

.panel h2 {
    display: flex;
    align-items: center;
    font-family: 'Baloo 2', cursive;
    font-size: 1.15rem;
    font-weight: 700;
    margin: 1.5rem 0 0.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px dashed var(--line);
}

.panel h2:first-child { margin-top: 0; }

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.preview-head h2 { flex: 1; border-bottom: none; margin: 0; padding-bottom: 0; }

.preview-sticker {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 0.8rem;
    color: #6b4a00;
    background: var(--gold);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    transform: rotate(3deg);
    box-shadow: 0 3px 0 rgba(0, 0, 0, .08);
    flex: none;
    margin-bottom: 1.1rem;
}
.preview-sticker svg { width: 0.9rem; height: 0.9rem; }

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 1.8rem;
    height: 1.8rem;
    margin-right: 0.6rem;
    border-radius: 50%;
    background: var(--gold);
    color: #6b4a00;
    font-family: 'Baloo 2', cursive;
    font-size: 1rem;
    font-weight: 700;
    transform: rotate(-6deg);
    box-shadow: 0 2px 0 rgba(0, 0, 0, .08);
}

.section-hint {
    margin: 0.35rem 0 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

.field-label {
    margin-bottom: 0.4rem;
    font-size: 0.92rem;
    font-weight: 700;
}

form label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.92rem;
    font-weight: 700;
}

form input[type="number"],
form input[type="text"],
form select,
form textarea {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.55rem 0.7rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--ink);
}

form select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7f6c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 1.1rem;
    padding-right: 2.2rem;
}

form input:focus-visible,
form select:focus-visible,
form textarea:focus-visible {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 3px rgba(77, 157, 224, 0.25);
}

.operations-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.operations-grid--fit {
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
}

.operation-chip {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-width: 0;
    margin-bottom: 0 !important;
    padding: 0.75rem 0.5rem;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.operation-chip > span {
    overflow-wrap: break-word;
    min-width: 0;
    white-space: nowrap;
}

.operation-chip input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.operation-chip .chip-icon { width: 1.5rem; height: 1.5rem; flex: none; color: var(--muted); }

.operation-chip:hover { border-color: var(--info); }

.operation-chip:has(input:checked) {
    background: var(--gold);
    border-color: var(--gold-dark);
    color: #6b4a00;
    transform: rotate(-1.5deg);
    box-shadow: 0 4px 0 rgba(0, 0, 0, .06);
}

.operation-chip:has(input:checked) .chip-icon { color: #6b4a00; }

.operation-chip:has(input:focus-visible) {
    outline: 3px solid rgba(77, 157, 224, 0.4);
    outline-offset: 2px;
}

.value-grid {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.value-grid--range {
    grid-template-columns: repeat(5, 1fr);
}

.value-grid--compact {
    grid-template-columns: repeat(auto-fit, minmax(2.6rem, 1fr));
}

.value-chip {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    margin-bottom: 0 !important;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fff;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.value-chip--compact {
    border-radius: 10px;
    font-size: 0.85rem;
}

.value-chip input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.value-chip:hover { border-color: var(--info); }

.value-chip:has(input:checked) {
    background: var(--gold);
    border-color: var(--gold-dark);
    color: #6b4a00;
    transform: rotate(-1.5deg);
    box-shadow: 0 4px 0 rgba(0, 0, 0, .06);
}

.value-chip:has(input:focus-visible) {
    outline: 3px solid rgba(77, 157, 224, 0.4);
    outline-offset: 2px;
}

.field-label--sub {
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.custom-range-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.custom-range-group {
    padding: 0.75rem 0.85rem;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: #fff;
}

.range-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.range-inputs label {
    margin-bottom: 0 !important;
    font-size: 0.8rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-family: 'Baloo 2', cursive;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem 0.2rem 0.45rem;
    border-radius: 999px;
    margin-left: 0.4rem;
    vertical-align: middle;
    transform: rotate(-2deg);
}

.badge-gold { background: var(--gold); color: #6b4a00; }
.badge-icon { width: 0.7rem; height: 0.7rem; }

.tooltip-wrapper {
    position: relative;
    display: inline-flex;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.tooltip-trigger {
    width: 1.3rem;
    height: 1.3rem;
    padding: 0;
    border-radius: 50%;
    border: 2px solid var(--info);
    background: #eaf5ff;
    color: var(--info-dark);
    font-family: 'Quicksand', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
}

.tooltip-bubble {
    position: absolute;
    bottom: calc(100% + 0.55rem);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 230px;
    background: var(--ink);
    color: #fff8ec;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.35;
    padding: 0.55rem 0.7rem;
    border-radius: 12px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease;
    z-index: 20;
    pointer-events: none;
}

.tooltip-bubble::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--ink);
}

.tooltip-wrapper:hover .tooltip-bubble,
.tooltip-wrapper:focus-within .tooltip-bubble {
    opacity: 1;
    visibility: visible;
}

.switch-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 1rem !important;
}

.switch {
    position: relative;
    display: inline-block;
    flex: none;
    width: 2.7rem;
    height: 1.55rem;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.switch-track {
    position: absolute;
    inset: 0;
    background: #dcd3bd;
    border-radius: 999px;
    transition: background-color 0.15s ease;
}

.switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 1.15rem;
    height: 1.15rem;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
}

.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(1.15rem); }

.switch input:focus-visible + .switch-track {
    outline: 3px solid rgba(77, 157, 224, 0.4);
    outline-offset: 2px;
}

.actions {
    display: flex;
    gap: 0.9rem;
    margin-top: 1.4rem;
}

button.primary,
button.secondary {
    font-family: 'Baloo 2', cursive;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.7rem 1.4rem;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    transition: transform 0.05s ease, box-shadow 0.05s ease;
}

button.primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 5px 0 var(--primary-dark);
}

button.primary:active {
    box-shadow: 0 1px 0 var(--primary-dark);
    transform: translateY(4px);
}

button.secondary {
    background: #fff;
    color: var(--info-dark);
    box-shadow: 0 5px 0 #cfe4f5, inset 0 0 0 2px #cfe4f5;
}

button.secondary:active {
    box-shadow: 0 1px 0 #cfe4f5, inset 0 0 0 2px #cfe4f5;
    transform: translateY(4px);
}

.hint { font-size: 0.8rem; font-weight: 600; color: var(--muted); }

.snapshots { list-style: none; margin: 0; padding: 0; }

.snapshots li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border-bottom: 1px dashed var(--line);
    font-size: 0.9rem;
}

.snapshot-actions { display: inline-flex; gap: 0.75rem; }
.snapshot-actions form { display: inline; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--info-dark);
    text-decoration: underline;
    cursor: pointer;
}

.link-button.danger { color: var(--danger-dark); }

.preview-panel {
    position: sticky;
    top: 1rem;
    display: flex;
    flex-direction: column;
}

.preview-panel .preview-sheet {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.preview-sheet {
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.preview-sheet svg {
    display: block;
    width: 100%;
    height: auto;
}

.preview-sheet.loading { opacity: 0.5; }
.preview-sheet.has-error { border-color: var(--danger); }

.preview-placeholder {
    margin: 0;
    padding: 3rem 1rem;
    text-align: center;
    font-weight: 600;
    color: var(--muted);
}

.preview-error-message {
    margin: 0;
    padding: 3rem 1rem;
    text-align: center;
    font-weight: 700;
    color: var(--danger-dark);
    white-space: pre-wrap;
}

@media (max-width: 480px) {
    .operations-grid { grid-template-columns: 1fr; }
    .actions { flex-direction: column; }
    .actions button { width: 100%; }
}

/* Musi być ostatnią regułą w pliku, żeby wygrywać w kaskadzie
   z innymi !important-owymi regułami display (np. .switch-label, .operation-chip). */
[hidden] { display: none !important; }
