:root {
  --paper: #FAFCFF;
  --grid: #E3EAF6;
  --ink: #2340A8;        /* modrý inkoust: akce, odkazy */
  --text: #17224F;       /* tmavý inkoust: text */
  --muted: #5C6688;
  --line: #CBD5EA;
  --pen: #D2342B;        /* červená propiska: chyby, známka */
  --pen-bg: #FCECEA;
  --done: #1F8A4D;       /* zelená: zmáknuto */
  --done-bg: #E3F4E9;
  --card: #FFFFFF;
  --focus: #F2B705;
  --radius: 14px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  /* čtverečkovaný papír ze sešitu */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--text);
  font: 17px/1.5 var(--body);
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 34px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 700; margin-top: 32px; margin-bottom: 12px; }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }

a { color: var(--ink); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; min-height: 40px; }
.back { font-family: var(--display); font-weight: 700; text-decoration: none; color: var(--ink); padding: 8px 0; }

/* Tlačítka */
button, .btn {
  font: 700 17px/1 var(--body);
  border: 2px solid var(--ink);
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 18px;
  min-height: 50px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button.secondary, .btn.secondary { background: var(--card); color: var(--ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink); padding-inline: 8px; }
button.danger { background: var(--card); color: var(--pen); border-color: var(--pen); }
button.done { background: var(--done); border-color: var(--done); }
button:disabled { opacity: .5; cursor: default; }
button.wide, .btn.wide { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Formuláře */
label { display: block; font-weight: 700; margin: 14px 0 6px; }
input, textarea, select {
  width: 100%;
  font: 17px/1.4 var(--body);
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--ink); outline: none; }

/* Seznamy: řádky v sešitu, ne karty */
.list { border-top: 2px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 4px;
  border-bottom: 2px solid var(--line);
  color: inherit; text-decoration: none;
  background: transparent;
}
.item:hover { background: rgba(35, 64, 168, .04); }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-family: var(--display); font-weight: 700; font-size: 19px; }
.item .meta { color: var(--muted); font-size: 15px; }
.item.mastered { background: var(--done-bg); border-bottom-color: #B8DFC6; }
.item.mastered .title { color: var(--done); }

.chip { font-size: 14px; font-weight: 700; border-radius: 999px; padding: 4px 10px; white-space: nowrap; border: 2px solid var(--line); color: var(--muted); }
.chip.new { border-color: var(--ink); color: var(--ink); }
.chip.ok { border-color: var(--done); color: var(--done); background: #fff; }
.chip.draft { border-style: dashed; }

.empty { padding: 28px 4px; color: var(--muted); }

.panel { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.linkbox { word-break: break-all; font-size: 15px; color: var(--muted); margin-bottom: 12px; }

details > summary { cursor: pointer; font-family: var(--display); font-weight: 700; color: var(--ink); padding: 8px 0; }

/* AI rozhovor */
.chat { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.msg { max-width: 88%; padding: 12px 14px; border-radius: 16px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 2px solid var(--line); border-bottom-left-radius: 4px; }

/* Editor otázek */
.q { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.q .qhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.q .qnum { font-family: var(--display); font-weight: 800; color: var(--ink); }
.opt { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.opt input[type=radio] { width: 24px; height: 24px; flex: none; accent-color: var(--done); }

/* Dítě: otázka */
.progress { height: 8px; background: var(--grid); border-radius: 99px; overflow: hidden; margin: 8px 0 24px; }
.progress > div { height: 100%; background: var(--ink); transition: width .25s ease; }
.prompt { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1.25; margin: 8px 0 24px; }
.prompt .blank { color: var(--ink); border-bottom: 3px solid var(--ink); padding: 0 .2em; }
.choices { display: grid; gap: 10px; }
.choice {
  background: var(--card); color: var(--text);
  border: 2px solid var(--line);
  text-align: left; justify-content: flex-start;
  font: 700 20px/1.3 var(--body);
  padding: 16px 18px; min-height: 60px;
}
.choice[aria-pressed="true"] { border-color: var(--ink); background: #EEF2FD; color: var(--ink); }
.fill { font-size: 26px; text-align: center; padding: 16px; }
.qnav { display: flex; gap: 10px; margin-top: 24px; }
.qnav > :last-child { flex: 1; }

/* Výsledek: známka zakroužkovaná červenou propiskou */
.grade { text-align: center; margin: 12px 0 24px; }
.grade .circle {
  display: inline-grid; place-items: center;
  width: 150px; height: 130px;
  border: 4px solid var(--pen);
  border-radius: 52% 48% 55% 45% / 50% 55% 45% 50%;
  transform: rotate(-6deg);
  color: var(--pen);
  font: 800 44px/1 var(--display);
}
.grade.perfect .circle { border-color: var(--done); color: var(--done); }
.grade p { margin-top: 14px; font-family: var(--display); font-weight: 700; font-size: 22px; }

.wrong { border-bottom: 2px solid var(--line); padding: 14px 4px; }
.wrong .given { color: var(--pen); text-decoration: line-through; text-decoration-thickness: 2px; }
.wrong .right { color: var(--done); font-weight: 700; }
.wrong .why { color: var(--muted); font-size: 15px; margin-top: 4px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-weight: 700;
  max-width: calc(100% - 32px);
}

.spinner { width: 22px; height: 22px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.actionbar {
  position: sticky; bottom: 0; z-index: 2;
  margin: 20px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(250, 252, 255, .94);
  border-top: 2px solid var(--line);
  backdrop-filter: blur(6px);
}
