/* Chess Academy — design tokens, layout and components.
   Light and dark are both first-class; the board keeps its own palette in either theme. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --ink: #16181d;
  --ink-2: #5b636e;
  --ink-3: #8a919c;
  --line: #e3e6ea;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --good: #16794a;
  --good-bg: #e8f5ee;
  --warn: #9a6207;
  --warn-bg: #fdf3e2;
  --bad: #b02525;
  --bad-bg: #fdeceb;
  --info-bg: #eaf0fd;

  --board-light: #ebecd0;
  --board-dark: #779556;
  --board-mark: rgba(20, 24, 30, .28);
  --board-select: #f6f669;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .05), 0 6px 20px rgba(16, 20, 28, .05);
  --sidebar-w: 276px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1d2128;
  --ink: #eef1f5;
  --ink-2: #a3acba;
  --ink-3: #757f8d;
  --line: #262b34;
  --accent: #6c93f7;
  --accent-ink: #0b1220;
  --good: #5fcf96;
  --good-bg: #13291f;
  --warn: #e0b263;
  --warn-bg: #2b2315;
  --bad: #f08a83;
  --bad-bg: #2d1a1a;
  --info-bg: #182135;
  --board-mark: rgba(240, 244, 250, .32);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.02em; }

a { color: var(--accent); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; top: -60px; left: 12px; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none; transition: top .15s;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.noscript { max-width: 560px; margin: 80px auto; padding: 24px; text-align: center; }

/* ------------------------------------------------------------------ app shell */

.app { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 6px 10px 20px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--ink); color: var(--surface);
  display: grid; place-items: center; font-size: 22px; flex: 0 0 40px;
}
.brand-name { font-size: 14px; font-weight: 700; display: block; }
.brand-sub { font-size: 10px; color: var(--ink-3); letter-spacing: .1em; text-transform: uppercase; }
.brand-sub:empty { display:none; }

.nav-group-label {
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); padding: 14px 12px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; height: 40px; padding: 0 12px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2);
  text-align: left; cursor: pointer; font-size: 13.5px;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; flex: 0 0 18px; font-size: 15px; }
.nav-spacer { flex: 1 1 auto; min-height: 12px; }

.main { flex: 1 1 auto; min-width: 0; padding: 26px 34px 60px; max-width: 1400px; margin: 0 auto; width: 100%; }

.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.kicker { font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3); }
.page-title { font-size: 27px; margin: 4px 0 2px; }
.page-sub { color: var(--ink-2); font-size: 13.5px; max-width: 65ch; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ----------------------------------------------------------------- components */

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; align-items: start; }
/* Grid and flex children default to min-width:auto, which lets a wide table or chart push
   the whole page sideways. Pinning them to 0 keeps overflow inside the scrolling wrapper. */
.grid > *, .training-layout > *, .analysis-layout > * { min-width: 0; max-width: 100%; }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; } .col-12 { grid-column: 1 / -1; }

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-title { font-size: 15px; font-weight: 650; }
.card h3 { font-size: 16px; margin-bottom: 6px; }

.muted { color: var(--ink-2); font-size: 13px; }
.tiny { font-size: 11.5px; color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12.5px; }

.metric { font-size: 28px; font-weight: 700; letter-spacing: -.03em; margin: 4px 0 2px; }
.metric-row { display: flex; gap: 20px; flex-wrap: wrap; }
.metric-block { min-width: 90px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  /* A minimum rather than a fixed height, with matching vertical padding. A label long
     enough to wrap — which happens on a narrow screen — used to overflow a fixed 40px box
     and print its last line outside the border. */
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: center;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-lg { min-height: 48px; padding: 10px 24px; font-size: 15px; }
.btn-sm { min-height: 32px; padding: 6px 11px; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.input, .select {
  height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); outline: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill-good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill-bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.pill-info { background: var(--info-bg); color: var(--accent); border-color: transparent; }

.hero {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}
.hero h2 { font-size: 23px; margin: 8px 0 8px; }

.list { display: grid; gap: 9px; }
.list-item {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--surface);
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.list-item-main { min-width: 0; }
.list-item-title { font-weight: 600; font-size: 13.5px; }

button.list-item { width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
button.list-item:hover { background: var(--surface-2); }

.table-wrap { overflow-x: auto; margin-top: 8px; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; min-width: 180px; }

.bar { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-good > span { background: var(--good); }
.bar-warn > span { background: var(--warn); }
.bar-bad > span  { background: var(--bad); }

.state { padding: 34px 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--ink-2); }
.state h3 { margin-bottom: 6px; color: var(--ink); }
.state-icon { font-size: 30px; display: block; margin-bottom: 8px; opacity: .55; }
.state-error { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.state-error h3 { color: var(--bad); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
  border-radius: 6px; height: 14px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 14px;
}
.banner-info { background: var(--info-bg); color: var(--ink); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-bad  { background: var(--bad-bg);  color: var(--bad); }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; max-width: 360px;
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* ---------------------------------------------------------------------- board */

.board-wrap { width: 100%; max-width: 620px; margin: 0 auto; }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  /* Rows as explicit as columns. Without this the implicit rows size to their content, so a
     rank holding no pieces collapses and the board is drawn squashed. */
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(16, 20, 28, .18);
  touch-action: manipulation;
}

.sq {
  position: relative; border: 0; padding: 0; margin: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--board-light);
}
.sq.dark { background: var(--board-dark); }
.sq:disabled { cursor: default; }
.sq.selected { box-shadow: inset 0 0 0 4px var(--board-select); }
.sq.last-move::before {
  content: ""; position: absolute; inset: 0; background: var(--board-select); opacity: .38;
}
.sq.target::after {
  content: ""; position: absolute; width: 26%; height: 26%;
  border-radius: 50%; background: var(--board-mark);
}
.sq.target.occupied::after {
  width: 82%; height: 82%; border-radius: 50%;
  background: transparent; border: 5px solid var(--board-mark);
}
.sq.check-square { box-shadow: inset 0 0 0 4px var(--bad); }
.sq.move-anim-dest .piece {
  animation: piece-move .55s cubic-bezier(.22,.61,.36,1) both;
}
@keyframes piece-move {
  from { transform: translate(var(--move-x), var(--move-y)); opacity: 1; }
  to { transform: translate(0, 0); opacity: 1; }
}

.piece {
  width: 88%; height: 88%; z-index: 1;
  user-select: none; pointer-events: none;
  /* A shadow under the piece rather than around the glyph: it lifts the shape off the
     square without the halo a text-shadow used to need to make white pieces visible. */
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35));
}
.piece path, .piece circle {
  fill: currentColor;
  stroke: var(--piece-line);
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}
/* Cut lines — the bishop's slit, the king's cross — are strokes, not filled shapes. */
.piece .cut { fill: none; stroke: var(--piece-line); stroke-width: 2.2; }
.piece .eye { fill: var(--piece-line); stroke: none; }
/* `color` is the fill; `--piece-line` is the outline. Two variables, one set of artwork. */
.piece-w { color: #f7f6f3; --piece-line: #22201d; }
.piece-b { color: #2b2825; --piece-line: #0d0c0b; }
.piece-b .eye { fill: #f0efec; }
.piece-b .cut { stroke: #d9d6d0; }

.sq .coord {
  position: absolute; font-size: 9px; font-weight: 700; opacity: .65;
  pointer-events: none; color: var(--board-dark);
}
.sq.dark .coord { color: var(--board-light); }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }

.board-toolbar { display: flex; gap: 6px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

.eval-bar {
  height: 10px; border-radius: 999px; overflow: hidden;
  background: #2c2f36; display: flex; margin-bottom: 10px;
}
.eval-bar > span { display: block; background: #f2f3f5; transition: width .25s; }

/* ------------------------------------------------------------------- analysis */

.analysis-layout { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(300px, 420px); gap: 18px; align-items: start; }

.movelist { max-height: 340px; overflow-y: auto; display: grid; grid-template-columns: 44px 1fr 1fr; gap: 2px; font-size: 13px; }
.movelist .num { color: var(--ink-3); padding: 5px 6px; font-size: 12px; text-align: right; }
.move-btn {
  border: 0; background: transparent; border-radius: 5px; padding: 5px 7px;
  text-align: left; cursor: pointer; font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  display: flex; justify-content: space-between; gap: 6px; align-items: center;
}
.move-btn:hover { background: var(--surface-2); }
.move-btn[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
.move-tag { font-size: 10px; font-weight: 700; }
.tag-blunder { color: var(--bad); } .tag-mistake { color: var(--warn); } .tag-inaccuracy { color: var(--ink-3); }
.move-btn[aria-current="true"] .move-tag { color: inherit; }

.moment { border-left: 3px solid var(--line); padding: 10px 0 10px 13px; margin-bottom: 10px; }
.moment-blunder { border-left-color: var(--bad); }
.moment-mistake { border-left-color: var(--warn); }
.moment-inaccuracy { border-left-color: var(--ink-3); }
.moment-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }

/* ------------------------------------------------------------------- training */

.training-layout { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(290px, 400px); gap: 18px; align-items: start; }
.feedback { margin-top: 14px; border-radius: var(--radius-sm); padding: 13px 15px; font-size: 13.5px; }
.feedback-ok  { background: var(--good-bg); color: var(--good); }
.feedback-bad { background: var(--bad-bg);  color: var(--bad); }
.feedback strong { display: block; margin-bottom: 4px; font-size: 14px; }

.dna-skill { padding: 14px 0; border-bottom: 1px solid var(--line); }
.dna-skill:last-child { border-bottom: 0; }
.dna-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.dna-name { font-weight: 650; font-size: 14px; }
.dna-evidence { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.dna-stat { font-size: 12px; color: var(--ink-2); }
.dna-stat b { display: block; font-size: 15px; color: var(--ink); font-weight: 650; }

/* --------------------------------------------------------------------- charts */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .1; }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-label { font-size: 10px; fill: var(--ink-3); }
.chart-dot { fill: var(--accent); }
.chart-bar { fill: var(--accent); }

/* ----------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  .analysis-layout, .training-layout { grid-template-columns: 1fr; }
  .col-3, .col-4, .col-5 { grid-column: span 6; }
  .col-7, .col-8, .col-9 { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 12px;
  }
  .brand { padding: 4px 8px 12px; }
  .sidebar nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
  .nav-group-label { grid-column: 1 / -1; padding: 8px 10px 2px; }
  .nav-spacer { display: none; }
  .main { padding: 18px 14px 48px; }
  .grid { grid-template-columns: 1fr; }
  .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-12 { grid-column: 1; }
  .page-title { font-size: 22px; }
  .card { padding: 15px 16px; }
  th, td { padding: 9px 10px; }
  .toast { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media (max-width: 420px) {
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  .metric { font-size: 24px; }
}

@media print {
  .sidebar, .btn-row, .toast { display: none; }
  .main { padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* ------------------------------------------------- puzzles, bot levels, move list */

.board-head {
  display: flex; gap: 8px; align-items: center;
  justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap;
}
.pill-light { background: #f2efe9; color: #2b2825; border-color: #ddd8cd; }
.pill-dark { background: #2b2825; color: #f2efe9; border-color: #14120f; }

/* The strength ladder: one tile per level, the number large and what it means beneath it. */
.level-grid {
  display: grid; gap: 8px; margin-top: 4px;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
}
.level-btn {
  flex-direction: column; gap: 2px; min-height: 58px; padding: 10px 8px; line-height: 1.25;
}
.level-btn b { font-size: 17px; }
.level-btn .tiny { font-weight: 500; opacity: .75; }

/* Move list: move number, White's move, Black's move. */
.move-list {
  display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 2px 8px;
  font-variant-numeric: tabular-nums; font-size: 13px; max-height: 320px; overflow-y: auto;
}
.move-list .move-num { color: var(--ink-3); text-align: right; }
.move-list .move-uci { font-family: var(--mono, ui-monospace, monospace); }
.chat-log{display:flex;flex-direction:column;gap:8px;height:min(65vh,620px);overflow-y:auto;padding-right:6px}.chat-msg{display:flex;gap:9px;align-items:baseline;line-height:1.45}.chat-who{font-weight:700;flex-shrink:0}.chat-body{word-break:break-word}.chat-when{margin-left:auto;color:var(--ink-3);font-size:11px;flex-shrink:0}
.rating-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}.rating-grid .card{padding:14px}@media(max-width:800px){.rating-grid{grid-template-columns:repeat(2,1fr)}}

/* --------------------------------------------------------- promotion picker */
.board { position: relative; }

.promotion-picker {
  position: absolute;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--square-size);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .38);
  border-radius: 5px;
  overflow: hidden;
}

.promotion-picker__option {
  width: var(--square-size);
  height: var(--square-size);
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--board-light);
  cursor: pointer;
  animation: promotion-picker-in 120ms ease-out backwards;
}

.promotion-picker__option:nth-child(even) { background: var(--board-dark); }
.promotion-picker__option .piece { width: 84%; height: 84%; }
.promotion-picker__option:hover,
.promotion-picker__option:focus-visible {
  outline: 3px solid var(--board-select);
  outline-offset: -3px;
  filter: brightness(1.06);
}

@media (prefers-reduced-motion: reduce) {
  .promotion-picker__option { animation: none; }
}

@keyframes promotion-picker-in {
  from { opacity: 0; transform: scale(.85); }
  to { opacity: 1; transform: scale(1); }
}

/* One-minute coordinate trainer. The target stays readable, then gently fades during its
   five-second life; a new coordinate restarts the animation without rebuilding the page. */
.vision-hud { display:grid; grid-template-columns:1fr 1.4fr 1fr; align-items:center; gap:12px; margin-bottom:14px; }
.vision-target-wrap { text-align:center; }
.vision-target { font-size:clamp(30px,5vw,52px); line-height:1; font-weight:800; letter-spacing:.05em; margin-top:4px; }
.vision-target-live { animation:vision-target-life 5s linear both; }
@keyframes vision-target-life { 0%,70% { opacity:1; transform:scale(1); } 100% { opacity:.18; transform:scale(.94); } }
.vision-feedback { min-height:28px; text-align:center; font-weight:700; padding-top:8px; }
@media (prefers-reduced-motion: reduce) { .vision-target-live { animation:none; } }

/* ===================================================== XP, TITLES, AVATARS, DUELS === */
.xp-sidebar {
  display:flex; align-items:center; gap:11px; min-height:66px; padding:9px 11px; margin:10px 4px 8px;
  border:1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius:16px;
  background:linear-gradient(135deg, color-mix(in srgb, var(--accent) 12%, var(--surface)), var(--surface));
  box-shadow:0 8px 28px rgba(0,0,0,.08); overflow:visible;
}
.xp-sidebar-loading { opacity:.72; }
.xp-sidebar-main { min-width:0; flex:1; overflow:visible; }
.xp-sidebar-row { display:flex; justify-content:space-between; align-items:center; gap:8px; font-size:12px; }
.xp-sidebar-title {
  margin-top:3px; overflow:visible; text-overflow:clip; white-space:normal;
  overflow-wrap:anywhere; line-height:1.25; font-size:11px; color:var(--ink-2);
}
.xp-sidebar .avatar-sm { width:46px; height:46px; font-size:23px; flex-basis:46px; line-height:1; }
.xp-mult { font:700 10px/1 var(--mono); color:var(--accent); background:color-mix(in srgb, var(--accent) 12%, transparent); padding:4px 5px; border-radius:999px; }
.xp-track { height:5px; border-radius:999px; background:var(--surface-2); overflow:hidden; margin-top:7px; }
.xp-track > span { display:block; height:100%; border-radius:inherit; background:linear-gradient(90deg,var(--accent),color-mix(in srgb,var(--accent) 55%,#fff)); transition:width .45s ease; }
.xp-orb { width:30px; height:30px; border-radius:50%; display:grid; place-items:center; background:var(--accent); color:var(--accent-ink); font-weight:900; }

.profile-avatar {
  --avatar-a:#3b82f6; --avatar-b:#7c3aed;
  display:inline-grid; place-items:center; flex:0 0 auto; border-radius:50%; color:#fff;
  background:radial-gradient(circle at 32% 24%,rgba(255,255,255,.36),transparent 28%), linear-gradient(145deg,var(--avatar-a),var(--avatar-b));
  border:2px solid rgba(255,255,255,.35); box-shadow:0 6px 20px rgba(0,0,0,.18), inset 0 0 0 1px rgba(0,0,0,.1);
  font-weight:900; line-height:1; overflow:visible; text-shadow:0 1px 3px rgba(0,0,0,.3); user-select:none;
}
.avatar-xs{width:26px;height:26px;font-size:13px}.avatar-sm{width:36px;height:36px;font-size:18px}.avatar-md{width:48px;height:48px;font-size:23px}.avatar-lg{width:68px;height:68px;font-size:32px}.avatar-xl{width:112px;height:112px;font-size:54px}
.avatar-azure{--avatar-a:#0ea5e9;--avatar-b:#2563eb}.avatar-emerald{--avatar-a:#10b981;--avatar-b:#047857}.avatar-violet{--avatar-a:#8b5cf6;--avatar-b:#6d28d9}.avatar-amber{--avatar-a:#f59e0b;--avatar-b:#b45309}.avatar-crimson{--avatar-a:#ef4444;--avatar-b:#991b1b}.avatar-cyan{--avatar-a:#06b6d4;--avatar-b:#0e7490}.avatar-indigo{--avatar-a:#6366f1;--avatar-b:#3730a3}.avatar-rose{--avatar-a:#f43f5e;--avatar-b:#be123c}.avatar-lime{--avatar-a:#84cc16;--avatar-b:#3f6212}.avatar-obsidian{--avatar-a:#475569;--avatar-b:#0f172a}

.xp-profile-hero { position:relative; overflow:hidden; background:linear-gradient(135deg,color-mix(in srgb,var(--accent) 16%,var(--surface)),var(--surface) 58%,color-mix(in srgb,#7c3aed 8%,var(--surface))); }
.xp-profile-hero::after { content:'✦'; position:absolute; right:4%; top:-30px; font-size:160px; opacity:.035; transform:rotate(16deg); pointer-events:none; }
.xp-profile-main { display:flex; gap:18px; align-items:center; flex-wrap:wrap; }
.xp-profile-copy { flex:1; min-width:220px; }
.xp-profile-name { font-size:clamp(22px,3vw,34px); font-weight:800; margin:0; }
.xp-profile-title { margin-top:3px; font-weight:700; color:var(--accent); }
.xp-profile-stats { display:flex; gap:10px; flex-wrap:wrap; margin-top:12px; }
.xp-stat-chip { border:1px solid var(--line); border-radius:12px; padding:9px 11px; background:color-mix(in srgb,var(--surface) 88%,transparent); min-width:110px; }
.xp-stat-chip b { display:block; font-size:16px; }
.xp-next { margin-top:14px; }
.xp-next-row { display:flex; justify-content:space-between; gap:10px; font-size:11px; color:var(--ink-2); }

.title-gallery { display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:10px; max-height:560px; overflow:auto; padding:2px; }
.title-card { position:relative; display:flex; gap:10px; align-items:center; width:100%; text-align:left; padding:11px; border:1px solid var(--line); border-radius:13px; background:var(--surface); color:var(--ink); cursor:pointer; transition:transform .15s ease,border-color .15s ease,box-shadow .15s ease; }
.title-card:hover:not(:disabled){ transform:translateY(-2px); border-color:color-mix(in srgb,var(--accent) 55%,var(--line)); box-shadow:0 8px 24px rgba(0,0,0,.09); }
.title-card:disabled { cursor:not-allowed; opacity:.48; filter:saturate(.25); }
.title-card.active { border-color:var(--accent); box-shadow:0 0 0 2px color-mix(in srgb,var(--accent) 18%,transparent); }
.title-card-copy { min-width:0; flex:1; }
.title-card-name { font-size:12px; font-weight:750; line-height:1.25; }
.title-card-meta { margin-top:3px; font-size:10px; color:var(--ink-3); }
.title-rank-badge { position:absolute; right:8px; top:7px; font:700 9px/1 var(--mono); color:var(--ink-3); }

.title-unlock-overlay { position:fixed; inset:0; z-index:9999; display:grid; place-items:center; background:radial-gradient(circle at center,rgba(54,30,105,.40),rgba(4,8,18,.82)); backdrop-filter:blur(7px); animation:unlock-overlay-in .28s ease both; cursor:pointer; overflow:hidden; }
.title-unlock-overlay.leaving { animation:unlock-overlay-out .42s ease both; }
.title-unlock-card { width:min(92vw,520px); padding:34px 28px 30px; text-align:center; border-radius:28px; color:#fff; background:linear-gradient(145deg,rgba(19,27,48,.96),rgba(44,26,76,.95)); border:1px solid rgba(255,255,255,.22); box-shadow:0 28px 90px rgba(0,0,0,.48),0 0 80px rgba(124,58,237,.24); animation:unlock-card-in .62s cubic-bezier(.16,1,.3,1) both; }
.title-unlock-kicker { font-size:12px; font-weight:900; letter-spacing:.24em; color:#facc15; }
.title-unlock-avatar { margin:18px auto 10px; animation:unlock-avatar .9s cubic-bezier(.16,1,.3,1) both; }
.title-unlock-rank { font:800 12px/1 var(--mono); opacity:.72; }
.title-unlock-card h2 { margin:7px 0 4px; font-size:clamp(26px,5vw,42px); line-height:1.05; }
.title-unlock-card p { margin:10px 0 0; opacity:.78; }
.title-burst { position:absolute; inset:0; pointer-events:none; }
.title-burst i { --angle:calc(var(--i) * 15deg); position:absolute; left:50%; top:50%; width:7px; height:22px; border-radius:99px; background:hsl(calc(var(--i)*15) 92% 62%); transform:translate(-50%,-50%) rotate(var(--angle)) translateY(-80px); animation:unlock-particle 1.3s cubic-bezier(.12,.75,.25,1) both; animation-delay:calc(var(--i)*12ms); }
@keyframes unlock-overlay-in{from{opacity:0}to{opacity:1}}@keyframes unlock-overlay-out{to{opacity:0;transform:scale(1.03)}}
@keyframes unlock-card-in{0%{opacity:0;transform:scale(.58) rotate(-4deg)}65%{transform:scale(1.06) rotate(1deg)}100%{opacity:1;transform:scale(1)}}
@keyframes unlock-avatar{0%{transform:scale(.2) rotate(-120deg);filter:brightness(2)}70%{transform:scale(1.15) rotate(8deg)}100%{transform:scale(1) rotate(0)}}
@keyframes unlock-particle{0%{opacity:0;transform:translate(-50%,-50%) rotate(var(--angle)) translateY(-70px) scale(.2)}22%{opacity:1}100%{opacity:0;transform:translate(-50%,-50%) rotate(var(--angle)) translateY(-330px) scale(1)}}

.xp-chip { display:inline-flex; align-items:center; gap:6px; padding:8px 11px; border-radius:999px; font-weight:800; font-size:12px; color:var(--accent); background:color-mix(in srgb,var(--accent) 10%,var(--surface)); border:1px solid color-mix(in srgb,var(--accent) 24%,var(--line)); }
.duel-glow { border-color:color-mix(in srgb,var(--accent) 42%,var(--line)); box-shadow:0 10px 35px color-mix(in srgb,var(--accent) 12%,transparent); }
.super-duel-card { background:linear-gradient(145deg,var(--surface),color-mix(in srgb,#7c3aed 7%,var(--surface))); }
.duel-selected { min-height:45px; display:flex; gap:7px; flex-wrap:wrap; align-items:center; margin-top:9px; padding:8px; border:1px dashed var(--line); border-radius:10px; }
.selected-person { display:inline-flex; align-items:center; gap:7px; padding:5px 8px; border-radius:999px; background:var(--surface-2); font-size:12px; }
.duel-list-item { align-items:center; }
.duel-hero { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; padding:18px; border:1px solid var(--line); border-radius:18px; background:linear-gradient(135deg,color-mix(in srgb,var(--accent) 10%,var(--surface)),var(--surface)); }
.duel-hero.super { background:linear-gradient(135deg,color-mix(in srgb,#7c3aed 15%,var(--surface)),var(--surface)); }
.duel-status { font-size:22px; font-weight:850; margin-top:3px; }
.duel-participants { display:grid; gap:9px; }
.duel-person { display:grid; grid-template-columns:auto 1fr auto; gap:10px; align-items:center; padding:10px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); }
.duel-score { font:800 17px/1.2 var(--mono); margin-top:5px; }
.duel-countdown { text-align:center; font-size:18px; }
.duel-board-link { width:100%; }
.duel-chat { height:240px; overflow:auto; display:flex; flex-direction:column; gap:8px; padding:9px; background:var(--surface-2); border-radius:12px; }
.duel-chat-msg { display:grid; grid-template-columns:auto 1fr auto; gap:8px; align-items:baseline; padding:7px 9px; border-radius:10px; background:var(--surface); border:1px solid var(--line); }
.duel-chat-msg span { word-break:break-word; }.duel-chat-msg small{color:var(--ink-3)}
.duel-payout { margin-top:16px; border-color:color-mix(in srgb,#f59e0b 55%,var(--line)); background:linear-gradient(135deg,color-mix(in srgb,#f59e0b 8%,var(--surface)),var(--surface)); }

@media(max-width:860px){.xp-sidebar{margin:8px 0}.duel-hero{grid-template-columns:1fr}.title-gallery{grid-template-columns:1fr 1fr}.xp-profile-main{align-items:flex-start}.avatar-xl{width:92px;height:92px;font-size:44px}}
@media(max-width:520px){.title-gallery{grid-template-columns:1fr}.duel-chat-msg{grid-template-columns:1fr}.duel-chat-msg small{justify-self:start}}
@media(prefers-reduced-motion:reduce){.title-unlock-overlay,.title-unlock-card,.title-unlock-avatar,.title-burst i{animation:none!important}.title-card{transition:none}}


/* ------------------------------------------------------------ leaderboards */
.leaderboard-tabs { display:flex; flex-wrap:wrap; gap:8px; }
.leaderboard-player { display:flex; align-items:center; gap:10px; min-width:180px; }
.leaderboard-player .xp-avatar { width:36px; height:36px; flex:0 0 36px; font-size:18px; }
.leaderboard-title, .leaderboard-value-label { display:block; margin-top:1px; }
.leaderboard-me td { background: var(--info-bg); }
.leaderboard-table td { vertical-align: middle; }
