/* Klasówka: papier w kratkę, atrament, czerwony długopis, zakreślacz. */
:root {
  color-scheme: light;
  --bg: #f2f5f9;
  --grid: #e1e7f0;
  --paper: #ffffff;
  --ink: #1f3a93;          /* atrament */
  --ink-dark: #15296c;
  --ink-soft: #e8edfa;
  --graphite: #23262b;     /* tekst */
  --muted: #5b6270;
  --line: #d3dae5;
  --red: #c8102e;          /* czerwony długopis */
  --red-soft: #fdecee;
  --marker: #ffe45c;       /* zakreślacz */
  --marker-soft: #fff6c2;
  --green: #23704a;
  --green-soft: #e5f3eb;
  --radius: 10px;
  --font: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Atkinson Hyperlegible Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--graphite);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; color: var(--graphite); }
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; font-weight: 800; margin-top: 1.6em; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 .8em; }
a { color: var(--ink); text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .9em; background: var(--ink-soft); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.grow { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 4px; }

/* ---------- Formularze i przyciski ---------- */
label { display: block; font-weight: 600; }
input, textarea, select {
  font: inherit;
  color: var(--graphite);
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
input:focus, textarea:focus, select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--ink-soft); }
textarea { resize: vertical; line-height: 1.45; }
input[type="radio"], input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--ink); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: 4px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; text-decoration: none;
  padding: 10px 18px; min-height: 44px;
  border-radius: 8px; border: 1.5px solid transparent;
  cursor: pointer; background: transparent; color: var(--ink);
  transition: background-color .15s, border-color .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--ink-dark); }
.btn-ghost { border-color: var(--line); background: #fff; }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a50d26; }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: .92rem; }
.btn-lg { padding: 14px 22px; min-height: 54px; font-size: 1.08rem; }
.btn-block { width: 100%; }
.btn.is-busy { cursor: progress; }
.icon-btn {
  font: inherit; font-size: 1.1rem; line-height: 1; width: 36px; height: 36px;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: var(--graphite); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.icon-btn.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.alert { padding: 12px 14px; border-radius: 8px; border-left: 5px solid; background: #fff; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert-error { border-color: var(--red); background: var(--red-soft); }
.alert-warn { border-color: #d9b800; background: var(--marker-soft); }
.alert-ok { border-color: var(--green); background: var(--green-soft); }

/* Kartka papieru: biała, z czerwonym marginesem jak w zeszycie */
.sheet, .paper {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.sheet { padding: 20px 22px; }
.paper { padding: 26px 22px 26px 46px; }
.paper::before {
  content: '';
  position: absolute; top: 0; bottom: 0; left: 30px;
  border-left: 2px solid rgba(200, 16, 46, .55);
}

/* ---------- Panel nauczycielki ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px; background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--graphite); font-weight: 600; }
.topbar nav a:hover { background: var(--ink-soft); }
.topbar nav a.is-active { color: var(--ink); background: var(--ink-soft); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 24px 120px; }
.narrow { max-width: 440px; margin: 9vh auto; padding: 32px 26px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.page-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title h1 { margin-bottom: 4px; }
.empty { background: var(--paper); border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 32px; max-width: 620px; }

.table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .88rem; color: var(--muted); font-weight: 600; background: #fafbfd; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 4px; }
.code-cell { font-family: var(--mono); font-weight: 700; letter-spacing: .08em; }

.chip, .state { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .88rem; font-weight: 600; background: var(--ink-soft); color: var(--ink); white-space: nowrap; }
.chip-running, .state-run { background: var(--ink-soft); color: var(--ink); }
.chip-lobby, .state-wait { background: #eef0f3; color: var(--muted); }
.chip-ended, .state-ok { background: var(--green-soft); color: var(--green); }
.state-warn { background: var(--marker); color: #4a3d00; }
.state-fail { background: var(--red); color: #fff; }
.state-away { background: var(--red-soft); color: var(--red); outline: 1.5px solid var(--red); }
.state-lost { background: #eef0f3; color: var(--graphite); outline: 1.5px dashed var(--muted); }

.dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 460px; width: calc(100% - 32px); }
.dialog::backdrop { background: rgba(20, 28, 50, .45); }
.dialog h2 { margin-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: min(560px, calc(100% - 32px)); padding: 12px 18px; border-radius: 8px;
  background: var(--graphite); color: #fff; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--red); }
.toast-ok { background: var(--green); }

/* Edytor testu */
.label-strong { font-weight: 800; font-size: 1.05rem; }
.prompt-box textarea { margin: 10px 0 8px; }
.prompt-box, .refine-box { margin-bottom: 20px; }
.refine-box { margin-top: 28px; }
.editor-head { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 18px; }
.title-field { flex: 1; }
.title-field input { font-size: 1.3rem; font-weight: 800; }
.questions { list-style: none; padding: 0; margin: 0; }
.q { margin-bottom: 14px; padding-left: 22px; }
.q > * + * { margin-top: 12px; }
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-num { font-weight: 800; font-size: 1.1rem; color: var(--ink); min-width: 28px; }
.q-head select { width: auto; margin: 0; padding: 7px 10px; }
.pts { display: flex; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }
.pts input { width: 64px; margin: 0; padding: 7px 8px; }
.q-prompt { font-weight: 600; }
.opts { display: grid; gap: 8px; }
.opt-row { display: flex; align-items: center; gap: 8px; }
.opt-row .opt-text { margin: 0; }
.opt-correct { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; }
.opt-correct input { width: 20px; height: 20px; }
.opt-letter { font-weight: 800; color: var(--muted); width: 18px; }
.add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px; align-items: center; padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line);
}

/* Panel na żywo */
.join { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 20px; padding-left: 46px; }
.join::before { content: ''; position: absolute; top: 0; bottom: 0; left: 30px; border-left: 2px solid rgba(200, 16, 46, .55); }
.join-text p { margin-bottom: 6px; }
.code { display: flex; gap: 8px; margin: 8px 0 14px; font-family: var(--mono); font-weight: 700; font-size: 3rem; line-height: 1; }
.code span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.15em; height: 1.35em; color: var(--ink);
  border: 2px solid var(--ink); border-radius: 8px; background: #fff;
}
.qr { width: 168px; height: 168px; image-rendering: pixelated; }
.counters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.counter { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; min-width: 120px; }
.counter-v { display: block; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.counter-l { color: var(--muted); font-size: .9rem; }
.counter.ok .counter-v { color: var(--green); }
.counter.warn { border-left: 5px solid var(--marker); }
.counter.fail .counter-v { color: var(--red); }
.live-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.live-grid h2 { margin-top: 0; }
.people .actions { white-space: normal; }
.people .actions .btn { margin: 2px 0 2px 4px; }
.people tr.row-away td, .people tr.row-fail td { background: var(--red-soft); }
.log { list-style: none; margin: 0; padding: 6px 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); max-height: 70vh; overflow: auto; }
.log li { display: flex; gap: 10px; padding: 8px 14px; border-bottom: 1px solid #edf0f5; font-size: .95rem; }
.log li:last-child { border-bottom: 0; }
.log time { font-family: var(--mono); color: var(--muted); font-size: .88rem; padding-top: 2px; flex-shrink: 0; }
.log .log-warn { background: var(--marker-soft); }
.log .log-fail { background: var(--red-soft); }
.log .log-lost time { color: var(--graphite); }
.projector {
  position: fixed; inset: 0; z-index: 90; background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh; text-align: center; padding: 24px;
}
.projector p { font-size: clamp(1.2rem, 3vw, 2.4rem); }
.code-xl { font-size: clamp(3rem, 12vw, 10rem); gap: 2vw; }
.qr-xl { width: min(32vh, 60vw); height: min(32vh, 60vw); }
.projector-count { color: var(--muted); }

/* Wyniki */
.grading-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.grading-bar h2 { margin: 0 0 4px; }
.open-q { margin-bottom: 18px; }
.open-list { list-style: none; padding: 0; margin: 12px 0 0; }
.open-answer { border-top: 1px solid var(--line); padding: 14px 0; }
.oa-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.oa-text { white-space: pre-wrap; margin: 8px 0; padding: 10px 12px; background: #fafbfd; border-radius: 8px; border: 1px solid #edf0f5; }
.ai-note { font-size: .95rem; }
.pts-input { width: 80px; margin: 0; padding: 7px 8px; }
.pts-input.is-saved { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.details { margin-top: 18px; }
.detail-list { padding-left: 22px; }
.detail-list li { padding: 10px 0; border-bottom: 1px solid #edf0f5; }
.detail-list li p { margin: 2px 0; }
.detail-list .d-q { font-weight: 600; }
.detail-list .is-wrong .d-q { text-decoration: underline wavy var(--red); text-underline-offset: 5px; }

/* ---------- Uczeń (telefon) ---------- */
body.student { font-size: 18px; }
.student-main, #app { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.join-paper { margin-top: 6vh; }
.lead { font-size: 1.08rem; }
.code-input { font-family: var(--mono); font-size: 2rem; letter-spacing: .3em; text-align: center; font-weight: 700; color: var(--ink); }
.form-error { color: var(--red); font-weight: 600; }
.wait-note { display: flex; gap: 10px; align-items: center; padding: 12px 14px; background: var(--ink-soft); border-radius: 8px; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); flex-shrink: 0; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.rules, .tips { padding-left: 22px; }
.rules li, .tips li { margin-bottom: 8px; }
.rules strong { background: linear-gradient(transparent 55%, var(--marker) 55%); }

.test-page #app { padding-top: 0; }
.testbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 -16px 14px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(242, 245, 249, .96); border-bottom: 1px solid var(--line);
}
.testbar-progress { font-weight: 800; font-variant-numeric: tabular-nums; }
.strike-pill { background: var(--marker); color: #4a3d00; font-weight: 700; font-size: .85rem; padding: 3px 10px; border-radius: 999px; }
.net { background: var(--graphite); color: #fff; font-size: .85rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.timer { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.is-low { color: var(--red); }
.q-paper { min-height: 50vh; }
.q-meta { font-weight: 800; color: var(--ink); margin-bottom: 10px; }
.q-paper .q-prompt { font-size: 1.15rem; line-height: 1.55; white-space: pre-wrap; margin-bottom: 18px; }
.nocopy { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; font-weight: 400;
  padding: 14px 14px; min-height: 56px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-letter {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); font-weight: 800; color: var(--muted);
}
.choice.is-checked { border-color: var(--ink); background: var(--ink-soft); }
.choice.is-checked .choice-letter { background: var(--ink); border-color: var(--ink); color: #fff; }
.choice:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
.gap-line { line-height: 2.4; }
.gap-input {
  display: inline-block; width: 8em; max-width: 100%; margin: 0 4px; padding: 4px 8px; vertical-align: baseline;
  border: 0; border-bottom: 2.5px solid var(--ink); border-radius: 4px 4px 0 0; background: var(--ink-soft);
  font-size: 1.1rem; font-weight: 600; color: var(--ink);
}
.open-input { font-size: 1.05rem; }
.qnav { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 14px; }

.result-paper { margin-top: 8vh; }
.result-paper.ok h1 { color: var(--green); }
.result-paper.fail::before { border-left-color: var(--red); border-left-width: 4px; }
.result-paper.fail h1 { color: var(--red); }

.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(20, 28, 50, .55);
}
.overlay-box { width: 100%; max-width: 480px; background: var(--paper); border-radius: 14px; padding: 24px 22px; max-height: 92vh; overflow: auto; }
.overlay-box h2 { margin-top: 0; }
.overlay-box .btn + .btn { margin-top: 10px; }
.warn-overlay { background: rgba(255, 228, 92, .92); }
.warn-overlay .overlay-box { border: 3px solid #4a3d00; }
.warn-overlay h2 { background: linear-gradient(transparent 50%, var(--marker) 50%); display: inline; }
.warn-overlay h2 + p { margin-top: 14px; }
.sheet-overlay { align-items: flex-end; }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin: 12px 0; }
.qcell { font: inherit; font-weight: 800; height: 52px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; color: var(--graphite); cursor: pointer; }
.qcell.is-done { background: var(--ink); border-color: var(--ink); color: #fff; }
.qcell.is-current { outline: 3px solid var(--marker); outline-offset: 1px; }

/* ---------- Małe ekrany ---------- */
@media (max-width: 860px) {
  .live-grid { grid-template-columns: 1fr; }
  .join { flex-direction: column; align-items: flex-start; }
  .code { font-size: 2.3rem; }
}
@media (max-width: 640px) {
  .wrap { padding: 20px 16px 120px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table thead { display: none; }
  .table tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table td { border: 0; padding: 4px 14px; text-align: left !important; }
  .table .actions { white-space: normal; }
  .table td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); }
  .savebar { padding-left: 16px; padding-right: 16px; flex-wrap: wrap; }
  .savebar #total { width: 100%; }
  .paper { padding-left: 40px; padding-right: 16px; }
  .paper::before { left: 24px; }
  .editor-head { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
