/* Piškvorky — mobil na prvním místě, velké dotykové cíle. */

:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --card: #1e293b;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    /* Barvy hráčů 1 až 4. Zeleň se schválně nepoužívá — ta patří
       stavu "online" a vítězné řadě, jinak by se pletly. */
    --p1: #38bdf8;   /* × modrá   */
    --p2: #fb7185;   /* ○ růžová  */
    --p3: #fbbf24;   /* △ žlutá   */
    --p4: #c084fc;   /* □ fialová */
    --win: #4ade80;
    --danger: #f87171;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100dvh;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.screen {
    max-width: 620px;
    margin: 0 auto;
    padding: 16px 14px 32px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.hidden { display: none !important; }

/* ---------- typografie ---------- */

h1, h2 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.05rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.logo {
    font-size: 2.4rem;
    text-align: center;
    background: linear-gradient(90deg, var(--p1), var(--p2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sub { margin: 0 0 18px; color: var(--muted); font-size: .92rem; text-align: center; }
.error { color: var(--danger); font-size: .9rem; margin: 4px 0 0; }

/* ---------- karty a lišty ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.who { color: var(--muted); font-size: .95rem; }
.who strong { color: var(--text); }

.code-badge {
    font-size: .9rem;
    color: var(--muted);
}
.code-badge strong {
    color: var(--accent);
    letter-spacing: .18em;
    font-size: 1.15rem;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.notice {
    background: #422006;
    border: 1px solid #a16207;
    color: #fde68a;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: .9rem;
}

/* ---------- formuláře ---------- */

label {
    display: block;
    margin: 12px 0 6px;
    font-size: .85rem;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#pin { letter-spacing: .4em; }

/* ---------- tlačítka ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 13px 18px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }

.btn.primary {
    background: linear-gradient(135deg, #0284c7, #0ea5e9);
    border-color: #0ea5e9;
    color: #f0f9ff;
}
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; margin-top: 14px; }
.btn.small { padding: 8px 12px; font-size: .85rem; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- výběr symbolu a varianty ---------- */

.pick-label {
    margin: 0 0 8px;
    font-size: .82rem;
    color: var(--muted);
}
.symbols + .pick-label { margin-top: 18px; }

.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.count-opt {
    padding: 12px 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 1.15rem;
    font-weight: 700;
}
.count-opt:active { transform: scale(.98); }
.count-opt.on { border-color: var(--accent); background: #0c4a6e33; color: #f0f9ff; }

.symbols { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }

.sym-opt {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    background: var(--bg);
    /* Barva i písmo musí být explicitně — u <button> by se jinak použil
       výchozí styl prohlížeče, tedy černá na tmavém podkladu. */
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
}
.sym-opt:active { transform: scale(.98); }
.sym-opt.on { border-color: var(--accent); background: #0c4a6e33; }

.sym-mark { font-size: 2.2rem; font-weight: 800; line-height: 1; }

.p1 { color: var(--p1); }
.p2 { color: var(--p2); }
.p3 { color: var(--p3); }
.p4 { color: var(--p4); }

/* Výběr symbolu přímo v řádku čekajícího hráče — nabízejí se jen volné. */
.sym-choices { display: flex; gap: 6px; flex: 0 0 auto; }

.sym-choice {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    font-family: inherit;
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
}
.sym-choice:active { transform: scale(.94); }

.variants { display: flex; flex-direction: column; gap: 8px; }

.variant {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    background: var(--bg);
    /* Tyhle čtyři řádky musí být explicitně: je to <button>, a bez nich
       si vezme výchozí styl prohlížeče — černý text v systémovém písmu,
       na tmavém podkladu prakticky nečitelný. */
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    width: 100%;
}
.variant:active { transform: scale(.98); }
.variant.on {
    border-color: var(--accent);
    background: #0c4a6e33;
    color: #f0f9ff;
    font-weight: 600;
}
.variant .dot {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 2px solid var(--line);
    flex: 0 0 auto;
}
.variant.on .dot { border-color: var(--accent); background: var(--accent); }

/* ---------- seznam hráčů ---------- */

.people { display: flex; flex-direction: column; gap: 8px; }

.person {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-align: left;
    width: 100%;
    color: var(--text);
    font-family: inherit;
    font-size: .95rem;
}

/* Ten, ke komu se dá klepnutím připojit, musí jít poznat na první pohled. */
.person.joinable {
    border-color: var(--win);
    background: #14532d33;
}

.person-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.person-nick {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 7px;
}

/* Symbol, který si hráč zabral, hned vedle jména. */
.person-sym { font-size: 1.15rem; font-weight: 800; line-height: 1; }
.person-stav { font-size: .78rem; color: var(--muted); }
.person-stav.waiting { color: var(--win); font-weight: 600; }
.person-stav.on { color: var(--win); }
.person-stav.busy { color: var(--accent); }

.dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: #475569;
}
.dot.on, .dot.waiting { background: var(--win); box-shadow: 0 0 0 3px #4ade8033; }
.dot.busy { background: var(--accent); box-shadow: 0 0 0 3px #38bdf833; }
.dot.off { background: #475569; }

/* Kdo čeká, tomu kolečko decentně bliká, ať to dítě v seznamu najde. */
.dot.waiting { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
    50% { box-shadow: 0 0 0 7px #4ade8000; }
}

.empty-hint { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }

/* ---------- hráči a stav ---------- */

.players {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
}
/* Při třech a čtyřech hráčích se jména nevejdou vedle sebe do jednoho řádku. */
.players.many { grid-template-columns: repeat(2, 1fr); }

.player {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 5px 7px;
    border-radius: 8px;
    border: 1px solid transparent;
}
.player .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.player .sym { font-size: 1.4rem; font-weight: 800; line-height: 1; flex: 0 0 auto; }
.player.p1 .sym { color: var(--p1); }
.player.p2 .sym { color: var(--p2); }
.player.p3 .sym { color: var(--p3); }
.player.p4 .sym { color: var(--p4); }

/* Kdo je na tahu, je zvýrazněný — při čtyřech hráčích je to jediné,
   podle čeho se dá rychle poznat, na koho se čeká. */
.player.turn { background: #0ea5e926; border-color: var(--accent); }
.player.you .name { text-decoration: underline; text-underline-offset: 3px; }
.player.offline .name { color: var(--muted); font-style: italic; }
.player.out { opacity: .45; }
.player.out .name { text-decoration: line-through; }

.h2h {
    margin: 0;
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
}

.status {
    text-align: center;
    margin: 0;
    padding: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: var(--radius);
    background: var(--card);
    border: 1px solid var(--line);
}
.status.win { color: var(--win); border-color: var(--win); }
.status.loss { color: var(--danger); border-color: var(--danger); }
.status.wait { color: var(--muted); font-weight: 500; }

/* ---------- deska ---------- */

.board-wrap {
    width: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: 2px;
    background: var(--line);
    border: 2px solid var(--line);
    border-radius: 8px;
    width: min(96vw, 560px);
    aspect-ratio: 1;
    touch-action: manipulation;
}

.cell {
    background: var(--bg-soft);
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    color: var(--text);
    aspect-ratio: 1;
    font-size: calc(min(96vw, 560px) / var(--n) * 0.62);
}
.cell:disabled { cursor: default; }
.cell.p1 { color: var(--p1); }
.cell.p2 { color: var(--p2); }
.cell.p3 { color: var(--p3); }
.cell.p4 { color: var(--p4); }
.cell.last { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.win { background: #14532d; color: var(--win); }

.board.locked .cell:not(:disabled) { cursor: default; }

/* ---------- žebříček ---------- */

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { color: var(--accent); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }

/* ---------- pruh o stavu spojení ---------- */

.conn {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: #7c2d12;
    color: #fed7aa;
    text-align: center;
    padding: 8px;
    font-size: .85rem;
    z-index: 100;
}

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

/* ================= Lodě (Battleship) ================= */

.board.bs { width: min(94vw, 460px); }
.board.bs.mine { width: min(70vw, 320px); }

/* políčka */
.cell.ship { background: #334155; box-shadow: inset 0 0 0 2px #475569; }
.cell.miss { color: var(--muted); }
.cell.miss::after { content: '•'; font-size: 1.1em; opacity: .7; }
.cell.hit  { background: #7f1d1d; color: #fecaca; }
.cell.hit::after { content: '✕'; }
.cell.sunk { background: #450a0a; color: #fca5a5; box-shadow: inset 0 0 0 2px #b91c1c; }
.cell.sunk::after { content: '✕'; }
.cell.aim  { background: #0ea5e926; box-shadow: inset 0 0 0 2px var(--accent); }

/* enemy board — políčka, na která se dá střílet, mírně napovědí */
#enemy-board .cell:not(:disabled):hover { background: #0ea5e91a; }

.board-label {
    text-align: center; font-weight: 700; color: var(--text);
    margin: .25rem 0 .5rem; font-size: .95rem;
}
.board-label.mt { margin-top: 1.25rem; }

/* rozmisťování */
.place-controls {
    display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: .75rem;
}
.fleet-hint { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.fleet-chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: .75rem; }
.ship-chip {
    display: inline-flex; flex-direction: column; align-items: center; gap: .2rem;
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
    padding: .4rem .6rem; cursor: pointer; color: var(--text); font-family: inherit;
}
.ship-chip.sel { border-color: var(--accent); background: #0ea5e926; }
.chip-boat { letter-spacing: 1px; color: #94a3b8; }
.ship-chip.sel .chip-boat { color: var(--accent); }
.chip-info { font-size: .75rem; color: var(--muted); }
.all-placed { color: var(--win); font-weight: 700; }

.btn.small { padding: .4rem .8rem; font-size: .85rem; }

.linklike {
    background: none; border: none; color: var(--accent); cursor: pointer;
    font: inherit; text-decoration: underline; padding: 0;
}

.player .name { display: inline; }

/* tvary lodí v žetonech */
.ship-chip .mini { display: grid; gap: 1px; }
.ship-chip .mini i { width: 8px; height: 8px; background: #1e293b; border-radius: 1px; }
.ship-chip .mini i.on { background: #94a3b8; }
.ship-chip.sel .mini i.on { background: var(--accent); }
.ship-chip { min-width: 46px; }
.ship-chip .chip-info { font-size: .72rem; color: var(--muted); }
