:root {
  --bg: #312e2b;
  --panel: #262522;
  --panel2: #2b2926;
  --row-alt: #2a2825;
  --line: #3d3a37;
  --text: #ffffff;
  --muted: #a5a3a0;
  --green: #81b64c;
  --green-hi: #95c15f;
  --green-edge: #537133;
  --btn: #454441;
  --btn-hi: #4f4e4b;
  --btn-edge: #1f1e1c;
  --red: #fa412d;
  --gold: #e8c34a;
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --sq-light-hl: #f5f682;
  --sq-dark-hl: #b9ca43;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h2 { font-size: 1.5rem; margin-bottom: 4px; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* Viršutinė juosta */
.top { background: var(--panel); border-bottom: 1px solid #1d1c1a; }
.top-in {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 4px 20px; padding: 0 16px; max-width: 1000px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.brand h1 { font-size: 1.3rem; letter-spacing: -0.01em; }
.logo-img { background: #fff; border-radius: 4px; padding: 2px; object-fit: contain; }
.tabs { display: flex; gap: 2px; }
.tabs button {
  min-height: 52px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent;
  background: none; color: var(--muted); font-weight: 600; font-size: 15px;
}
.tabs button:hover { color: var(--text); background: var(--panel2); }
.tabs button[aria-current="page"] { color: var(--text); border-bottom-color: var(--green); }

main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 32px; }
.panel { background: var(--panel); border-radius: 6px; padding: 18px 20px 20px; }
.panel > h2 { margin-bottom: 2px; }
.panel > .muted { margin: 0; font-size: 14px; }
.scroll { overflow-x: auto; margin-top: 14px; }

.foot { text-align: center; padding: 24px 16px 40px; font-size: 14px; }
.foot p { margin: 8px 0 0; }
.foot img { background: #fff; border-radius: 6px; padding: 6px; height: auto; opacity: 0.92; }

/* Lentelės */
table { width: 100%; border-collapse: collapse; }
table.wide { min-width: 560px; }
.legend { font-size: 13px; margin: 12px 0 0; }
th, td { text-align: left; padding: 10px 12px; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 6px; padding-bottom: 8px; }
tbody tr:nth-child(odd) { background: var(--row-alt); }
tbody tr:hover { background: #33312d; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { box-shadow: inset 0 0 0 0 transparent; }
tr.me { background: #35422a !important; }
tr.me td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.rank { font-weight: 700; width: 52px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-1 { color: var(--gold); } .rank-2 { color: #c9cbd1; } .rank-3 { color: #d98e55; }
.rating { font-weight: 700; }
.who { display: flex; align-items: center; gap: 10px; }
.av {
  width: 30px; height: 30px; border-radius: 4px; flex: none; color: #fff; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; text-transform: uppercase;
}
.av0 { background: #5a8b3c; } .av1 { background: #3f7ca8; } .av2 { background: #a65f3b; }
.av3 { background: #7d5aa6; } .av4 { background: #b0903a; } .av5 { background: #3f8f86; }

button.link {
  background: none; border: 0; padding: 0; color: var(--text); font-weight: 600;
}
button.link:hover { color: var(--green-hi); text-decoration: underline; }
.muted button.link, .links button.link { color: var(--green-hi); }

/* Mygtukai (kaip chess.com: plokšti su tamsesne apatine briauna) */
button.primary, button.secondary {
  min-height: 44px; padding: 0 20px; border-radius: 6px; font-weight: 700; border: 0;
}
button.primary { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-edge); margin-bottom: 4px; }
button.primary:hover:not(:disabled) { background: var(--green-hi); }
button.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-edge); }
button.secondary { background: var(--btn); color: var(--text); box-shadow: 0 4px 0 var(--btn-edge); margin-bottom: 4px; }
button.secondary:hover:not(:disabled) { background: var(--btn-hi); }
button.secondary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--btn-edge); }
button.small { min-height: 34px; padding: 0 12px; font-size: 13px; box-shadow: 0 3px 0 var(--btn-edge); }
#games-more { margin-top: 16px; }

.pos { color: var(--green-hi); }
.neg { color: var(--red); }
.delta { font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Paskyra */
.card { background: var(--panel); border-radius: 6px; padding: 20px; margin-top: 16px; max-width: 460px; }
.card h3 { margin-bottom: 14px; font-size: 1.15rem; }
form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
select {
  min-height: 44px; padding: 0 10px; border-radius: 6px; border: 1px solid #4a4743; background: #1f1e1c; color: var(--text); font: inherit; font-weight: 400;
}
select:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 1px var(--green); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea {
  padding: 10px 12px; border-radius: 6px; border: 1px solid #4a4743; background: #1f1e1c; color: var(--text); font: inherit; font-weight: 400; resize: vertical; min-height: 84px;
}
textarea:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 1px var(--green); }
.fine { font-size: 12px; margin: 0; }
input {
  min-height: 44px; padding: 0 12px; border-radius: 6px; border: 1px solid #4a4743;
  background: #1f1e1c; color: var(--text); font: inherit; font-weight: 400;
}
input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 1px var(--green); }
.msg { margin: 0; min-height: 1.4em; font-size: 14px; }
.msg.err { color: #ff7b6b; }
.msg.ok { color: var(--green-hi); }
.links { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.stat { background: #1f1e1c; border-radius: 6px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; white-space: nowrap; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* Partijos sąrašas */
.pl { display: flex; align-items: center; gap: 8px; line-height: 1.6; white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 2px; flex: none; border: 1px solid #00000066; }
.dot.w { background: #fff; } .dot.b { background: #403d39; border-color: #77746f; }
.sc { font-weight: 700; text-align: center; width: 36px; line-height: 1.6; }
.sc div { display: block; }
.res-badge { display: inline-block; min-width: 28px; text-align: center; font-weight: 700; padding: 0 6px; border-radius: 3px; background: #1f1e1c; }
.rr { font-size: 12px; font-weight: 400; color: var(--muted); }

/* Partijos peržiūra */
.replay { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; margin-top: 16px; }
.r-board { flex: 1 1 340px; max-width: 560px; min-width: 0; }
.r-side { flex: 1 1 260px; max-width: 380px; background: var(--panel); border-radius: 6px; overflow: hidden; }
.pbar { display: flex; align-items: center; gap: 10px; padding: 6px 2px; min-height: 44px; }
.pbar .name { font-weight: 700; }
.pbar .rt { color: var(--muted); font-size: 13px; }
.pbar .res { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.board {
  position: relative; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: hidden;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; background: var(--sq-light); min-height: 0; overflow: hidden; }
.sq.dark { background: var(--sq-dark); }
.sq.last { background: var(--sq-light-hl); }
.sq.dark.last { background: var(--sq-dark-hl); }
.co { position: absolute; font-size: 11px; font-weight: 700; line-height: 1; color: var(--sq-dark); pointer-events: none; }
.sq.dark .co { color: var(--sq-light); }
.co.rk { top: 3px; left: 3px; }
.co.fl { bottom: 3px; right: 3px; }
.piece { display: block; width: 100%; height: 100%; }
.piece svg { display: block; width: 100%; height: 100%; }
.pc.w path, .pc.w circle, .pc.w rect { fill: #fff; stroke: #1e1c1a; stroke-width: 1.4; stroke-linejoin: round; }
.pc.w .d { fill: none; stroke: #1e1c1a; stroke-width: 1.1; stroke-linecap: round; }
.pc.w .e { fill: #1e1c1a; stroke: none; }
.pc.w .x { fill: none; stroke-width: 3; stroke-linecap: round; }
.pc.b path, .pc.b circle, .pc.b rect { fill: #4a4744; stroke: #0d0c0b; stroke-width: 1.4; stroke-linejoin: round; }
.pc.b .d { fill: none; stroke: #d8d6d2; stroke-width: 1.1; stroke-linecap: round; }
.pc.b .e { fill: #d8d6d2; stroke: none; }
.pc.b .x { fill: none; stroke-width: 3; stroke-linecap: round; }

.r-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.r-head h2 { font-size: 1.1rem; margin-bottom: 4px; }
.r-head p { margin: 0; font-size: 13px; }
.moves { max-height: 360px; overflow-y: auto; }
.mv { display: grid; grid-template-columns: 44px 1fr 1fr; align-items: stretch; font-size: 15px; }
.mv:nth-child(odd) { background: var(--row-alt); }
.mv .no { background: #1f1e1c; color: var(--muted); font-size: 13px; padding: 6px 0; text-align: center; align-self: stretch; display: flex; align-items: center; justify-content: center; }
.mv button { background: none; border: 0; color: var(--text); text-align: left; padding: 6px 10px; font-weight: 600; }
.mv button:hover { background: #3a3733; }
.mv button[aria-current="true"] { background: #4b4845; }
.controls { display: flex; border-top: 1px solid var(--line); }
.controls button {
  flex: 1; min-height: 46px; background: var(--panel2); border: 0; color: var(--text); font-size: 20px; font-weight: 700;
}
.controls button + button { border-left: 1px solid var(--line); }
.controls button:hover:not(:disabled) { background: #3a3733; }
.r-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.r-foot p { margin: 0; }

/* Žaidimas naršyklėje */
.board.playable .sq { cursor: pointer; }
.sq.sel { background: #f5f682 !important; }
.sq.tgt::after { content: ''; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(0, 0, 0, 0.2); }
.sq.cap::after { content: ''; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(0, 0, 0, 0.22); }
.piece { position: relative; z-index: 1; }

/* Turnyrai */
.bracket { display: flex; gap: 18px; overflow-x: auto; margin-top: 18px; padding-bottom: 8px; align-items: flex-start; }
.bk-round { flex: 0 0 230px; display: flex; flex-direction: column; gap: 12px; justify-content: space-around; }
.bk-round h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.bk-match { background: #1f1e1c; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.bk-match.mine { border-color: var(--green); }
.bk-p { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; font-weight: 600; }
.bk-p + .bk-p { border-top: 1px solid var(--line); }
.bk-p.win { background: #35422a; color: #fff; }
.bk-p.empty { color: #6f6c68; font-weight: 400; }
.bk-foot { padding: 6px 12px; font-size: 12px; background: var(--panel2); }
.bk-admin { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 10px; background: var(--panel2); }
.champ { margin: 12px 0; font-size: 1.4rem; font-weight: 800; color: var(--gold); }

/* Tiesioginė žiūra */
.live-list { padding: 14px 16px; }
.live-list h3 { font-size: 1rem; margin-bottom: 8px; }
.live-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.live-item.cur button.link { color: var(--green-hi); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 3px; background: var(--btn); color: var(--text); text-transform: uppercase; letter-spacing: 0.04em; }
.tag.feat { background: var(--green); }
.live-tag { margin: 0 0 4px; font-weight: 700; color: var(--green-hi); }
.live-over { margin: 8px 0 0; font-weight: 700; font-size: 1.1rem; }
.moves-line { margin: 10px 0 0; font-size: 13px; }
.live-empty { padding: 40px 0; }
.clk { margin-left: auto; min-width: 84px; text-align: right; padding: 4px 10px; border-radius: 4px; background: var(--panel); color: var(--muted); font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.clk.active { background: #fff; color: #262522; }
.clk.low.active { background: var(--red); color: #fff; }
.live-tools { margin-top: 10px; }

/* Didelio ekrano režimas (projektoriui) */
body.tv .top, body.tv .foot, body.tv h2, body.tv #view-live > p { display: none; }
body.tv main { max-width: none; padding: 12px; }
body.tv .panel { background: none; padding: 0; }
body.tv .replay { justify-content: center; margin-top: 0; }
body.tv .r-board { flex: 0 1 calc(100vh - 150px); max-width: calc(100vh - 150px); }
body.tv .pbar { min-height: 56px; }
body.tv .pbar .name { font-size: 1.6rem; }
body.tv .pbar .rt { font-size: 1.1rem; }
body.tv .clk { font-size: 2rem; }
body.tv .live-tag { font-size: 1.4rem; }
body.tv .live-over { font-size: 1.8rem; }
body.tv .tv-exit { position: fixed; top: 8px; right: 8px; opacity: 0.35; }
body.tv .tv-exit:hover { opacity: 1; }

@media (max-width: 560px) {
  .tabs { width: 100%; overflow-x: auto; }
  body.tv .tv-exit { position: static; opacity: 1; margin-top: 8px; }
  .tabs button { flex: 1 0 auto; padding: 0 10px; font-size: 14px; }
  main { padding: 12px 8px 24px; }
  .panel { padding: 14px 12px 16px; }
  .tabs button { padding: 0 12px; }
  .moves { max-height: 240px; }
  .r-side { max-width: none; }
}

.tabs button.alert::after { content: ''; display: inline-block; width: 9px; height: 9px; margin-left: 6px; border-radius: 50%; background: var(--green); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.3; } to { opacity: 1; } }

/* Viso ekrano iššūkio langas */
.ov { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 14, 13, 0.92); }
.ov-card { width: min(100%, 520px); padding: 32px 24px; border-radius: 10px; background: var(--bg); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); }
.ov-card h2 { font-size: clamp(1.5rem, 6vw, 2.2rem); margin: 8px 0 12px; }
.ov-kicker { margin: 0; font-weight: 800; letter-spacing: 0.12em; color: var(--green-hi); animation: pulse 0.7s infinite alternate; }
.ov-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.ov-actions button { min-height: 56px; font-size: 1.1rem; }

.cls { display: inline-block; min-width: 26px; padding: 1px 6px; margin-left: 6px; border-radius: 4px; background: var(--green, #769656); color: #fff; font-size: 11px; font-weight: 700; text-align: center; vertical-align: middle; line-height: 16px; }

.tos { max-width: 720px; }
.tos h3 { margin: 22px 0 6px; }
.tos ul { padding-left: 20px; }
.tos li { margin: 6px 0; }
.foot .link { font-size: 14px; }

button.danger { background: #b33a3a; color: #fff; border: 0; border-bottom: 3px solid #7d2626; border-radius: 8px; padding: 10px 16px; font-weight: 700; cursor: pointer; }

.av.has-img { background: #333; overflow: hidden; }
.av.has-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo { display: flex; gap: 14px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.photo-prev .av { width: 72px; height: 72px; font-size: 30px; border-radius: 8px; }
.hidden { display: none; }

.card.lock { border-left: 4px solid #b0903a; }

.cls.teacher { background: #3f7ca8; }
.two[hidden] { display: none; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.cf { min-height: 0; margin: 10px 0; }

body.gate { display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; }
.gate-box { text-align: center; max-width: 560px; padding: 24px 18px; }
.gate-logo { border-radius: 12px; background: #fff; padding: 6px; }
.gate-box h1 { margin: 14px 0 6px; }
.gate-line { display: flex; gap: 12px; align-items: center; justify-content: center; font-size: 18px; }
.spin { width: 20px; height: 20px; border: 3px solid #555; border-top-color: #81b64c; border-radius: 50%; animation: gspin 0.9s linear infinite; flex: none; }
.spin[hidden] { display: none; }
@keyframes gspin { to { transform: rotate(360deg); } }
#gate-widget { display: flex; justify-content: center; margin: 18px 0; min-height: 4px; }

.prof-card { padding: 28px 22px; }
.prof-img { display: block; width: 160px; height: 160px; margin: 0 auto 14px; border-radius: 12px; object-fit: cover; background: #333; }
.prof-init { display: flex; align-items: center; justify-content: center; font-size: 72px; font-weight: 800; color: #fff; }
.prof-card h2 { margin: 6px 0 8px; }
.pl button.link, .pbar button.link, .bk-p button.link { font: inherit; color: inherit; }

.sugg-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 6px; }
textarea { width: 100%; }
