:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #14161f;
  --muted: #646b80;
  --line: #e3e6ef;
  --accent: #fdb21a;       /* pomarańcz z logo BoozniakEdu */
  --accent-ink: #1f1604;
  --accent-text: #a85a00;  /* ciemniejszy odcień do tekstu na jasnym tle */
  --soft: #fff3d9;
  --danger: #dc2626;
  --g0: #8a90a3;
  --g1: #dc2626;
  --g2: #ea580c;
  --g3: #b45309;
  --g4: #4d7c0f;
  --g5: #15803d;
  --g6: #0e7490;
  --shadow: 0 1px 2px rgba(20, 22, 31, .06), 0 4px 14px rgba(20, 22, 31, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1017;
    --card: #171a24;
    --ink: #eef0f6;
    --muted: #9aa1b4;
    --line: #272c3b;
    --accent: #fdb21a;
    --accent-ink: #1f1604;
    --accent-text: #fdb21a;
    --soft: #2b2415;
    --danger: #f87171;
    --g0: #8a90a3;
    --g1: #f87171;
    --g2: #fb923c;
    --g3: #fbbf24;
    --g4: #a3e635;
    --g5: #4ade80;
    --g6: #22d3ee;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1017;
  --card: #171a24;
  --ink: #eef0f6;
  --muted: #9aa1b4;
  --line: #272c3b;
  --accent: #fdb21a;
  --accent-ink: #1f1604;
  --accent-text: #fdb21a;
  --soft: #2b2415;
  --danger: #f87171;
  --g0: #8a90a3;
  --g1: #f87171;
  --g2: #fb923c;
  --g3: #fbbf24;
  --g4: #a3e635;
  --g5: #4ade80;
  --g6: #22d3ee;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.top {
  padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
  max-width: 560px;
  margin: 0 auto;
}
.top h1 { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0; letter-spacing: .01em; }

main { max-width: 560px; margin: 0 auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.tab { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 16px; font-weight: 650; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.count { color: var(--muted); font-size: 13px; }

/* ----- wynik ----- */
.result { --gc: var(--g0); display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; align-items: center; }
.result[data-grade="1"] { --gc: var(--g1); }
.result[data-grade="2"] { --gc: var(--g2); }
.result[data-grade="3"] { --gc: var(--g3); }
.result[data-grade="4"] { --gc: var(--g4); }
.result[data-grade="5"] { --gc: var(--g5); }
.result[data-grade="6"] { --gc: var(--g6); }

.grade-box {
  background: color-mix(in srgb, var(--gc) 14%, transparent);
  border-radius: 16px;
  padding: 10px 16px 8px;
  text-align: center;
  min-width: 118px;
}
.grade-num { font-size: 64px; line-height: 1; font-weight: 750; color: var(--gc); font-variant-numeric: tabular-nums; }
.grade-name { font-size: 13px; font-weight: 600; color: var(--gc); margin-top: 4px; min-height: 18px; }

.stats { display: flex; flex-direction: column; gap: 6px; }
.stat { display: flex; flex-direction: column; }
.stat-val { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 13px; color: var(--muted); }
.stat-lbl b { color: var(--ink); font-weight: 600; }
.hint-line { grid-column: 1 / -1; margin: 6px 0 0; font-size: 14px; color: var(--muted); min-height: 20px; }

.warn { margin: 8px 0 0; padding: 8px 10px; border-radius: 10px; font-size: 14px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.result .warn { grid-column: 1 / -1; }

/* ----- chipy z punktami ----- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 48px; height: 44px; padding: 0 10px 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--soft); color: var(--ink);
  font: inherit; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.chip .x { font-size: 15px; font-weight: 400; color: var(--muted); }
.chip.bad { border-color: var(--danger); color: var(--danger); }
.chip .idx { font-size: 11px; font-weight: 500; color: var(--muted); align-self: flex-start; margin-top: 5px; margin-left: -6px; margin-right: 2px; }
.empty { margin: 0; font-size: 14px; color: var(--muted); }

/* ----- mikrofon ----- */
.mic {
  width: 100%; height: 64px; border-radius: 16px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 18px; font-weight: 650;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer;
}
.mic svg { width: 26px; height: 26px; fill: currentColor; }
.mic.on { background: var(--danger); color: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); } 50% { box-shadow: 0 0 0 10px transparent; } }
@media (prefers-reduced-motion: reduce) { .mic.on { animation: none; } }

.heard { margin: 8px 0 0; min-height: 22px; font-size: 15px; color: var(--ink); font-style: italic; }
.hint { margin: 6px 0 12px; font-size: 13px; color: var(--muted); }

#entryForm { display: flex; gap: 8px; }
#entryForm input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"] {
  height: 46px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 16px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 12px; }
.pad button {
  height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 18px; font-weight: 600; cursor: pointer;
}
.pad button:active { background: var(--soft); }
.pad button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ----- przyciski ----- */
.btn {
  height: 48px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:active { background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.actions { display: flex; gap: 8px; }
.grow { flex: 1; }


/* ----- skala ----- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.field input { width: 100%; }
.switch { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; cursor: pointer; }
.switch input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.switch span { font-size: 15px; }
.switch small { display: block; color: var(--muted); font-size: 13px; }

.th-grid { display: flex; flex-direction: column; gap: 8px; }
.th-row { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: 10px; }
.th-row label { display: flex; align-items: baseline; gap: 8px; font-weight: 600; }
.th-row label small { font-weight: 400; color: var(--muted); font-size: 13px; }
.th-row .g { display: inline-block; min-width: 18px; font-weight: 750; font-size: 18px; }
.th-row .inp { position: relative; }
.th-row .inp input { width: 100%; padding-right: 28px; text-align: right; }
.th-row .inp::after { content: "%"; position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.th-row.fixed { opacity: .8; }

table.scale { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scale th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px 8px; text-transform: uppercase; letter-spacing: .04em; }
.scale td { padding: 10px 6px; border-top: 1px solid var(--line); }
.scale td:first-child { font-weight: 650; }
.scale td .gn { font-size: 20px; font-weight: 750; margin-right: 8px; }
.scale td small { color: var(--muted); }
.scale tr.unreach td { color: var(--muted); text-decoration: line-through; }

/* ----- wyniki ----- */
.dist { display: flex; align-items: flex-end; gap: 8px; height: 120px; margin-bottom: 10px; }
.dist .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; }
.dist .bar { width: 100%; border-radius: 8px 8px 3px 3px; min-height: 3px; background: var(--c); opacity: .85; }
.dist .n { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dist .g { font-size: 15px; font-weight: 750; color: var(--c); }

.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.hist li:first-child { border-top: 0; }
.hist .no { color: var(--muted); font-size: 13px; }
.hist .pts b { font-weight: 650; }
.hist .pts small { color: var(--muted); margin-left: 6px; }
.hist .gr { font-size: 22px; font-weight: 750; min-width: 28px; text-align: center; color: var(--c); }
.hist .del { border: 0; background: none; color: var(--muted); font-size: 20px; width: 36px; height: 36px; cursor: pointer; border-radius: 10px; }
.hist .del:active { background: var(--soft); }

/* ----- dolna nawigacja ----- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative; flex: 1; max-width: 180px; height: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; border-radius: 14px;
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button[aria-selected="true"] { color: var(--accent-text); background: var(--soft); }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; line-height: 18px; text-align: center;
}

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 500; text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  main, .top { padding-left: 0; padding-right: 0; }
  .top { padding-left: 0; }
}

/* ===== nagłówek i przełącznik trybu ===== */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mode-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.mode-btn svg { width: 16px; height: 16px; fill: currentColor; color: var(--muted); }

/* ===== ekran startowy ===== */
.start {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.start[hidden] { display: none; }
.start-inner { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 14px; }
.start h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; text-align: center; }
.choice {
  position: relative; display: flex; align-items: center; gap: 16px; width: 100%;
  min-height: 104px; padding: 18px 20px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.choice:active { background: var(--soft); }
.choice svg { width: 36px; height: 36px; flex: none; fill: var(--accent-text); }
.choice-text { display: flex; flex-direction: column; gap: 2px; }
.choice-text b { font-size: 21px; }
.choice-text small { font-size: 14px; color: var(--muted); }
.choice[data-mode="voice"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice[data-mode="voice"] svg { fill: currentColor; }
.choice[data-mode="voice"] small { color: inherit; opacity: .8; }
.choice[disabled] { opacity: .55; cursor: not-allowed; }
.choice .last {
  position: absolute; top: 10px; right: 14px; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: rgba(127,127,127,.2);
}
.start-note { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ===== zależne od trybu ===== */
body[data-mode="voice"] .only-manual,
body[data-mode="manual"] .only-voice { display: none; }


/* ===== uczeń ===== */
.student { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.student label { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.student input { flex: 1; min-width: 0; height: 40px; font-weight: 600; }

/* ===== dyktowanie skali ===== */
#scaleForm.inline { display: flex; gap: 8px; margin-top: 12px; }
#scaleForm input { flex: 1; min-width: 0; }
.hint b { font-weight: 600; color: var(--ink); }
.said { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--soft); font-size: 14px; line-height: 1.5; white-space: pre-line; }

/* ===== lista prac z imionami ===== */
.hist li { grid-template-columns: 1fr auto auto; }
.hist .who { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.hist .who b { font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.hist .who small { color: var(--muted); font-size: 13px; }

/* ===== duże klawisze w trybie ręcznym ===== */
button, summary { touch-action: manipulation; }
.pad { grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 0; }
.pad button {
  height: 72px; border-radius: 18px; font-size: 30px; font-weight: 650;
  background: var(--soft); border-color: transparent; font-variant-numeric: tabular-nums;
}
.pad button:active { transform: scale(.96); background: var(--accent); color: var(--accent-ink); }
.pad button.wide { grid-column: span 2; }
.pad button.on { background: var(--accent); color: var(--accent-ink); }
.kbd { margin-top: 14px; }
.kbd summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); padding: 6px 2px; list-style: none; }
.kbd summary::-webkit-details-marker { display: none; }
.kbd summary::before { content: "▸ "; }
.kbd[open] summary::before { content: "▾ "; }
.kbd #entryForm { margin-top: 8px; }
body[data-mode="manual"] .actions .btn { height: 56px; font-size: 17px; }

/* pasek akcji zawsze na wierzchu nad dolną nawigacją */
#tab-score .actions {
  position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 5;
  padding: 10px 0 6px; margin-bottom: -6px;
  background: linear-gradient(to top, var(--bg) 82%, transparent);
}

/* tryb ręczny: zagęszczona góra, żeby cała klawiatura mieściła się na ekranie */
body[data-mode="manual"] #tab-score { gap: 10px; }
body[data-mode="manual"] .student { padding: 6px 14px; }
body[data-mode="manual"] .student input { height: 38px; }
body[data-mode="manual"] .result { padding: 10px 14px; gap: 2px 16px; }
body[data-mode="manual"] .grade-box { padding: 6px 12px 5px; min-width: 96px; border-radius: 14px; }
body[data-mode="manual"] .grade-num { font-size: 46px; }
body[data-mode="manual"] .grade-name { font-size: 12px; margin-top: 2px; min-height: 15px; }
body[data-mode="manual"] .stats { flex-direction: row; gap: 22px; }
body[data-mode="manual"] .stat-val { font-size: 26px; }
body[data-mode="manual"] .hint-line { margin: 2px 0 0; min-height: 0; font-size: 13px; }
body[data-mode="manual"] .card:has(#chips) { padding: 10px 14px; }
body[data-mode="manual"] .card:has(#chips) .card-head { margin-bottom: 6px; }
body[data-mode="manual"] .card:has(#chips) h2 { font-size: 14px; color: var(--muted); }
body[data-mode="manual"] #chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
body[data-mode="manual"] #chips::-webkit-scrollbar { display: none; }
body[data-mode="manual"] .chip { flex: none; height: 40px; font-size: 19px; }
body[data-mode="manual"] .card.only-manual { padding: 12px; }
body[data-mode="manual"] .pad { gap: 8px; }
body[data-mode="manual"] .pad button { height: 64px; font-size: 28px; }
body[data-mode="manual"] .kbd { margin-top: 8px; }

/* ===== logo i stopka na ekranie startowym ===== */
.start-top { flex: none; }
.start-logo { display: block; width: min(250px, 64vw); height: auto; }
.start-inner { margin: auto 0; }
.start-foot { flex: none; margin: 18px 0 0; font-size: 14px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.start-foot b { font-weight: 750; color: var(--ink); }
.start-foot span { color: var(--accent); font-weight: 750; }
.mode-btn svg { color: var(--accent-text); }

.start-top { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.start-lead { margin: 0; max-width: 330px; text-align: center; font-size: 15px; line-height: 1.45; color: var(--muted); text-wrap: balance; }

/* ----- raport (PDF / Word) ----- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field input[type="date"] { min-height: 44px; }
.inline-actions { margin: 4px 0 10px; }
.inline-actions .btn { height: 48px; }

/* ----- okno z danymi sprawdzianu ----- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; overflow-y: auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(10, 12, 20, .55);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 460px; margin: auto; padding: 20px; border-radius: 22px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 14px; font-size: 22px; }
.modal-card .actions { margin-top: 14px; }
.modal-card .actions .btn { height: 50px; }
.req { margin-left: 6px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent-text); }
.field small { font-weight: 400; }

.testbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  min-height: 40px; margin-bottom: 10px; padding: 6px 14px; border-radius: 12px;
  border: 1px dashed var(--line); background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer;
}
.testbar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.testbar svg { width: 16px; height: 16px; flex: none; fill: currentColor; }
.testbar.empty { color: var(--accent-text); border-color: var(--accent); }
.meta-summary { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.chip.ghost { opacity: .4; border-style: dashed; pointer-events: none; }
.count.short { color: var(--accent-text); font-weight: 600; }
.count.full { color: var(--g5, #15803d); font-weight: 600; }
.count.over { color: var(--danger); font-weight: 600; }
.pad button.full { grid-column: span 3; }

/* ----- odnośniki i okno informacyjne ----- */
.start-links { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 2px 6px; margin: 18px 0 6px; color: var(--muted); }
.linkbtn { padding: 8px 6px; border: 0; background: none; font: inherit; font-size: 14px; color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.info-card { max-width: 520px; }
.info-card h3 { margin: 16px 0 4px; font-size: 16px; }
.info-card p, .info-card li { font-size: 15px; line-height: 1.5; }
.info-card p { margin: 4px 0 8px; }
.info-card ul { margin: 4px 0 8px; padding-left: 20px; }
.info-card .hint { margin-top: 14px; }
.info-card .actions { position: sticky; bottom: 0; margin: 14px -20px -20px; padding: 12px 20px 20px; background: var(--card); border-radius: 0 0 22px 22px; }

/* ----- klawiatura-kalkulator (maks. za zadanie > 10) ----- */
.pad.calc { grid-template-columns: repeat(3, 1fr); }
.pad-display {
  grid-column: span 2; display: flex; align-items: center; justify-content: flex-end; min-height: 46px; padding: 0 16px;
  border-radius: 16px; background: var(--card); border: 1px solid var(--line);
  font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.pad-display.wide3 { grid-column: span 3; }
.pad-display.empty { font-size: 16px; font-weight: 500; color: var(--muted); }
.pad button:disabled { opacity: .3; pointer-events: none; }
.pad button.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 22px; }
body[data-mode="manual"] .pad.calc button { height: 46px; font-size: 24px; border-radius: 14px; }
body[data-mode="manual"] .pad.calc button.go { font-size: 20px; }

/* ----- klawisz 10+ i ekran z liczbami od 10 ----- */
.pad.more { grid-template-columns: repeat(5, 1fr); }
.pad.more button.full { grid-column: span 5; }
.pad.more button.span3 { grid-column: span 3; }
.pad button.more-key { background: var(--card); border: 2px solid var(--accent); color: var(--accent-text); }
body[data-mode="manual"] .pad.more button { height: 56px; font-size: 24px; }
body[data-mode="manual"] .pad.more button.wide, body[data-mode="manual"] .pad.more button.span3, body[data-mode="manual"] .pad.more button.full { font-size: 18px; }

/* ----- nagłówek bez tytułu; toast z ostrzeżeniem ----- */
.top h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.toast.bad { background: var(--danger); color: #fff; font-weight: 600; }

/* ===== telefon: ekran bez przewijania, klawiatura nieruchoma ===== */
@media (max-width: 699px) {
  html, body { height: 100%; }
  body { height: 100dvh; padding-bottom: 0; display: flex; flex-direction: column; overflow: hidden; }
  .top { flex: none; width: 100%; padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 6px; }
  main { flex: 1 1 auto; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 10px; }
  .tabbar { position: static; flex: none; }
  #tab-score { flex: 1 0 auto; }
  #tab-score .actions { position: static; margin: 0; padding: 0; background: none; flex: none; }

  /* ręcznie: klawiatura rozciąga się na całą wolną wysokość */
  body[data-mode="manual"] .card.only-manual { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 250px; }
  body[data-mode="manual"] #pad { flex: 1 1 0; min-height: calc(var(--rows, 4) * 46px + (var(--rows, 4) - 1) * 8px); grid-auto-rows: minmax(46px, 108px); align-content: end; }
  body[data-mode="manual"] #pad button,
  body[data-mode="manual"] #pad.calc button,
  body[data-mode="manual"] #pad.more button { height: auto; min-height: 44px; }
  body[data-mode="manual"] #pad.more { grid-auto-rows: minmax(46px, 84px); align-content: start; }
  body[data-mode="manual"] .pad-display { min-height: 0; }

  /* głosowo: duży przycisk mikrofonu wypełnia resztę */
  body[data-mode="voice"] .card.only-voice { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 170px; }
  body[data-mode="voice"] .mic { flex: 1 1 auto; min-height: 84px; }
}

/* niskie telefony (np. 667 px): zagęszczenie, żeby klawiatura i przyciski nadal mieściły się bez przewijania */
@media (max-width: 699px) and (max-height: 740px) {
  .top { padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .mode-btn { height: 30px; }
  main { padding-top: 4px; padding-bottom: 6px; }
  #tab-score, body[data-mode="manual"] #tab-score { gap: 6px; }
  .tabbar { padding-top: 3px; padding-bottom: calc(3px + env(safe-area-inset-bottom)); }
  .tabbar button { height: 46px; }
  .tabbar svg { width: 22px; height: 22px; }
  body[data-mode="manual"] .student { padding: 4px 12px; }
  body[data-mode="manual"] .student input { height: 34px; }
  body[data-mode="manual"] .result { padding: 8px 12px; }
  body[data-mode="manual"] .grade-num { font-size: 36px; }
  body[data-mode="manual"] .grade-box { padding: 4px 10px 3px; }
  body[data-mode="manual"] .stat-val { font-size: 22px; }
  .hint-line { display: none; }
  body[data-mode="manual"] .card:has(#chips) { padding: 8px 12px; }
  body[data-mode="manual"] .chip { height: 34px; font-size: 17px; }
  body[data-mode="manual"] .card.only-manual { min-height: 0; padding: 8px; }
  body[data-mode="manual"] #pad { gap: 6px; min-height: calc(var(--rows, 4) * 38px + (var(--rows, 4) - 1) * 6px); grid-auto-rows: minmax(38px, 108px); }
  body[data-mode="manual"] #pad button, body[data-mode="manual"] #pad.calc button, body[data-mode="manual"] #pad.more button { min-height: 38px; font-size: 22px; }
  body[data-mode="manual"] .kbd { display: none; }
  body[data-mode="manual"] .actions .btn { height: 48px; }
  body[data-mode="voice"] .card.only-voice { min-height: 0; }
}

/* telefony: zwarty ekran trybu głosowego (bez przewijania), także na wysokich ekranach */
@media (max-width: 699px) {
  body[data-mode="voice"] #tab-score { gap: 6px; }
  body[data-mode="voice"] .student { padding: 4px 12px; }
  body[data-mode="voice"] .student input { height: 34px; }
  body[data-mode="voice"] .result { padding: 8px 12px; gap: 2px 14px; }
  body[data-mode="voice"] .grade-box { padding: 4px 10px 3px; min-width: 90px; }
  body[data-mode="voice"] .grade-num { font-size: 36px; }
  body[data-mode="voice"] .grade-name { margin-top: 0; min-height: 14px; font-size: 12px; }
  body[data-mode="voice"] .stats { flex-direction: row; gap: 18px; }
  body[data-mode="voice"] .stat-val { font-size: 22px; }
  body[data-mode="voice"] .card:has(#chips) { padding: 8px 12px; }
  body[data-mode="voice"] .card:has(#chips) .card-head { margin-bottom: 4px; }
  body[data-mode="voice"] #chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  body[data-mode="voice"] #chips::-webkit-scrollbar { display: none; }
  body[data-mode="voice"] .chip { flex: none; height: 34px; font-size: 17px; }
  body[data-mode="voice"] .actions .btn { height: 48px; }
}
@media (max-width: 699px) and (max-height: 740px) {
  body[data-mode="voice"] #voiceHint { display: none; }
}

/* przy 5 i więcej rzędach klawiszy na telefonie chowamy pole „Wpisz kilka liczb naraz”, żeby wszystko się mieściło */
@media (max-width: 699px) {
  body[data-mode="manual"] .card.only-manual[data-rows="5"] .kbd,
  body[data-mode="manual"] .card.only-manual[data-rows="6"] .kbd,
  body[data-mode="manual"] .card.only-manual[data-rows="7"] .kbd { display: none; }
}

/* ----- okno progów ocen ----- */
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; height: 44px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.thr-lbl { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.thr-sum { margin: -4px 0 12px; font-size: 13px; color: var(--muted); }
.thr-sum .linkbtn { padding: 2px 6px; }
.th-row.thr { grid-template-columns: 1fr auto 104px; gap: 8px; }
.th-row.thr .inp::after { content: attr(data-u); }
.th-row.thr .inp input { padding-right: 40px; }
.th-row.thr .eq { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.btn.block { width: 100%; margin-bottom: 12px; }
#thrRows { margin-bottom: 4px; }

/* ----- zwijane sekcje w zakładce Skala ----- */
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; list-style: none; touch-action: manipulation; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary h2 { margin: 0; }
.fold > summary::after { content: "▾"; color: var(--muted); font-size: 16px; transition: transform .15s; }
.fold:not([open]) > summary::after { transform: rotate(-90deg); }
.fold[open] > summary { margin-bottom: 12px; }

/* ----- ikona w nagłówku ----- */
.top-icon { flex: none; margin-right: auto; display: block; line-height: 0; }
.top-icon img { height: 40px; width: auto; display: block; }

/* ----- przełącznik jasny / ciemny ----- */
img.th-dark { display: none; }
:root[data-theme="dark"] .th-light { display: none; }
:root[data-theme="dark"] .th-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .th-light { display: none; }
  :root:not([data-theme="light"]) .th-dark { display: block; }
}
.theme-btn { width: 34px; padding: 0; justify-content: center; flex: none; }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .i-moon { display: none; }
}
.theme-btn.on-start { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px; z-index: 2; }

/* ----- dyktowanie w oknach Dane i Progi ----- */
.mic-sm {
  width: 100%; height: 48px; margin-bottom: 12px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 16px; font-weight: 650;
  display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
.mic-sm svg { width: 22px; height: 22px; fill: currentColor; }
.mic-sm.on { background: var(--danger); color: #fff; animation: pulse 1.6s ease-in-out infinite; }
.modal-card .said { margin: 0 0 12px; }
body[data-mode="manual"] .mic-sm, body[data-mode="manual"] .modal-card .said.only-voice { display: none; }
@media (prefers-reduced-motion: reduce) { .mic-sm.on { animation: none; } }

/* ----- okno progów: układ zwarty, żeby mieściło się bez przewijania ----- */
.thr-top { display: grid; grid-template-columns: 1fr 1.15fr; gap: 10px; align-items: end; }
.thr-top .field { margin-bottom: 10px; }
#thr .th-grid { gap: 6px; }
#thr .th-row input { height: 42px; }
#thr h2, #setup h2 { margin-bottom: 10px; }
#thr .hint, #setup .hint { margin: 8px 0 0; font-size: 12.5px; }
#thr .warn { margin: 6px 0 0; }
#thr .modal-card, #setup .modal-card { padding: 16px; }
#thr .actions, #setup .actions { margin-top: 10px; }
.modal-card .said { font-size: 13px; line-height: 1.4; padding: 8px 10px; white-space: normal; }
@media (max-height: 740px) {
  #thr .th-grid { gap: 4px; }
  #thr .th-row input { height: 38px; }
  .mic-sm { height: 42px; margin-bottom: 8px; }
  #thr .thr-top .field, #setup .field { margin-bottom: 8px; }
  #thr .actions .btn, #setup .actions .btn { height: 46px; }
  #setup .hint { display: none; }
}
.start-foot time { font: inherit; color: inherit; }
