/* Chess Review App — chess.com-inspired dark theme.
   Colors verified against Screenshot Examples (Build Process Research §5). */

:root {
  --bg: #312e2b;
  --panel: #262421;
  --panel-2: #211f1c;
  --card: #3c3936;
  --card-2: #454140;
  --text: #e2e0dd;
  --muted: #989795;
  --green: #81b64c;
  --green-hover: #8fc65b;
  --green-shadow: #45753c;
  --light-sq: #eeeed2;
  --dark-sq: #769656;
  --hl: rgba(255, 255, 51, 0.5);
  --red: #fa412d;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { -webkit-user-drag: none; user-select: none; }

/* ---------------------------------------------------------------- home screen */

#home {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 42px;
}
.home-logo {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.home-logo img { width: 64px; height: 64px; }
.home-sub { color: var(--muted); font-size: 15px; margin-top: -30px; }

.green-btn {
  background: var(--green);
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  padding: 16px 64px;
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--green-shadow);
  transition: background 0.15s;
}
.green-btn:hover { background: var(--green-hover); }
.green-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--green-shadow); }

/* ---------------------------------------------------------------- main layout */

#main {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  flex: 0 0 auto;
}
#btn-sidebar {
  font-size: 22px;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 6px;
}
#btn-sidebar:hover { color: var(--text); background: var(--card); }
.topbar-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar-title img { width: 22px; height: 22px; }

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ---------------------------------------------------------------- sidebar */

#sidebar {
  width: 280px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid #1b1917;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}
#sidebar.closed { margin-left: -280px; }
.sidebar-header {
  padding: 14px 16px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
#game-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 8px 12px; }
#game-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
#game-list li:hover { background: var(--card); }
#game-list li.active { background: var(--card-2); }
.gl-result {
  width: 22px; height: 22px;
  border-radius: 5px;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800; color: #fff;
}
.gl-result.win { background: var(--green); }
.gl-result.loss { background: var(--red); }
.gl-result.draw { background: var(--muted); }
.gl-text { min-width: 0; }
.gl-opp { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gl-date { font-size: 12px; color: var(--muted); }
.gl-empty { color: var(--muted); font-size: 13px; padding: 10px 12px; cursor: default; }
#backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 8;
}

/* ---------------------------------------------------------------- content: board */

#content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 16px;
  overflow: auto;
}

#board-zone { display: flex; flex-direction: column; gap: 8px; }

.nameplate {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  padding-left: 42px; /* clear the eval bar */
}
.np-avatar {
  width: 32px; height: 32px;
  border-radius: 5px;
  background: var(--card-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.np-avatar.white-av { background: #f0f0f0; color: #444; }
.np-avatar.black-av { background: #333; color: #eee; }
.np-name { font-weight: 700; font-size: 14px; }
.np-elo { color: var(--muted); font-size: 13px; }

.board-row { display: flex; gap: 10px; align-items: stretch; }

/* eval bar */
#evalbar {
  width: 26px;
  border-radius: 4px;
  overflow: hidden;
  background: #403d3a;   /* black's share */
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
#evalbar-white {
  background: #f0f0f0;
  width: 100%;
  height: 50%;
  transition: height 0.45s ease;
}
#evalbar-num {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-size: 9.5px;
  font-weight: 700;
  color: #666;
  bottom: 3px;
}
#evalbar-num.on-black { color: #ddd; bottom: auto; top: 3px; }

/* board — yields horizontal space to the panel when a game is open */
#board {
  --sq: min(78vh - 110px, calc(100vw - 420px), 640px);
  width: var(--sq);
  height: var(--sq);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.sq { position: relative; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq .hl-layer { position: absolute; inset: 0; }
.sq.hl .hl-layer { background: var(--hl); }
.sq img.piece { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; }
.coord {
  position: absolute;
  font-size: 12px;
  font-weight: 700;
  z-index: 1;
  user-select: none;
}
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 4px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }
.board-badge {
  position: absolute;
  top: -6px; right: -6px;
  width: 42%;
  max-width: 30px;
  z-index: 3;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

/* ---------------------------------------------------------------- review panel */

#panel {
  width: 400px;
  flex: 0 0 auto;
  max-width: 96vw;
  height: min(calc(78vh + 24px), 720px);
  background: var(--panel);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px;
  font-size: 17px;
  font-weight: 800;
  flex: 0 0 auto;
  position: relative;
}
.panel-header img { width: 22px; height: 22px; }
.panel-back {
  position: absolute;
  left: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}
.panel-back:hover { color: var(--text); background: var(--card); }

.panel-scroll { flex: 1; overflow-y: auto; padding: 0 16px 16px; }

/* coach bubble */
.coach-row { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0 14px; }
.coach-avatar {
  width: 52px; height: 52px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--card-2);
  display: flex; align-items: center; justify-content: center;
}
.coach-avatar img { width: 38px; height: 38px; }
.coach-bubble {
  background: #fff;
  color: #312e2b;
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
  position: relative;
}
.coach-bubble::before {
  content: "";
  position: absolute;
  left: -7px; top: 16px;
  border: 7px solid transparent;
  border-right-color: #fff;
  border-left: 0;
}

/* eval graph */
#evalgraph-wrap { background: var(--panel-2); border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
#evalgraph { display: block; width: 100%; height: 92px; cursor: pointer; }

/* players / accuracy / rating rows */
.sum-grid { display: grid; grid-template-columns: 1fr auto auto; gap: 8px 18px; align-items: center; }
.sum-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.sum-players { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 18px; align-items: end; margin-bottom: 10px; }
.player-col { width: 86px; text-align: center; }
.player-name { font-size: 12.5px; font-weight: 700; margin-bottom: 6px; word-break: break-all; }
.player-tile {
  width: 62px; height: 62px;
  margin: 0 auto;
  border-radius: 8px;
  background: var(--card-2);
  display: flex; align-items: center; justify-content: center;
  border: 3px solid transparent;
}
.player-tile.jacob { border-color: var(--green); }
.player-tile img { width: 44px; height: 44px; }
.acc-box {
  width: 74px;
  margin: 8px auto 0;
  background: #fff;
  color: #262421;
  border-radius: 7px;
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  padding: 7px 0;
}
.acc-box.rating { background: var(--card-2); color: var(--text); }

/* classification counts */
.counts { margin: 18px 0 4px; border-top: 1px solid var(--card); padding-top: 12px; }
.count-row {
  display: grid;
  grid-template-columns: 1fr 60px 40px 60px;
  align-items: center;
  padding: 4.5px 0;
  font-size: 14.5px;
  font-weight: 700;
}
.count-row .cr-label { font-weight: 700; }
.count-row .cr-n { text-align: center; }
.count-row .cr-n.zero { opacity: 0.35; }
.count-row img { width: 21px; height: 21px; display: block; margin: 0 auto; }

.panel-footer { padding: 14px 16px; flex: 0 0 auto; }
.panel-footer .green-btn { width: 100%; padding: 15px 0; font-size: 17px; }

/* ---------------------------------------------------------------- review mode */

.comment-box {
  background: var(--card);
  border-radius: 10px;
  padding: 11px 14px;
  margin: 4px 16px 10px;
  flex: 0 0 auto;
  min-height: 74px;
}
.comment-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 14.5px;
  margin-bottom: 5px;
}
.comment-head img { width: 20px; height: 20px; }
.comment-text { font-size: 13.5px; line-height: 1.4; color: var(--text); }

#movelist {
  flex: 1;
  overflow-y: auto;
  padding: 2px 16px 8px;
  font-size: 14.5px;
}
.mrow {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-items: center;
  padding: 1.5px 0;
}
.mnum { color: var(--muted); font-weight: 600; font-size: 13px; }
.mv {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  justify-self: start;
}
.mv:hover { background: rgba(255, 255, 255, 0.06); }
.mv.current { background: rgba(255, 255, 255, 0.14); }
.mv img { width: 16px; height: 16px; }

#controls {
  display: flex;
  gap: 8px;
  padding: 12px 16px 14px;
  flex: 0 0 auto;
  border-top: 1px solid var(--card);
}
#controls button {
  flex: 1;
  height: 46px;
  background: var(--card);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#controls button:hover:not(:disabled) { background: var(--card-2); }
#controls button:disabled { opacity: 0.35; cursor: default; }
#controls svg { width: 22px; height: 22px; fill: var(--text); }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  html, body { overflow: auto; }
  #main { height: 100dvh; }
  #content {
    flex-direction: column;
    gap: 12px;
    padding: 10px;
    align-items: center;
    justify-content: flex-start;
  }
  #board { --sq: min(92vw - 40px, 60vh); }
  #panel {
    width: 100%;
    max-width: 560px;
    height: auto;
    max-height: 72dvh;
  }
  #movelist { min-height: 130px; }
  #sidebar {
    position: absolute;
    z-index: 9;
    height: 100%;
    left: 0; top: 0;
    box-shadow: 4px 0 18px rgba(0, 0, 0, 0.5);
  }
  #sidebar.closed { margin-left: 0; transform: translateX(-100%); }
  #backdrop.show { display: block; }
  .nameplate { padding-left: 36px; }
}
