/* Knightfall: dark Chess.com-style theme */
:root {
  --bg: #312e2b; --bg2: #262421; --panel: #262522; --panel2: #21201d; --panel3: #1c1b19; --line: #3c3a37;
  --text: #fff; --text2: #c3c2c1; --muted: #8b8987; --green: #81b64c; --green-d: #45753c; --green-h: #a3d160;
  --red: #e02828; --yellow: #f6c454; --blue: #5d9cd3; --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --board-img: none; --side-w: 156px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
a.link, .link { color: #a6c7e8; cursor: pointer; } a.link:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0 0 10px; }
input, select, textarea, button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 11px; }
.pad { padding: 12px; } .pad-lg { padding: 32px; } .center { text-align: center; justify-content: center; }
.row { display: flex; align-items: center; } .col { display: flex; flex-direction: column; }
.gap { gap: 10px; } .gap-sm { gap: 6px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; } .between { justify-content: space-between; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.win { color: var(--green); } .loss { color: var(--red); } .draw { color: var(--muted); }

/* ---------- layout ---------- */
.sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--side-w); background: var(--bg2); display: flex; flex-direction: column; padding: 8px 0; z-index: 30; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 6px; padding: 8px 12px 14px; font-weight: 800; font-size: 19px; letter-spacing: -.3px; }
.logo-mark { width: 30px; height: 30px; position: relative; }
.logo-mark piece { position: absolute; inset: 0; width: 100%; height: 100%; background-size: cover; }
.nav-links { display: flex; flex-direction: column; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 14px; font-weight: 700; font-size: 15px; color: var(--text2); border-left: 3px solid transparent; }
.nav-link:hover { background: #1f1e1b; color: #fff; }
.nav-link.active { color: #fff; background: #1f1e1b; border-left-color: var(--green); }
.nav-link.small { font-size: 13px; font-weight: 600; }
.nav-ico { width: 24px; height: 24px; display: inline-flex; color: #bababa; } .nav-link.active .nav-ico, .nav-link:hover .nav-ico { color: var(--green-h); }
.nav-ico svg, .ico svg { width: 100%; height: 100%; }
.nav-bottom { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.nav-user { padding: 8px 6px; border: 0; overflow: hidden; } .nav-user span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-icons { display: flex; justify-content: space-around; }
#main { margin-left: var(--side-w); padding: 20px 24px 60px; max-width: 1280px; }
#main.wide { max-width: none; }
.topbar { display: none; }
.shroud { display: none; }
@media (max-width: 900px) {
  :root { --side-w: 0px; }
  .topbar { display: flex; align-items: center; justify-content: space-between; height: 50px; padding: 0 8px; background: var(--bg2); position: sticky; top: 0; z-index: 25; }
  .topbar .logo { padding: 0; }
  .sidebar { width: 230px; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .shroud { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 29; }
  #main { margin-left: 0; padding: 12px 10px 60px; }
}

/* ---------- buttons, inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 6px; border: 0; cursor: pointer;
  background: #464441; color: #fff; font-weight: 700; font-size: 15px; box-shadow: 0 3px 0 #2b2927; transition: filter .1s, transform .05s; user-select: none; white-space: nowrap; }
.btn:hover { filter: brightness(1.12); } .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #2b2927; }
.btn:disabled { opacity: .5; cursor: default; filter: none; transform: none; }
.btn-green { background: var(--green); box-shadow: 0 4px 0 var(--green-d); text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn-green:active { box-shadow: 0 1px 0 var(--green-d); }
.btn-red { background: #c33; box-shadow: 0 3px 0 #7d1f1f; }
.btn-lg { padding: 16px 26px; font-size: 21px; border-radius: 10px; }
.btn-xl { padding: 20px 30px; font-size: 25px; border-radius: 12px; width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; box-shadow: none; color: var(--text2); } .btn-ghost:hover { background: #3a3835; }
.icon-btn { background: transparent; border: 0; color: #bababa; width: 36px; height: 36px; padding: 6px; border-radius: 6px; cursor: pointer; position: relative; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: #3a3835; color: #fff; }
.icon-btn svg { width: 22px; height: 22px; }
.ico { display: inline-flex; width: 20px; height: 20px; }
.badge { position: absolute; top: 2px; right: 0; background: var(--red); color: #fff; font-size: 10px; font-weight: 800; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  background: #1d1c1a; border: 1px solid #4a4845; border-radius: 6px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 6px 0; }
.seg { display: inline-flex; background: #1d1c1a; border-radius: 6px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { background: transparent; border: 0; padding: 7px 12px; border-radius: 4px; cursor: pointer; color: var(--text2); font-weight: 700; }
.seg button.on { background: #464441; color: #fff; }

/* ---------- cards, lists, tabs ---------- */
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-title { font-weight: 800; font-size: 17px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; } .grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); } .grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 10px 14px; font-weight: 700; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: #fff; border-bottom-color: var(--green); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 9px 8px; border-bottom: 1px solid #2f2d2a; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #2d2b28; }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; font-weight: 800; color: #fff; flex-shrink: 0; text-shadow: 0 1px 1px rgba(0,0,0,.3); }
.user-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.user-link:hover .user-name { text-decoration: underline; }
.user-rating { color: var(--muted); font-weight: 400; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #3a3835; font-size: 12px; font-weight: 700; color: var(--text2); }
.pill-green { background: var(--green-d); color: #fff; } .pill-red { background: #7d1f1f; color: #fff; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.spinner { width: 28px; height: 28px; border: 3px solid #555; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toasts, modals, popovers ---------- */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f1e1c; border-left: 4px solid var(--blue); padding: 12px 16px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.5); opacity: 0; transform: translateX(20px); transition: .25s; max-width: 340px; }
.toast.show { opacity: 1; transform: none; } .toast-error { border-color: var(--red); } .toast-good { border-color: var(--green); }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 420px; max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.modal-wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 0; } .modal-head h2 { margin: 0; }
.modal-body { padding: 16px; } .modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 16px 16px; }
.notif-pop { position: fixed; left: calc(var(--side-w) + 8px); bottom: 12px; width: 340px; max-height: 70vh; overflow: auto; background: var(--panel2); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.6); z-index: 80; }
@media (max-width: 900px) { .notif-pop { left: 8px; right: 8px; top: 56px; bottom: auto; width: auto; } }
.notif-head { padding: 12px; font-weight: 800; border-bottom: 1px solid var(--line); }
.notif { display: block; padding: 10px 12px; border-bottom: 1px solid #2f2d2a; } .notif:hover { background: #2d2b28; } .notif.unread { border-left: 3px solid var(--green); }

/* ---------- board ---------- */
.board-wrap { position: relative; width: 100%; aspect-ratio: 1; user-select: none; }
.cg-wrap { width: 100%; height: 100%; position: relative; }
.cg-wrap.mini { aspect-ratio: 1; height: auto; }
cg-board { background-image: var(--board-img) !important; background-size: cover; border-radius: 3px; }
cg-board square.move-dest { background: radial-gradient(rgba(20,85,30,.5) 19%, rgba(0,0,0,0) 20%); }
cg-board square.oc.move-dest { background: radial-gradient(transparent 0%, transparent 79%, rgba(20,85,30,.4) 80%); }
cg-board square.last-move { background-color: rgba(255,255,51,.42); }
cg-board square.selected { background-color: rgba(255,255,51,.55); }
cg-board square.check { background: radial-gradient(ellipse at center, rgba(255,0,0,1) 0%, rgba(231,0,0,1) 25%, rgba(169,0,0,0) 89%, rgba(158,0,0,0) 100%); }
cg-board square.premove-dest { background: radial-gradient(rgba(20,30,85,.5) 19%, rgba(0,0,0,0) 20%); }
cg-board square.current-premove { background-color: rgba(20,30,85,.45); }
.cg-wrap coords { font-weight: 700; font-size: clamp(8px, 1.5vw, 12px); opacity: 1; font-family: var(--font); }
.cg-wrap coords.ranks { left: 3px; top: 0; height: 100%; width: auto; }
.cg-wrap coords.ranks coord { transform: none; display: flex; align-items: flex-start; padding-top: 2px; }
.cg-wrap coords.files { left: 0; bottom: 1px; width: 100%; height: auto; text-transform: lowercase; }
.cg-wrap coords.files coord { text-align: right; padding-right: 3px; }
.cg-wrap coords coord { color: var(--sq-dark) !important; }
.cg-wrap coords.ranks coord:nth-child(odd), .cg-wrap coords.files coord:nth-child(odd) { color: var(--sq-light) !important; }
.cg-wrap coords.ranks.black coord:nth-child(odd), .cg-wrap coords.files.black coord:nth-child(odd) { color: var(--sq-dark) !important; }
.cg-wrap coords.ranks.black coord:nth-child(even), .cg-wrap coords.files.black coord:nth-child(even) { color: var(--sq-light) !important; }
.promo-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.promo { position: absolute; width: 12.5%; display: flex; flex-direction: column; background: #fff; border-radius: 4px; box-shadow: 0 4px 20px rgba(0,0,0,.6); }
.promo-piece { aspect-ratio: 1; border: 0; background: #fff; cursor: pointer; position: relative; padding: 0; }
.promo-piece:hover { background: #ddd; }
.promo-piece piece { position: absolute; inset: 5%; width: 90%; height: 90%; background-size: cover; }

/* ---------- game page ---------- */
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; max-width: 1200px; }
.board-col { max-width: min(calc(100vh - 140px), 760px); width: 100%; justify-self: end; }
@media (max-width: 1100px) { .game-layout { grid-template-columns: 1fr; } .board-col { justify-self: center; max-width: min(100%, calc(100vh - 200px), 640px); } }
.player-bar { display: flex; align-items: center; gap: 8px; padding: 6px 0; min-height: 46px; }
.player-bar .pname { font-weight: 700; } .player-bar .prating { color: var(--muted); }
.player-bar .online-dot { width: 8px; height: 8px; border-radius: 50%; background: #666; } .player-bar .online-dot.on { background: var(--green); }
.material { display: flex; align-items: center; gap: 0; height: 18px; color: var(--muted); font-size: 13px; }
.material piece { width: 18px; height: 18px; background-size: cover; position: relative; display: inline-block; margin-right: -6px; }
.material .adv { margin-left: 10px; }
.clock { margin-left: auto; background: #2b2926; color: #9b9996; font: 700 24px/1 "Roboto Mono", Consolas, monospace; padding: 8px 12px; border-radius: 5px; min-width: 112px; text-align: right; }
.clock.white-clock { background: #989795; color: #4b4a48; }
.clock.running { background: #fff; color: #000; } .clock.running.black-clock { background: #3a3835; color: #fff; }
.clock.low { color: #fff !important; background: #b33430 !important; }
.side-panel { background: var(--panel); border-radius: var(--radius); display: flex; flex-direction: column; height: min(calc(100vh - 140px), 760px); min-height: 460px; }
@media (max-width: 1100px) { .side-panel { height: auto; min-height: 360px; } }
.side-panel .tabs { margin: 0; padding: 0 8px; }
.panel-body { flex: 1; overflow-y: auto; min-height: 120px; }
.opening-name { padding: 8px 12px; color: var(--text2); font-size: 13px; border-bottom: 1px solid var(--line); min-height: 34px; }
.movelist { display: grid; grid-template-columns: 44px 1fr 1fr; font-size: 15px; }
.movelist .num { color: var(--muted); padding: 5px 8px; background: #2a2926; }
.movelist .mv { padding: 5px 8px; cursor: pointer; font-weight: 600; border-radius: 3px; display: flex; align-items: center; gap: 6px; }
.movelist .mv:hover { background: #3a3835; } .movelist .mv.cur { background: #4b4847; }
.movelist .row-alt { background: #2a2926; }
.mv-icon { width: 16px; height: 16px; border-radius: 50%; font-size: 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 900; color: #fff; }
.nav-buttons { display: flex; gap: 4px; padding: 8px; border-top: 1px solid var(--line); }
.nav-buttons .btn { flex: 1; padding: 8px; }
.game-actions { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.game-actions .btn { flex: 1; font-size: 14px; padding: 9px 8px; }
.offer-bar { padding: 10px 12px; background: #3a3835; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.status-line { padding: 10px 12px; font-weight: 700; text-align: center; border-bottom: 1px solid var(--line); }
.chat-box { display: flex; flex-direction: column; height: 100%; }
.chat-lines { flex: 1; overflow-y: auto; padding: 8px 12px; font-size: 14px; }
.chat-line { margin-bottom: 4px; word-wrap: break-word; } .chat-line b { margin-right: 6px; }
.chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.game-over { text-align: center; }
.game-over .result-big { font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.rating-change { font-size: 22px; font-weight: 800; }
.eval-bar { width: 22px; background: #403d39; border-radius: 3px; position: relative; overflow: hidden; flex-shrink: 0; }
.eval-bar .eval-white { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; transition: height .4s; }
.eval-bar .eval-text { position: absolute; left: 0; right: 0; font-size: 10px; font-weight: 800; text-align: center; z-index: 2; }
.board-row { display: flex; gap: 6px; }

/* ---------- home ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr; } }
.tc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tc-btn { background: #3c3a37; border: 2px solid transparent; border-radius: 6px; padding: 12px 6px; cursor: pointer; font-weight: 700; font-size: 16px; color: #fff; }
.tc-btn:hover { background: #4b4845; } .tc-btn.on { border-color: var(--green); background: #47513a; }
.tc-label { display: flex; align-items: center; gap: 6px; color: var(--text2); font-weight: 700; margin: 6px 0; font-size: 14px; }
.seek-row td:last-child { text-align: right; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: center; padding: 24px 0; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }
.hero h1 { font-size: 44px; } .hero p { font-size: 18px; color: var(--text2); }
.stat-row { display: flex; gap: 24px; color: var(--muted); font-weight: 700; }
.stat-row b { color: #fff; }
.bot-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 6px; cursor: pointer; border: 2px solid transparent; background: #2d2b28; }
.bot-card:hover { background: #3a3835; } .bot-card.on { border-color: var(--green); }
.bot-face { width: 48px; height: 48px; border-radius: 6px; display: flex; align-items: center; justify-content: center; position: relative; }
.bot-face piece { position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px); background-size: cover; }

/* ---------- puzzles ---------- */
.puzzle-status { padding: 14px; border-radius: 6px; font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.puzzle-status.good { background: #3c5a2a; } .puzzle-status.bad { background: #6a2424; } .puzzle-status.neutral { background: #3a3835; }
.rush-score { font-size: 48px; font-weight: 900; text-align: center; }
.strikes { display: flex; gap: 6px; justify-content: center; }
.strike { width: 24px; height: 24px; border-radius: 50%; background: #3a3835; } .strike.hit { background: var(--red); }
.rush-results { display: flex; flex-wrap: wrap; gap: 4px; }
.rush-results span { width: 26px; height: 26px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; }
.rush-results .ok { background: var(--green-d); } .rush-results .no { background: #7d1f1f; }

/* ---------- profile ---------- */
.profile-head { display: flex; gap: 20px; align-items: center; }
.rating-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.rating-card { background: #2d2b28; border-radius: 6px; padding: 12px; cursor: pointer; border: 2px solid transparent; }
.rating-card.on { border-color: var(--green); }
.rating-card .rc-name { color: var(--muted); font-weight: 700; font-size: 13px; text-transform: capitalize; }
.rating-card .rc-val { font-size: 26px; font-weight: 800; }
.graph { width: 100%; height: 160px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach { background: #2d2b28; border-radius: 6px; padding: 10px; } .ach.locked { opacity: .35; }
.ach b { display: block; } .ach small { color: var(--muted); }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.mini-game { background: #2d2b28; border-radius: 6px; padding: 8px; display: block; } .mini-game:hover { background: #3a3835; }
.mini-game .mg-p { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; padding: 4px 2px; }

/* ---------- review ---------- */
.review-summary { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 14px; align-items: center; font-weight: 700; }
.review-summary .rs-w, .review-summary .rs-b { text-align: center; min-width: 40px; }
.acc-box { font-size: 28px; font-weight: 900; padding: 6px 12px; border-radius: 6px; background: #fff; color: #000; display: inline-block; }
.acc-box.black { background: #403d39; color: #fff; }
.c-brilliant { background: #26c2a3; } .c-great { background: #749bbf; } .c-best { background: #81b64c; } .c-excellent { background: #96bc4b; }
.c-good { background: #77915f; } .c-book { background: #a88865; } .c-inaccuracy { background: #f7c631; } .c-mistake { background: #e58f2a; }
.c-blunder { background: #ca3431; } .c-miss { background: #ff7769; }
.eval-graph { width: 100%; height: 90px; cursor: pointer; display: block; background: #403d39; border-radius: 4px; }
.engine-line { font-family: Consolas, monospace; font-size: 13px; padding: 6px 10px; border-bottom: 1px solid #2f2d2a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.engine-line:hover { background: #2d2b28; }
.engine-line b { display: inline-block; min-width: 52px; }
.coach { display: flex; gap: 10px; padding: 10px 12px; background: #2d2b28; border-radius: 6px; margin: 8px; align-items: flex-start; }

/* keep grids inside the screen on phones */
.game-layout > *, .home-grid > *, .grid > *, .hero > * { min-width: 0; }
.board-col { width: 100%; }
@media (max-width: 1100px) { .board-col { max-width: min(100%, 640px); } }
.notif.row { display: flex; }
.tabs button { padding: 10px 11px; font-size: 14px; }
.tabs { scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
.notif .pill { min-width: 48px; text-align: center; }
