/* =====================================================================
   pisqorky.cz – vizuální systém „Sešit“
   Piškvorky na zadní straně čtverečkovaného sešitu: papír, tužka,
   červená a modrá propiska, zvýrazňovač. Jediné téma (papír je papír).

   Struktura souboru:
   1. tokeny   2. základ   3. komponenty (znovupoužitelné i pro statistiky)
   4. úvodní obrazovka   5. herní obrazovka   6. Piškvoráček   7. responzivita
   ===================================================================== */

/* ---------- 1. Tokeny ---------- */
:root {
  --paper: #f9f6ee;
  --paper-2: #fffdf6;          /* štítek, bubliny */
  --grid: #c7d5e6;             /* čtverečky */
  --graphite: #3b3b3b;         /* tužka */
  --graphite-soft: #6d6d6d;
  --graphite-faint: #a9a49a;
  --red: #c8342b;              /* červená propiska – křížky, poznámky na okraji */
  --blue: #1f4db0;             /* modrá propiska – kolečka, jméno hráče */
  --marker: #ffe86a;           /* zvýrazňovač – vítězná řada */
  --shadow: 2px 3px 0 rgba(59, 59, 59, .15);

  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --text: "Nunito Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* velikost čtverečku = buňka hracího pole; stránka je stejnou mřížkou podložená */
  --cell: clamp(28px, min(5.6vw, 5.6vh), 46px);

  /* typografická škála (rukopis je opticky menší než sans, proto větší hodnoty) */
  --fs-body: 1.125rem;         /* 18px */
  --fs-hand: 1.7rem;
  --fs-hand-lg: 2.4rem;
  --fs-hand-xl: clamp(3.2rem, 9vw, 5rem);
}

/* ---------- 2. Základ ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: var(--fs-body)/1.45 var(--text);
  color: var(--graphite);
  background: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: calc(var(--cell) / 2) calc(var(--cell) / 2);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- 3. Komponenty ---------- */
/* Rukopisné písmo */
.hand, .hand-title, .name, .say, .note, .margin-note, .link-wavy, .tally, .opt > span, .row .k, .line-input, .btn-graphite {
  font-family: var(--hand);
}
.hand-title { margin: 0; font-weight: 700; font-size: var(--fs-hand-xl); line-height: 1; letter-spacing: -.01em; }
.hand-title small { display: block; font-weight: 500; font-size: var(--fs-hand); line-height: 1.2; color: var(--graphite-soft); margin-top: 6px; }

/* Štítek na sešitu (červený dvojitý rámeček, mírně nakřivo) */
.label {
  background: var(--paper-2);
  border: 3px solid var(--red);
  outline: 1.5px solid var(--red); outline-offset: 3px;
  padding: 30px 34px 28px;
  box-shadow: var(--shadow);
  display: grid; gap: 20px;
  transform: rotate(-1.2deg);
}

/* Tužkový rámeček (hrací pole, později karty statistik) */
.pencil-box { position: relative; background: var(--paper); }
.pencil-box::after {
  content: ""; position: absolute; inset: -3px; pointer-events: none;
  border: 2.5px solid var(--graphite);
  border-radius: 2px 4px 3px 5px;
  transform: rotate(-.5deg);
}

/* Řádek formuláře „Popisek: ______“ */
.row { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: baseline; font-size: var(--fs-hand); font-weight: 500; }
.row .k { color: var(--graphite-soft); }
.line-input {
  width: 100%; background: transparent; border: 0; border-bottom: 2px dotted var(--graphite-soft);
  padding: 0 6px 2px; font-weight: 700; font-size: 2rem; line-height: 1.15; color: var(--blue); border-radius: 0;
}
.line-input::placeholder { color: var(--graphite-faint); font-weight: 500; }
.line-input:focus-visible { outline: none; border-bottom-color: var(--blue); border-bottom-style: solid; }

.line-static { border-bottom: 2px dotted var(--graphite-soft); padding: 0 6px 2px; font-size: 2rem; line-height: 1.15; font-weight: 700; display: flex; gap: 14px; align-items: baseline; }
.nick-blue { color: var(--blue); }
.auth-rows { display: grid; gap: 20px; }
.label[data-mode="login"] .register-only { display: none; }
.check { display: flex; gap: 10px; align-items: baseline; font-family: var(--text); font-size: .95rem; color: var(--graphite-soft); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--graphite); flex: none; }
.actions { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.link-wavy.small { font-size: 1.2rem; }

/* Volba zakroužkovaná tužkou */
.opts { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.opt { position: relative; padding: 4px 12px; cursor: pointer; display: grid; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt > span { font-size: var(--fs-hand); font-weight: 500; line-height: 1.1; }
.opt small { font-family: var(--text); font-size: .85rem; color: var(--graphite-soft); }
.opt::before {
  content: ""; position: absolute; inset: -6px -12px -8px -10px; pointer-events: none;
  border: 2.5px solid transparent; border-radius: 48% 52% 50% 46% / 58% 42% 56% 44%; transform: rotate(-2deg);
  transition: border-color .15s;
}
.opt:has(input:checked)::before { border-color: var(--graphite); }
.opt:has(input:focus-visible)::before { border-color: var(--blue); }
.opt:hover::before { border-color: var(--graphite-faint); }

/* Tlačítko „vygumovaný“ grafitový blok */
.btn-graphite {
  justify-self: start; font-weight: 700; font-size: 1.9rem; line-height: 1;
  color: var(--paper-2); background: var(--graphite);
  padding: 14px 30px 16px; border-radius: 14px 12px 16px 10px / 10px 16px 12px 14px;
  box-shadow: 2px 2px 0 var(--graphite-soft); transform: rotate(.6deg);
}
.btn-graphite:hover { background: #222; }
.btn-graphite:disabled { opacity: .5; cursor: default; }

/* Odkaz s vlnovkou (propiska) */
.link-wavy {
  font-size: 1.55rem; font-weight: 500; color: var(--graphite);
  text-decoration: underline wavy var(--graphite-soft); text-underline-offset: 4px;
}
.link-wavy:hover { color: var(--blue); text-decoration-color: var(--blue); }

/* Poznámky: na okraji sešitu (červeně) a volné (tužkou) */
.note { font-size: 1.4rem; font-weight: 500; line-height: 1.15; color: var(--graphite-soft); }
.margin-notes { display: grid; gap: 8px; align-content: start; }
.margin-note { font-size: 1.5rem; font-weight: 500; line-height: 1.1; transform: rotate(-6deg); display: inline-block; }
.margin-note.red { color: var(--red); }

/* Jméno + symbol */
.who { display: flex; gap: 12px; align-items: baseline; }
.name { font-size: var(--fs-hand-lg); font-weight: 700; line-height: 1; }
.symbol { font-size: 1.8rem; font-weight: 700; line-height: 1; font-family: var(--hand); }
.symbol.x, .name.x { color: var(--red); }
.symbol.o, .name.o { color: var(--blue); }

/* Skóre čárkami (po pěti se škrtá) */
.tally { display: flex; gap: 22px; flex-wrap: wrap; justify-content: flex-end; font-size: 1.55rem; font-weight: 500; }
.tally .t { display: inline-flex; align-items: center; gap: 10px; }
.tally .t b { font-weight: 700; }
.tally .marks { display: inline-flex; gap: 10px; }
.tally .g { display: inline-flex; gap: 4px; position: relative; height: 26px; }
.tally .g i { display: block; width: 3px; height: 26px; background: var(--graphite); border-radius: 2px; transform: rotate(-3deg); }
.tally .g.full::after { content: ""; position: absolute; left: -3px; right: -3px; top: 50%; height: 3px; background: var(--graphite); border-radius: 2px; transform: rotate(-32deg); }
.tally .zero { color: var(--graphite-faint); }
.tally .num { font-weight: 700; }

.error { color: var(--red); margin: 0; font-family: var(--text); }

/* ---------- 4. Úvodní obrazovka ---------- */
.screen-start { display: grid; place-items: center; padding: 24px 16px 40px; }
.label-wrap { position: relative; width: min(600px, 100%); margin-bottom: 230px; }
.rowie-start { position: absolute; right: -44px; bottom: -160px; width: 220px; transform: rotate(3deg); pointer-events: none; }
.note-start { position: absolute; left: 4px; bottom: -235px; max-width: 400px; margin: 0; transform: rotate(-2deg); font-size: 1.6rem; line-height: 1.2; }

/* patička úvodu: provozovatel a povinné odkazy, na mobilu pod sebou */
.screen-start { grid-template-rows: 1fr auto auto; align-content: space-between; }
.site-foot { justify-self: center; align-self: end; display: flex; flex-wrap: wrap; gap: 6px 22px; justify-content: center; align-items: baseline;
  font-family: var(--hand); font-size: 1.25rem; color: var(--graphite-soft); padding-top: 24px; }
.site-foot a { color: var(--graphite-soft); text-decoration: underline wavy var(--graphite-faint); text-underline-offset: 4px; }
.site-foot a:hover, .site-foot a:focus-visible { color: var(--blue); }

.hand-title .h1-tail { display: block; font-weight: 500; font-size: var(--fs-hand-lg); color: var(--red); margin-top: 2px; }
.subtitle { margin: -8px 0 0; font-family: var(--hand); font-weight: 500; font-size: var(--fs-hand); line-height: 1.2; color: var(--graphite-soft); }

/* indexovatelný text „o hře“ pod štítkem – běžný text, rukopisné nadpisy */
.about { justify-self: center; width: min(600px, 100%); display: grid; gap: 10px; margin-top: 40px; padding-top: 24px; border-top: 2px dotted var(--graphite-faint); }
.about-title { margin: 0; font-family: var(--hand); font-weight: 700; font-size: 2.1rem; line-height: 1.05; }
.about h3 { margin: 8px 0 0; font-family: var(--hand); font-weight: 700; font-size: 1.6rem; line-height: 1.1; color: var(--red); }
.about p { margin: 0; font-size: 1.02rem; line-height: 1.55; max-width: 66ch; }
.about a { color: var(--blue); }

/* Široký monitor: úvod jako otevřený sešit – vlevo štítek s Piškvoráčkem, vpravo „zápisky o hře“
   s červenou linkou okraje. Text je součást papíru; na mobilu zůstává pod štítkem. */
@media (min-width: 1100px) {
  .screen-start { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: 1fr auto; column-gap: 0; padding: 40px 32px 40px; }
  .label-wrap { grid-column: 1; margin-bottom: 210px; justify-self: center; align-self: center; }
  .note-start { bottom: -225px; left: 40px; }
  .about {
    grid-column: 2; align-self: center; margin: 0 0 0 40px; padding: 28px 28px 28px 56px; border: 0;
    width: min(520px, 100%); position: relative; box-shadow: inset 1px 0 0 var(--grid);
  }
  .about::before { content: ""; position: absolute; left: 36px; top: 0; bottom: 0; border-left: 2px solid rgba(200, 52, 43, .55); }  /* okraj sešitu */
  .about::after { content: attr(data-margin-note); position: absolute; left: 52px; top: -6px; font-family: var(--hand); color: var(--red); font-size: 1.2rem; transform: rotate(-4deg); }
  .about-title { font-size: 2.3rem; }
  .about p { font-family: var(--hand); font-size: 1.45rem; line-height: 1.25; color: var(--graphite); }
  .site-foot { grid-column: 1 / -1; padding-top: 10px; }
}

/* ---------- 5. Herní obrazovka ---------- */
.screen-game {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "notes board bot"
    ".     board ."
    "player board corner";
  gap: 14px; padding: 22px 24px;
}
.margin-notes { grid-area: notes; justify-self: start; }
.board-wrap { grid-area: board; display: grid; place-items: center; }
.bot { grid-area: bot; justify-self: end; align-self: start; }
.player { grid-area: player; justify-self: start; align-self: end; display: grid; gap: 4px; }
.corner { grid-area: corner; justify-self: end; align-self: end; display: grid; gap: 10px; justify-items: end; }
.links { display: flex; gap: 12px 22px; flex-wrap: wrap; justify-content: flex-end; }
.links .link-wavy { white-space: nowrap; }
.status { color: var(--graphite-soft); font-size: 1.05rem; min-height: 1.5em; }

/* Hrací pole = kus papíru se stejnou mřížkou, orámovaný tužkou */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n, 15), var(--cell));
  grid-auto-rows: var(--cell);
  background: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  touch-action: manipulation;
}
.board::after {
  content: ""; position: absolute; inset: -3px; pointer-events: none;
  border: 2.5px solid var(--graphite); border-radius: 2px 4px 3px 5px; transform: rotate(-.5deg);
}
.cell {
  position: relative; display: grid; place-items: center; cursor: pointer; user-select: none;
  font-family: var(--hand); font-weight: 700; font-size: calc(var(--cell) * 1.3); line-height: 1;
}
.cell:hover:not(.x):not(.o) { background: rgba(31, 77, 176, .08); }
.board.locked .cell { cursor: default; }
.board.locked .cell:hover { background: transparent; }
.cell.x, .cell.o { cursor: default; }
.cell.x::after { content: "x"; color: var(--red); --dx: -.13; --dy: -.345; transform: translate(calc(var(--cell) * var(--dx)), calc(var(--cell) * var(--dy))) rotate(-4deg); }
.cell.o::after { content: "o"; color: var(--blue); font-size: .95em; --dx: -.085; --dy: -.275; transform: translate(calc(var(--cell) * var(--dx)), calc(var(--cell) * var(--dy))) rotate(6deg); }
.cell.x::after, .cell.o::after { animation: scribble .18s ease-out; display: block; }
.cell.last::before {
  content: ""; position: absolute; inset: 6%; border: 2px solid var(--graphite-soft); border-radius: 50% 46% 52% 48% / 48% 52% 46% 54%;
  transform: rotate(8deg); pointer-events: none;
}
/* zvýrazňovač přes vítěznou řadu – pozici a úhel počítá JS */
.marker {
  position: absolute; height: calc(var(--cell) * .72);
  left: calc(var(--cell) * (var(--ax) - .4));
  top: calc(var(--cell) * (var(--ay) - .36));
  width: calc(var(--cell) * var(--len));
  transform: rotate(var(--ang)); transform-origin: calc(var(--cell) * .4) 50%;
  background: var(--marker); mix-blend-mode: multiply; border-radius: 999px; opacity: .95;
  pointer-events: none; animation: swipe .5s ease-out;
}
@keyframes scribble { from { opacity: 0; } to { opacity: 1; } }
@keyframes swipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ---------- 6. Piškvoráček ---------- */
/* Kresba a nálady jsou v piskvoracek.css (SVG se vkládá do .figure-slot). Tady jen umístění a poznámka. */
.bot { position: relative; width: min(250px, 30vw); display: grid; justify-items: center; gap: 4px; }
.bot-img { width: 100%; }
.figure-slot svg { width: 100%; height: auto; display: block; overflow: visible; }
.say {
  position: absolute; right: 86%; top: 6px; width: 170px; text-align: right;
  font-size: 1.45rem; font-weight: 500; line-height: 1.1; color: var(--graphite);
  transform: rotate(-4deg); transition: opacity .3s;
}
.say::after { content: ""; position: absolute; right: -32px; top: 60%; width: 28px; border-top: 2px solid var(--graphite-soft); transform: rotate(-25deg); }
.say:empty { opacity: 0; }

/* ---------- 7. Responzivita ---------- */
@media (max-width: 820px) {
  :root { --cell: min(6.2vw, 5.4vh); --fs-body: 1rem; --fs-hand: 1.45rem; --fs-hand-lg: 2rem; }
  .screen-game {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "notes bot" "board board" "board board" "player corner";
    padding: 12px; gap: 10px;
  }
  .bot { width: min(170px, 44vw); }
  .say { width: 120px; font-size: 1.15rem; right: 80%; }
  .rowie-start { width: 130px; right: -10px; bottom: -110px; }
  .site-foot { padding-top: 20px; font-size: 1.15rem; }
  .label-wrap { margin-bottom: 130px; }
  .about { margin-top: 10px; }
  .note-start { display: none; }
  .label { padding: 22px 20px; }
  .link-wavy { font-size: 1.3rem; }
  .tally { font-size: 1.3rem; gap: 14px; }
}

/* ---------- 8. Multiplayer ---------- */
.margin-note.link { cursor: pointer; text-decoration: underline wavy var(--graphite-soft); text-underline-offset: 4px; color: var(--graphite); }
.margin-note.link:hover { color: var(--blue); }
.margin-note .count { color: var(--blue); }
.margin-note.faint { color: var(--graphite-faint); font-size: 1.15rem; transform: none; }

/* Lístek – kus papíru přilepený přes stránku */
.slip {
  position: absolute; z-index: 5; background: var(--paper-2); padding: 20px 24px; box-shadow: var(--shadow);
  border: 1.5px solid var(--graphite-soft); border-radius: 3px 6px 4px 5px; width: min(380px, calc(100vw - 32px));
  display: grid; gap: 12px; transform: rotate(-.8deg);
}
.slip::before { /* izolepa */
  content: ""; position: absolute; top: -12px; left: 50%; width: 70px; height: 22px; transform: translateX(-50%) rotate(-3deg);
  background: rgba(255, 232, 106, .45); border: 1px solid rgba(59, 59, 59, .08);
}
.slip-title { margin: 0; font-family: var(--hand); font-weight: 700; font-size: 1.9rem; line-height: 1.05; }
.slip-text { margin: 0; font-size: .95rem; color: var(--graphite-soft); }
.slip-text.hand-note { font-family: var(--hand); font-size: 1.35rem; color: var(--graphite); }
.slip-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-family: var(--hand); font-size: 1.55rem; }
.slip-list li { display: flex; gap: 14px; align-items: baseline; }
.slip-list .nick { font-weight: 700; color: var(--blue); }
.slip-list .muted { color: var(--graphite-faint); font-size: 1.2rem; }
.slip-blocked { font-size: .9rem; color: var(--graphite-soft); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.slip-actions { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.btn-graphite.small { font-size: 1.5rem; padding: 10px 22px 12px; }
.link-wavy.faint { color: var(--graphite-faint); }
.mp-panel { left: 24px; top: 90px; }
.invite-note { left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(1deg); }

/* soupeř vpravo nahoře, Piškvoráček pod ním jako menší divák */
.opp { grid-area: bot; justify-self: end; align-self: start; display: grid; gap: 4px; justify-items: end; text-align: right; }
.screen-game.human .bot { width: min(150px, 20vw); margin-top: 110px; }
.screen-game.human .bot .who { display: none; }
.screen-game.human .bot .say { width: 130px; font-size: 1.15rem; }
.opp .status.turn { color: var(--red); font-weight: 600; }

/* chat – lístek v pravém dolním rohu */
.chat { display: grid; gap: 8px; width: min(340px, 40vw); justify-items: stretch; margin-bottom: 8px; }
.chat-title { margin: 0; font-family: var(--hand); font-weight: 700; font-size: 1.5rem; }
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 150px; overflow-y: auto; font-size: .95rem; }
.chat-list li { padding: 2px 0; border-bottom: 1px dotted var(--grid); }
.chat-list li b { font-family: var(--hand); font-size: 1.15rem; font-weight: 700; margin-right: 6px; color: var(--blue); }
.chat-list li.mine b { color: var(--red); }
.chat-quick { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.chat-quick button { font-family: var(--hand); font-size: 1.15rem; color: var(--graphite-soft); text-decoration: underline dotted; text-underline-offset: 3px; }
.chat-quick button:hover { color: var(--blue); }
.chat-form { display: flex; gap: 10px; align-items: baseline; }
.chat-input { font-size: 1.35rem; font-weight: 500; color: var(--graphite); }

@media (max-width: 820px) {
  .mp-panel { left: 12px; top: 70px; }
  .chat { width: 100%; }
  .screen-game.human .bot { width: 90px; margin-top: 70px; }
}

/* vlajka jazyka hráče (CZ / EN) – malý „razítkový“ obdélník, inline SVG z app.js */
.flag { display: inline-block; width: 26px; height: 18px; vertical-align: -2px; border: 1px solid var(--graphite-soft); border-radius: 2px; overflow: hidden; box-shadow: 1px 1px 0 rgba(59,59,59,.15); transform: rotate(-3deg); }
.flag svg { display: block; width: 100%; height: 100%; }
.flag:empty { display: none; }
.slip-list .flag { width: 22px; height: 15px; }
