:root {
  --fog: #E7ECEF;
  --channel: #17313D;
  --sea: #2B7A87;
  --silt: #5D6C74;
  --tide: #B8C7CF;
  --surface: #F5F8F9;
  --felt-1: #1E7A47;
  --felt-2: #0B4A28;
  --ok: #1F8A4C;
  --bad: #C0392B;
  --gold: #F2C94C;
  --c-hit: #C2453F;
  --c-stand: #C98A12;
  --c-double: #2E8B4F;
  --c-double-s: #1B6E66;
  --c-split: #2F64B8;
  --card-w: 78px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fog: #0F1A21;
    --channel: #E3EAEE;
    --sea: #62B4C0;
    --silt: #95A4AC;
    --tide: #2A3D48;
    --surface: #16242D;
    --ok: #4CC27E;
    --bad: #EF6F61;
  }
}
@media (max-width: 640px) {
  :root { --card-w: 58px; }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--fog);
  color: var(--channel);
  font-family: "Work Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
}
h1, h2, h3 { font-family: "Gloock", Georgia, serif; font-weight: 400; line-height: 1.15; }
a { color: var(--sea); }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--fog);
  border-bottom: 1px solid var(--tide);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 0;
}
.title-row { max-width: 72rem; margin: 0 auto; display: flex; align-items: baseline; gap: 14px; }
.home { font-family: "Gloock", Georgia, serif; color: var(--silt); text-decoration: none; font-size: 1.1rem; }
.home:hover { color: var(--sea); }
.top h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
.tabs {
  max-width: 72rem;
  margin: 8px auto 0;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none;
  padding: 8px 12px 10px;
  color: var(--silt);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--channel); }
.tabs a[aria-current="page"] { color: var(--channel); border-bottom-color: var(--sea); }

main { max-width: 72rem; margin: 0 auto; padding: 24px 16px 48px; }

/* Buttons and inputs */
button, .button, select, input {
  font: inherit;
  color: inherit;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--tide);
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  touch-action: manipulation;
}
button:hover:not(:disabled), .button:hover { border-color: var(--sea); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--sea); border-color: var(--sea); color: #fff; }
.button.subtle { min-height: 36px; font-size: 0.95rem; }
kbd {
  font: 0.75em/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0.75;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 2px 4px;
}
@media (hover: none) { kbd { display: none; } }
input[type="text"], input[inputmode], select {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--tide);
  background: var(--surface);
}
input[inputmode] { width: 7rem; font-size: 1.1rem; text-align: center; }
label { display: flex; align-items: center; gap: 10px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--sea); }
input[type="range"] { flex: 1; accent-color: var(--sea); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.actions.left { justify-content: flex-start; }
.act { color: #fff; border: none; min-width: 7.5rem; }
.act.hit { background: var(--c-hit); }
.act.stand { background: var(--c-stand); }
.act.double { background: var(--c-double); }
.act.split { background: var(--c-split); }
@media (max-width: 640px) {
  .actions .act { flex: 1 1 40%; min-width: 0; }
}

/* Layout */
.layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr) 300px; } }
.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.narrow { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.prose { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.lesson, .note-box, .stats {
  background: var(--surface);
  border: 1px solid var(--tide);
  border-radius: 14px;
  padding: 18px 20px;
}
.lesson { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.lesson h2 { font-size: 1.6rem; }
.lesson ul { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 4px; }
.formula { font-weight: 600; font-size: 1.1rem; }
.rules { color: var(--silt); font-size: 0.85rem; }

.hilo { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; }
.hilo div { display: flex; flex-direction: column; align-items: center; padding: 10px; border-radius: 10px; text-align: center; }
.hilo span { font-weight: 600; }
.hilo b { font-size: 1.5rem; }
.hilo .plus { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.hilo .zero { background: color-mix(in srgb, var(--silt) 15%, transparent); color: var(--silt); }
.hilo .minus { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.hilo span { color: var(--channel); }

/* Felt and cards */
.felt {
  background: radial-gradient(ellipse at center, var(--felt-1), var(--felt-2) 75%);
  border-radius: 20px;
  padding: 24px 12px;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 340px;
  justify-content: center;
}
.felt .label { font-weight: 600; opacity: 0.9; }
.felt .status { color: var(--gold); font-weight: 500; min-height: 1.5em; text-align: center; }
.cards { display: flex; justify-content: center; }
.cards .card + .card { margin-left: calc(var(--card-w) * -0.45); }
.card {
  position: relative;
  flex: none;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border-radius: calc(var(--card-w) * 0.1);
  background: #fff;
  color: #111;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 0, 0, 0.15);
}
.card.red { color: #C21A27; }
.card .corner {
  position: absolute;
  top: 5%;
  left: 8%;
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.22);
  line-height: 1;
  text-align: center;
}
.card .corner small { display: block; font-size: 0.85em; }
.card .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.48);
  padding-top: 12%;
}
.card.down {
  background: repeating-linear-gradient(45deg, #2A4A8F 0 6px, #3A2470 6px 12px);
  border: 3px solid #fff;
}
.card.big { --card-w: 120px; }
.card.small { --card-w: 46px; }
.slot {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: calc(var(--card-w) * 0.1);
}
.hands { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.hand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; border-radius: 12px; border: 3px solid transparent; }
.hand.active { border-color: var(--gold); }
.hand .meta { font-size: 0.95rem; }
.badge { padding: 2px 10px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; color: #fff; }
.badge.win { background: var(--c-double); }
.badge.lose { background: var(--c-hit); }
.badge.push { background: #6B7780; }

/* Feedback */
.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--tide);
  border-left: 5px solid var(--ok);
}
.banner.bad { border-left-color: var(--bad); }
.banner .icon { font-size: 1.3rem; line-height: 1.2; color: var(--ok); font-weight: 700; }
.banner.bad .icon { color: var(--bad); }
.banner strong { display: block; }
.banner p { color: var(--silt); }
.log { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.muted { color: var(--silt); }

.stats { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; }
.stats div { display: flex; justify-content: space-between; gap: 10px; }
.stats dt { color: var(--silt); }
.stats dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.stats hr { border: none; border-top: 1px solid var(--tide); margin: 4px 0; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.center { justify-content: center; }
.spacer { flex: 1; }
.bet { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: center; }
.round { width: 44px; padding: 0; font-size: 1.3rem; }

/* Chart */
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0 20px; font-size: 0.95rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .cell { width: 28px; height: 24px; font-size: 0.8rem; }
.chart-block { margin-bottom: 28px; }
.chart-block h2 { font-size: 1.6rem; margin-bottom: 10px; }
.chart-scroll { overflow-x: auto; }
table.chart { border-collapse: separate; border-spacing: 2px; }
table.chart th { font-weight: 600; padding: 4px; min-width: 2.6rem; }
table.chart th[scope="row"] { text-align: left; padding-right: 10px; white-space: nowrap; }
table.chart caption { text-align: left; color: var(--silt); font-size: 0.85rem; padding-bottom: 4px; }
.cell {
  display: inline-grid;
  place-items: center;
  font-style: normal;
  font-weight: 700;
  color: #fff;
  border-radius: 4px;
}
td.cell { display: table-cell; text-align: center; height: 32px; min-width: 2.6rem; }
.cell.H { background: var(--c-hit); }
.cell.S { background: var(--c-stand); }
.cell.D { background: var(--c-double); }
.cell.Ds { background: var(--c-double-s); }
.cell.P { background: var(--c-split); }
.note-box h3 { font-size: 1.3rem; margin-bottom: 4px; }

/* Drills */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--tide); border-radius: 12px; padding: 14px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tile .big-num { font-family: "Gloock", Georgia, serif; font-size: clamp(2rem, 7vw, 2.8rem); line-height: 1; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tiles .tile:last-child { grid-column: span 2; }
}
.settings { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--tide); border-radius: 14px; padding: 16px 18px; }
.settings label { justify-content: space-between; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--tide); border-radius: 999px; overflow: hidden; }
.seg button { border: none; border-radius: 0; min-width: 48px; background: transparent; }
.seg button[aria-pressed="true"] { background: var(--sea); color: #fff; }
.review { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px; }
.review figure { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.review .up { color: var(--ok); }
.review .down { color: var(--bad); }
.progress { height: 6px; border-radius: 3px; background: var(--tide); overflow: hidden; }
.progress div { height: 100%; background: var(--sea); transition: width 0.2s; }
.flash { min-height: 220px; display: flex; gap: 14px; justify-content: center; align-items: center; }
.stage { scroll-margin-top: 120px; }
@media (max-width: 640px) {
  .felt { min-height: 260px; gap: 14px; padding: 18px 10px; }
}

/* Disclaimer and problem-gambling help, shown under every section */
.disclaimer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 20px 16px 32px;
  border-top: 1px solid var(--tide);
  color: var(--silt);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.disclaimer p { max-width: 760px; }
.disclaimer strong { color: var(--channel); font-weight: 600; }
.disclaimer a { white-space: nowrap; font-weight: 500; }
