:root {
  color-scheme: dark;
  --page-bg: #00163e;
  --accent: #fdb317;
  --board-light: #dfe2e6;
  --board-dark: #717c93;
  --text: #ffffff;
  --muted: #8e98ad;
  --panel-bg: #0a2050;
  --surface: #0a2050;
  --surface-soft: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.24);
  --success: #5cb87f;
  --fail: #e87761;
  /* Speed-rating heatmap scale (gold pinnacle → green → teal → indigo → slate) + ring track. */
  --r-master: #fdb317;
  --r-expert: #5cb87f;
  --r-advanced: #3fa6a8;
  --r-intermediate: #6f86c9;
  --r-novice: #8190ad;
  --pd-ring-track: rgba(255, 255, 255, 0.1);
  --app-max-width: 1600px;
  --page-inline-padding: clamp(12px, 4vw, 48px);
  --board-size-layout-max: calc(
    min(var(--app-max-width), 100vw)
    - (2 * var(--page-inline-padding))
    - var(--left-col-size)
    - (2 * var(--board-column-gap))
    - var(--right-col-min)
  );
  --board-size-preferred: min(60vw, max(0px, var(--board-size-layout-max)));
  --board-size: var(--board-size-preferred);
  --board-column-gap: 40px;
  --board-bottom-clearance: 48px;
  --mini-board-size: 112px;
  --left-col-size: 240px;
  --right-col-min: clamp(140px, 18vw, 280px);
  --build-grid-gap: 6px;
  --build-grid-breakpoint: 320px;
  --build-grid-button-size: calc((var(--build-grid-breakpoint) - (3 * var(--build-grid-gap))) / 4);
  --piece-choice-size: 78px;
  --piece-choice-gap: 8px;
  --piece-choices-width: calc((5 * var(--piece-choice-size)) + (4 * var(--piece-choice-gap)));
  --large-prompt-height: clamp(150px, 25vmin, 220px);
  --prompt-choices-gap: 14px;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  /* Always reserve the scrollbar gutter so the centered layout doesn't shift
     when switching between tall, scrolling views (board drills) and short ones
     that don't scroll (Name/Match the Piece). No-op with overlay scrollbars. */
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page-bg);
  color: var(--text);
  font-family:
    "Figtree",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--left-col-size) var(--board-size) minmax(var(--right-col-min), 1fr);
  align-items: start;
  align-content: start;
  justify-content: center;
  column-gap: var(--board-column-gap);
  row-gap: 14px;
  width: min(var(--app-max-width), 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: var(--page-inline-padding) var(--page-inline-padding) clamp(16px, 4vw, 48px);
}

.trainer-stage {
  display: contents;
}

.prompt-row {
  grid-column: 2;
  grid-row: 2;
}

.board-wrap {
  grid-column: 2;
  grid-row: 3;
}

.dashboard-page {
  display: contents;
}

.dashboard-page[hidden] {
  display: none;
}

.dashboard-title {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  width: var(--board-size);
  max-width: 100%;
  min-height: 58px;
  margin: 0;
}

.dashboard-content {
  grid-column: 2;
  grid-row: 3;
  width: var(--board-size);
  max-width: 100%;
  min-height: var(--board-size);
}

/* Test-mode-only testing controls, stacked in the board column between the title (row 2) and the
   stats. The test-mode page is display:contents, so these place directly into the .app-shell grid
   like the title/content do. Content drops to row 4 to make room. */
.test-mode-controls {
  grid-column: 2;
  grid-row: 3;
  width: var(--board-size);
  max-width: 100%;
  margin: 0;
}

#testModeDashboardPage .dashboard-content {
  grid-row: 4;
}

.test-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

.test-mode-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.dashboard-panel {
  display: grid;
  gap: 28px;
  align-content: start;
  padding-bottom: var(--board-bottom-clearance);
}

.dashboard-completion {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.dashboard-completion-value {
  color: var(--accent);
  font-weight: 600;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(6.5rem, auto);
  column-gap: 10px;
  row-gap: 28px;
}

.dashboard-section {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  row-gap: 14px;
}

.dashboard-section-title {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--accent);
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.dashboard-group-heading {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dashboard-item {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  row-gap: 6px;
}

.dashboard-item-title {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
}

.dashboard-detail-list {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  margin: 0;
  padding: 0;
  list-style: none;
  row-gap: 4px;
}

.dashboard-detail-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: baseline;
}

.dashboard-orientation-group {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  row-gap: 4px;
}

.dashboard-orientation-label {
  grid-column: 1;
  padding-left: 12px;
  font-weight: 500;
}

.dashboard-quadrant-list {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  margin: 0;
  padding: 0;
  list-style: none;
  row-gap: 4px;
}

.dashboard-detail-label {
  grid-column: 1;
  padding-left: 12px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.35;
}

.dashboard-quadrant-list .dashboard-detail-label {
  padding-left: 24px;
}

.dashboard-status {
  grid-column: 2;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.35;
}

.dashboard-status-action {
  border: 0;
  border-radius: 6px;
  padding: 0 4px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.dashboard-status-action:hover,
.dashboard-status-action:focus-visible {
  background: rgba(83, 122, 246, 0.1);
  color: var(--accent);
  outline: none;
}

.dashboard-status--incomplete {
  color: var(--muted);
  font-weight: 400;
}

.dashboard-status--passed {
  color: var(--success);
}

.dashboard-status--speed {
  color: var(--accent);
}

.dashboard-reset-button {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 18px;
  background: var(--surface-soft);
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.dashboard-reset-button:hover,
.dashboard-reset-button:focus-visible {
  border-color: var(--fail);
  background: rgba(232, 119, 97, 0.08);
  color: var(--fail);
  outline: none;
}

/* ===========================================================================
   Public progress dashboard (.progress-dashboard) — the heatmap-style redesign.
   Scoped so it never touches the Test Mode dashboard's .dashboard-* layout above.
   Colors lean on the app's own tokens (panel = --surface, borders = --line) per
   the agreed flat-navy box style; rating tints come from the --r-* scale.
   =========================================================================== */

/* The public dashboard spans the full shell width and renders its own "Your progress"
   title, so the generic .dashboard-title ("Dashboard") is dropped here. Test Mode keeps
   the narrow board-column layout defined earlier. */
#dashboardPage .dashboard-title {
  display: none;
}
#dashboardPage .dashboard-content {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  max-width: none;
  min-height: 0;
}

.progress-dashboard {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding-bottom: var(--board-bottom-clearance);
}

.progress-dashboard .tnum {
  font-variant-numeric: tabular-nums;
}

.pd-title {
  margin: 0 0 22px;
  font-size: clamp(1.8rem, 3.4vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Match the app's right-column boxes (e.g. the instruction box): subtle --surface-soft fill, a
   --line border, and a 1px inset top highlight instead of a drop shadow. */
.progress-dashboard .panel {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

/* ---- shared progress ring ---- */
.pd-ring {
  position: relative;
  flex: 0 0 auto;
}
.pd-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.pd-ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

/* ---- icon masks (reuse the app's --icon-src pattern) ---- */
.progress-dashboard .pd-ic {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-color: currentColor;
  -webkit-mask: var(--icon-src) center / contain no-repeat;
  mask: var(--icon-src) center / contain no-repeat;
  flex-shrink: 0;
}

.pd-eyebrow {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---- hero ---- */
.pd-hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 22px;
  margin-bottom: 22px;
}

.pd-fluency {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(18px, 3vw, 34px);
  align-items: center;
  padding: clamp(20px, 2.6vw, 30px);
}
.pd-fluency-ring {
  width: 156px;
  height: 156px;
}
.pd-fluency-ring .pd-ring-pct {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}
.pd-fluency-ring .pd-ring-label {
  margin-top: 4px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pd-fluency-body .pd-eyebrow {
  margin-bottom: 8px;
}
.pd-fluency-rating {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
}
.pd-grade {
  font-size: clamp(2rem, 4vw, 2.9rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
}
.pd-grade-detail {
  color: var(--muted);
  font-size: 1rem;
}
.pd-fluency-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
  max-width: 46ch;
}

/* ---- resume / continue card ---- */
.pd-resume {
  display: flex;
  flex-direction: column;
  padding: clamp(22px, 2.4vw, 28px);
}
.pd-resume-head {
  display: flex;
  align-items: center;
  gap: 13px;
}
.pd-resume-ic {
  display: grid;
  place-content: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: rgba(253, 179, 23, 0.12);
  border: 1px solid rgba(253, 179, 23, 0.28);
  color: var(--accent);
}
.pd-resume-head .pd-eyebrow {
  color: var(--accent);
}
.pd-resume-title {
  margin: 20px 0 0;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.pd-resume-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}
.pd-resume-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
}
.pd-resume-copy {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.5;
  max-width: 40ch;
}
/* Gold pill CTA. A fixed gap above it (not margin-top:auto — the resume card is the taller hero
   panel, so there's no free space for auto to distribute and the button would jam against the copy). */
.pd-cta {
  align-self: flex-start;
  margin-top: 24px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  padding: 13px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #11202a;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(253, 179, 23, 0.28);
  transition: transform 130ms ease, box-shadow 130ms ease;
}
.pd-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(253, 179, 23, 0.36);
}
.pd-cta .pd-cta-ic {
  width: 18px;
  height: 18px;
}

/* ---- module grid ---- */
.pd-section-label {
  margin: 8px 2px 16px;
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.pd-modules {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 22px;
}
.pd-module {
  display: flex;
  flex-direction: column;
  padding: 20px 22px 22px;
}
.pd-module-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}
.pd-module-ic {
  display: grid;
  place-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--accent);
}
.pd-module-name {
  font-size: 1.22rem;
  font-weight: 600;
  line-height: 1.1;
}
.pd-module-ring {
  width: 56px;
  height: 56px;
}
.pd-module-pct {
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.pd-module-divider {
  height: 1px;
  margin: 16px 0 4px;
  background: var(--line);
}

.pd-drill {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}
.pd-drill + .pd-drill {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.pd-drill-name {
  font-size: 0.98rem;
  font-weight: 500;
}
.pd-drill-num {
  margin-right: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.pd-cells {
  display: flex;
  gap: 8px;
}

/* ---- heatmap cells (display-only) ---- */
.pd-cell {
  position: relative;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1px;
  width: 94px;
  min-height: 50px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  text-align: center;
}
.pd-cell-v {
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
  white-space: nowrap;
}
.pd-cell-time {
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.pd-cell-rate {
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.85;
  white-space: nowrap;
}

/* tested: tinted by rating via --rc (default advanced; overridden per data-rating below) */
.pd-cell[data-status="tested"] {
  --rc: var(--r-advanced);
  background: color-mix(in srgb, var(--rc) 18%, transparent);
  border-color: color-mix(in srgb, var(--rc) 48%, transparent);
}
.pd-cell[data-rating="master"] {
  --rc: var(--r-master);
}
.pd-cell[data-rating="expert"] {
  --rc: var(--r-expert);
}
.pd-cell[data-rating="advanced"] {
  --rc: var(--r-advanced);
}
.pd-cell[data-rating="intermediate"] {
  --rc: var(--r-intermediate);
}
.pd-cell[data-rating="novice"] {
  --rc: var(--r-novice);
}
.pd-cell[data-status="tested"] .pd-cell-time {
  color: color-mix(in srgb, var(--rc) 72%, white);
}
.pd-cell[data-status="tested"] .pd-cell-rate {
  color: var(--rc);
}
.pd-cell[data-status="tested"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--rc);
}

.pd-cell[data-status="done"] {
  background: rgba(92, 184, 127, 0.1);
  border-color: rgba(92, 184, 127, 0.34);
}
.pd-cell[data-status="done"] .pd-check {
  width: 18px;
  height: 18px;
  color: var(--success);
}
.pd-cell[data-status="done"] .pd-cell-rate {
  color: var(--success);
  opacity: 0.9;
}

.pd-cell[data-status="available"] {
  border-color: var(--line-strong);
}
.pd-cell[data-status="available"] .pd-cell-empty {
  color: var(--muted);
  opacity: 0.6;
}

.pd-cell[data-status="locked"] {
  background: repeating-linear-gradient(
    135deg,
    transparent,
    transparent 6px,
    rgba(255, 255, 255, 0.03) 6px,
    rgba(255, 255, 255, 0.03) 12px
  );
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.16);
}
.pd-lock {
  width: 15px;
  height: 15px;
  opacity: 0.4;
}

/* ---- legend ---- */
.pd-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px 26px;
  margin-top: 22px;
  padding: 16px 20px;
}
.pd-legend-title {
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.pd-legend-scale {
  display: flex;
  align-items: center;
  gap: 22px;
}
.pd-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pd-legend-sw {
  width: 16px;
  height: 16px;
  border-radius: 5px;
}
.pd-legend-label {
  font-size: 0.86rem;
}

.progress-dashboard .dashboard-reset-button {
  margin-top: 24px;
}

@media (max-width: 880px) {
  .pd-hero,
  .pd-modules {
    grid-template-columns: 1fr;
  }
}

.app-shell.is-dashboard-view .trainer-stage,
.app-shell.is-dashboard-view > .right-panel.right-panel {
  display: none;
}

.trainer-stage:not(.has-side-panel-answers) ~ .right-panel {
  display: contents;
}

.trainer-stage:not(.has-side-panel-answers) ~ .right-panel .answer-area {
  grid-column: 2;
  grid-row: 4;
}

/* Minimap click modes (Find the Rank/File/Square) answer on the board, so the
   answer-area only holds the minimap + feedback + drill actions. Keep that whole
   stack in the right column with its top edge aligned to the main board. Stretch
   the children so the feedback and speed-test result span the full column width
   (matching the choice modes); the minimap keeps its own fixed width regardless. */
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area {
  grid-column: 3;
  grid-row: 3;
  align-self: start;
  display: grid;
  width: 100%;
  max-width: 100%;
  justify-items: stretch;
}

.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .minimap-panel {
  grid-column: auto;
  grid-row: auto;
  order: 2;
}

.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .play-move-side {
  grid-column: auto;
  grid-row: auto;
  order: 3;
}

.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .restart-drill,
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .next-drill {
  grid-column: auto;
  grid-row: auto;
  order: 0;
}

.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .speed-test-button {
  grid-column: auto;
  grid-row: auto;
  order: 1;
}

/* When a speed test result is showing, move the tier table above the action buttons. */
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result) .play-move-side {
  order: 0;
}
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result) .minimap-panel {
  order: 1;
}
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result) .speed-test-button {
  order: 2;
}
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result) .restart-drill,
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result) .next-drill {
  order: 3;
}

/* Drill view after a passed speed test: Repeat Drill stays above Retake Test. */
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result):has(.restart-drill:not([hidden])) .restart-drill {
  order: 2;
}
.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area:has(.feedback.has-speed-result):has(.restart-drill:not([hidden])) .speed-test-button {
  order: 3;
}

.trainer-stage:not(.has-side-panel-answers) ~ .right-panel .build-preview-panel,
.trainer-stage:not(.has-side-panel-answers) ~ .right-panel .game-panel {
  grid-column: 3;
  grid-row: 3;
  align-self: start;
}

.play-move-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

.trainer-stage.has-side-panel-answers .play-move-side {
  display: contents;
}

.play-move-side .tier-jump-control {
  order: 1;
}

.play-move-side .feedback {
  order: 2;
}

.trainer-stage.has-board-move-panel .play-move-side .feedback {
  order: 1;
}

.trainer-stage.has-board-move-panel .play-move-side .tier-jump-control {
  order: 2;
}

/* Play the Move: stack feedback, tier, and drill actions beside the board */
.trainer-stage.has-board-move-panel:not(.has-side-panel-answers) ~ .right-panel .answer-area {
  grid-column: 3;
  grid-row: 3;
  align-self: start;
  width: 100%;
  min-width: 0;
}

.trainer-stage.has-board-move-panel:not(.has-side-panel-answers) ~ .right-panel .play-move-side {
  width: 100%;
  min-width: 0;
}

.trainer-stage.has-board-move-panel:not(.has-side-panel-answers) ~ .right-panel .answer-area .next-drill,
.trainer-stage.has-board-move-panel:not(.has-side-panel-answers) ~ .right-panel .answer-area .restart-drill,
.trainer-stage.has-board-move-panel:not(.has-side-panel-answers) ~ .right-panel .answer-area .speed-test-button {
  grid-column: auto;
  grid-row: auto;
}

.site-header {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding-bottom: clamp(10px, 4vw, 24px);
  margin-bottom: clamp(10px, 4vw, 24px);
  position: relative;
}

/* Full-bleed divider: the header lives inside the padded, max-width app-shell,
   so a plain border-bottom stops short of the viewport edges. This pseudo-element
   spans the full window width instead. */
.site-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

.site-header .brand-logo {
  grid-column: 1;
  justify-self: start;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(20px, 4vw, 56px);
}

.site-nav-primary {
  grid-column: 2;
  justify-content: center;
  justify-self: center;
  gap: clamp(10px, 1.8vw, 20px);
}

.site-nav-divider {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  background-color: var(--muted);
  opacity: 0.62;
  -webkit-mask-image: var(--icon-src);
  mask-image: var(--icon-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  flex-shrink: 0;
  pointer-events: none;
  user-select: none;
}

.site-nav-secondary {
  grid-column: 3;
  justify-content: flex-end;
  justify-self: end;
  gap: 16px;
}

/* Icon-only gear linking to the Test Mode Dashboard, sitting just right of Dashboard. */
.site-nav-test-mode {
  padding: 4px;
}

.site-nav-test-mode .nav-icon {
  width: 1.4em;
  height: 1.4em;
}

/* The Test Mode Dashboard is hidden from everyone by default — both the gear in the header
   (.site-nav-test-mode) and the "Test Mode" entry in the mobile drawer (.drawer-test-mode). Visiting
   `?testmode=<token>` adds `body.test-mode-enabled`, which removes this gate and lets the normal
   display rules take over. See applyTestModeActivationFromUrl() in src/app/main.js. */
body:not(.test-mode-enabled) .site-nav-test-mode,
body:not(.test-mode-enabled) .drawer-test-mode {
  display: none !important;
}

/* The Dashboard link is hidden until the user clears every Files and Ranks module — both the header
   entry and its mobile-drawer twin (.drawer-dashboard). renderNavLocks() adds body.dashboard-unlocked
   once those sections are complete (test mode's "unlock all" reveals it too). */
body:not(.dashboard-unlocked) .site-nav-link[data-category="dashboard"],
body:not(.dashboard-unlocked) .drawer-dashboard[data-category="dashboard"] {
  display: none !important;
}

/* The collapse wrapper is transparent to layout on desktop/tablet: its children
   (the primary + secondary navs) participate directly in the header grid. On mobile
   it becomes the dropdown panel that the hamburger toggles. */
.site-nav-collapse {
  display: contents;
}

.nav-toggle {
  display: none;
  grid-column: 3;
  justify-self: end;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.nav-toggle:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.45);
  outline-offset: 3px;
}

/* Hamburger glyph built from a bar + two pseudo-element bars; morphs to an X when open. */
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 160ms ease, opacity 160ms ease;
}

.nav-toggle-bars {
  position: relative;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-bars::before {
  top: -7px;
}

.nav-toggle-bars::after {
  top: 7px;
}

.site-header.is-menu-open .nav-toggle-bars {
  background: transparent;
}

.site-header.is-menu-open .nav-toggle-bars::before {
  transform: translateY(7px) rotate(45deg);
}

.site-header.is-menu-open .nav-toggle-bars::after {
  transform: translateY(-7px) rotate(-45deg);
}

.site-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color 140ms ease;
}

.nav-icon {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  background-color: currentColor;
  opacity: 0.75;
  -webkit-mask-image: var(--icon-src);
  mask-image: var(--icon-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  flex-shrink: 0;
  transition: opacity 140ms ease;
}

.site-nav-link.is-active .nav-icon,
.site-nav-link:hover .nav-icon,
.site-nav-link:focus-visible .nav-icon {
  opacity: 1;
}

.site-nav-link.is-active {
  color: var(--accent);
  font-weight: 400;
}

.site-nav-link:hover,
.site-nav-link:focus-visible {
  color: var(--accent);
}

.site-nav-link:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.45);
  outline-offset: 5px;
  border-radius: 4px;
}

.site-nav-link.is-complete::after {
  content: "✓";
  color: var(--success);
  font-size: 1em;
  font-weight: 700;
  line-height: 1;
}

.prompt-row,
.answer-area {
  width: var(--board-size);
  max-width: 100%;
}

.prompt-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  /* Reserve the prompt-box's full height (matches .prompt-box height clamp) so
     the row never grows when the box appears — keeps the board from shifting
     down when switching between hide-prompt and show-prompt modes. */
  min-height: clamp(58px, 7.7vmin, 63px);
  padding: 0 2px;
}

.prompt-row > div:first-child {
  min-width: 0;
  text-align: left;
}

.mode-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: 0.01em;
}

.movement-meta {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.2;
}

.movement-meta[hidden] {
  display: none;
}

.movement-meta > span {
  display: block;
}

.prompt-box {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: clamp(56px, 9vmin, 74px);
  height: clamp(49px, 7.7vmin, 63px);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: clamp(1.8rem, 5.4vmin, 3.05rem);
  font-weight: 400;
  line-height: 1;
  text-transform: uppercase;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.prompt-box[hidden] {
  display: none;
}

.right-panel {
  grid-column: 3;
  grid-row: 3;
  align-self: start;
  align-content: start;
  display: grid;
  gap: 16px;
  width: 100%;
  min-width: 0;
}

.trainer-stage.has-side-panel-answers ~ .right-panel .answer-area {
  width: 100%;
  max-width: 100%;
}

.trainer-stage.has-build-panel ~ .right-panel .feedback {
  display: none;
}

.trainer-stage.has-no-board .board-wrap {
  display: none;
}

.trainer-stage.has-no-board ~ .right-panel .answer-area {
  grid-row: 3;
}

.trainer-stage.has-no-board.has-large-prompt .prompt-row {
  display: contents;
}

.trainer-stage.has-no-board.has-large-prompt .prompt-row > div:first-child {
  grid-column: 2;
  grid-row: 2;
  /* .prompt-row's min-height (which keeps shell row 2 a constant height across
     modes) stops applying once the row goes display: contents, so re-apply it
     here — otherwise row 3 (side nav, content) shifts up when entering these
     modes. Center the title to match its position in board modes. */
  display: grid;
  align-content: center;
  min-height: clamp(58px, 7.7vmin, 63px);
}

.trainer-stage.has-no-board.has-large-prompt .prompt-box {
  grid-column: 2;
  grid-row: 3;
  width: var(--piece-choices-width);
  max-width: 100%;
  justify-self: start;
}

.trainer-stage.has-piece-letter-prompt ~ .right-panel .answer-area,
.trainer-stage.has-piece-glyph-prompt ~ .right-panel .answer-area {
  gap: var(--prompt-choices-gap);
}

.trainer-stage.has-piece-letter-prompt ~ .right-panel .play-move-side .feedback,
.trainer-stage.has-piece-glyph-prompt ~ .right-panel .play-move-side .feedback {
  min-height: 0;
  margin-top: 2px;
}

.trainer-stage.has-no-board.has-large-prompt:not(:is(.has-piece-letter-prompt, .has-piece-glyph-prompt))
  ~ .right-panel
  .answer-area {
  grid-column: 2;
  grid-row: 3;
  align-self: start;
  margin-top: calc(var(--large-prompt-height) + var(--prompt-choices-gap));
}

.trainer-stage.has-no-board.has-large-prompt:not(:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)):has(
    .prompt-box[hidden]
  )
  ~ .right-panel
  .answer-area {
  margin-top: var(--prompt-choices-gap);
}

/* Name/Match the Piece: the prompt is a single piece, far narrower than a board,
   so collapse the choices column to the choices width and move everything else —
   instructions, keyboard shortcuts, progress counter, drill actions — into the
   open right column beside the prompt, top-aligned with it. The choices sit out
   of the row-sizing flow (absolute) so the right-column stack starts at the
   prompt's top edge; the area reserves their footprint with min-height.
   --prompt-offset is the choices' distance from the area top: prompt height +
   gap normally, just the gap when the prompt is hidden. */
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .answer-area {
  --prompt-offset: calc(var(--large-prompt-height) + var(--prompt-choices-gap));
  position: relative;
  grid-column: 2 / 4;
  grid-row: 3;
  grid-template-columns: var(--piece-choices-width) minmax(var(--right-col-min), 1fr);
  column-gap: var(--board-column-gap);
  align-self: start;
  width: auto;
  max-width: none;
  margin-top: 0;
  min-height: calc(var(--prompt-offset) + 96px);
}

.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt):has(
    .prompt-box[hidden]
  )
  ~ .right-panel
  .answer-area {
  --prompt-offset: var(--prompt-choices-gap);
}

.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .answer-choices {
  position: absolute;
  top: var(--prompt-offset);
  left: 0;
  width: var(--piece-choices-width);
}

/* The right-column stack takes successive auto rows in DOM order (instructions,
   shortcuts, counter/result, then actions), so hidden items leave no gap. */
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .instruction-box,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .keyboard-box,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .play-move-side,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .restart-drill,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .speed-test-button,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .next-drill {
  grid-column: 2;
  grid-row: auto;
  align-self: start;
}

.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .instruction-box,
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .keyboard-box {
  margin-top: 0;
}

.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .play-move-side {
  width: 100%;
  min-width: 0;
}

/* Speed-test idle: the progress counter ("N / total") lives in .play-move-side,
   which sits above the Start Speed Test button in DOM order. While the start
   button is available, push the counter below it so the call-to-action leads.
   Scoped to the idle start state so the post-test result/retake stack — where
   .play-move-side holds the result text — is untouched. */
.trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
  ~ .right-panel
  .answer-area:has(#startSpeedTest:not([hidden]))
  .play-move-side {
  order: 1;
}

.trainer-stage.has-large-prompt .prompt-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  min-height: 0;
}

.trainer-stage.has-large-prompt .prompt-box {
  width: 100%;
  height: var(--large-prompt-height);
  border: none;
  border-radius: 4px;
  background: var(--board-dark);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.32),
    0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

.trainer-stage.has-piece-letter-prompt .prompt-box {
  color: var(--text);
  text-transform: uppercase;
}

.prompt-letter-svg {
  width: clamp(72px, 24vmin, 120px);
  height: clamp(72px, 24vmin, 120px);
}

.prompt-letter-svg text {
  font-family:
    "Figtree",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 72px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

.trainer-stage.has-notation-prompt .prompt-box {
  width: clamp(112px, 17vmin, 150px);
  font-size: clamp(1.55rem, 4.2vmin, 2.4rem);
  text-transform: none;
}

.board-wrap {
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.32),
    0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

.minimap-panel {
  display: none;
  width: var(--mini-board-size);
  padding-top: 0;
}

.build-preview-panel {
  width: 100%;
}

.build-preview-panel[hidden] {
  display: none;
}

.build-preview-panel .build-preview {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1.2em;
  gap: 8px;
  padding: 14px;
}

.build-preview-panel .build-preview-value {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1.2;
  min-height: 1.2em;
  overflow-x: hidden;
  overflow-y: visible;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.build-preview-feedback {
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 400;
  line-height: 1.2;
}

.build-preview-feedback:empty {
  visibility: hidden;
}

.build-preview-panel.is-success .build-preview-feedback {
  color: var(--success);
}

.build-preview-panel.is-fail .build-preview-feedback {
  color: var(--fail);
}

.trainer-stage.has-visible-minimap ~ .right-panel .minimap-panel {
  display: block;
  margin-top: 0;
  margin-bottom: 10px;
}

.game-panel {
  display: none;
  width: 100%;
  height: var(--board-size);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow:
    0 16px 38px rgba(0, 0, 0, 0.22),
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.trainer-stage.has-game-panel ~ .right-panel .game-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 14px;
}

.game-panel[hidden] {
  display: none;
}

.trainer-stage.has-game-panel ~ .right-panel .game-upload {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 400;
  cursor: pointer;
}

.game-upload[hidden] {
  display: none;
}

.game-upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.game-select-control {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 400;
}

.game-select {
  width: 100%;
  min-height: 34px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 400;
}

.game-upload:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.09);
}

.game-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.25;
}

.game-score {
  display: grid;
  align-content: start;
  gap: 3px;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.game-score::-webkit-scrollbar {
  width: 8px;
}

.game-score::-webkit-scrollbar-track {
  background: transparent;
}

.game-score::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.22);
}

.game-score::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.34);
}

.game-score-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
}

.game-score-row.is-current {
  background: rgba(253, 179, 23, 0.13);
}

.game-score-number {
  color: rgba(232, 230, 223, 0.58);
}

.game-score-move {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-score-move:empty::after {
  color: rgba(232, 230, 223, 0.32);
  content: "...";
}

.game-score-move.is-success {
  color: var(--success);
}

.game-score-move.is-fail {
  color: var(--fail);
}

.game-reset {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 400;
  cursor: pointer;
}

.game-reset:disabled {
  cursor: default;
  opacity: 0.45;
}

.game-reset:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.09);
}

.game-reset:focus-visible,
.game-select:focus-visible,
.game-upload:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

.mini-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  overflow: hidden;
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.mini-square {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.mini-square.is-light-square {
  background: var(--board-light);
}

.mini-square.is-dark-square {
  background: var(--board-dark);
}

.mini-square.is-out-of-quadrant {
  opacity: 0.38;
}

/* Completed (green) squares in an inactive quadrant: dimmed, but bright enough
   to still read as progress next to the active quadrant. */
.mini-square.is-out-of-quadrant.is-hit {
  opacity: 0.52;
}

.mini-square::after {
  position: absolute;
  inset: 0;
  content: "";
}

.mini-square.is-hit::after {
  background: rgba(92, 184, 127, 0.72);
}

.mini-square.is-hit-1::after {
  background: rgba(92, 184, 127, 0.72);
}

.mini-square.is-hit-2::after {
  background: rgba(92, 184, 127, 0.72);
}

.mini-square.is-miss::after {
  background: rgba(232, 119, 97, 0.72);
}

.chess-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  user-select: none;
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  appearance: none;
  color: inherit;
  font: inherit;
  opacity: 1;
}

.square:focus {
  outline: none;
}

.square:focus-visible {
  z-index: 4;
  box-shadow: 0 0 0 3px rgba(253, 179, 23, 0.72) inset;
}

.square.is-light-square {
  background: var(--board-light);
}

.square.is-dark-square {
  background: var(--board-dark);
}

.square.is-out-of-quadrant {
  opacity: 0.42;
  filter: grayscale(0.28);
}

.chess-board[data-active-quadrant]::before,
.mini-board[data-active-quadrant]::before {
  position: absolute;
  z-index: 6;
  box-sizing: border-box;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22);
  pointer-events: none;
  content: "";
}

.chess-board[data-active-quadrant]::before {
  border: 3px solid rgba(253, 179, 23, 0.95);
}

.mini-board[data-active-quadrant]::before {
  border: 1px solid rgba(253, 179, 23, 0.95);
}

.chess-board.orientation-white[data-active-quadrant="wq"]::before,
.mini-board.orientation-white[data-active-quadrant="wq"]::before {
  left: 0;
  top: 50%;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-white[data-active-quadrant="wk"]::before,
.mini-board.orientation-white[data-active-quadrant="wk"]::before {
  left: 50%;
  top: 50%;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-white[data-active-quadrant="bq"]::before,
.mini-board.orientation-white[data-active-quadrant="bq"]::before {
  left: 0;
  top: 0;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-white[data-active-quadrant="bk"]::before,
.mini-board.orientation-white[data-active-quadrant="bk"]::before {
  left: 50%;
  top: 0;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-black[data-active-quadrant="wq"]::before,
.mini-board.orientation-black[data-active-quadrant="wq"]::before {
  left: 50%;
  top: 0;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-black[data-active-quadrant="wk"]::before,
.mini-board.orientation-black[data-active-quadrant="wk"]::before {
  left: 0;
  top: 0;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-black[data-active-quadrant="bq"]::before,
.mini-board.orientation-black[data-active-quadrant="bq"]::before {
  left: 50%;
  top: 50%;
  width: 50%;
  height: 50%;
}

.chess-board.orientation-black[data-active-quadrant="bk"]::before,
.mini-board.orientation-black[data-active-quadrant="bk"]::before {
  left: 0;
  top: 50%;
  width: 50%;
  height: 50%;
}

.square::after {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: transparent;
  content: "";
  pointer-events: none;
}

.square.is-target::after {
  background: rgba(253, 179, 23, 0.7);
}

.square.is-last-move::after {
  background: rgba(253, 179, 23, 0.7);
}

.square.is-last-move-source::after {
  background: rgba(253, 179, 23, 0.34);
}

.square.is-last-move-target::after {
  background: rgba(253, 179, 23, 0.78);
}

.square.is-selected-source::after {
  background: rgba(253, 179, 23, 0.7);
  box-shadow: 0 0 0 3px rgba(253, 179, 23, 0.95) inset;
}

.square.is-drag-source::after {
  background: rgba(253, 179, 23, 0.6);
  box-shadow: 0 0 0 3px rgba(253, 179, 23, 0.85) inset;
}

.square.is-move-hint::before {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  content: "";
  pointer-events: none;
  z-index: 4;
}

.square.is-move-hint-capture::before {
  position: absolute;
  inset: 6%;
  border: 6px solid rgba(0, 0, 0, 0.22);
  border-radius: 50%;
  box-sizing: border-box;
  content: "";
  pointer-events: none;
  z-index: 4;
}

.square.is-hit::after {
  background: rgba(92, 184, 127, 0.5);
}

.square.is-miss::after {
  background: rgba(232, 119, 97, 0.5);
}

.square.has-capture-indicator::before {
  position: absolute;
  top: 4%;
  right: 6%;
  z-index: 5;
  color: #ff5f57;
  font-size: clamp(1.45rem, calc(var(--board-size) * 0.045), 2.25rem);
  font-weight: 400;
  line-height: 1;
  content: "\00d7";
  pointer-events: none;
}

.chess-board.is-click-mode .square {
  cursor: pointer;
  touch-action: none;
}

.square-coord-label {
  position: absolute;
  bottom: 3%;
  left: 4%;
  z-index: 5;
  font-size: clamp(0.5rem, calc(var(--board-size) * 0.018), 0.875rem);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.square-coord-label.rank-coord-label {
  bottom: auto;
  left: auto;
  top: 3%;
  right: 4%;
}

.square.is-light-square .square-coord-label {
  color: var(--board-dark);
}

.square.is-dark-square .square-coord-label {
  color: var(--board-light);
}

.piece.is-fading-capture {
  opacity: 0;
  transition: opacity 150ms ease-out;
}

.piece {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.piece.is-dragging {
  z-index: 10;
  cursor: grabbing;
  will-change: transform;
  transition: none;
  pointer-events: none;
}

.piece.notation-flying-piece {
  inset: auto;
  z-index: 5;
  transition-property: transform;
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.prompt-piece {
  width: min(18%, 92px);
  height: min(46%, 92px);
  object-fit: contain;
}

.side-panel {
  grid-column: 1;
  grid-row: 3;
  align-self: start;
  width: var(--left-col-size);
  display: grid;
  gap: 18px;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  line-height: 1;
  text-decoration: none;
}

.brand-logo img {
  display: block;
  width: auto;
  height: clamp(45px, 5.25vw, 65px);
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(2.35rem, 3.8vw, 3.15rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.mode-nav {
  display: grid;
  gap: 24px;
  width: 100%;
}

.mode-group {
  display: grid;
  gap: 4px;
}

.mode-group.is-collapsed-group {
  display: none;
}

.mode-nav-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mode-nav-num {
  flex: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: color 140ms ease;
}

.mode-nav-label {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.25;
  transition: color 140ms ease;
}

.mode-nav-chevron {
  flex: 0 0 auto;
  width: 0.72em;
  height: 0.72em;
  background-color: var(--text);
  opacity: 0.72;
  transform: rotate(0deg);
  transform-origin: center;
  transition: transform 140ms ease, opacity 140ms ease;
  -webkit-mask-image: url("./assets/icons/caret-right-bold.svg");
  mask-image: url("./assets/icons/caret-right-bold.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.mode-item.is-active:has(.orientation-options, .mode-subnav) > .mode-nav-row .mode-nav-chevron {
  transform: rotate(90deg);
}

.mode-nav-row.is-active .mode-nav-chevron {
  opacity: 0.88;
}

.mode-nav-row.is-active .mode-nav-num {
  color: var(--accent);
}

.mode-nav-row.is-active .mode-nav-label {
  color: var(--text);
}

.mode-nav-row:hover .mode-nav-label,
.mode-nav-row:focus-visible .mode-nav-label {
  color: var(--text);
}

.mode-nav-row:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 2px;
}

.mode-button,
.answer-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  letter-spacing: 0;
  cursor: pointer;
}

.mode-button {
  justify-self: start;
  min-height: 26px;
  border-color: transparent;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
  text-align: left;
}

.mode-item {
  display: grid;
  gap: 0;
}

.mode-item[hidden] {
  display: none;
}

.mode-item.is-active .orientation-options,
.mode-item.is-active .mode-subnav {
  display: grid;
  gap: 4px;
  padding-top: 0;
  padding-bottom: 10px;
}

.mode-item.is-active .mode-nav-row {
  min-height: 36px;
  padding-bottom: 2px;
}

.orientation-options,
.mode-subnav {
  display: none;
  gap: 6px;
  padding: 0 0 8px calc(1.5rem + 11px);
}

.orientation-branch,
.subnav-branch {
  display: grid;
  gap: 4px;
}

.mode-subnav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 2px 0;
}

.mode-subnav-label {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.25;
  transition: color 140ms ease;
}

.mode-subnav-row .mode-nav-chevron {
  flex: 0 0 auto;
  width: 0.68em;
  height: 0.68em;
  transform: rotate(0deg);
}

.subnav-branch.is-current .mode-subnav-row .mode-nav-chevron {
  transform: rotate(90deg);
}

.mode-subnav-button.is-current-branch .mode-subnav-label {
  color: var(--text);
}

.mode-subnav-row:hover .mode-subnav-label,
.mode-subnav-row:focus-visible .mode-subnav-label {
  color: var(--text);
}

.mode-subnav-button.is-current-branch .mode-nav-chevron {
  opacity: 0.88;
}

.orientation-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 2px 0;
}

.orientation-nav-label {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.25;
  transition: color 140ms ease;
}

.orientation-nav-row .mode-nav-chevron {
  flex: 0 0 auto;
  width: 0.68em;
  height: 0.68em;
  transform: rotate(0deg);
}

.orientation-branch.is-current .orientation-nav-row .mode-nav-chevron {
  transform: rotate(90deg);
}

.orientation-option.is-current-branch .orientation-nav-label {
  color: var(--text);
}

.orientation-nav-row:hover .orientation-nav-label,
.orientation-nav-row:focus-visible .orientation-nav-label {
  color: var(--text);
}

.orientation-option.is-current-branch .mode-nav-chevron {
  opacity: 0.88;
}

.quadrant-options,
.tier-options,
.phase-options {
  display: none;
  gap: 4px;
  padding: 0 0 4px 1rem;
}

.mode-item.is-active .orientation-branch.is-current .quadrant-options,
.mode-item.is-active .orientation-branch.is-current .tier-options,
.mode-item.is-active .orientation-branch.is-current .phase-options,
.mode-item.is-active .subnav-branch.is-current .phase-options {
  display: grid;
}

.orientation-option:not(.orientation-nav-row).is-complete::after,
.mode-subnav-button:not(.mode-subnav-row).is-complete::after,
.mode-subnav-row.is-complete .mode-subnav-label::after,
.quadrant-option.is-complete::after,
.tier-option.is-complete::after,
.phase-option.is-complete::after,
.mode-nav-row.is-complete .mode-nav-label::after,
.orientation-option.orientation-nav-row.is-complete .orientation-nav-label::after {
  content: "✓";
  margin-left: 0.35em;
  color: var(--success);
  font-size: 1em;
  font-weight: 700;
  line-height: 1;
}

.orientation-option,
.mode-subnav-button,
.quadrant-option,
.tier-option,
.phase-option {
  font-size: 0.92rem;
  font-weight: 400;
}

.mode-button:hover {
  color: var(--text);
}

.mode-button.is-active {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.mode-button:focus-visible,
.answer-button:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

/* Linear-progression locks: modules the user hasn't reached yet read as faded and are inert.
   Opacity is set per element (never on a container that also wraps another locked element) so
   nested locked controls don't compound into near-invisibility. */
.site-nav-link.is-locked,
.mode-nav-row.is-locked,
.mode-button.is-locked {
  opacity: 0.38;
  pointer-events: none;
}

.mode-group.is-locked .mode-group-title {
  opacity: 0.38;
}

.answer-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  min-height: 92px;
  align-content: start;
}

.speed-test-button,
.next-drill,
.restart-drill {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  justify-self: start;
  gap: 8px;
  width: min(100%, 188px);
  min-height: 38px;
  margin-top: 0;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 18px;
  background: var(--accent);
  color: var(--panel-bg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 120ms ease, transform 120ms ease;
}

.next-drill-label {
  flex: 1 1 auto;
  min-width: 0;
}

.next-drill-shortcut {
  flex: 0 0 auto;
  margin-left: auto;
  opacity: 0.45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  font-size: 0.85em;
  font-weight: 500;
  line-height: 1;
  transform: translateY(0.06em);
}

.button-icon {
  display: inline-block;
  flex: 0 0 auto;
  width: 1.1em;
  height: 1.1em;
  background-color: currentColor;
  -webkit-mask-image: var(--icon-src);
  mask-image: var(--icon-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.speed-test-button {
  background: var(--success);
  border-color: var(--success);
  color: var(--panel-bg);
}

.speed-test-button + .speed-test-button {
  background: transparent;
  color: var(--success);
}

.restart-drill {
  background: transparent;
  color: var(--accent);
}

.speed-test-button:hover,
.next-drill:hover,
.restart-drill:hover {
  filter: brightness(1.08);
}

.speed-test-button:active,
.next-drill:active,
.restart-drill:active {
  transform: translateY(1px);
}

.speed-test-button:focus-visible,
.next-drill:focus-visible,
.restart-drill:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

.speed-test-button[hidden],
.next-drill[hidden],
.restart-drill[hidden] {
  display: none;
}

.answer-area .tier-jump-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 40px;
  margin-top: 2px;
}

.answer-choices {
  display: grid;
  grid-template-columns: repeat(8, minmax(34px, 1fr));
  gap: 8px;
  container-type: inline-size;
  container-name: answer-choices;
}

.answer-choices[hidden] {
  display: none;
}

.answer-choices.is-color-selector {
  grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.color-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.45;
}

.color-hint[hidden] {
  display: none;
}

.instruction-box {
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.instruction-box[hidden] {
  display: none;
}

.instruction-box-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.instruction-box-title .button-icon {
  width: 1.4em;
  height: 1.4em;
}

.instruction-box-text {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.45;
}

.keyboard-box {
  container-type: inline-size;
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.keyboard-box[hidden] {
  display: none;
}

.keyboard-box-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.keyboard-box-title .button-icon {
  width: 1.5em;
  height: 1.5em;
}

.keycap-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keycap-row {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px;
  justify-content: start;
}

@container (min-width: 248px) {
  .keycap-row {
    grid-template-columns: repeat(8, auto);
  }
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.9em;
  height: 1.9em;
  padding: 0 0.45em;
  border: 1px solid var(--line);
  border-bottom-color: rgba(0, 0, 0, 0.45);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.14) inset,
    0 1.5px 1.5px rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
  text-transform: none;
}

.answer-choices.is-piece-selector,
.answer-choices.is-piece-find-selector {
  grid-template-columns: repeat(5, var(--piece-choice-size));
  gap: var(--piece-choice-gap);
  width: var(--piece-choices-width);
  max-width: 100%;
}

.piece-glyph-choice {
  display: grid;
  gap: 4px;
  justify-items: center;
}

.answer-choices.is-piece-selector .piece-glyph-answer,
.answer-choices.is-piece-find-selector .piece-find-answer {
  width: var(--piece-choice-size);
  height: var(--piece-choice-size);
  padding: 8px;
  text-transform: uppercase;
}

/* The piece prompt above these choices casts a large drop shadow (see
   .has-large-prompt .prompt-box) and the choices sit just --prompt-choices-gap
   below it, so the shared --surface-soft default — being nearly transparent —
   let that shadow bleed through. Give the choices an opaque fill in every
   state: the same tints as the shared .answer-button states, composited over
   --page-bg so they read identically but block the shadow. */
.answer-choices.is-piece-selector .piece-glyph-answer,
.answer-choices.is-piece-find-selector .piece-find-answer {
  background: linear-gradient(var(--surface-soft), var(--surface-soft)), var(--page-bg);
}

.answer-choices.is-piece-selector .piece-glyph-answer:hover,
.answer-choices.is-piece-find-selector .piece-find-answer:hover {
  background: linear-gradient(rgba(253, 179, 23, 0.08), rgba(253, 179, 23, 0.08)), var(--page-bg);
}

.answer-choices.is-piece-selector .piece-glyph-answer.is-selected,
.answer-choices.is-piece-find-selector .piece-find-answer.is-selected {
  background: linear-gradient(rgba(253, 179, 23, 0.22), rgba(253, 179, 23, 0.22)), var(--page-bg);
}

.answer-choices.is-piece-selector .piece-glyph-answer.is-success,
.answer-choices.is-piece-find-selector .piece-find-answer.is-success {
  background: linear-gradient(rgba(92, 184, 127, 0.34), rgba(92, 184, 127, 0.34)), var(--page-bg);
}

.answer-choices.is-piece-selector .piece-glyph-answer.is-fail,
.answer-choices.is-piece-find-selector .piece-find-answer.is-fail {
  background: linear-gradient(rgba(232, 119, 97, 0.34), rgba(232, 119, 97, 0.34)), var(--page-bg);
}

.piece-glyph-name {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.2;
  text-align: center;
  text-transform: capitalize;
}

.piece-find-icon {
  width: min(100%, 48px);
  aspect-ratio: 1;
  object-fit: contain;
}

.answer-choices.is-build-selector {
  grid-template-columns: 1fr;
  gap: 12px;
}

.answer-choices.is-axis-selector .build-label {
  color: var(--text);
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 500;
}

.answer-choices.is-axis-selector .build-answer {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.34);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.1) inset,
    0 4px 14px rgba(0, 0, 0, 0.18);
  font-size: clamp(0.88rem, 2vmin, 1.05rem);
  font-weight: 500;
}

.answer-choices.is-axis-selector .build-answer:hover {
  border-color: rgba(253, 179, 23, 0.7);
  background: rgba(253, 179, 23, 0.14);
}

.answer-choices.is-axis-selector .build-answer:focus-visible {
  border-color: rgba(253, 179, 23, 0.85);
  background: rgba(253, 179, 23, 0.16);
}

.answer-choices.is-axis-selector .build-answer.is-selected {
  border-color: rgba(253, 179, 23, 0.9);
  background: rgba(253, 179, 23, 0.22);
}

.answer-choices.is-axis-selector .build-answer.is-selected:hover {
  border-color: rgba(253, 179, 23, 0.9);
  background: rgba(253, 179, 23, 0.28);
}

.answer-choices.is-axis-selector .build-answer.is-success {
  border-color: rgba(92, 184, 127, 0.95);
  background: rgba(92, 184, 127, 0.34);
}

.answer-choices.is-axis-selector .build-answer.is-fail {
  border-color: rgba(232, 119, 97, 0.95);
  background: rgba(232, 119, 97, 0.34);
}

.answer-choices.has-answer-input {
  align-items: stretch;
}

.answer-input-form {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
}

.notation-input-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 400;
}

.answer-input {
  width: 100%;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  letter-spacing: 0;
  text-align: center;
  text-transform: lowercase;
}

.answer-input:disabled {
  opacity: 0.55;
}

.notation-answer-input {
  text-transform: none;
}

.trainer-stage.has-side-panel-answers ~ .right-panel .notation-answer-input {
  height: auto;
  min-height: 58px;
  padding: 10px 14px;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1;
  text-align: left;
}

.answer-input::placeholder {
  color: rgba(232, 230, 223, 0.42);
}

.answer-input:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

.answer-choices.has-answer-input .answer-button {
  text-transform: none;
}

.answer-button {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  font-size: clamp(1rem, 2.7vmin, 1.35rem);
  text-transform: lowercase;
  transition: border-color 140ms ease, background 140ms ease;
}

.answer-button:hover {
  border-color: rgba(253, 179, 23, 0.55);
  background: rgba(253, 179, 23, 0.08);
}

.answer-button.is-selected {
  border-color: rgba(253, 179, 23, 0.9);
  background: rgba(253, 179, 23, 0.22);
}

.answer-button.is-success {
  border-color: rgba(92, 184, 127, 0.95);
  background: rgba(92, 184, 127, 0.34);
}

.answer-button.is-fail {
  border-color: rgba(232, 119, 97, 0.95);
  background: rgba(232, 119, 97, 0.34);
}

.color-answer {
  aspect-ratio: 2.35;
  min-height: 76px;
  border-color: rgba(255, 255, 255, 0.2);
  font-size: clamp(1rem, 2.2vmin, 1.25rem);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 14px 28px rgba(0, 0, 0, 0.18);
}

.color-answer.is-light-square {
  background: var(--board-light);
  color: #1a2745;
}

.color-answer.is-dark-square {
  background: var(--board-dark);
  color: #ffffff;
}

.color-answer.is-success {
  border-color: rgba(92, 184, 127, 0.95);
  box-shadow:
    0 0 0 4px rgba(92, 184, 127, 0.28),
    0 14px 28px rgba(0, 0, 0, 0.18);
}

.color-answer.is-fail {
  border-color: rgba(232, 119, 97, 0.95);
  box-shadow:
    0 0 0 4px rgba(232, 119, 97, 0.28),
    0 14px 28px rgba(0, 0, 0, 0.18);
}

.build-preview {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.build-preview-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.build-preview-value {
  min-width: 0;
  color: var(--text);
  font-size: clamp(1.55rem, 4.5vmin, 2.35rem);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0;
}

.build-preview-value:empty::after {
  color: rgba(232, 230, 223, 0.34);
  content: "...";
}

.build-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.build-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.1;
}

.build-row.is-active .build-label {
  color: var(--accent);
  font-weight: 600;
}

.build-row.is-active .build-options .build-answer:not(.is-success):not(.is-fail) {
  border-color: rgba(253, 179, 23, 0.35);
}

.build-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  gap: var(--build-grid-gap);
}

.build-options.is-build-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.build-options.is-build-grid.is-build-lone {
  justify-content: start;
}

.build-options.is-build-grid.is-build-lone .build-answer {
  grid-column: 1;
  justify-self: start;
  width: 100%;
  max-width: var(--build-grid-button-size);
  aspect-ratio: auto;
}

@container answer-choices (min-width: 320px) {
  .build-options.is-build-grid {
    grid-template-columns: repeat(8, minmax(0, var(--build-grid-button-size)));
    justify-content: start;
  }
}

.build-answer,
.build-next {
  min-height: 42px;
  aspect-ratio: auto;
  padding: 0 8px;
  font-size: clamp(0.78rem, 1.8vmin, 0.96rem);
  line-height: 1.05;
  text-transform: none;
}

.build-next {
  width: 100%;
  min-height: 48px;
  font-weight: 400;
}

.tier-jump-control[hidden] {
  display: none;
}

.tier-jump-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.tier-jump-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tier-jump-select:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

.feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  min-height: 24px;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 400;
}

.feedback:empty {
  display: none;
}

.trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .feedback:empty {
  display: flex;
  visibility: hidden;
}

/* During a running speed test the right panel shows only the movement meta — the
   feedback counter and tier control are intentionally gone. Drop the now-empty
   container and the meta's leading margin so the meta sits flush at the top. */
.trainer-stage.has-running-speed-test ~ .right-panel .play-move-side {
  display: none;
}

.trainer-stage.has-running-speed-test ~ .right-panel .movement-meta {
  margin-top: 0;
}

.feedback.is-success {
  color: var(--success);
}

.feedback.is-fail {
  color: var(--fail);
}

.feedback.is-fail.is-speed-test-fail {
  display: grid;
  gap: 4px;
}

.feedback.has-speed-result {
  display: grid;
  align-items: stretch;
  gap: 8px;
  width: min(100%, 360px);
  color: var(--text);
}

.speed-result-summary {
  display: grid;
  gap: 2px;
}

.speed-result-label {
  color: var(--success);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.speed-result-time {
  color: var(--text);
  font-size: clamp(1.25rem, 3vw, 1.55rem);
  font-weight: 700;
  line-height: 1.05;
}

.speed-result-detail {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.2;
}

.speed-scale {
  display: grid;
  gap: 3px;
  width: 100%;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.feedback.has-speed-result .speed-scale {
  margin-bottom: 12px;
}

.speed-scale-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 8px;
  border-left: 4px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.speed-scale-item.is-current {
  border-color: var(--success);
  background: rgba(92, 184, 127, 0.2);
  color: var(--text);
}

.speed-scale-name {
  min-width: 0;
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.speed-scale-range {
  color: inherit;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
}

/* Below-Intermediate pass: recolor the summary to caution and highlight the scale's current
   (Novice) tier in amber rather than success green. */
.feedback.has-speed-result.is-below-pass .speed-result-label {
  color: var(--accent);
}

.feedback.has-speed-result.is-below-pass .speed-scale-item.is-current {
  border-color: var(--accent);
  background: rgba(253, 179, 23, 0.18);
}

.speed-result-gate {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: rgba(253, 179, 23, 0.12);
}

.speed-result-gate strong {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

.speed-result-gate span {
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.35;
}

.solution-link {
  border: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 400;
  text-decoration: underline;
  cursor: pointer;
}

.solution-link:focus-visible {
  outline: 3px solid rgba(253, 179, 23, 0.5);
  outline-offset: 3px;
}

/* ============================================================
   Responsive scaffolding — drawer elements are hidden on the
   desktop layout (>1100px) and only appear in the tablet/mobile
   media queries below. Desktop layout is intentionally untouched.
   ============================================================ */
.nav-scrim,
.drawer-head,
.drawer-dashboard,
.mode-group-title {
  display: none;
}

/* ============================================================
   Tablet + mobile (<= 1100px): single centered column with the
   board as the hero, and a unified off-canvas navigation drawer.
   ============================================================ */
@media (max-width: 1100px) {
  /* ---- Shell: stack everything in one centered column ---- */
  .app-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: clamp(14px, 2.6vw, 22px);
  }

  /* ---- Header: brand + hamburger only ---- */
  .site-header {
    position: relative;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin-bottom: 0;
  }

  .nav-toggle {
    display: inline-flex;
  }

  /* ---- Home page (no trainer side-panel) keeps a simple dropdown ---- */
  .app-shell:not(:has(.side-panel)) .site-nav-collapse {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 60;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  }

  .app-shell:not(:has(.side-panel)) .site-header.is-menu-open .site-nav-collapse {
    display: flex;
  }

  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-primary,
  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-secondary {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: 100%;
    overflow: visible;
    flex-wrap: nowrap;
  }

  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-secondary {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
  }

  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-divider {
    display: none;
  }

  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-link {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 1.05rem;
  }

  .app-shell:not(:has(.side-panel)) .site-nav-collapse .site-nav-link.is-active {
    background: rgba(253, 179, 23, 0.12);
  }

  /* ---- Trainer page: hide the desktop top nav (drawer replaces it) ---- */
  .app-shell:has(.side-panel) .site-nav-collapse {
    display: none;
  }

  /* ---- Scrim behind the drawer ---- */
  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(1, 7, 24, 0.62);
    opacity: 0;
    visibility: hidden;
    transition: opacity 220ms ease, visibility 220ms ease;
  }

  .app-shell.is-nav-open > .nav-scrim.nav-scrim {
    opacity: 1;
    visibility: visible;
  }

  /* ---- The side-panel becomes a left off-canvas drawer ---- */
  .app-shell:has(.side-panel) .side-panel {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(86vw, 360px);
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    padding: 18px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--panel-bg);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.55);
    transform: translateX(-100%);
    transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-shell.is-nav-open > .side-panel.side-panel {
    transform: none;
  }

  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .drawer-head-title {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--text);
    cursor: pointer;
  }

  .drawer-close:focus-visible {
    outline: 3px solid rgba(253, 179, 23, 0.45);
    outline-offset: 2px;
  }

  .drawer-close-x {
    position: relative;
    width: 18px;
    height: 18px;
  }

  .drawer-close-x::before,
  .drawer-close-x::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    margin-top: -1px;
    border-radius: 2px;
    background: currentColor;
  }

  .drawer-close-x::before {
    transform: rotate(45deg);
  }

  .drawer-close-x::after {
    transform: rotate(-45deg);
  }

  /* Drawer shows every category at once, each under its own title */
  .mode-nav {
    gap: 16px;
    width: 100%;
  }

  .mode-group {
    gap: 2px;
  }

  .mode-group.is-collapsed-group {
    display: grid;
  }

  .mode-group-title {
    display: block;
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .mode-nav-row {
    min-height: 48px;
    padding: 8px 0;
  }

  .mode-button {
    min-height: 36px;
    font-size: 0.95rem;
    text-align: left;
  }

  .drawer-dashboard {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding: 16px 2px 2px;
    color: var(--text);
    font-size: 1rem;
    text-decoration: none;
  }

  .drawer-dashboard .nav-icon {
    opacity: 0.85;
  }

  .drawer-dashboard:hover,
  .drawer-dashboard:focus-visible {
    color: var(--accent);
  }

  .drawer-dashboard.is-active {
    color: var(--accent);
  }

  /* Test Mode sits directly beneath Dashboard; Dashboard's margin-top:auto already pins the pair. */
  .drawer-test-mode {
    margin-top: 0;
    padding-top: 4px;
  }

  /* ---- Content column: prompt -> board -> answers, all centered ---- */
  .prompt-row,
  .board-wrap,
  .dashboard-page,
  .answer-area,
  .right-panel,
  .build-preview-panel,
  .game-panel {
    width: var(--cn-stage);
    max-width: 100%;
  }

  .board-wrap {
    margin-inline: auto;
  }

  /* Right-panel defaults to align-self:start (left) for the desktop grid; center
     it so side-panel-answer modes line up under the board in the flex column. */
  .right-panel {
    align-self: center;
  }

  .prompt-row {
    min-height: 0;
  }

  /* Minimap mode: minimap sits directly under the board, feedback after it.
     Align it to the left edge so it lines up with the feedback / speed-scale
     stack rather than centering in the column. */
  .minimap-panel {
    width: var(--mini-board-size);
    margin-inline: 0;
    justify-self: start;
  }

  .trainer-stage.has-minimap ~ .right-panel .answer-area {
    order: 1;
  }

  /* Restore answer-area as a box on narrow layouts; desktop uses display:contents. */
  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .answer-area {
    display: grid;
  }

  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .minimap-panel {
    grid-column: auto;
    grid-row: auto;
    order: 2;
  }

  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .play-move-side {
    grid-column: auto;
    grid-row: auto;
    order: 3;
  }

  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .restart-drill,
  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .next-drill {
    grid-column: auto;
    grid-row: auto;
    order: 0;
  }

  .trainer-stage.has-minimap:not(.has-side-panel-answers) ~ .right-panel .speed-test-button {
    grid-column: auto;
    grid-row: auto;
    order: 1;
  }

  .game-panel {
    height: auto;
    min-height: 260px;
  }

  /* No-board / large-prompt modes (e.g. Name the Piece) */
  .trainer-stage.has-no-board.has-large-prompt .prompt-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: var(--cn-stage);
  }

  .trainer-stage.has-no-board.has-large-prompt .prompt-box {
    width: 100%;
    justify-self: stretch;
  }

  .trainer-stage.has-no-board.has-large-prompt ~ .right-panel .answer-area {
    width: var(--cn-stage);
    margin-top: 0;
    align-self: center;
  }

  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .answer-area {
    grid-column: auto;
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
    width: var(--cn-stage);
    position: static;
    min-height: 92px;
  }

  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .answer-choices {
    /* Back in the normal flow at full width on narrow screens. */
    position: static;
    width: 100%;
  }

  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .answer-choices,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .instruction-box,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .keyboard-box,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .play-move-side,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .restart-drill,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .speed-test-button,
  .trainer-stage.has-no-board.has-large-prompt:is(.has-piece-letter-prompt, .has-piece-glyph-prompt)
    ~ .right-panel
    .next-drill {
    /* Single-column stack on narrow screens: undo the desktop two-column placement. */
    grid-column: auto;
    grid-row: auto;
    margin-top: 0;
    align-self: auto;
  }

  /* Piece selectors stay a tidy 5-up grid that fills the column */
  .answer-choices {
    gap: 8px;
  }

  .answer-choices.is-piece-selector,
  .answer-choices.is-piece-find-selector {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .answer-choices.is-piece-selector .piece-glyph-answer,
  .answer-choices.is-piece-find-selector .piece-find-answer {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
}

/* Tablet: larger board, generous column */
@media (max-width: 1100px) and (min-width: 761px) {
  :root {
    --cn-stage: min(74vw, 60vh);
  }
}

/* Mobile: board fills the width */
@media (max-width: 760px) {
  :root {
    --cn-stage: min(92vw, 60vh);
  }

  .answer-area {
    min-height: 0;
  }
}

.home-hero {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(640px, 100%);
  margin: clamp(20px, 6vh, 80px) auto 0;
  text-align: center;
}

.home-headline {
  margin: 0;
  color: var(--text);
  font-size: clamp(2rem, 4.4vw, 3.1rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.005em;
}

.home-subheadline {
  margin: 0;
  color: var(--accent);
  font-size: clamp(1.05rem, 1.8vw, 1.3rem);
  font-weight: 500;
  line-height: 1.35;
}

.home-body {
  margin: 6px 0 0;
  max-width: 56ch;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.55;
}

.home-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  padding: 17px 44px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--page-bg);
  font-size: clamp(1.1rem, 1.6vw, 1.3rem);
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: filter 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.home-cta:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(253, 179, 23, 0.3);
}

.home-cta:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 3px;
}

.site-footer {
  border-top: 1px solid var(--line);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 28px;
  width: min(var(--app-max-width), 100%);
  margin: 0 auto;
  padding: 20px var(--page-inline-padding);
}

.site-footer-copyright {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.site-footer-feedback {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
  text-decoration: none;
  transition: color 140ms ease;
}

.site-footer-feedback:hover,
.site-footer-feedback:focus-visible {
  color: var(--text);
}

.site-footer-feedback:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 4px;
}

.site-footer-feedback-icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  background-color: currentColor;
  -webkit-mask: var(--icon-src) center / contain no-repeat;
  mask: var(--icon-src) center / contain no-repeat;
  flex-shrink: 0;
}

@media (max-width: 760px) {
  .site-footer-inner {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

/* ---- Suggestion Box dialog ---- */
.feedback-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: 440px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  overflow: visible;
}

.feedback-dialog::backdrop {
  background: rgba(0, 8, 28, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

@keyframes feedbackPop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.feedback-dialog .feedback {
  position: relative;
  display: grid;
  gap: 18px;
  padding: 26px 26px 24px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 140px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  animation: feedbackPop 160ms ease;
}

.feedback-view {
  display: grid;
  gap: 18px;
}

/* A class with `display` beats the UA's [hidden] rule, so restore it for the inactive view. */
.feedback-view[hidden] {
  display: none;
}

.feedback-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.feedback-close:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.feedback-close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 22;
  stroke-linecap: round;
}

.feedback-close:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.feedback-head {
  display: grid;
  gap: 9px;
  padding-right: 26px;
}

.feedback-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-bottom: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(253, 179, 23, 0.12);
}

.feedback-badge-icon {
  display: block;
  width: 22px;
  height: 22px;
  background-color: var(--accent);
  -webkit-mask: var(--icon-src) center / contain no-repeat;
  mask: var(--icon-src) center / contain no-repeat;
}

.feedback-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.feedback-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.feedback-label {
  display: block;
  margin-bottom: 8px;
  padding: 0;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.feedback-optional {
  color: var(--muted);
  font-weight: 400;
}

.feedback-textarea,
.feedback-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  box-sizing: border-box;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.feedback-textarea {
  padding: 11px 13px;
  min-height: 112px;
  resize: vertical;
}

.feedback-input {
  padding: 10px 13px;
}

.feedback-textarea::placeholder,
.feedback-input::placeholder {
  color: rgba(142, 152, 173, 0.72);
}

.feedback-textarea:hover,
.feedback-input:hover {
  border-color: var(--line-strong);
}

.feedback-textarea:focus,
.feedback-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(253, 179, 23, 0.16);
}

.feedback-count {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.feedback-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

/* Honeypot: present and fillable, but off-screen rather than display:none (some bots skip the latter). */
.feedback-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.feedback-status {
  margin: 0;
  color: var(--fail);
  font-size: 0.82rem;
  line-height: 1.45;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
}

.feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border-radius: 9px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 140ms ease, transform 140ms ease, background 140ms ease,
    border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.feedback-btn-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--page-bg);
}

.feedback-btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(253, 179, 23, 0.28);
}

.feedback-btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.feedback-btn-ghost:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--text);
}

.feedback-btn:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.feedback-btn:disabled {
  opacity: 0.65;
  cursor: default;
  pointer-events: none;
}

.feedback-success {
  justify-items: center;
  gap: 14px;
  padding: 10px 6px 6px;
  text-align: center;
}

.feedback-success-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(92, 184, 127, 0.16);
  color: var(--success);
}

.feedback-success-mark svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 24;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feedback-success .feedback-btn {
  margin-top: 4px;
}

@media (max-width: 760px) {
  .feedback-dialog .feedback {
    padding: 22px 18px 20px;
    border-radius: 14px;
  }

  .feedback-actions {
    flex-direction: column-reverse;
  }

  .feedback-btn {
    width: 100%;
  }
}
