/* Matematikon: úlohy z Hejného sešitu (1. ročník). Vzhled sešitu: papír na kropenatém stole,
   oranžový pruh s natrženým okrajem, šedá políčka, oranžový trojúhelník, odpovědi modrou propiskou.
   Záměrně jeden světlý vzhled: sešit je papír. */
:root {
  --desk: #F1EBDD; --fleck-1: #E7B49A; --fleck-2: #D9CFA6;
  --paper: #FFFEFA; --edge: #E4DDCC; --edge-2: #D8D0BD;
  --ink: #2A2C3A; --soft: #6A6E7E; --white: #FFFFFF;
  --band: #E8775D; --band-check: rgba(255, 255, 255, .07);
  --cell: #DCDCDC; --cell-line: #FFFFFF; --cell-hi: #FFF1B8; --okraj: #F4ECDC;
  --tri: #F3A23A; --tri-hi: #FFD27A; --pen: #2847B6; --brace: #6E86C8;
  --pink: #E66FA9; --blue: #3E5CB0; --green: #4FA246; --red: #DD4A3B; --gold: #FFC93C;
  --piece-line: #23252F; --grid-line: #C9C3B4;
  --snake: #5CAF49; --snake-dark: #3C8730; --label: #FFD94F;
  --ok: #2E9D5A; --ok-soft: #CDEFD8; --bad: #DF473D; --bad-soft: #F8D3CF;
  --lock: #EDE8DC; --key: #FFFFFF; --key-shadow: #D9D2C1;
  --font: "Nunito", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --hand: "Gochi Hand", "Comic Sans MS", "Chalkboard SE", cursive;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 500 18px/1.35 var(--font); color: var(--ink);
  background:
    radial-gradient(circle at 20% 30%, var(--fleck-1) 0 1.6px, transparent 2.2px) 0 0 / 37px 41px,
    radial-gradient(circle at 70% 65%, var(--fleck-2) 0 1.3px, transparent 1.9px) 0 0 / 53px 47px,
    var(--desk);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 4px solid var(--gold); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }

.desk {
  padding-block: max(14px, env(safe-area-inset-top, 0px)) max(28px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.page {
  max-width: 980px; margin: 0 auto; background: var(--paper); border-radius: 6px 6px 10px 10px; overflow: hidden;
  box-shadow: 0 1px 0 var(--edge), 3px 5px 0 -1px var(--edge-2), 0 14px 30px rgba(70, 50, 20, .12);
}

/* ===== Oranžový pruh se šachovnicí a natrženým spodním okrajem ===== */
.band {
  --s: 8px;
  display: flex; align-items: center; gap: 10px; min-height: 74px; padding: 10px 16px calc(10px + var(--s));
  color: var(--white); background: repeating-conic-gradient(var(--band-check) 0 25%, transparent 0 50%) 0 0 / 18px 18px, var(--band);
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--s)) 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--s)) 100%;
}
.band .back {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .2); color: var(--white); font-weight: 600; text-decoration: none;
}
.band h1 { flex: 1; min-width: 0; font-size: clamp(19px, 4.6vw, 28px); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.band .total, .band .serie { flex: none; font-weight: 700; font-size: clamp(17px, 4vw, 22px); font-variant-numeric: tabular-nums; }
.band .serie { padding: 2px 10px; border-radius: 999px; background: rgba(255, 255, 255, .2); }
.band .live { flex: none; display: flex; font-size: clamp(20px, 5vw, 28px); line-height: 1; }
.band .live i { font-style: normal; color: rgba(255, 255, 255, .35); transition: color .3s; }
.band .live i.on { color: var(--gold); }

.sheet { display: flex; flex-direction: column; gap: 16px; padding: 18px clamp(12px, 3vw, 28px) 26px; }
.obsah { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.task { display: flex; align-items: center; gap: 10px; font-size: clamp(22px, 5vw, 28px); font-weight: 600; }
.num { flex: none; width: 1.45em; height: 1.45em; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: var(--white); font-weight: 700; font-size: .95em; }
.tecky { margin-left: auto; display: flex; gap: 8px; }
.tecky i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--edge-2); }
.tecky i.on { background: var(--ok); border-color: var(--ok); }
.tecky i.cur { border-color: var(--ink); }

/* ===== Tik-Tak a bublina ===== */
.tiktak { display: flex; align-items: center; gap: 12px; }
.mascot { flex: none; border: 0; background: none; padding: 0; }
.mascot img { display: block; width: clamp(56px, 13vw, 78px); height: auto; }
.bubble {
  position: relative; flex: 1; min-width: 0; min-height: 3.2em; display: flex; align-items: center;
  padding: 10px 16px; background: var(--white); border: 2px solid var(--edge-2); border-radius: 18px; font-size: clamp(17px, 3.6vw, 21px);
}
.bubble::before { content: ""; position: absolute; left: -9px; top: 50%; width: 14px; height: 14px; background: var(--white); border-left: 2px solid var(--edge-2); border-bottom: 2px solid var(--edge-2); transform: translateY(-50%) rotate(45deg); }
body.talking .mascot img { animation: talk .36s ease-in-out infinite alternate; }
@keyframes talk { from { transform: rotate(-3deg); } to { transform: rotate(3deg) scale(1.04); } }
body.yay .mascot img { animation: hop .8s ease; }
@keyframes hop { 30% { transform: translateY(-18px) rotate(-8deg); } 60% { transform: translateY(0) rotate(4deg); } }

/* ===== Tlačítka ===== */
.akce { display: flex; gap: 10px; flex-wrap: wrap; }
.akce:empty { display: none; }
.btn { min-height: 56px; padding: 0 22px; border: 0; border-radius: 16px; font-weight: 600; font-size: 20px; background: var(--white); box-shadow: 0 0 0 2px var(--edge-2), 0 3px 0 2px var(--edge-2); }
.btn.go { background: var(--ok); color: var(--white); box-shadow: 0 3px 0 0 var(--snake-dark); }
.btn:active { transform: translateY(2px); }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ===== Klávesnice s čísly ===== */
.keypad { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; max-width: 540px; }
.keypad button { min-height: 52px; border: 0; border-radius: 14px; background: var(--key); box-shadow: 0 0 0 2px var(--edge-2), 0 4px 0 2px var(--key-shadow); font-size: 24px; font-weight: 600; }
.keypad button:active { transform: translateY(3px); box-shadow: 0 0 0 2px var(--edge-2), 0 1px 0 2px var(--key-shadow); }
.keypad .del { color: var(--soft); }
.keypad[inert] { opacity: .45; }

/* ===== Políčka sešitu ===== */
.cell {
  width: var(--cw); height: var(--cw); display: grid; place-items: center; padding: 0;
  background: var(--cell); border: 2px solid var(--cell-line); font-size: calc(var(--cw) * .5); font-weight: 500; color: var(--ink);
}
.cell.pen, .tri.pen { font-family: var(--hand); color: var(--pen); font-size: calc(var(--cw) * .7); }
.cell.sel { background: var(--cell-hi); box-shadow: inset 0 0 0 3px var(--tri); }
.cell.bad { background: var(--bad-soft); }
.cell.win { background: var(--ok-soft); transition: background .3s; }
.tri {
  flex: none; width: calc(var(--cw) * .95); height: var(--cw); border: 0; background: var(--tri); clip-path: polygon(0 50%, 100% 0, 100% 100%);
  display: grid; place-items: center; padding: 0 0 0 calc(var(--cw) * .32); font-size: calc(var(--cw) * .44); font-weight: 600; color: var(--ink);
}
button.tri { background: var(--tri-hi); }
.tri.sel { background: var(--cell-hi); }

/* Sousedé: pás se závorkami nad a pod trojicemi (jako v řešení v sešitě), nebo tabulka */
.sousedi { --cw: clamp(32px, calc((100vw - 72px) / (var(--n) + 1)), 62px); display: flex; align-items: center; overflow-x: auto; padding-block: 4px; }
.sousedi .cells { display: grid; grid-template-columns: repeat(var(--n), var(--cw)); grid-template-rows: 30px var(--cw) 30px; }
.sousedi.mrizka { --cw: clamp(40px, calc((100vw - 90px) / (var(--n) + 1)), 64px); align-items: flex-start; }
.sousedi.mrizka .cells { grid-template-rows: repeat(var(--r), var(--cw)); }
.brace { position: relative; margin: 0 7px; height: 9px; border: 2.5px solid var(--brace); border-bottom: 0; border-radius: 12px 12px 0 0; align-self: end; opacity: .55; }
.brace.top { grid-row: 1; }
.brace.bottom { grid-row: 3; align-self: start; border-top: 0; border-bottom: 2.5px solid var(--brace); border-radius: 0 0 12px 12px; }
.brace b { position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%); font-size: 17px; font-weight: 600; }
.brace.bottom b { bottom: auto; top: 7px; }
.brace.ok { --brace: var(--ok); opacity: 1; color: var(--ok); }
.brace.bad { --brace: var(--bad); opacity: 1; color: var(--bad); }

/* Nalezená řešení (Sousedé s víc řešeními, Parkety) */
.reseni { display: flex; flex-direction: column; gap: 8px; }
.reseni h3 { font-size: 18px; font-weight: 600; color: var(--soft); }
.reseni > .mini { display: flex; gap: 2px; font-family: var(--hand); color: var(--pen); font-size: 22px; }
.reseni > .mini i { font-style: normal; width: 28px; height: 28px; display: grid; place-items: center; background: var(--cell); }
.reseni > .mini i.print { font-family: var(--font); color: var(--ink); font-size: 16px; }

/* Parkety: deska R × S, podnos s dílky, sbírka nalezených řešení */
.parkety { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }
.board {
  --pc: clamp(44px, calc((100vw - 110px) / var(--S)), 80px);
  display: grid; grid-template-columns: repeat(var(--S), var(--pc)); grid-template-rows: repeat(var(--R), var(--pc));
  border: 3px solid var(--piece-line); background: var(--paper); touch-action: none;
}
.board .sq { border: 1px solid var(--grid-line); }
.board .sq.full { background: var(--c); border: 1.5px solid var(--piece-line); cursor: grab; }
.board .sq.ok { background: var(--ok-soft); }
.board .sq.no { background: var(--bad-soft); }
.tray { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; }
.slot { --tc: clamp(18px, 6vw, 26px); width: calc(4 * var(--tc) + 18px); height: calc(4 * var(--tc) + 18px); display: grid; place-items: center; border: 2px dashed var(--edge-2); border-radius: 14px; }
.piece { display: grid; grid-template-columns: repeat(var(--w), var(--tc)); grid-template-rows: repeat(var(--h), var(--tc)); padding: 6px; border-radius: 10px; touch-action: none; cursor: grab; }
.piece i { background: var(--c); border: 1.5px solid var(--piece-line); }
.piece i.gap { visibility: hidden; }
.piece.sel { box-shadow: 0 0 0 3px var(--tri); }
.piece.lifted { opacity: .2; }
.piece.ghost { position: fixed; z-index: 50; padding: 0; pointer-events: none; filter: drop-shadow(0 8px 10px rgba(40, 30, 10, .3)); }
.sbirka { display: flex; flex-wrap: wrap; gap: 12px; }
.sbirka .mini { display: grid; grid-template-columns: repeat(var(--S), 14px); grid-auto-rows: 14px; border: 2px solid var(--piece-line); }
.sbirka .mini i { background: var(--c); border: .5px solid rgba(0, 0, 0, .25); }

/* Hadi: kolečka spojená šipkami, nad šipkou žlutý štítek s číslem */
.snake-wrap { overflow-x: auto; padding: 46px 4px 8px; }
.snake { --nd: clamp(38px, 9.5vw, 64px); --ln: clamp(40px, 11vw, 86px); display: flex; align-items: center; width: max-content; }
.snake.dlouhy { --nd: clamp(34px, 8vw, 58px); --ln: clamp(30px, 8vw, 72px); }
.snake .tail { width: 14px; height: calc(var(--nd) * .42); background: var(--snake); border-radius: 999px 0 0 999px; }
.snake .node {
  position: relative; z-index: 1; width: var(--nd); height: var(--nd); border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: var(--white); border: 5px solid var(--snake); font-size: calc(var(--nd) * .44); font-weight: 600; color: var(--ink);
}
.snake button.node { background: var(--cell); }
.snake .node.pen { font-family: var(--hand); color: var(--pen); font-size: calc(var(--nd) * .56); }
.snake .node.sel { background: var(--cell-hi); border-color: var(--tri); }
.snake .link { position: relative; width: var(--ln); height: calc(var(--nd) * .56); margin: 0 -4px; background: var(--snake); display: grid; place-items: center; }
.snake .link.bad { background: var(--bad); }
.snake .arrow { font-style: normal; font-weight: 700; font-size: calc(var(--nd) * .5); color: var(--ink); line-height: 1; }
.snake .label {
  position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%); min-width: calc(var(--nd) * .8); height: calc(var(--nd) * .8);
  display: grid; place-items: center; padding: 0 4px; background: var(--label); border: 0; font-size: calc(var(--nd) * .42); font-weight: 600; color: var(--ink);
}
.snake button.label { box-shadow: inset 0 0 0 2px var(--tri); }
.snake .label.pen { font-family: var(--hand); color: var(--pen); font-size: calc(var(--nd) * .55); }
.snake .label.sel { background: var(--cell-hi); box-shadow: inset 0 0 0 3px var(--tri); }
.snake .head { position: relative; width: calc(var(--nd) * .75); height: calc(var(--nd) * .62); background: var(--snake); border-radius: 0 60% 60% 0; margin-left: -4px; }
.snake .head i { position: absolute; top: 18%; width: 22%; height: 26%; background: var(--white); border-radius: 50%; box-shadow: inset 0 0 0 3px var(--piece-line); }
.snake .head i:first-child { right: 38%; }
.snake .head i:last-child { right: 12%; }
.snake .head::after { content: ""; position: absolute; right: -12px; top: 58%; width: 14px; height: 4px; background: var(--bad); border-radius: 2px; }

/* Součtové tabulky: roh „+“, okraje světlé, políčka šedá */
.soucty { --cw: clamp(40px, calc((100vw - 80px) / var(--s)), 64px); display: grid; grid-template-columns: repeat(var(--s), var(--cw)); width: max-content; }
.soucty .roh { width: var(--cw); height: var(--cw); display: grid; place-items: center; font-size: calc(var(--cw) * .6); font-weight: 700; color: var(--tri); }
.soucty .cell.okraj { background: var(--okraj); font-weight: 700; }
.soucty .cell.okraj.sel { background: var(--cell-hi); }
.soucty .cell.okraj.bad { background: var(--bad-soft); }
.soucty .cell.okraj.win { background: var(--ok-soft); }

/* ===== Mapa: hodnost, ostrovy s cestou úrovní, odznaky ===== */
.hodnost { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border: 2px solid var(--edge); border-radius: 18px; }
.hodnost .radek { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.hodnost b { font-size: 24px; font-weight: 700; }
.hodnost span { color: var(--soft); font-size: 16px; }
.pruh { height: 14px; border-radius: 999px; background: var(--lock); overflow: hidden; }
.pruh i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }

.ostrov { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 12px; border: 2px solid var(--edge); border-left: 8px solid var(--c); border-radius: 18px; }
.ostrov h2, .odznaky h2 { display: flex; align-items: center; gap: 10px; font-size: clamp(21px, 5vw, 26px); font-weight: 600; }
.ostrov h2 small, .odznaky h2 small { margin-left: auto; color: var(--soft); font-size: 16px; font-weight: 500; }
.ikona { font-size: 1.1em; }
.cesta { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px 6px; }
.cesta li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 62px; }
/* cestička mezi kolečky */
.cesta li + li::before { content: ""; position: absolute; top: 27px; right: calc(100% - 4px); width: 14px; border-top: 3px dotted var(--edge-2); }
.lvl {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  border: 3px solid var(--c); background: var(--white); color: var(--c); font-size: 24px; font-weight: 700;
}
.lvl.hotova { background: var(--c); color: var(--white); }
.lvl.zlata { box-shadow: 0 0 0 4px var(--gold); }
.lvl.zamcena { border-color: var(--edge-2); background: var(--lock); font-size: 20px; }
.lvl.dalsi { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 25%, transparent); } }
.hv { display: flex; font-size: 15px; line-height: 1; }
.hv i, .velke-hv i { font-style: normal; color: var(--edge-2); }
.hv i.on, .velke-hv i.on { color: var(--gold); }

.odznaky { display: flex; flex-direction: column; gap: 10px; }
.odznaky .nadpis { flex: 1; display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; font: inherit; text-align: left; }
.odznaky ul, .nove-odznaky { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.odznaky li, .nove-odznaky li { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; text-align: center; font-size: 15px; font-weight: 600; border: 2px solid var(--edge); border-radius: 16px; background: var(--white); }
.odznaky li span, .nove-odznaky li span { font-size: 34px; line-height: 1; }
.odznaky li.ne { opacity: .45; filter: grayscale(1); }

/* ===== Konec úrovně ===== */
.konec { display: flex; flex-direction: column; align-items: center; gap: 16px; padding-block: 10px; text-align: center; }
.konec h2 { font-size: clamp(28px, 7vw, 40px); font-weight: 700; }
.velke-hv { display: flex; gap: 6px; font-size: clamp(56px, 15vw, 84px); line-height: 1; }
.velke-hv i { animation: pop .5s backwards; }
.velke-hv i:nth-child(2) { animation-delay: .3s; }
.velke-hv i:nth-child(3) { animation-delay: .6s; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } }
.nova-hodnost { font-size: 22px; }
.nova-hodnost b { color: var(--band); }
.nove-odznaky { display: flex; flex-wrap: wrap; justify-content: center; }
.nove-odznaky li { width: 118px; }
.konec .akce { justify-content: center; }

.konfety { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.konfety i { position: absolute; top: -20px; left: var(--x); width: 10px; height: 16px; background: var(--c); border-radius: 2px; animation: pad 2.6s var(--d) ease-in forwards; }
@keyframes pad { to { transform: translateY(110vh) rotate(var(--r)); } }

@media (prefers-reduced-motion: reduce) {
  body.yay .mascot img, body.talking .mascot img, .lvl.dalsi, .velke-hv i, .shake { animation: none; }
}
