/* Blackjack Basic Strategy: one stylesheet for the Blazor app and the static pages.
   Tokens first, then base, layout, trainer, chart, ads, utilities. */

@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin-wght.woff2") format("woff2");
}

:root {
  /* Surfaces */
  --felt: #15423a;
  --felt-deep: #0d2d28;
  --felt-edge: #1d5449;
  --paper: #fbf8f1;
  --paper-2: #efe9dc;
  --ink: #17201f;
  --ink-2: #4b5a57;
  --on-felt: #f0ece2;
  --on-felt-2: #afc1bb;
  --line-felt: rgba(255, 255, 255, 0.14);
  --line-paper: #d8d0bf;
  --bar: #0c100f;
  --bar-edge: #1f2a27;

  /* The four plays. These are the only saturated colors on the site. */
  --hit: #8ec5ff;
  --stand: #ff9b91;
  --double: #ffd76a;
  --split: #9fe6a8;

  /* Verdicts */
  --ok: #2f9e5b;
  --bad: #d2493f;

  /* Type */
  --font: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-0: 0.875rem;
  --fs-1: 1rem;
  --fs-2: 1.25rem;
  --fs-3: 1.6rem;
  --fs-4: 2.2rem;
  --fs-5: 3rem;
  --lh: 1.5;

  /* Shape and space */
  --r-sm: 6px;
  --r-md: 12px;
  --r-card: 8px;
  --gap: 1rem;
  --page-max: 72rem;
  --measure: 66ch;

  --shadow-card: 0 10px 24px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font);
  font-size: 100%;
  line-height: var(--lh);
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
  background: var(--bar);
}

body {
  margin: 0;
  color: var(--on-felt);
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, var(--felt-edge) 0%, var(--felt) 45%, var(--felt-deep) 100%) fixed,
    var(--felt-deep);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* The Blazor host wraps header, main and footer in #app; let it fill the viewport so the footer sits at the bottom. */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em;
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-4);
}

/* Blazor moves focus to the h1 on navigation for screen readers; no ring needed for a non-interactive element. */
h1:focus {
  outline: none;
}

h2 {
  font-size: var(--fs-3);
}

h3 {
  font-size: var(--fs-2);
}

p,
ul,
ol {
  margin: 0 0 1em;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.35);
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 3px solid var(--double);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
}

kbd {
  font: inherit;
  font-size: 0.8em;
  padding: 0.05em 0.4em;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: 0.75;
}

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

/* ---------- Site frame ---------- */

.site-header {
  background: var(--bar);
  border-bottom: 1px solid var(--bar-edge);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  text-decoration: none;
  font-weight: 800;
  font-size: var(--fs-2);
  letter-spacing: -0.02em;
}

.brand .suit {
  font-size: 1.1em;
  color: #fff;
}

.site-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.site-nav a {
  text-decoration: none;
  padding: 0.45rem 0.75rem;
  border-radius: var(--r-sm);
  color: var(--on-felt-2);
}

.site-nav a:hover {
  color: var(--on-felt);
  background: rgba(255, 255, 255, 0.06);
}

.site-nav a.active,
.site-nav a[aria-current="page"] {
  color: var(--on-felt);
  background: rgba(255, 255, 255, 0.1);
}

.site-nav a.nav-donate {
  color: var(--double);
}

.site-nav a.nav-donate:hover {
  color: var(--double);
}

.wrap {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 1rem;
}

.site-main {
  flex: 1;
  padding: 1.5rem 0 2rem;
}

.site-footer {
  margin-top: auto;
  background: var(--bar);
  border-top: 1px solid var(--bar-edge);
  color: var(--on-felt-2);
  font-size: var(--fs-1);
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  padding: 1.1rem 1rem;
}

.site-footer a {
  text-decoration: none;
  color: var(--on-felt-2);
}

.site-footer a:hover {
  color: var(--on-felt);
}

/* ---------- Content pages (chart, how it works, privacy) ---------- */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 1rem;
}

.page header {
  margin-bottom: 1.5rem;
}

.page .lede {
  font-size: var(--fs-2);
  color: var(--on-felt-2);
  max-width: var(--measure);
}

.page section {
  max-width: var(--measure);
  margin-bottom: 2rem;
}

.page section h2 {
  margin-top: 0;
}

.page li {
  margin-bottom: 0.35em;
}

/* ---------- Trainer ---------- */

.trainer {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
  align-items: start;
}

.table {
  display: grid;
  gap: 1.25rem;
}

.seat {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  text-align: center;
}

.seat-label {
  color: var(--on-felt-2);
  font-size: var(--fs-0);
}

.seat-label strong {
  color: var(--on-felt);
  font-weight: 700;
}

.cards {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.card-img {
  width: clamp(84px, 24vw, 132px);
  height: auto;
  aspect-ratio: 500 / 726;
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  background: #fff;
  display: block;
}

.card-img.is-back {
  background: transparent;
}

.hand-name {
  font-size: var(--fs-2);
  font-weight: 700;
  min-height: 1.5em;
}

/* Action buttons: colored by play, so they double as the chart legend. */

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: var(--r-md);
  padding: 0.9rem 0.75rem;
  font-weight: 700;
  font-size: var(--fs-1);
  color: var(--ink);
  background: var(--paper);
  transition: transform 80ms ease, filter 120ms ease;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  filter: none;
  transform: none;
}

.btn kbd {
  opacity: 0.55;
  border-color: rgba(0, 0, 0, 0.35);
}

.btn.act-hit { background: var(--hit); }
.btn.act-stand { background: var(--stand); }
.btn.act-double { background: var(--double); }
.btn.act-split { background: var(--split); }

.btn-deal {
  background: var(--paper);
  width: 100%;
  padding: 1rem;
  font-size: var(--fs-2);
}

.btn-quiet {
  background: transparent;
  color: var(--on-felt-2);
  border: 1px solid var(--line-felt);
  padding: 0.5rem 0.8rem;
  font-weight: 600;
  font-size: var(--fs-0);
}

.btn-quiet:hover {
  color: var(--on-felt);
  filter: none;
}

/* Verdict panel: paper with a colored edge; the chart cell is the only strongly colored thing. */

.verdict {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 1rem 1.1rem;
  border-left: 8px solid var(--ok);
  display: grid;
  gap: 0.5rem;
}

.verdict.is-wrong {
  border-left-color: var(--bad);
}

.verdict h2 {
  font-size: var(--fs-2);
  margin: 0;
}

.verdict p {
  margin: 0;
  color: var(--ink-2);
}

.verdict .chip {
  margin-right: 0.3rem;
}

.verdict-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
}

.verdict .btn-quiet {
  color: var(--ink-2);
  border-color: var(--line-paper);
}

.verdict .btn-quiet:hover {
  color: var(--ink);
}

.verdict .chart {
  margin-top: 0.5rem;
}

/* Countdown to the next hand when auto-deal is on. The bar empties over the same duration as the delay. */
.auto-deal-bar {
  height: 0.35rem;
  border-radius: 999px;
  background: var(--paper-2);
  overflow: hidden;
}

.auto-deal-bar i {
  display: block;
  height: 100%;
  background: var(--ok);
  transform-origin: left center;
  animation: auto-deal-drain linear forwards;
}

@keyframes auto-deal-drain {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.verdict table.chart caption {
  color: var(--ink-2);
  font-size: var(--fs-1);
}

.welcome {
  display: grid;
  gap: 1rem;
  max-width: var(--measure);
}

.welcome p {
  color: var(--on-felt-2);
  margin: 0;
}

.welcome ol {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--on-felt-2);
}

.welcome .btn-deal {
  margin-top: 1.25rem;
}

/* Session panel */

.session {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.stat {
  border: 1px solid var(--line-felt);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.6rem;
}

.stat b {
  display: block;
  font-size: var(--fs-3);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat span {
  color: var(--on-felt-2);
  font-size: var(--fs-0);
}

.accuracy-bars {
  display: grid;
  gap: 0.35rem;
  font-size: var(--fs-0);
}

.accuracy-bars > div {
  display: grid;
  grid-template-columns: 3.5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.accuracy-bars .bar {
  height: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.accuracy-bars .bar i {
  display: block;
  height: 100%;
  background: var(--on-felt);
  border-radius: 999px;
}

.accuracy-bars .pct {
  text-align: right;
  color: var(--on-felt-2);
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 0.3rem;
  font-size: var(--fs-0);
  color: var(--on-felt-2);
}

.field select {
  font: inherit;
  font-size: var(--fs-1);
  color: var(--on-felt);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line-felt);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.6rem;
}

.field label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--on-felt);
  font-size: var(--fs-1);
}

.misses {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
  font-size: var(--fs-0);
}

.misses li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid var(--line-felt);
  padding-bottom: 0.3rem;
}

.misses li span:last-child {
  color: var(--on-felt-2);
  white-space: nowrap;
}

.session h2 {
  font-size: var(--fs-1);
  color: var(--on-felt-2);
  font-weight: 600;
  margin: 0;
}

.session-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- Chart ---------- */

.chart-legend {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.chart-legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  height: 1.7em;
  border-radius: 5px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
}

.chip.act-hit { background: var(--hit); }
.chip.act-stand { background: var(--stand); }
.chip.act-double { background: var(--double); }
.chip.act-split { background: var(--split); }

.chart-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
  margin-bottom: 2rem;
}

table.chart {
  border-collapse: separate;
  border-spacing: 3px;
  width: 100%;
  max-width: 40rem;
  color: var(--ink);
  background: var(--paper);
  border-radius: var(--r-md);
  padding: 0.5rem;
  font-variant-numeric: tabular-nums;
}

table.chart caption {
  caption-side: top;
  text-align: left;
  color: var(--on-felt);
  font-weight: 700;
  font-size: var(--fs-2);
  padding: 0 0 0.5rem 0.25rem;
}

table.chart th,
table.chart td {
  text-align: center;
  padding: 0.35rem 0.2rem;
  font-size: var(--fs-0);
  border-radius: 4px;
}

table.chart thead th {
  font-weight: 700;
  color: var(--ink-2);
}

table.chart tbody th {
  text-align: left;
  font-weight: 700;
  white-space: nowrap;
  padding-left: 0.4rem;
  padding-right: 0.6rem;
  color: var(--ink);
}

table.chart .chart-corner {
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--ink-2);
  padding-left: 0.4rem;
}

table.chart .chart-corner span {
  display: block;
}

table.chart td {
  font-weight: 800;
}

table.chart td abbr {
  text-decoration: none;
}

table.chart td.act-hit { background: var(--hit); }
table.chart td.act-stand { background: var(--stand); }
table.chart td.act-double { background: var(--double); }
table.chart td.act-split { background: var(--split); }

/* Highlighted situation: dim the rest, ring the cell. */

table.chart.has-focus td:not(.is-cell),
table.chart.has-focus tbody th {
  opacity: 0.45;
}

table.chart.has-focus tr.is-row th,
table.chart.has-focus tr.is-row td,
table.chart.has-focus thead th.is-col {
  opacity: 1;
}

table.chart td.is-cell {
  outline: 3px solid var(--ink);
  outline-offset: -1px;
  transform: scale(1.12);
  position: relative;
  z-index: 1;
}

table.chart thead th.is-col {
  background: var(--paper-2);
}

table.chart tr.is-row th {
  background: var(--paper-2);
}

.chart-compact {
  max-width: 32rem;
}

.page .chart-image {
  max-width: none;
}

.chart-image figure {
  margin: 0;
}

.chart-image img {
  display: block;
  width: 100%;
  max-width: 60rem;
  height: auto;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
}

.chart-image figcaption {
  margin-top: 0.6rem;
  color: var(--on-felt-2);
  font-size: var(--fs-0);
}

/* ---------- Lightbox (chart image) ---------- */

.chart-image a.chart-lightbox {
  display: block;
  cursor: zoom-in;
}

dialog.lightbox {
  border: 0;
  padding: 0;
  margin: auto;
  width: min(96vw, 1920px);
  max-width: 96vw;
  max-height: 96vh;
  background: var(--bar);
  color: var(--on-felt);
  border-radius: var(--r-md);
  overflow: auto;
}

dialog.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--bar-edge);
  position: sticky;
  top: 0;
  background: var(--bar);
}

.lightbox-title {
  font-weight: 700;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.lightbox-actions a {
  text-decoration: none;
  color: var(--double);
  font-weight: 600;
  font-size: var(--fs-0);
}

.lightbox-close {
  border: 1px solid var(--bar-edge);
  background: transparent;
  color: var(--on-felt);
  border-radius: var(--r-sm);
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1rem;
}

.lightbox-img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- Ads ---------- */

/* Each slot reserves its height so ads never shift the layout. Placeholders show until a publisher id is configured. */

.ad-slot {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: var(--ad-h, 100px);
  border-radius: var(--r-sm);
}

/* Until a publisher id is configured the slots are hidden entirely; once ads are on they reserve their height. */
.ad-slot[data-enabled="false"] {
  display: none;
}

.ad-slot.is-hidden {
  display: none;
}

.ad-bottom {
  --ad-h: 100px;
  margin: 2rem auto 0;
  max-width: var(--page-max);
  padding: 0 1rem;
}

.ad-side {
  --ad-h: 250px;
  max-width: 300px;
}

/* ---------- Blazor loading and errors ---------- */

.loading-progress {
  position: relative;
  display: block;
  width: 6rem;
  height: 6rem;
  margin: 3rem auto 1rem;
}

.loading-progress circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 0.5rem;
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
}

.loading-progress circle:last-child {
  stroke: var(--double);
  stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
  transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
  text-align: center;
  font-weight: 600;
  color: var(--on-felt-2);
}

.loading-progress-text::after {
  content: var(--blazor-load-percentage-text, "Loading the trainer");
}

#blazor-error-ui {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding: 0.75rem 1.25rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}

/* ---------- Responsive ---------- */

@media (min-width: 640px) {
  :root {
    --fs-4: 2.6rem;
  }

  .site-header .wrap {
    padding: 1rem;
  }
}

@media (min-width: 960px) {
  .trainer {
    grid-template-columns: minmax(0, 1fr) 20rem;
    gap: 2.5rem;
  }

  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-grid .chart-hard {
    grid-row: span 2;
  }
}

@media (min-width: 1280px) {
  .chart-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chart-grid .chart-hard {
    grid-row: auto;
  }
}

@media (max-width: 480px) {
  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .btn kbd {
    display: none;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }

  table.chart td.is-cell {
    transform: none;
  }

  .auto-deal-bar i {
    animation: none;
    transform: scaleX(1);
  }
}
