/* ==========================================================================
 * app.css — shell chrome, home, game, review and profile views.
 * ========================================================================== */

/* ================================================================ header = */

.app-header {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -.02em;
  text-decoration: none;
  padding-right: 12px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  --piece-fill: #fff; --piece-stroke: #2f4a17; --piece-detail: #2f4a17;
}
.brand-mark svg { width: 26px; height: 26px; }

.app-nav { display: flex; gap: 2px; }
.nav-link {
  appearance: none; border: none; background: none;
  color: var(--text-2);
  font: inherit; font-weight: 650;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { color: var(--text); background: var(--surface-2); }

.header-actions { display: flex; align-items: center; gap: 6px; }
#btn-sound.is-off .sound-wave-2 { display: none; }
#btn-sound.is-off { color: var(--text-3); }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 12px 5px 5px;
  border: none;
  background: var(--surface-2);
  border-radius: 99px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  transition: background .14s var(--ease);
}
.user-chip:hover { background: var(--surface-3); }
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-name { font-weight: 700; font-size: .86rem; }
.user-rating { font-size: .74rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

.avatar {
  width: 32px; height: 32px;
  flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(140deg,
    hsl(var(--hue, 210) 62% 52%), hsl(calc(var(--hue, 210) + 38) 58% 42%));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.avatar.bot { background: linear-gradient(140deg, #6f7a86, #454f5a); }
.avatar.bot svg { width: 60%; height: 60%; }

/* ================================================================= views = */

.view { display: none; animation: fade-in-up .28s var(--ease); }
.view.is-active { display: block; }

.view-home, .view-review, .view-profile {
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 18px 70px;
}

/* ================================================================== home = */

.hero {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 46px;
  align-items: center;
  margin-bottom: 46px;
}
.hero-copy h1 {
  font-size: clamp(2rem, 4.4vw, 3.15rem);
  line-height: 1.06;
  letter-spacing: -.032em;
  margin-bottom: 16px;
}
.hero-sub { color: var(--text-2); font-size: 1.06rem; max-width: 46ch; margin-bottom: 26px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-note {
  margin-top: 18px;
  font-size: .82rem;
  color: var(--text-3);
  display: flex; align-items: center; gap: 8px;
}
.hero-note code {
  font-family: var(--mono); font-size: .95em;
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
}
.hero-note .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3); flex: none;
}
.hero-note .dot.ok  { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hero-note .dot.bad { background: var(--warning); }

.hero-board {
  position: relative;
  transform: perspective(1400px) rotateX(6deg) rotateY(-9deg) rotateZ(1.5deg);
  filter: drop-shadow(0 30px 46px rgba(0, 0, 0, .42));
}
.hero-board::after {
  content: '';
  position: absolute;
  inset: -14% -10% -22%;
  background: radial-gradient(closest-side, var(--accent-soft), transparent 72%);
  z-index: -1;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 34px;
}
.play-card {
  padding: 24px 22px;
  cursor: pointer;
  transition: transform .16s var(--ease), border-color .16s var(--ease),
              box-shadow .16s var(--ease);
}
.play-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.play-card h3 { margin-bottom: 6px; }
.play-card p { font-size: .88rem; margin: 0; }
.play-icon {
  width: 46px; height: 46px;
  border-radius: 13px;
  display: grid; place-items: center;
  margin-bottom: 15px;
  color: #fff;
}
.play-icon svg { width: 24px; height: 24px; }
.play-icon.online   { background: linear-gradient(140deg, #81b64c, #5d8a35); }
.play-icon.computer { background: linear-gradient(140deg, #5f9ed6, #3d6f9e); }
.play-icon.local    { background: linear-gradient(140deg, #b98b5e, #8b6440); }

.home-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-body { padding: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stat-tile {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 1.32rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-label { font-size: .72rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }

.wdl-bar {
  display: flex; height: 8px; border-radius: 99px; overflow: hidden;
  margin-top: 16px; background: var(--surface-2); gap: 2px;
}
.wdl-bar .w { background: var(--accent); }
.wdl-bar .d { background: var(--surface-3); }
.wdl-bar .l { background: var(--danger); }
.wdl-legend {
  display: flex; justify-content: space-between;
  font-size: .76rem; color: var(--text-3); margin-top: 7px; font-weight: 600;
}

.leader-list { list-style: none; margin: 0; padding: 0; }
.leader-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.leader-list li:last-child { border-bottom: none; }
.leader-list .rank {
  width: 20px; font-size: .8rem; font-weight: 800; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.leader-name { flex: 1; font-weight: 600; font-size: .92rem; }
.leader-rating { font-weight: 700; color: var(--text-2); }

.empty-note {
  color: var(--text-3);
  font-size: .9rem;
  text-align: center;
  padding: 22px 10px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}

/* ================================================================== game = */

.view-game { padding: 18px; }
.view-game.is-active { display: flex; justify-content: center; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, auto) 352px;
  gap: 20px;
  align-items: start;
  justify-content: center;
  width: 100%;
  max-width: 1340px;
}

.board-column {
  display: flex;
  flex-direction: column;
  gap: 9px;
  /* Sized from the viewport, not from the track: inside an `auto` grid
     column a percentage width would be circular and collapse the board. */
  width: min(calc(100vw - 440px), calc(100vh - 230px));
  min-width: 300px;
  margin-inline: auto;
}
.board-wrap { display: flex; gap: 9px; align-items: stretch; }
#board-mount { flex: 1; min-width: 0; }

/* --------------------------------------------------------- player strip -- */

.player-strip { min-height: 46px; }
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 8px 5px 6px;
  border-radius: var(--radius);
  transition: background .18s var(--ease);
}
.player.is-active { background: var(--surface); }
.player-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.player-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.player-name {
  font-weight: 700; font-size: .95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-sub { font-size: .76rem; color: var(--text-3); font-variant-numeric: tabular-nums; }
.player-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.clock {
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -.02em;
  padding: 4px 13px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  min-width: 92px;
  text-align: center;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.clock.running { background: var(--text); color: var(--bg); }
.player.is-low .clock.running { background: var(--danger); color: #fff; animation: clock-warn 1s ease-in-out infinite; }
@keyframes clock-warn { 50% { opacity: .74; } }

/* ------------------------------------------------------------- toolbar -- */

.board-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------ side card -- */

.side-column { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 78px; }
.side-card { overflow: hidden; display: flex; flex-direction: column; }

.side-tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; }
.side-tab {
  flex: 1;
  appearance: none; border: none; background: none;
  color: var(--text-3);
  font: inherit; font-weight: 700; font-size: .88rem;
  padding: 12px 8px;
  cursor: pointer;
  position: relative;
  transition: color .14s var(--ease);
}
.side-tab:hover { color: var(--text-2); }
.side-tab.is-active { color: var(--text); }
.side-tab.is-active::after {
  content: '';
  position: absolute;
  left: 14%; right: 14%; bottom: -1px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--accent);
}

.side-panel { display: none; flex-direction: column; min-height: 0; }
.side-panel.is-active { display: flex; }

.coach-toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: .86rem;
  font-weight: 600;
}
.coach-body { padding: 14px; overflow-y: auto; max-height: min(52vh, 460px); }

.coach-empty { text-align: center; padding: 32px 18px; color: var(--text-3); }
.coach-empty-icon {
  width: 46px; height: 46px; margin: 0 auto 12px;
  color: var(--text-3); opacity: .5;
}
.coach-empty p { font-size: .9rem; margin: 0; }

.coach-thinking {
  display: flex; align-items: center; gap: 11px;
  padding: 26px 14px;
  color: var(--text-2);
  font-size: .9rem;
}

.coach-card { animation: fade-in-up .22s var(--ease); }
.coach-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.coach-badge {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
  background: var(--tone, var(--accent));
}
.coach-label { font-weight: 800; font-size: .96rem; }
.coach-metrics {
  display: flex; gap: 10px;
  font-size: .76rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  margin-top: 2px;
}
.coach-headline { font-size: .96rem; line-height: 1.45; margin-bottom: 8px; }
.coach-detail { font-size: .88rem; color: var(--text-2); line-height: 1.5; }
.coach-tips {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.coach-tips li {
  position: relative;
  padding: 9px 12px 9px 30px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: .85rem;
  line-height: 1.45;
  color: var(--text-2);
}
.coach-tips li::before {
  content: '';
  position: absolute;
  left: 12px; top: 15px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.coach-show-best { margin-top: 12px; width: 100%; }

/* tone colours shared by badges, dots and cards */
.tone-brilliant  { --tone: var(--c-brilliant); }
.tone-great      { --tone: var(--c-great); }
.tone-best       { --tone: var(--c-best); }
.tone-excellent  { --tone: var(--c-excellent); }
.tone-good       { --tone: var(--c-good); }
.tone-book       { --tone: var(--c-book); }
.tone-inaccuracy { --tone: var(--c-inaccuracy); }
.tone-mistake    { --tone: var(--c-mistake); }
.tone-miss       { --tone: var(--c-miss); }
.tone-blunder    { --tone: var(--c-blunder); }

/* --------------------------------------------------------- move list --- */

.move-list { overflow-y: auto; max-height: min(52vh, 460px); padding: 6px; }
.move-rows { display: flex; flex-direction: column; }
.move-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  align-items: stretch;
  border-radius: var(--radius-sm);
}
.move-row:nth-child(odd) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.move-no {
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 10px;
  font-size: .8rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.move-cell {
  appearance: none; border: none; background: none;
  color: var(--text);
  font: inherit; font-weight: 620; font-size: .9rem;
  text-align: left;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: background .12s var(--ease);
}
.move-cell:hover { background: var(--surface-3); }
.move-cell.is-current { background: var(--accent); color: var(--accent-ink); }
.mv-badge { font-style: normal; font-weight: 800; font-size: .82rem; color: var(--tone); }
.move-cell.is-current .mv-badge { color: var(--accent-ink); }
.mv-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--tone); flex: none;
}
.move-list-foot {
  display: flex; gap: 6px; padding: 8px;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------- chat ---- */

.chat-log {
  flex: 1;
  overflow-y: auto;
  max-height: min(48vh, 400px);
  min-height: 180px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.chat-msg {
  max-width: 82%;
  padding: 7px 11px;
  border-radius: 13px;
  background: var(--surface-2);
  font-size: .87rem;
  line-height: 1.4;
  align-self: flex-start;
  word-break: break-word;
}
.chat-msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.chat-form { display: flex; gap: 7px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form .input { padding: 8px 11px; font-size: .88rem; }

.game-actions { padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* ================================================================ review = */

.review-head { margin-bottom: 22px; }
.review-head h2 { margin-bottom: 4px; }

.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.review-scorecard { grid-column: 1 / -1; }
.review-moves { grid-column: 1 / -1; }

.acc-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}
.acc-middle { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.review-result { font-weight: 800; font-size: 1.1rem; }

.acc-ring { position: relative; display: grid; place-items: center; aspect-ratio: 1; }
.acc-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.acc-track { stroke: var(--surface-3); }
.acc-fill {
  stroke: var(--tone, var(--accent));
  stroke-linecap: round;
  transition: stroke-dashoffset .8s var(--ease);
}
.acc-value { font-size: 1.28rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.acc-label {
  position: absolute;
  bottom: -20px;
  font-size: .72rem; font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.acc-side { padding-bottom: 20px; }

.eval-graph {
  width: 100%;
  height: 92px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
  display: block;
}
.eg-bg   { fill: var(--surface-2); }
.eg-area { fill: color-mix(in srgb, var(--text) 20%, transparent); }
.eg-line { fill: none; stroke: var(--text); stroke-width: .6; vector-effect: non-scaling-stroke; }
.eg-mid  { stroke: var(--border-strong); stroke-width: .5; vector-effect: non-scaling-stroke; }
.eg-cursor { stroke: var(--accent); stroke-width: 1; vector-effect: non-scaling-stroke; }

.class-table table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.class-table th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); padding-bottom: 8px; font-weight: 700;
}
.class-table th:first-child { text-align: left; }
.class-table th:last-child { text-align: right; }
.class-table td { padding: 5px 0; }
.class-table .num {
  font-variant-numeric: tabular-nums; font-weight: 800; width: 46px;
}
.class-table tr td.num:last-child { text-align: right; }
.class-table .cls {
  text-align: center; color: var(--text-2);
  display: flex; align-items: center; justify-content: center; gap: 7px;
}

.coach-advice {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  padding: 11px 13px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--text-2);
}
.key-moment {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.key-moment h4 {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin-bottom: 6px;
}
.key-moment p { margin-bottom: 4px; font-size: .92rem; }

.rm-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 5px;
}
.rm-item {
  display: grid;
  grid-template-columns: 42px 62px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  background: var(--surface-2);
  border: none;
  border-left: 3px solid var(--tone, var(--surface-3));
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .12s var(--ease);
}
.rm-item:hover { background: var(--surface-3); }
.rm-no { font-size: .78rem; color: var(--text-3); font-variant-numeric: tabular-nums; }
.rm-san { font-weight: 700; font-size: .88rem; }
.rm-tag { font-size: .76rem; color: var(--tone, var(--text-3)); font-weight: 700; }
.rm-eval { font-size: .76rem; color: var(--text-3); }

.review-progress .progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 14px;
}
.review-progress .progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width .3s var(--ease);
}

/* =============================================================== profile = */

.profile-head { margin-bottom: 16px; }
.profile-head .panel-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
}
.profile-id h2 { margin-bottom: 2px; }
.profile-head .stat-grid { grid-column: 1 / -1; }

.history-list { display: flex; flex-direction: column; gap: 4px; }
.history-item {
  display: grid;
  grid-template-columns: 26px auto 1fr auto auto;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: .9rem;
}
.hist-badge {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: .74rem; font-weight: 800;
  background: var(--surface-3); color: var(--text-2);
}
.history-item.win  .hist-badge { background: var(--accent); color: var(--accent-ink); }
.history-item.loss .hist-badge { background: var(--danger); color: #fff; }
.hist-opp { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-tc, .hist-time { font-size: .8rem; }

/* ================================================================ modals = */

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease);
}
.modal-scrim.in { opacity: 1; pointer-events: auto; }
.modal {
  width: min(440px, 100%);
  max-height: min(88vh, 780px);
  overflow-y: auto;
  transform: translateY(10px) scale(.98);
  transition: transform .2s var(--ease);
  box-shadow: var(--shadow-lg);
}
.modal-scrim.in .modal { transform: none; }
.modal-wide { width: min(720px, 100%); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

.field-label {
  display: block;
  font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3);
  margin-bottom: 9px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 20px;
}
.level-btn {
  appearance: none;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 9px 5px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  display: flex; flex-direction: column; gap: 1px;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.level-btn:hover { border-color: var(--text-3); }
.level-btn.is-active { border-color: var(--accent); background: var(--accent-soft); }
.level-name { font-size: .78rem; font-weight: 700; }
.level-elo { font-size: .7rem; color: var(--text-3); font-variant-numeric: tabular-nums; }

.side-picker { display: flex; gap: 7px; margin-bottom: 22px; }
.side-btn {
  flex: 1;
  appearance: none;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  color: var(--text);
  font: inherit; font-weight: 650; font-size: .86rem;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.side-btn.is-active { border-color: var(--accent); background: var(--accent-soft); }
.side-swatch {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--border-strong);
}
.side-swatch.w { background: #fff; }
.side-swatch.b { background: #2e2b28; }
.side-swatch.r { background: linear-gradient(135deg, #fff 50%, #2e2b28 50%); }

.tc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 22px;
}
.tc-btn {
  appearance: none;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 11px 4px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  display: flex; flex-direction: column; gap: 1px;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.tc-btn.is-active { border-color: var(--accent); background: var(--accent-soft); }
.tc-label { font-weight: 800; font-size: .92rem; font-variant-numeric: tabular-nums; }
.tc-kind { font-size: .68rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }

.auth-error {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 12px;
}
.auth-switch { text-align: center; font-size: .87rem; color: var(--text-2); margin: 14px 0 0; }

.account-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.account-name { font-weight: 800; font-size: 1.05rem; }

.searching { text-align: center; padding: 34px 22px; }
.searching h3 { margin-bottom: 5px; }
.searching p { margin-bottom: 22px; }
.search-anim { display: flex; gap: 7px; justify-content: center; margin-bottom: 20px; }
.search-anim span {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent);
  animation: search-bounce 1.1s ease-in-out infinite;
}
.search-anim span:nth-child(2) { animation-delay: .16s; }
.search-anim span:nth-child(3) { animation-delay: .32s; }
@keyframes search-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-10px); opacity: 1; }
}

.result-modal { text-align: center; padding: 30px 24px 24px; }
.result-modal .result-icon {
  width: 66px; height: 66px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--text-2);
}
.result-modal .result-icon svg { width: 34px; height: 34px; }
.result-modal.win .result-icon  { background: var(--accent-soft); color: var(--accent); }
.result-modal.loss .result-icon { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.result-modal h2 { margin-bottom: 5px; }
.result-modal.win h2  { color: var(--accent); }
.result-modal.loss h2 { color: var(--danger); }

/* ================================================================ toasts = */

.toast-stack {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
@media (max-width: 620px) {
  .toast-stack { top: auto; bottom: 92px; left: 50%; right: auto;
                 transform: translateX(-50%); align-items: center; }
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 99px;
  font-size: .88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity .22s var(--ease), transform .22s var(--ease);
  max-width: min(360px, 80vw);
  text-align: center;
}
.toast.in { opacity: 1; transform: none; }
.toast.good { border-color: var(--accent); }
.toast.bad  { border-color: var(--danger); color: var(--danger); }

/* ============================================================ responsive = */

@media (max-width: 1120px) {
  .game-layout { grid-template-columns: auto 310px; }
  .side-column { top: 72px; }
}

@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; gap: 30px; }
  .hero-board { max-width: 400px; margin: 0 auto; transform: none; }
  .home-bottom { grid-template-columns: 1fr; }
  .review-grid { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .board-column { width: min(100%, 78vh); }
  .side-column { position: static; width: min(100%, 560px); margin-inline: auto; }
  .acc-row { grid-template-columns: 1fr; gap: 26px; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .app-header { padding: 0 12px; gap: 4px; }
  .brand-name { display: none; }
  .nav-link { padding: 8px 10px; font-size: .9rem; }
  .view-home, .view-review, .view-profile { padding: 22px 14px 60px; }
  .view-game { padding: 10px; }
  .board-column { width: 100%; gap: 7px; }
  .clock { font-size: 1.1rem; min-width: 74px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .tc-grid { grid-template-columns: repeat(2, 1fr); }
  .eval-bar { width: 18px; }
  .rm-list { grid-template-columns: 1fr; }
  .profile-head .panel-body { grid-template-columns: 1fr; text-align: center; justify-items: center; }
}

/* ============================================================= game bar = */

.game-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 1340px;
  margin: 0 auto 8px;
  padding: 2px 2px 6px;
  border-bottom: 1px solid var(--border);
}
.game-bar-title {
  font-weight: 700;
  font-size: .92rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.view-game.is-active { flex-direction: column; align-items: center; }

/* ---------------------------------------------------------- immersive -- */

body.immersive .app-header { display: none; }
body.immersive .view-game { padding: 10px 14px 14px; }
body.immersive .side-column { top: 10px; }
body.immersive .board-column {
  width: min(calc(100vw - 410px), calc(100vh - 280px));
}
body.immersive .coach-body,
body.immersive .move-list { max-height: min(56vh, 520px); }
body.immersive .chat-log { max-height: min(50vh, 460px); }

body.is-fullscreen .game-bar { padding-top: 4px; }

@media (max-width: 960px) {
  body.immersive .board-column { width: min(100%, 74vh); }
  body.immersive .side-column { top: 0; }
}

/* ====================================================== review analysis = */

.review-analysis { grid-column: 1 / -1; }
.rv-board-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin: 0 auto 12px;
  width: min(100%, 560px);
}
#review-board-mount { flex: 1; min-width: 0; }

.rv-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  background: var(--surface-2);
  border-radius: var(--radius);
  width: min(100%, 560px);
  margin: 0 auto;
}
.rv-status {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rv-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 10px auto 0;
  font-size: .76rem;
  color: var(--text-3);
  font-weight: 600;
}
.rv-legend span { display: inline-flex; align-items: center; gap: 6px; }
.rv-legend .swatch {
  width: 16px; height: 4px; border-radius: 2px;
}
.rv-legend .swatch.played { background: rgba(255, 170, 0, .85); }
.rv-legend .swatch.best   { background: rgba(56, 178, 172, .9); }
.rv-legend .swatch.alt    { background: rgba(90, 158, 214, .85); }

.rv-detail {
  width: min(100%, 560px);
  margin: 14px auto 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.rv-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.rv-headline { font-size: .95rem; line-height: 1.45; margin-bottom: 6px; }
.rv-best, .rv-alts {
  font-size: .86rem;
  color: var(--text-2);
  margin-top: 8px;
  padding: 8px 11px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.rv-best .mono { font-weight: 700; color: var(--accent-text); }
.rv-alts .mono { font-weight: 700; }
.dim { color: var(--text-3); }

.rm-item.is-current {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--surface-3);
}

@media (min-width: 1100px) {
  .review-grid { grid-template-columns: minmax(0, 620px) minmax(0, 1fr); }
  .review-analysis { grid-column: 1; grid-row: 1 / span 2; }
  .review-scorecard { grid-column: 2; }
  .review-moves { grid-column: 1 / -1; }
}

/* ============================================================ game pulse = */
/* The signature element: the whole game's quality, one cell per ply.
   White on the top row, Black beneath, blunders impossible to miss. */

#pulse-mount:empty { display: none; }

.game-pulse {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pulse-labels {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: none;
}
.pulse-labels span {
  height: 8px;
  line-height: 8px;
  font-size: .58rem;
  font-weight: 800;
  color: var(--text-3);
  letter-spacing: .06em;
}
.pulse-rows { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pulse-row { display: flex; gap: 2px; height: 8px; }

.pulse-cell {
  flex: 1 1 0;
  min-width: 3px;
  height: 100%;
  padding: 0;
  border: none;
  border-radius: 2px;
  /* fall back inside the value, never by re-declaring --tone here:
     .pulse-cell and .tone-* have equal specificity and would fight */
  background: var(--tone, var(--surface-3));
  cursor: pointer;
  transition: transform .12s var(--ease), filter .12s var(--ease);
}
.pulse-cell:hover { transform: scaleY(1.9); filter: brightness(1.25); }
.pulse-cell.is-current {
  box-shadow: 0 0 0 1.5px var(--bg), 0 0 0 3px var(--text);
  transform: scaleY(1.45);
}
.pulse-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =========================================================== turn chip == */

.turn-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 99px;
  background: var(--surface-2);
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
}
.turn-chip.is-mine { background: var(--accent-soft); color: var(--accent-text); }
.turn-chip.is-over { background: var(--surface-3); color: var(--text); }
.turn-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35);
}
.turn-dot.w { background: #f4f4f3; }
.turn-dot.b { background: #2e2b28; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3); }
.turn-chip.is-mine .turn-dot { animation: turn-pulse 1.6s ease-in-out infinite; }
@keyframes turn-pulse {
  50% { box-shadow: 0 0 0 4px var(--accent-soft), inset 0 0 0 1px rgba(0, 0, 0, .35); }
}

@media (max-width: 720px) {
  .turn-chip { font-size: .72rem; padding: 3px 8px; }
  .game-bar-title { display: none; }
}
