:root {
  --bg: #111827;
  --card: #1f2937;
  --field: #111827;
  --border: #4b5563;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #dc2626;
  --accent-hover: #b91c1c;
  --secondary: #374151;
  --secondary-hover: #4b5563;
  --link: #93c5fd;
  --error: #fca5a5;
  --warn: #fcd34d;
}
* { box-sizing: border-box; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  max-width: 1120px;
  margin: 4vh auto;
  padding: 0 16px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--link); }
h2 { margin: 0 0 4px; font-size: 1.25rem; }
h3 { margin: 0 0 10px; font-size: 1.05rem; }
header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.brand { display: inline-flex; background: #fff; border-radius: 10px; padding: 8px 14px; line-height: 0; }
.brand img { height: 48px; width: auto; max-width: 200px; object-fit: contain; }
.title { font-size: 1.6rem; font-weight: 700; color: var(--text); text-decoration: none; }
.card { padding: 20px; background: var(--card); border-radius: 12px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; margin-top: 18px; }
@media (max-width: 820px) { .layout { grid-template-columns: minmax(0, 1fr); } }

fieldset { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
label { display: block; margin-bottom: 6px; }
input[type="url"], input[type="text"], input[type="number"], select, button { font: inherit; border-radius: 8px; padding: 11px; }
input[type="url"], input[type="text"], input[type="number"], select {
  width: 100%;
  min-width: 0;
  background: var(--field);
  color: #fff;
  border: 1px solid var(--border);
}
input:disabled, select:disabled { opacity: .5; }
input[type="number"] { padding: 9px 8px; }
button { background: var(--accent); color: #fff; border: 0; cursor: pointer; }
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: var(--secondary); }
button.secondary:hover:not(:disabled) { background: var(--secondary-hover); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="file"] { width: 100%; color: var(--muted); font: inherit; }
input[type="file"]::file-selector-button {
  font: inherit; border: 0; border-radius: 8px; padding: 10px 12px; margin-right: 10px;
  background: var(--secondary); color: #fff; cursor: pointer;
}

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.grow { flex: 1 1 280px; min-width: 0; }
.inline { display: flex; gap: 8px; }
.inline > input { flex: 1; }
.inline > button { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grid4 label, .grid2 label { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.mt { margin-top: 10px; }
.ratio-row { display: flex; align-items: center; gap: 8px; }
.ratio-row input { flex: 1 1 0; text-align: center; font-weight: 600; }
.ratio-row .colon { font-weight: 700; font-size: 1.2rem; color: var(--muted); }
.ratio-row button { flex: 0 0 auto; padding: 9px 14px; font-size: 1.1rem; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.mt-lg { margin-top: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 10px; font-size: .9rem; background: var(--secondary); border-radius: 999px; }
.chip:hover:not(:disabled) { background: var(--secondary-hover); }
.chip.active, .chip.active:hover:not(:disabled) { background: var(--accent); }

/* ---------- obszar zdjęcia ---------- */
.stage {
  background: #0b1220;
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 320px;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.stage.dragover { border-color: var(--accent); background: #1a1020; }
.drop { text-align: center; padding: 30px 12px; }
.drop p { margin: 4px 0; }
.canvas-box {
  position: relative;
  line-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}
/* Przyciemnienie przycięte do zdjęcia; uchwyty kadru mogą wystawać poza krawędź. */
.clip {
  position: relative;
  overflow: hidden;
  /* szachownica pod przezroczystymi obrazami */
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d1d5db 25%, transparent 25%),
    linear-gradient(-45deg, #d1d5db 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d1d5db 75%),
    linear-gradient(-45deg, transparent 75%, #d1d5db 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.clip canvas { display: block; }
.shade {
  position: absolute;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(3, 7, 18, .62);
}
.crop {
  position: absolute;
  outline: 2px solid #fff;
  cursor: move;
}
.crop:focus-visible { outline: 2px solid var(--accent); }
.crop .grid {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to right, transparent calc(33.333% - .5px), rgba(255,255,255,.45) calc(33.333% - .5px), rgba(255,255,255,.45) calc(33.333% + .5px), transparent calc(33.333% + .5px),
      transparent calc(66.666% - .5px), rgba(255,255,255,.45) calc(66.666% - .5px), rgba(255,255,255,.45) calc(66.666% + .5px), transparent calc(66.666% + .5px)),
    linear-gradient(to bottom, transparent calc(33.333% - .5px), rgba(255,255,255,.45) calc(33.333% - .5px), rgba(255,255,255,.45) calc(33.333% + .5px), transparent calc(33.333% + .5px),
      transparent calc(66.666% - .5px), rgba(255,255,255,.45) calc(66.666% - .5px), rgba(255,255,255,.45) calc(66.666% + .5px), transparent calc(66.666% + .5px));
}
.h {
  position: absolute; width: 18px; height: 18px;
  background: #fff; border: 2px solid var(--accent); border-radius: 50%;
  transform: translate(-50%, -50%);
}
/* większy obszar dotyku */
.h::after { content: ""; position: absolute; inset: -12px; }
.h[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.h[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.h[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.h[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.h.edge { width: 22px; height: 8px; border-radius: 4px; }
.h[data-h="n"] { left: 50%; top: 0; cursor: ns-resize; }
.h[data-h="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.h[data-h="e"] { left: 100%; top: 50%; cursor: ew-resize; width: 8px; height: 22px; }
.h[data-h="w"] { left: 0; top: 50%; cursor: ew-resize; width: 8px; height: 22px; }
.crop.locked .edge { display: none; }

.result { font-weight: 600; margin: 12px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions button { flex: 1 1 auto; }

/* ---------- kalkulator ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 14px; }
@media (max-width: 700px) { .calc-grid { grid-template-columns: 1fr; } }
.calc-part { background: var(--field); border-radius: 10px; padding: 16px; min-width: 0; }
.big { font-size: 1.8rem; font-weight: 700; margin: 12px 0 0; }

.muted { color: var(--muted); font-size: .92rem; }
.error { color: var(--error); }
.warn { color: var(--warn); font-size: .92rem; margin: 8px 0 0; }
footer { margin-top: 16px; color: var(--muted); }
[hidden] { display: none !important; }
