:root {
  --navy: #14304f;
  --blue: #1a6fb5;
  --red: #d0242b;
  --yellow: #f2b62a;
  --green: #1b7a3a;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6877;
  --line: #dde3ea;
  --ok-bg: #e5f4ea;
  --part-bg: #fdf3dc;
  --bad-bg: #fbe6e6;
  --info-bg: #e7f0fa;
  --radius: 12px;
  /* Paski systemowe telefonu (aplikacja na Androidzie rysuje stronę pod nimi; Capacitor podaje --safe-area-inset-*). */
  --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --card: #1a212b;
    --text: #e6ebf1;
    --muted: #9aa6b4;
    --line: #2c3643;
    --navy: #9cc3ec;
    --ok-bg: #173323;
    --part-bg: #3a2f14;
    --bad-bg: #3d1c1c;
    --info-bg: #182a3e;
  }
  .topbar { background: #0c1118 !important; }
  .katex { color: var(--text); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}
main { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(64px + var(--sab)); }
.topbar[hidden] ~ main { padding-top: calc(16px + var(--sat)); }
h1 { font-size: 1.5rem; margin: 8px 0 16px; color: var(--navy); }
h2 { font-size: 1.2rem; margin: 24px 0 12px; color: var(--navy); }
h3 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .875rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #14304f; color: #fff; padding: calc(8px + var(--sat)) 16px 8px;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; }
.topbar .brand img { height: 28px; background: #fff; border-radius: 6px; padding: 2px 4px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { white-space: nowrap; color: #dbe7f5; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .ghost { color: #fff; border-color: rgba(255,255,255,.4); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card.task .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.content { overflow-x: auto; }
.content p { margin: 0 0 8px; }
.badge {
  display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--info-bg); color: var(--blue);
}
.badge.matura { background: #fdecec; color: var(--red); }
.badge.ok { background: var(--ok-bg); color: var(--green); }
.badge.part { background: var(--part-bg); color: #9a6a00; }
.badge.bad { background: var(--bad-bg); color: var(--red); }
.badge.wait { background: var(--info-bg); color: var(--blue); }
@media (prefers-color-scheme: dark) {
  .badge.matura, .badge.bad { color: #ff8f8f; }
  .badge.ok { color: #7fd69c; }
  .badge.part { color: #f2c75c; }
  .badge.wait, .badge { color: #9cc3ec; }
}

button, .button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--blue);
  background: var(--blue); color: #fff; padding: 10px 16px; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
button:disabled { opacity: .6; cursor: default; }
button.ghost, .button.ghost { background: transparent; color: var(--blue); }
button.small { min-height: 34px; padding: 4px 10px; font-size: .875rem; }
button.danger { background: var(--red); border-color: var(--red); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; margin-right: 6px; }
.check { display: flex; align-items: center; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

.login-box { max-width: 380px; margin: 40px auto; }
.login-box img { display: block; max-width: 240px; margin: 0 auto 16px; background: #fff; border-radius: 10px; padding: 8px; }
.error { color: var(--red); font-weight: 600; margin: 8px 0; }

.photo-pick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer;
  font-weight: 600; color: var(--blue);
}
.photo-pick input { display: none; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.thumbs img { height: 90px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; }
.photo-full { max-width: 100%; max-height: 85vh; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); display: block; margin: 8px 0; }

.result { border-radius: 10px; padding: 12px; margin-top: 10px; }
.result.ok { background: var(--ok-bg); }
.result.part { background: var(--part-bg); }
.result.bad { background: var(--bad-bg); }
.result.wait { background: var(--info-bg); }
.result .pts { font-weight: 700; font-size: 1.1rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--blue); border-color: var(--blue); font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--bg); font-weight: 600; position: sticky; top: 0; }
table.report td.cell { text-align: center; cursor: pointer; min-width: 44px; }
table.report th.col { text-align: center; font-size: .75rem; white-space: nowrap; }
table.report th.col.vol { background: var(--ok-bg); }
td.c-ok { background: var(--ok-bg); }
td.c-part { background: var(--part-bg); }
td.c-bad { background: var(--bad-bg); }
td.c-wait { background: var(--info-bg); }
td.sticky, th.sticky { position: sticky; left: 0; background: var(--card); z-index: 1; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.4rem; color: var(--navy); }

.passwords td { font-family: ui-monospace, Consolas, monospace; }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--sab)); transform: translateX(-50%); background: #1c2430; color: #fff;
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; }
details summary { cursor: pointer; color: var(--blue); font-weight: 600; }
.answer-box { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
@media print {
  .topbar, .no-print, .tabs { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; }
}
@media (max-width: 600px) {
  .topbar { gap: 4px 12px; }
  .topbar nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .topbar .ghost { margin-left: auto; }
}

/* Logowanie kontem Microsoft */
.ms-login { display: flex; width: 100%; margin: 18px 0 8px; box-sizing: border-box; gap: 10px; }
.ms-login svg { flex: none; background: #fff; padding: 2px; border-radius: 2px; }
.login-box .error { margin: 10px 0; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid3 { grid-template-columns: 1fr; } }
.md-table { border-collapse: collapse; margin: 8px 0; }
.md-table th, .md-table td { border: 1px solid #ccd; padding: 4px 10px; text-align: center; }
.topbar nav a.nav-back { font-weight: 700; padding: 6px 12px; }
.crumbs { font-size: .9rem; color: var(--muted); margin: 0 0 6px; }
.crumbs a { color: inherit; }
.figs { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.figs img { max-width: 100%; max-height: 420px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }

/* Grywalizacja: ranga i osiągnięcia */
.rank { display: inline-block; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: .85em; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.rank-drewniana { background: linear-gradient(135deg, #a0703c, #7a4e24); }
.rank-metalowa { background: linear-gradient(135deg, #8a949e, #5d6670); }
.rank-srebrna { background: linear-gradient(135deg, #d5dbe0, #9aa3ab); color: #2b3138; text-shadow: none; }
.rank-zlota { background: linear-gradient(135deg, #f5d04a, #c9971a); color: #3b2a00; text-shadow: none; }
.rank-platynowa { background: linear-gradient(135deg, #b9f0f2, #6fb7c9 60%, #c9b6f2); color: #133; text-shadow: none; }
.game .bar, .card .bar { height: 8px; background: rgba(127,127,127,.2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.game .bar > div, .card .bar > div { height: 100%; background: var(--blue); }
.game h3 { margin: 12px 0 4px; }
.ach { position: relative; display: inline-block; font-size: 1.3em; margin-right: 4px; }
.ach sup { font-size: .55em; }
.ach .x { display: none; position: absolute; top: -6px; right: -8px; padding: 0 4px; font-size: 11px; line-height: 14px; border-radius: 50%; background: #c33; color: #fff; border: 0; cursor: pointer; }
.ach:hover .x { display: inline-block; }
ul.achs { list-style: none; padding: 0; margin: 0; }
ul.achs li { padding: 4px 0; }
ul.achs.locked .ach { filter: grayscale(1); opacity: .5; }
.thumbs .thumb { position: relative; display: inline-block; }
.thumbs .thumb .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 0; background: #c33; color: #fff; font-size: 14px; line-height: 22px; cursor: pointer; }
/* Główny przycisk aparatu: pełny niebieski z białym tekstem (wcześniej niebieski tekst na niebieskim tle). */
button.photo-pick { width: 100%; font: inherit; cursor: pointer; background: var(--blue); border: 2px solid var(--blue); color: #fff; }
button.photo-pick .muted { color: rgba(255, 255, 255, .85); }
.native-cam { display: block; margin: 6px 0 0; color: var(--muted, #667); text-align: center; cursor: pointer; }
.native-cam input { display: none; }
.cam { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; flex-direction: column; }
.cam video { flex: 1; width: 100%; min-height: 0; object-fit: contain; background: #000; }
.cam-bar { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px calc(16px + var(--sab)); background: #000; color: #fff; }
.cam-bar .ghost { color: #fff; border-color: #fff; background: transparent; }
.cam .shot { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 3px #000; padding: 0; }
.cam .shot:active { transform: scale(.94); }
.cam-count { min-width: 64px; text-align: right; }
.cam.flash video { opacity: .3; }

/* Wybór zadania z banku (zestaw dnia, sprawdzanie prac) */
.pick-list { max-height: 60vh; overflow-y: auto; margin-top: 10px; }
.pick-item { border-top: 1px solid var(--line, #e3e7ee); padding: 10px 0; }
.pick-item .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pick-content { font-size: .92em; max-height: 9em; overflow: hidden; position: relative; }
.pick-content img { max-width: 260px; }
.paper-form .own textarea { width: 100%; }

/* Powiększone zdjęcie/rysunek (zamiast otwierania obrazka w całym oknie, z którego w aplikacji nie było wyjścia). */
.lightbox { position: fixed; inset: 0; z-index: 1100; background: #fff; overflow: hidden; touch-action: none; }
.lightbox .lb-stage { position: absolute; left: 0; right: 0; top: calc(56px + var(--sat)); bottom: calc(8px + var(--sab)); }
.lightbox img { width: 100%; height: 100%; object-fit: contain; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; }
.lightbox .lb-close { position: absolute; top: calc(8px + var(--sat)); right: 8px; z-index: 1; color: #fff; background: #14304f; border: 0; font-size: 1rem; }
.lightbox .lb-hint { position: absolute; top: calc(16px + var(--sat)); left: 12px; color: #5d6877; font-size: .8rem; }

/* Awatar ucznia */
.avatar { display: block; width: 100%; height: 100%; }
.card.game { display: flex; gap: 12px; align-items: flex-start; }
.game-body { flex: 1; min-width: 0; }
.game-avatar { flex: none; width: 64px; height: 64px; border-radius: 14px; overflow: hidden; }
.avatar-mini { display: inline-block; width: 32px; height: 32px; flex: none; border-radius: 8px; overflow: hidden; vertical-align: middle; }
.avatar-top { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.avatar-top > div:last-child { flex: 1; min-width: 200px; }
.avatar-big { width: 160px; height: 160px; border-radius: 20px; overflow: hidden; flex: none; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.avatar-balance { font-size: 1.3em; color: var(--green); }
.avatar-trial { background: var(--info-bg); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px; }
.avatar-trial button { margin: 6px 6px 0 0; }
.avatar-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
.avatar-grid .avatar-item { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px; margin: 0; background: var(--card); color: var(--text);
  border: 2px solid var(--line); border-radius: var(--radius); font-weight: 400; text-align: center; cursor: pointer; min-width: 0; }
.avatar-item svg { border-radius: 10px; aspect-ratio: 1; height: auto; }
.avatar-item .name { font-size: .85em; font-weight: 600; line-height: 1.2; }
.avatar-item .price { font-size: .78em; color: var(--muted); line-height: 1.2; }
.avatar-item.buy .price { color: var(--blue); font-weight: 700; }
.avatar-item.locked svg { opacity: .45; filter: grayscale(.6); }
.avatar-item.on { border-color: var(--green); }
.avatar-item.on .price { color: var(--green); font-weight: 700; }
.avatar-item.trial { border-color: var(--blue); }
@media (max-width: 600px) { .avatar-big { width: 120px; height: 120px; } }

/* Tygodniowy ranking klasy */
.rk-nav { justify-content: center; gap: 10px; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 8px 0 14px; flex-wrap: wrap; }
.pod { flex: 0 1 140px; text-align: center; background: var(--card, #fff); border-radius: 14px; padding: 10px 8px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.pod-1 { order: 2; padding-top: 18px; background: linear-gradient(180deg, rgba(245,180,0,.2), var(--card)); }
.pod-2 { order: 1; } .pod-3 { order: 3; }
.pod.me { outline: 2px solid #2b7de9; }
.pod-medal { font-size: 1.8em; line-height: 1; }
.pod-avatar { width: 84px; height: 84px; margin: 6px auto; border-radius: 16px; overflow: hidden; }
.pod-1 .pod-avatar { width: 104px; height: 104px; }
.pod-name { font-weight: 600; overflow-wrap: anywhere; }
.rk-list { padding: 4px 10px; }
.rk-row { border-bottom: 1px solid rgba(0,0,0,.07); }
.rk-row:last-child { border-bottom: 0; }
.rk-row > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px 2px; cursor: pointer; }
.rk-row > summary::-webkit-details-marker { display: none; }
.rk-row.me > summary { background: rgba(43,125,233,.08); border-radius: 10px; }
.rk-row.zero { opacity: .6; }
.rk-place { width: 2.2em; text-align: center; font-weight: 700; font-size: 1.1em; flex: none; }
.rk-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rk-achs .ach { font-size: .95em; }
.rk-pts { text-align: right; flex: none; }
.rk-more { display: flex; gap: 12px; padding: 4px 4px 12px 3em; }
.rk-avatar { width: 96px; height: 96px; flex: none; border-radius: 14px; overflow: hidden; }
.rk-sep { margin: 12px 0 2px; }
.you { display: inline-block; font-size: .75em; padding: 0 6px; border-radius: 999px; background: #2b7de9; color: #fff; vertical-align: middle; }
.ach-new { outline: 2px solid #f5b400; border-radius: 6px; }
@media (max-width: 480px) { .pod { flex-basis: 30%; } .pod-avatar { width: 64px; height: 64px; } .pod-1 .pod-avatar { width: 76px; height: 76px; } .rk-more { padding-left: 4px; } .rk-avatar { width: 72px; height: 72px; } }
