:root {
  color-scheme: dark;
  --bg: #151714;
  --panel: rgba(28, 33, 30, .92);
  --panel-2: rgba(245, 239, 220, .08);
  --text: #f4ecd9;
  --muted: #b8b09f;
  --gold: #e3b24c;
  --green: #5e8f67;
  --red: #c85b4a;
  /* Lichess "brown" board theme */
  --light: #f0d9b5;
  --dark: #b58863;
  --coord-light: #f0d9b5;
  --coord-dark: #b58863;
  --last-move: rgba(155, 199, 0, .41);
  --sel-move: rgba(20, 85, 30, .5);
  --good: rgba(106, 168, 79, .85);
  --bad: rgba(200, 60, 50, .85);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #151714 url("assets/Texture2D/Texture2D/fon-menu.png") center / cover fixed;
  color: var(--text);
}

#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
  backdrop-filter: saturate(1.05);
}

.sidebar {
  padding: 18px;
  background: rgba(14, 18, 16, .88);
  border-right: 1px solid rgba(255,255,255,.12);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand img {
  width: 58px;
  height: 58px;
  object-fit: contain;
}
.brand .brand-tagline {
  color: var(--gold);
  font-size: 13px;
  margin-top: 2px;
}
.brand .brand-user {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.brand .brand-user:empty { display: none; }

h1, h2, p { margin: 0; }
h1 { font-size: 25px; line-height: 1.05; }
h2 { font-size: 18px; margin: 16px 0 10px; }
.brand p, #gameMeta, .move-line { color: var(--muted); }

button {
  border: 1px solid rgba(255,255,255,.16);
  background: linear-gradient(#3d493c, #263029);
  color: var(--text);
  border-radius: 7px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--gold); }
button:disabled { opacity: .45; cursor: default; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}
.toolbar #soundBtn { padding: 10px 12px; }
.toolbar #soundBtn.muted { opacity: .6; }

.list {
  display: grid;
  gap: 8px;
}

.list button, .champ-card {
  text-align: left;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
}

.list button {
  display: block;
  width: 100%;
  min-height: 54px;
}

.stage {
  min-width: 0;
  padding: 24px;
  overflow: auto;
}

.champions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  max-width: 1180px;
}

.champ-card {
  min-height: 154px;
  padding: 14px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  align-content: end;
  position: relative;
  overflow: hidden;
}

.champ-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .82;
}

.champ-card strong, .champ-card span {
  position: relative;
  text-shadow: 0 2px 8px #000;
}
.champ-card strong { font-size: 22px; }
.champ-card span { color: var(--text); }

.hidden { display: none !important; }
.game-view {
  max-width: 1240px;
  background: rgba(13, 17, 15, .78);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 18px;
}

.topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.status {
  color: var(--gold);
  text-align: right;
  min-width: 160px;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, calc(100vh - 170px)) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.board {
  /* Always a perfect square: width drives height via aspect-ratio,
     and the column above caps width so the board never overflows. */
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.5), 0 2px 0 rgba(255,255,255,.05) inset;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  user-select: none;
  cursor: pointer;
}
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }

/* piece graphics */
.sq svg {
  width: 92%;
  height: 92%;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.28));
  transition: transform .08s ease;
}
.sq:hover svg { transform: scale(1.04); }

/* highlights, Lichess style */
.sq.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--last-move);
}
.sq.sel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sel-move);
}
.sq.good::after, .sq.bad::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 6px var(--good);
}
.sq.bad::after { box-shadow: inset 0 0 0 6px var(--bad); }

/* last-move arrow overlay */
.move-arrow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* hint: the piece you should move */
.sq.hintpiece::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(80,160,255,.0) 38%, rgba(80,160,255,.55) 40%, rgba(80,160,255,.0) 62%);
  z-index: 2;
  animation: hintpulse 1s ease-in-out infinite;
}
@keyframes hintpulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* legal-move hints (Lichess style dots / capture rings) */
.hint {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30%;
  height: 30%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(20, 85, 30, .5);
  pointer-events: none;
}
.hint.cap {
  width: 100%;
  height: 100%;
  background: none;
  border-radius: 0;
  box-shadow: inset 0 0 0 7px rgba(20, 85, 30, .5);
}

/* coordinates in the corners, colored opposite to the square (Lichess look) */
.coord {
  position: absolute;
  font-size: clamp(8px, 1.5vh, 13px);
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
}
.coord.file { right: 4px; bottom: 3px; }
.coord.rank { left: 4px; top: 3px; }
.sq.light .coord { color: var(--coord-dark); }
.sq.dark .coord { color: var(--coord-light); }

.panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 14px;
}
.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.move-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
}
.task-box, .comment-box {
  /* Size to content (no fixed min-height) so empty/placeholder states stay
     compact instead of reserving a large empty card. */
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-2);
  white-space: pre-wrap;
  line-height: 1.45;
}
/* the running annotation: give it a clear card look so it isn't overlooked */
.comment-box {
  margin-top: 10px;
  padding: 12px 14px 14px;
  background: rgba(94, 143, 103, .12);
  border: 1px solid rgba(94, 143, 103, .45);
  border-left: 4px solid var(--green);
  color: var(--text);
}
.comment-box .comment-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #9ec7a6;
  margin-bottom: 6px;
}
.comment-box .comment-move {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(227, 178, 76, .18);
  border: 1px solid rgba(227, 178, 76, .5);
  color: var(--gold);
  font-size: .8rem;
  letter-spacing: .02em;
  text-transform: none;
  vertical-align: middle;
}
.comment-box .comment-text { font-size: 1.02rem; }
.comment-box.empty {
  background: var(--panel-2);
  border-color: rgba(245, 239, 220, .12);
  border-left-color: rgba(245, 239, 220, .2);
}
.comment-box.empty .comment-text { color: var(--muted); font-style: italic; }
/* annotation glyph chip in the comment header */
.comment-box .glyph-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: none;
  color: #1a1a1a;
  vertical-align: middle;
}

/* Lichess-style annotation badge pinned to the move's destination square */
.sq .move-glyph {
  position: absolute;
  top: 2%;
  right: 2%;
  min-width: 34%;
  height: 34%;
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 800;
  font-size: clamp(11px, 2.2vw, 20px);
  line-height: 1;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
  pointer-events: none;
  z-index: 3;
}
/* glyph colour scale (shared by board badge and comment chip) */
.g-brilliant   { background: #21c2c2; }
.g-good        { background: #22ac38; }
.g-interesting { background: #4d99e6; }
.g-dubious     { background: #d9a521; }
.g-mistake     { background: #e8772e; }
.g-blunder     { background: #d9342b; }
.task-box {
  margin-bottom: 10px;
  color: #fff4cc;
  border: 1px solid rgba(227,178,76,.35);
}
/* make tasks & their solutions stand out so they aren't skipped while flipping */
.task-box .task-banner {
  display: block;
  margin: -4px -4px 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .2px;
}
.task-box .task-banner.active {
  background: linear-gradient(90deg, rgba(227,178,76,.32), rgba(227,178,76,.12));
  color: #ffe9a8;
  border: 1px solid rgba(227,178,76,.7);
  box-shadow: 0 0 0 1px rgba(227,178,76,.25), 0 0 18px rgba(227,178,76,.28);
  animation: taskpulse 1.5s ease-in-out infinite;
}
.task-box .task-banner.solved {
  background: linear-gradient(90deg, rgba(124,178,77,.28), rgba(124,178,77,.1));
  color: #d6f3c2;
  border: 1px solid rgba(124,178,77,.6);
}
@keyframes taskpulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(227,178,76,.25), 0 0 14px rgba(227,178,76,.22); }
  50%      { box-shadow: 0 0 0 1px rgba(227,178,76,.5),  0 0 22px rgba(227,178,76,.42); }
}
.task-box .task-prompt { font-weight: 600; margin-bottom: 6px; }
.task-box .task-note {
  margin: 6px 0;
  padding: 6px 9px;
  border-left: 3px solid rgba(120,180,220,.7);
  background: rgba(120,180,220,.1);
  border-radius: 0 6px 6px 0;
}
.task-box .task-worth { margin-top: 6px; color: var(--gold); }
.task-box .task-step { margin-top: 4px; color: var(--muted); }
.task-box button.continue {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 13px;
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(#2c4a30, #1b2e1f);
  border: 1px solid rgba(124,178,77,.6);
  color: #eafbe0;
}

.score-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 4px 0 10px;
  color: var(--gold);
  font-weight: 600;
}
.score-line .pts { color: var(--green); }

.var-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.var-bar:empty { display: none; }
.var-bar button {
  padding: 7px 11px;
  font-size: 14px;
  background: linear-gradient(#46402c, #2c2818);
  border-color: rgba(227,178,76,.35);
}
.var-bar button.back {
  background: linear-gradient(#2c3a44, #1b242b);
  border-color: rgba(120,180,220,.4);
}
/* loud, hard-to-skip call-out for side lines ("побочные варианты") */
.var-callout {
  flex: 1 1 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 15px;
}
.var-callout.unseen {
  background: linear-gradient(90deg, rgba(214,120,40,.4), rgba(214,120,40,.16));
  color: #ffd9ad;
  border: 1px solid rgba(230,140,60,.85);
  /* Steady, prominent glow (no animation) so it stands out without competing
     with the pulsing active-task banner — only one element pulses at a time. */
  box-shadow: 0 0 0 1px rgba(230,140,60,.45), 0 0 16px rgba(230,140,60,.45);
}
.var-callout.seen {
  background: rgba(120,180,220,.12);
  color: #cfe6f5;
  border: 1px solid rgba(120,180,220,.4);
  font-weight: 600;
}
.var-bar button.varbtn {
  flex: 1 1 100%;
  padding: 10px 13px;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
}
.var-bar button.varbtn.unseen {
  background: linear-gradient(90deg, #5a3a18, #3a2710);
  border: 1px solid rgba(230,140,60,.85);
  color: #ffe2c2;
}
.var-bar button.varbtn.seen {
  background: linear-gradient(#2c3a44, #1b242b);
  border-color: rgba(120,180,220,.4);
  color: #cfe6f5;
  font-weight: 600;
}

.end-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.end-bar:empty { display: none; }
.end-bar .end-msg {
  flex: 1 1 100%;
  padding: 8px 11px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.end-bar .end-msg.ok { background: rgba(124,178,77,.16); color: var(--green); border: 1px solid rgba(124,178,77,.4); }
.end-bar .end-msg.warn { background: rgba(227,178,76,.14); color: var(--gold); border: 1px solid rgba(227,178,76,.4); }
.end-bar button { padding: 8px 13px; font-size: 14px; }
.end-bar button.replay { background: linear-gradient(#46402c, #2c2818); border-color: rgba(227,178,76,.4); }
.end-bar button.nextgame { background: linear-gradient(#2c4a30, #1b2e1f); border-color: rgba(124,178,77,.5); color: #eafbe0; }

.stats-box {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.stats-box .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.stats-box .stat-row b { color: var(--text); font-weight: 600; }
.stats-box .bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(255,255,255,.1);
  overflow: hidden;
}
.stats-box .bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

/* game list: lock + score badges */
.list button { position: relative; }
.list button.locked { opacity: .55; cursor: default; }
.list button.locked:hover { border-color: rgba(255,255,255,.12); }
.list .badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 12px;
  color: var(--gold);
}
.list button.done .badge { color: var(--green); }
.list button.locked .badge { color: var(--muted); }

/* hint button bar */
.hint-bar {
  display: flex;
  gap: 8px;
  margin: 10px 0 0;
}
.hint-bar:empty { display: none; }
.hint-bar button {
  padding: 8px 12px;
  font-size: 14px;
  background: linear-gradient(#2c3a44, #1b242b);
  border-color: rgba(120,180,220,.45);
}
.hint-bar button:disabled { opacity: .5; }
.hint-bar .used { color: var(--muted); font-size: 13px; align-self: center; }

/* champion card progress badge */
.champ-card .progress {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(0,0,0,.55);
  color: var(--gold);
}
.champ-card .progress.done { color: var(--green); }

/* global summary on the home screen */
.home-stats {
  grid-column: 1 / -1;
  background: rgba(13, 17, 15, .82);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 4px;
}
.home-stats h3 {
  margin: 0 0 12px;
  font-size: 18px;
  color: var(--gold);
}
.home-stats .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}
.home-stats .cell {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 10px 12px;
}
.home-stats .cell .k { color: var(--muted); font-size: 13px; }
.home-stats .cell .v { font-size: 22px; font-weight: 700; color: var(--text); }
.home-stats .bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,.1);
  overflow: hidden;
  margin-top: 8px;
}
.home-stats .bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold));
}
.home-stats .weak {
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
}
.home-stats .weak b { color: var(--red); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid rgba(255,255,255,.12); }
  .play-area { grid-template-columns: 1fr; }
  .board { max-height: none; }
}

/* ============ auth gate ============ */
.auth-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #151714 url("assets/Texture2D/Texture2D/fon-menu.png") center / cover fixed;
  z-index: 100;
}
.auth-card {
  width: 320px;
  max-width: 90vw;
  background: rgba(14, 18, 16, .92);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,.5);
}
.auth-card img { width: 64px; height: 64px; object-fit: contain; align-self: center; }
.auth-card h1 { font-size: 26px; }
.auth-card p { color: var(--muted); margin-bottom: 6px; }
.auth-card input,
.add-student input {
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font: inherit;
}
.auth-card input:focus,
.add-student input:focus { outline: none; border-color: var(--gold); }
.auth-card button { padding: 12px; font-size: 16px; }
.auth-error { color: var(--red); font-size: 14px; min-height: 18px; }

/* ============ admin panel ============ */
.admin { min-height: 100vh; padding: 22px; max-width: 1200px; margin: 0 auto; }
.admin-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.admin-top p { color: var(--muted); }
.admin-actions { display: flex; gap: 8px; }
button.ghost { background: rgba(255,255,255,.06); }

.admin-cols {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
}
.admin-list, .admin-student {
  background: rgba(14, 18, 16, .82);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 16px;
}
.student-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.student-list button {
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.student-list button.active { border-color: var(--gold); background: rgba(227,178,76,.12); }
.student-list .s-name { font-weight: 600; }
.student-list .s-sub { color: var(--muted); font-size: 12px; }
.student-list .s-empty { color: var(--muted); font-size: 14px; }

.add-student { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.add-student h3 { margin: 0; font-size: 15px; color: var(--gold); }

.admin-placeholder { color: var(--muted); padding: 30px 8px; text-align: center; }
.admin-student h2 { margin-top: 0; }
.admin-student .who { color: var(--muted); margin-bottom: 12px; }
.admin-student .row-actions { display: flex; gap: 8px; margin-top: 14px; }
.admin-student .danger { border-color: rgba(200,90,74,.6); color: var(--red); }

/* per-champion table in admin */
.champ-table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
.champ-table th, .champ-table td { padding: 7px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.08); }
.champ-table th { color: var(--muted); font-weight: 600; }
.champ-table td.num, .champ-table th.num { text-align: right; }

.sidebar-foot { margin-top: 18px; }
.sidebar-foot button { width: 100%; }

@media (max-width: 760px) {
  .admin-cols { grid-template-columns: 1fr; }
}
