@font-face { font-family: Andika; font-weight: 400; font-display: swap; src: url(../fonts/andika-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Andika; font-weight: 400; font-display: swap; src: url(../fonts/andika-400-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: Andika; font-weight: 700; font-display: swap; src: url(../fonts/andika-700-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Andika; font-weight: 700; font-display: swap; src: url(../fonts/andika-700-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ef;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --der: #1f6fe0;
  --die: #e8408f;
  --das: #22a54a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 8px 24px rgba(20, 24, 40, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Andika, sans-serif;
  padding-bottom: 96px;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Pasek górny ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 1.15rem; }
.brand p { margin: 0; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.logo { display: inline-flex; gap: 3px; padding: 9px 8px; border-radius: 12px; background: var(--accent-soft); }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.badge { background: var(--accent); color: #fff; font-size: .72rem; padding: 1px 7px; border-radius: 999px; }
.menu { position: relative; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 1.1rem; }
.menu-pop { position: absolute; right: 0; top: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; min-width: 260px; display: grid; }
.menu-pop button, .menu-pop .as-button { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.menu-pop button:hover, .menu-pop .as-button:hover { background: var(--surface-2); }

/* ---------- Ogólne ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.panel-head h2 { font-size: 1.1rem; }
.pill { font-size: .75rem; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.edit-pill { background: #fff7e6; border-color: #fcd9a0; color: #9a5b00; }
.muted, .hint { color: var(--muted); font-size: .85rem; }
.hint.inline { font-weight: 400; margin-left: 6px; }
.center { text-align: center; justify-content: center; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.der { background: var(--der); }
.dot.die { background: var(--die); }
.dot.das { background: var(--das); }
.dot.none { background: transparent; border: 2px dashed #b9bfcc; }

.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 12px; font-weight: 600; cursor: pointer; min-height: 44px; transition: transform .05s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Formularz ---------- */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
.field { display: grid; gap: 8px; margin: 0 0 20px; border: 0; padding: 0; }
.label { font-weight: 700; font-size: .92rem; padding: 0; }
input[type=text], input[type=search] {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface-2);
  border-radius: 12px; padding: 12px 14px; outline: none; transition: border-color .15s, background .15s;
}
input[type=text]:focus, input[type=search]:focus { border-color: var(--accent); background: #fff; }
#wordInput { font-family: Andika, system-ui, sans-serif; font-size: 1.4rem; padding: 12px 16px; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; font-weight: 700; background: var(--surface-2);
  font-family: Andika, system-ui, sans-serif; font-size: 1.05rem;
}
.segmented .dot { width: 16px; height: 16px; }
.segmented input:checked + span { border-color: var(--ink); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.image-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dropzone {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 14px; min-height: 92px; padding: 12px 16px;
  border: 2px dashed #c9cede; border-radius: 14px; cursor: pointer; background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop-text { display: grid; }
.drop-text small { color: var(--muted); }
.current-image img { width: 68px; height: 68px; object-fit: contain; background: #fff; border-radius: 10px; border: 1px solid var(--line); }

.suggest { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); }
.suggest-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-weight: 700; font-size: .9rem; }
.suggest-search { display: flex; gap: 6px; flex: 1; min-width: 200px; max-width: 320px; }
.suggest-search input { padding: 7px 10px; font-size: .88rem; }
.suggest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; min-height: 96px; align-items: center; }
.suggest-grid .muted { grid-column: 1 / -1; margin: 0; text-align: center; }
.sugg {
  aspect-ratio: 1; border: 2px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; padding: 8px;
  display: grid; place-items: center; position: relative; transition: border-color .15s, transform .1s;
}
.sugg:hover { border-color: var(--accent); transform: translateY(-1px); }
.sugg.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sugg img { max-width: 100%; max-height: 100%; }
.sugg small { position: absolute; bottom: 2px; right: 6px; font-size: .62rem; color: var(--muted); }
.skeleton { aspect-ratio: 1; border-radius: 12px; background: linear-gradient(90deg, #eceef5, #f7f8fc, #eceef5); background-size: 200% 100%; animation: shimmer 1.1s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.preview-panel { position: sticky; top: 84px; }
.preview-canvas { width: 100%; height: auto; display: block; border-radius: 6px; box-shadow: 0 6px 20px rgba(20, 24, 40, .12); background: #fff; }
.preview-labels { display: grid; grid-template-columns: 1fr 1fr; text-align: center; font-size: .72rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Biblioteka ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px; margin-bottom: 16px; }
.toolbar #searchInput { flex: 1 1 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); background: var(--surface-2); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .88rem; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.toolbar-actions { display: flex; gap: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s, transform .1s; position: relative;
}
.card:hover { transform: translateY(-2px); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.card .thumb { padding: 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.card .thumb-img { width: 100%; height: auto; display: block; background: #fff; border-radius: 4px; box-shadow: 0 2px 8px rgba(20, 24, 40, .1); aspect-ratio: 2 / 1; }
.card .meta { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.card .word { font-family: Andika, system-ui, sans-serif; font-size: 1.15rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .letters { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.card .card-actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.card .card-actions .btn { flex: 0 0 44px; white-space: nowrap; }
.card .card-actions .btn[data-action=edit] { flex: 1; }
.select-box {
  position: absolute; top: 18px; left: 18px; width: 30px; height: 30px; border-radius: 9px; background: #fff;
  border: 2px solid #aab1c2; display: grid; place-items: center; z-index: 2; box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}
.select-box input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; width: 100%; height: 100%; }
.select-box::after { content: ''; width: 9px; height: 15px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -2px); opacity: 0; }
.card.selected .select-box { background: var(--accent); border-color: var(--accent); }
.card.selected .select-box::after { opacity: 1; }
.select-box:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

.empty { text-align: center; padding: 48px 16px; }
.empty-art { font-size: 3rem; }
.empty p { color: var(--muted); }

.printbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 16px; background: var(--ink); color: #fff;
  padding: 10px 10px 10px 20px; border-radius: 18px; box-shadow: 0 12px 32px rgba(20, 24, 40, .3);
  width: max-content; max-width: calc(100% - 32px);
}
.printbar .btn.primary { background: #fff; color: var(--ink); border-color: #fff; }

/* ---------- Dialogi ---------- */
dialog { border: 0; border-radius: 20px; padding: 0; box-shadow: 0 30px 80px rgba(0, 0, 0, .3); width: min(920px, calc(100% - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(20, 24, 40, .45); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.print-dialog[open] { display: flex; flex-direction: column; }
.print-options { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 14px 20px 0; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.notice { margin: 12px 20px 0; background: #fff8e8; border: 1px solid #fde3a7; padding: 10px 14px; border-radius: 12px; font-size: .88rem; }
.progress { margin: 12px 20px 0; height: 26px; background: var(--surface-2); border-radius: 999px; position: relative; overflow: hidden; border: 1px solid var(--line); }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .2s; }
.progress span { position: relative; display: block; text-align: center; font-size: .8rem; line-height: 24px; }
.sheets-preview { padding: 16px 20px; overflow: auto; flex: 1; display: grid; gap: 16px; justify-items: center; background: var(--surface-2); margin-top: 12px; }
.sheet-frame { overflow: hidden; box-shadow: 0 4px 18px rgba(0, 0, 0, .15); background: #fff; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.help-dialog { max-width: 560px; }
.help-dialog ol, .help-dialog p { padding: 0 20px 0 40px; }
.help-dialog p { padding: 0 20px 16px; }
.help-dialog li { margin: 8px 0; }

.menu-info { font-size: .8rem; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; background: var(--accent-soft); border-color: #c7cbff; padding: 14px 16px; }
.login-screen { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; padding: 28px 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }
/* Bez zalogowania widać wyłącznie ekran logowania */
body.auth-locked > *:not(#loginScreen):not(#toast) { display: none !important; }
.login-logo { display: inline-flex; gap: 4px; justify-self: center; padding: 10px; border-radius: 14px; background: var(--accent-soft); }
.login-logo .dot { width: 16px; height: 16px; }
input[type=password] { width: 100%; border: 1.5px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 12px 14px; outline: none; font-size: 1.05rem; }
input[type=password]:focus { border-color: var(--accent); background: #fff; }
.login-error { color: var(--danger); font-size: .9rem; }

/* Arkusz A4 – wymiary rzeczywiste */
.sheet { width: 210mm; height: 297mm; position: relative; background: #fff; overflow: hidden; }
.sheet img { position: absolute; display: block; }
.sheet-lines { position: absolute; inset: 0; width: 210mm; height: 297mm; }
.sheet-header { position: absolute; left: 12mm; top: 8mm; right: 12mm; font: 2.6mm/6mm Andika, system-ui, sans-serif; color: #6b7280; white-space: nowrap; }

#printRoot { display: none; }

.toast {
  position: fixed; left: 50%; top: 76px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 100;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; transition: all .25s; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsywność ---------- */
@media (max-width: 900px) {
  .editor-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; order: -1; }
}
@media (max-width: 640px) {
  body { padding-bottom: 110px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .brand p { display: none; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; justify-content: center; }
  .menu { margin-left: auto; }
  main { padding: 14px 12px; }
  .panel { padding: 16px; }
  .segmented { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .thumb { padding: 6px; }
  .card .card-actions { padding: 0 8px 8px; }
  .card .card-actions .btn { padding: 4px; font-size: .8rem; flex-basis: 36px; }
  .card .letters { display: none; }
  .select-box { top: 10px; left: 10px; }
  .printbar { gap: 10px; padding: 8px 8px 8px 14px; width: calc(100% - 24px); font-size: .85rem; justify-content: space-between; }
  .printbar #pageInfo { display: block; }
  .printbar .sep { display: none; }
  .printbar .btn { padding: 8px 12px; }
  .legend { display: none; }
  .actions .btn { flex: 1; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
}
@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
}

/* ---------- Druk z przeglądarki: tylko arkusze, skala 1:1 ---------- */
@page { size: A4 portrait; margin: 0; }
@media print {
  body { background: #fff; padding: 0; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  .sheet { page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
