/* ---------- Barvy (vzhled inspirovaný chess.com, přizpůsobí se tmavému/světlému režimu systému) ---------- */
:root {
  color-scheme: dark;
  --bg: #312e2b;
  --surface: #262421;
  --surface-2: #3c3936;
  --surface-3: #4b4845;
  --line: rgba(255, 255, 255, .08);
  --text: #ffffff;
  --text-2: #bababa;
  --text-3: #8b8987;
  --green: #81b64c;
  --green-hi: #95c95e;
  --green-shadow: #45753c;
  --btn: #45423f;
  --btn-hi: #524f4c;
  --btn-shadow: #2b2926;
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --bubble: #ffffff;
  --bubble-text: #312e2b;
  --scrim: rgba(0, 0, 0, .55);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f3f1;
    --surface: #ffffff;
    --surface-2: #ebe9e6;
    --surface-3: #dcd9d5;
    --line: rgba(0, 0, 0, .08);
    --text: #262421;
    --text-2: #5d5a57;
    --text-3: #8b8987;
    --btn: #e4e2df;
    --btn-hi: #d8d5d1;
    --btn-shadow: #bdb9b4;
    --bubble: #ffffff;
    --bubble-text: #262421;
    --scrim: rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Obecné prvky ---------- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.appbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 6px;
  padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.appbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; color: var(--text-2); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 20px; border-radius: 8px; font-weight: 700; font-size: 17px;
  background: var(--btn); box-shadow: 0 4px 0 var(--btn-shadow); color: var(--text);
  transition: background .12s, transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--btn-shadow); }
.btn.primary { background: var(--green); box-shadow: 0 4px 0 var(--green-shadow); color: #fff; }
.btn.primary:active { box-shadow: 0 2px 0 var(--green-shadow); }
@media (hover: hover) {
  .btn:hover { background: var(--btn-hi); }
  .btn.primary:hover { background: var(--green-hi); }
}
.btn.big { height: 56px; font-size: 20px; width: 100%; }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn .spinner { width: 20px; height: 20px; }

.chip {
  height: 34px; padding: 0 14px; border-radius: 17px; display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.chip:active { background: var(--surface-3); }
.chip svg { width: 16px; height: 16px; }
.chip.on { background: var(--green); color: #fff; }

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

.skeleton { display: block; height: 12px; border-radius: 6px; margin: 7px 0; background: linear-gradient(90deg, rgba(128,128,128,.18), rgba(128,128,128,.34), rgba(128,128,128,.18)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.content { max-width: 720px; margin: 0 auto; padding: 16px; }

/* ---------- Úvodní obrazovka ---------- */
.hero { text-align: center; padding: 24px 8px 12px; }
.hero .logo { width: 76px; height: 76px; margin: 0 auto 10px; border-radius: 20px; background: var(--green); display: grid; place-items: center; box-shadow: 0 5px 0 var(--green-shadow); }
.hero .logo img { width: 56px; height: 56px; }
.hero h2 { margin: 6px 0 4px; font-size: 26px; }
.hero p { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.4; }
.search { display: grid; grid-template-columns: 1fr 120px; gap: 10px; margin: 20px 0 8px; }
.field {
  height: 48px; border-radius: 8px; border: 2px solid var(--surface-3); background: var(--surface); padding: 0 14px;
  font-size: 17px; outline: none; width: 100%; min-width: 0;
}
.field:focus { border-color: var(--green); }
.hint { color: var(--text-3); font-size: 13px; min-height: 20px; margin: 4px 2px 0; }
.hint.err { color: #fa412d; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 700; margin: 22px 2px 10px; }
.game-card {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px; margin-bottom: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
}
.game-card:active { background: var(--surface-2); }
.game-card .tc { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); }
.game-card .tc svg { width: 20px; height: 20px; }
.game-card .who { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-card .meta { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.res { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.res.win { background: #81b64c; } .res.loss { background: #e02828; } .res.draw { background: #8b8987; }
.game-card.latest { border: 2px solid var(--green); }

/* ---------- Analýza (průběh) ---------- */
.progress-wrap { padding: 16px; max-width: 520px; margin: 0 auto; width: 100%; }
.progress-board { width: min(100%, 44dvh); margin: 8px auto 18px; }
.progress-title { font-weight: 700; font-size: 18px; text-align: center; margin: 0 0 4px; min-height: 24px; }
.progress-sub { color: var(--text-2); text-align: center; font-size: 14px; min-height: 20px; }
.bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 14px 0 8px; }
.bar > div { height: 100%; width: 0; background: var(--green); border-radius: 5px; transition: width .25s; }
.progress-engine { color: var(--text-3); font-size: 12px; text-align: center; min-height: 18px; font-variant-numeric: tabular-nums; }

/* ---------- Kouč / bublina ---------- */
.coach { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #4285f4, #9b72cb 55%, #d96570); display: grid; place-items: center; flex: none; }
.avatar svg { width: 26px; height: 26px; color: #fff; }
.bubble { position: relative; background: var(--bubble); color: var(--bubble-text); border-radius: 12px; padding: 10px 12px; font-size: 15px; line-height: 1.42; min-width: 0; }
.bubble::before { content: ""; position: absolute; left: -7px; top: 14px; border: 7px solid transparent; border-left: 0; border-right-color: var(--bubble); }
.bubble .head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; margin-bottom: 3px; }
.bubble .head .cls-icon { width: 22px; height: 22px; flex: none; }
.bubble .head .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eval-pill { font-size: 13px; font-weight: 800; padding: 2px 7px; border-radius: 4px; background: #fff; color: #312e2b; border: 1px solid #ccc; font-variant-numeric: tabular-nums; flex: none; }
.eval-pill.black { background: #403d39; color: #fff; border-color: #403d39; }
.bubble p { margin: 0; }
.bubble .src { font-size: 11px; color: #8b8987; margin-top: 4px; }

/* ---------- Souhrn ---------- */
.graph { position: relative; width: 100%; height: 88px; border-radius: 8px; overflow: hidden; background: #403d39; margin: 14px 0; cursor: pointer; touch-action: pan-y; }
.graph svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.graph.mini { height: 38px; margin: 0; border-radius: 0; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcard { text-align: center; padding: 12px 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.pcard .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .elo { color: var(--text-3); font-size: 13px; }
.acc { display: inline-block; margin-top: 8px; min-width: 84px; padding: 8px 10px; border-radius: 8px; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.acc.w { background: #fff; color: #312e2b; box-shadow: inset 0 -3px 0 #d0d0d0; }
.acc.b { background: #403d39; color: #fff; box-shadow: inset 0 -3px 0 #2b2926; }
.acc-label { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.table { margin-top: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); padding: 4px 0; }
.trow { display: grid; grid-template-columns: 1fr 44px 28px 44px; align-items: center; gap: 6px; padding: 5px 14px; font-size: 15px; }
.trow .lbl { font-weight: 600; }
.trow .n { text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.trow .cls-icon { width: 26px; height: 26px; }
.trow.zero .n { color: var(--text-3); font-weight: 600; }
.trow.phase .n { display: grid; place-items: center; }
.trow.phase .n .cls-icon { width: 26px; height: 26px; }
.trow.head { color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.opening { margin-top: 12px; color: var(--text-2); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.opening .cls-icon { width: 22px; height: 22px; flex: none; }
.bottom-bar { flex: none; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.bottom-bar .inner { max-width: 720px; margin: 0 auto; }

/* ---------- Rozbor ---------- */
.review { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.coach-panel { flex: none; height: 142px; padding: 10px 12px 8px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.coach-panel .coach { flex: 1; min-height: 0; }
.coach-panel .bubble { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.coach-actions { flex: none; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-left: 54px; }
.coach-actions::-webkit-scrollbar { display: none; }
.pbar { flex: none; height: 34px; display: flex; align-items: center; gap: 8px; padding: 0 12px; font-size: 14px; }
.pbar .sq { width: 22px; height: 22px; border-radius: 4px; flex: none; }
.pbar .sq.w { background: #fff; box-shadow: inset 0 0 0 1px #ccc; } .pbar .sq.b { background: #262421; box-shadow: inset 0 0 0 1px #555; }
.pbar .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pbar .e { color: var(--text-3); }
.pbar .a { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 13px; padding: 2px 8px; border-radius: 4px; background: var(--surface-2); }
.board-zone { flex: 1; min-height: 0; container-type: size; display: grid; place-items: center; }
.board-row { --side: min(calc(100cqw - 34px), 100cqh); display: flex; gap: 6px; width: calc(var(--side) + 18px); height: var(--side); }
.evalbar { width: 12px; flex: none; border-radius: 3px; overflow: hidden; background: #403d39; position: relative; }
.evalbar .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #fff; transition: height .35s ease; }
.evalbar.flip .fill { bottom: auto; top: 0; }
.evalbar .v { position: absolute; left: 0; right: 0; text-align: center; font-size: 7.5px; font-weight: 800; z-index: 1; }
.moves-strip { flex: none; height: 42px; display: flex; align-items: center; gap: 2px; overflow-x: auto; padding: 0 10px; background: var(--surface); scrollbar-width: none; border-top: 1px solid var(--line); }
.moves-strip::-webkit-scrollbar { display: none; }
.mv-num { color: var(--text-3); font-size: 13px; padding: 0 2px 0 8px; flex: none; }
.mv { height: 30px; flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 5px; font-weight: 700; font-size: 15px; color: var(--text-2); }
.mv .cls-icon { width: 16px; height: 16px; }
.mv.active { background: var(--surface-3); color: var(--text); }
.controls { flex: none; display: grid; grid-template-columns: 56px 56px 1fr 56px 56px; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); }
.controls .btn { height: 52px; padding: 0; width: 100%; }
.controls .btn svg { width: 26px; height: 26px; flex: none; }
.controls .btn.primary { font-size: 18px; }
.controls .btn .lbl { width: 5.5em; text-align: left; }

/* ---------- Šachovnice ---------- */
.board { position: relative; width: 100%; height: 100%; flex: 1; border-radius: 3px; overflow: hidden; user-select: none; -webkit-user-select: none; aspect-ratio: 1; }
.board .squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.board .s { position: relative; background: var(--sq-light); }
.board .s.d { background: var(--sq-dark); }
.board .s .hl { position: absolute; inset: 0; }
.board .coord { position: absolute; font-size: max(9px, calc(var(--side, 360px) * .028)); font-weight: 700; line-height: 1; pointer-events: none; }
.board .coord.r { left: 3%; top: 4%; } .board .coord.f { right: 5%; bottom: 4%; }
.board .s .coord { color: var(--sq-dark); } .board .s.d .coord { color: var(--sq-light); }
.board .pieces, .board .overlay { position: absolute; inset: 0; pointer-events: none; }
.board .piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; will-change: transform; }
.board .piece img { width: 100%; height: 100%; display: block; }
.board .piece.anim { transition: transform .16s ease-out; }
.board .badge { position: absolute; width: 6.2%; height: 6.2%; transform: translate(-45%, -55%); filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); z-index: 3; }
.board .badge .cls-icon { width: 100%; height: 100%; }
.board svg.arrows { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; }

/* ---------- Spodní panel (nastavení, chat) ---------- */
.sheet-scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 50; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.35); animation: up .2s ease-out;
  max-width: 720px; margin: 0 auto; padding-bottom: env(safe-area-inset-bottom);
}
@keyframes up { from { transform: translateY(30%); opacity: 0; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--surface-3); margin: 8px auto 2px; flex: none; }
.sheet header { display: flex; align-items: center; padding: 4px 8px 4px 16px; flex: none; }
.sheet header h3 { margin: 0; flex: 1; font-size: 18px; }
.sheet .body { padding: 8px 16px 16px; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.form-row .note { color: var(--text-3); font-size: 12px; margin-top: 5px; line-height: 1.4; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.seg button { height: 38px; border-radius: 7px; font-weight: 600; font-size: 14px; color: var(--text-2); }
.seg button.on { background: var(--green); color: #fff; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }

.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.ai .src { display: block; font-size: 11px; color: var(--text-3); margin-top: 6px; }
.msg.err { background: rgba(250, 65, 45, .15); color: #fa412d; }
.chat-input { display: grid; grid-template-columns: 1fr 48px; gap: 8px; padding: 10px 16px 12px; border-top: 1px solid var(--line); flex: none; }
.chat-input .btn { width: 48px; padding: 0; }
.chat-input .btn svg { width: 22px; height: 22px; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: #1f1d1b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: fade .2s; }

/* ---------- Širší obrazovky: šachovnice vlevo, panel vpravo ---------- */
@media (min-width: 900px) and (min-height: 560px) {
  .review { display: grid; grid-template-columns: 1fr 400px; grid-template-rows: 34px 1fr 34px; grid-template-areas: "top side" "board side" "bottom side"; padding: 12px 0 12px 12px; gap: 0 16px; }
  .review .pbar.top { grid-area: top; }
  .review .pbar.bottom { grid-area: bottom; }
  .review .board-zone { grid-area: board; }
  .review .side { grid-area: side; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); margin: -12px 0; }
  .review .coach-panel { height: 220px; }
  .review .moves-strip { flex: 1; height: auto; flex-wrap: wrap; align-content: flex-start; overflow-y: auto; padding: 10px; }
  .review .graph.mini { height: 70px; }
}
@media (max-width: 899px), (max-height: 559px) {
  .review .side { display: contents; }
  .review .coach-panel { order: 1; }
  .review .pbar.top { order: 2; }
  .review .board-zone { order: 3; }
  .review .pbar.bottom { order: 4; }
  .review .graph.mini { order: 5; }
  .review .moves-strip { order: 6; }
  .review .controls { order: 7; }
}
@media (max-height: 640px) and (max-width: 899px) {
  .coach-panel { height: 118px; }
  .review .graph.mini { display: none; }
}

/* fáze analýzy */
.progress-stage { text-align: center; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--green); margin-bottom: 6px; }
.progress-skip { display: flex; justify-content: center; margin-top: 18px; }
.progress-skip .btn { visibility: hidden; height: 42px; font-size: 15px; }
