:root {
  /* The colour themes. Red is the default; the game sets data-theme on <html>
     (green or blue override these) and reads the same variables for the canvas. */
  --theme-felt: #6e1a2c;
  --theme-light: #8c2639;
  --theme-dark: #4a0f1c;
  --theme-deep: #3d0d18;
  --theme-edge: #7f2336;
  --theme-meta: #4a0f1c;
  --theme-primary: #C41E3A;
  --theme-primary-hover: #D62A47;
  --theme-back-light: #d8344f;
  --theme-back-dark: #8f1229;
  --theme-accent: #EE6A80;
}
:root[data-theme="green"] {
  --theme-felt: #0b5a39;
  --theme-light: #127048;
  --theme-dark: #074029;
  --theme-deep: #0a3d27;
  --theme-edge: #05693A;
  --theme-meta: #074029;
  --theme-primary: #1C8B53;
  --theme-primary-hover: #25A363;
  --theme-back-light: #2FA866;
  --theme-back-dark: #0F5C36;
  --theme-accent: #6FD3A0;
}
:root[data-theme="blue"] {
  --theme-felt: #0d4a7a;
  --theme-light: #16609a;
  --theme-dark: #082f52;
  --theme-deep: #0a2f4d;
  --theme-edge: #0a5c94;
  --theme-meta: #082f52;
  --theme-primary: #2377C4;
  --theme-primary-hover: #3490DD;
  --theme-back-light: #3E91D8;
  --theme-back-dark: #154F85;
  --theme-accent: #7FBCF0;
}

/* Play page: settings preview card and the full-screen canvas stage. */

.play {
  padding-top: 1rem;
  padding-bottom: 3rem;
  display: grid;
  gap: 1.5rem;
}

/* Narrower than the navbar on a desktop, the same width as the personality quiz. */
.play.container {
  width: min(100% - 2rem, 56rem);
}

.play-card,
.play-rules {
  background: var(--color-surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
}

.play-card {
  text-align: center;
  padding-top: 1.25rem;
}

.play-eyebrow {
  margin: 0;
  color: var(--color-primary);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.play-title {
  font-family: var(--font-heading);
  color: var(--color-primary);
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 400;
  margin: 0.25rem 0 0.5rem;
}

.play-lead {
  margin: 0 0 1.5rem;
  color: var(--color-text-muted);
}

/* The hero: the cat, then the pitch and the form, in one centered column. */
.play-hero {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 1.25rem;
  padding-top: 1.75rem;
}

/* The game's table: its felt, lighter in the middle and darker at the edges,
   with light text and gold accents on it, as in the game. */
.play-hero {
  background: radial-gradient(circle at 50% 45%, var(--theme-light) 0%, var(--theme-dark) 85%);
  color: #FFF8F0;
}

.play-hero .play-eyebrow { color: #ffd27a; }

.play-hero .play-title { color: #FFF8F0; }

.play-hero .play-lead,
.play-hero .play-note,
.play-hero .play-mode-note { color: rgba(255, 248, 240, 0.82); }

.play-hero .play-perks li {
  background: rgba(255, 255, 255, 0.12);
  color: #FFF8F0;
}

.play-hero .play-perks li::before { background: #ffd27a; }

.play-hero .play-field legend { color: #FFF8F0; }

.play-hero .play-option span {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.18);
  color: #FFF8F0;
}

.play-hero .play-option small { color: rgba(255, 248, 240, 0.75); }

.play-hero .play-option:hover span { border-color: rgba(255, 210, 122, 0.6); }

.play-hero .play-option input:checked + span,
html.play-mode-payout:not(.play-settled) .play-hero .play-option input[value="payout"] + span {
  border-color: #F4A020;
  background: rgba(244, 160, 32, 0.16);
}

html.play-mode-payout:not(.play-settled) .play-hero .play-option input[value="practice"] + span {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.18);
}

/* Red on red would hide the way in: Start and Resume are gold here. */
.play-hero #play-start,
.play-hero #play-resume.btn-primary,
html.play-has-save:not(.play-settled) .play-hero #play-resume {
  background: linear-gradient(180deg, #ffd56b, #f4a020);
  color: #3a2200;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.play-hero #play-start:hover,
.play-hero #play-resume.btn-primary:hover {
  background: linear-gradient(180deg, #ffe08a, #f7ae3a);
  color: #3a2200;
}

.play-hero .btn-white {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.play-hero > * { position: relative; }

.play-cat {
  display: block;
  width: clamp(84px, 9vw, 120px);
  height: auto;
  margin: 0 auto;
  animation: play-float 4s ease-in-out infinite;
  -webkit-user-drag: none;
  user-select: none;
}

@keyframes play-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* A tile: an ivory face on a green back, like the game's. The SVGs are
   the faces alone. */
.play-tile {
  display: block;
  box-sizing: border-box;
  aspect-ratio: 3 / 4;
  border-radius: 7px;
  background: linear-gradient(180deg, #fffdf7 0%, #f3ead8 100%);
  padding: 6px 5px;
  flex: none;
}

.play-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
  user-select: none;
}

@keyframes play-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -6px; }
}

.play-perks {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.play-perks li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: rgba(var(--color-secondary-rgb), 0.16);
  color: var(--color-text);
  font-size: 0.88rem;
  font-weight: 600;
}

.play-perks li::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-primary);
}

/* The way in: a little bigger, with a slow shine across it. */
#play-start,
#play-resume {
  position: relative;
  overflow: hidden;
  padding-block: 1rem;
  font-size: 1.15rem;
}

/* Learn to play sits on the left, the way in on the right. */
#play-learn { order: -1; }

#play-start::after,
html.play-has-save #play-resume::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: play-shine 3.5s ease-in-out 1.5s infinite;
  pointer-events: none;
}

@keyframes play-shine {
  0%, 60% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}

.play-note {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.play-section-title {
  font-family: var(--font-heading);
  font-weight: 400;
  color: var(--color-primary);
  text-align: center;
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin: 0 0 1rem;
}

.play-why-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
}

.play-why-card,
.play-bot {
  background: var(--color-surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 1.25rem;
}

.play-why-card h3,
.play-bot h3 {
  margin: 0.6rem 0 0.35rem;
  font-size: 1.05rem;
}

.play-why-card p,
.play-bot p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

/* The link to the points guide, in the theme's red. */
.play-why-card p a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The coach's mode names, in a real bold (see .play-rules strong). */
.play-why-card p strong {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
  color: var(--color-text);
}

/* Each reason has a flower tile beside it, like the strategies below. */
.play-why-card {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  transition: transform 0.15s;
}

.play-why-card h3 { margin-top: 0; }

.play-why-lead,
.play-bots-lead {
  text-align: center;
  color: var(--color-text-muted);
  margin: -0.4rem 0 1rem;
}

/* The two section paragraphs, across the section's full width. */
.play-why-lead,
.play-bots-lead { line-height: 1.55; }

.play-bots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.play-bot {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  transition: transform 0.15s;
}

.play-why-card .play-tile,
.play-bot .play-tile {
  flex: none;
  width: 40px;
  box-shadow:
    inset 0 -2px 0 rgba(0, 0, 0, 0.08),
    0 3px 0 #2f8a5b,
    0 4px 0 #1f6a43,
    0 6px 10px rgba(0, 0, 0, 0.2);
}

.play-bot h3 { margin-top: 0; }

@media (hover: hover) and (pointer: fine) {
  .play-why-card:hover,
  .play-bot:hover { transform: translateY(-3px); }
  .play-why-card:hover .play-tile,
  .play-bot:hover .play-tile { animation: play-bob 1.2s ease-in-out infinite; }
}

/* On a tablet and a desktop, both card sections are two by two, except
   the strategies, which sit in one row of four on a desktop. */
@media (min-width: 601px) {
  .play-why-grid,
  .play-bots-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1025px) {
  .play-bots-grid { grid-template-columns: repeat(4, 1fr); }
}

/* A last invitation, after the reasons to play. */
.play-cta {
  text-align: center;
  color: #fff;
  border-radius: 10px;
  padding: 2rem 1.25rem;
  background: radial-gradient(circle at 50% 45%, var(--theme-light) 0%, var(--theme-dark) 85%);
  box-shadow: var(--shadow-lg);
}

.play-cta-title {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: clamp(1.6rem, 4.5vw, 2.2rem);
  color: #ffd56b;
  margin: 0 0 0.35rem;
}

.play-cta p { margin: 0 0 1.1rem; opacity: 0.9; }

.play-cta-btn {
  justify-content: center;
  min-width: min(100%, 240px);
  font-size: 1.1rem;
  padding-block: 0.95rem;
}

/* Gold, like Start in the hero above. */
.play-cta .play-cta-btn {
  background: linear-gradient(180deg, #ffd56b, #f4a020);
  color: #3a2200;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.play-cta .play-cta-btn:hover {
  background: linear-gradient(180deg, #ffe08a, #f7ae3a);
  color: #3a2200;
}

/* The picked mode's line, on a phone only (there the two modes are a short
   toggle, and their own descriptions are hidden). */
.play-mode-note { display: none; }

/* Past a phone: a bigger title, and the pitch and form in a readable column. */
@media (min-width: 601px) {
  .play-hero { padding: 2.25rem 2rem 2.5rem; }

  .play-hero-copy {
    width: min(100%, 44rem);
    margin: 0 auto;
  }

  .play-title { font-size: clamp(2.8rem, 5vw, 3.8rem); }

  .play-lead { font-size: 1.1rem; }
}

/* Phones: the two modes are a short toggle and the two buttons sit side by
   side, so both are on the first screen. */
@media (max-width: 600px) {
  .play-hero {
    gap: 0.4rem;
    padding: 1rem 1rem 1.25rem;
  }

  .play-cat { width: 64px; }

  .play-eyebrow { font-size: 0.72rem; }

  .play-title {
    font-size: 2rem;
    margin: 0 0 0.3rem;
  }

  .play-lead {
    font-size: 0.92rem;
    line-height: 1.45;
    margin-bottom: 0.7rem;
  }

  .play-perks {
    gap: 0.35rem;
    margin-bottom: 0.8rem;
  }

  .play-perks li {
    font-size: 0.78rem;
    padding: 0.3rem 0.55rem;
    gap: 0.3rem;
  }

  .play-form { gap: 0.8rem; }

  .play-field legend { margin-bottom: 0.35rem; font-size: 0.9rem; }

  .play-hero .play-options { grid-template-columns: 1fr 1fr; }

  .play-hero .play-option span {
    padding: 0.6rem 0.5rem;
    text-align: center;
  }

  .play-hero .play-option small { display: none; }

  .play-mode-note {
    margin: 0.45rem 0 0;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--color-text-muted);
    text-align: center;
    min-height: 2.7em;
  }

  .play-field:has(input[value="practice"]:checked) .play-mode-note[data-mode="practice"],
  .play-field:has(input[value="payout"]:checked) .play-mode-note[data-mode="payout"] { display: block; }

  .play-hero .play-actions {
    flex-direction: row;
    gap: 0.5rem;
    margin-top: 0;
  }

  .play-hero .play-start {
    width: auto;
    flex: 1 1 0;
    padding-inline: 0.5rem;
    font-size: 1rem;
    white-space: nowrap;
  }

  /* A little smaller on a phone. */
  .play-hero #play-start,
  .play-hero #play-resume,
  .play-hero #play-learn {
    padding-block: 0.75rem;
    font-size: 0.95rem;
  }

  .play-note { margin-top: 0.7rem; font-size: 0.78rem; }
}

@media (prefers-reduced-motion: reduce) {
  .play-cat,
  #play-start::after,
  html.play-has-save #play-resume::after,
  .play-why-card:hover .play-tile,
  .play-bot:hover .play-tile { animation: none; }
}

.play-form {
  display: grid;
  gap: 1.1rem;
  text-align: left;
}

.play-field {
  border: 0;
  margin: 0;
  padding: 0;
}

.play-field legend {
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.play-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.play-option {
  position: relative;
  cursor: pointer;
}

.play-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.play-option span {
  display: block;
  height: 100%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: calc(var(--radius) / 2);
  padding: 0.7rem 0.85rem;
}

html.play-settled .play-option span {
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.play-option strong { display: block; }

.play-option small {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  line-height: 1.35;
  margin-top: 0.2rem;
}

.play-option:hover span { border-color: rgba(var(--color-primary-rgb), 0.4); }

.play-option input:checked + span {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.06);
}

/* Until the saved choice is on the inputs, keep the stored mode on screen.
   Practice is checked in the markup, so a saved Full game would flash red first. */
html.play-mode-payout:not(.play-settled) .play-option input[value="practice"] + span {
  border-color: rgba(0, 0, 0, 0.1);
  background: transparent;
}

html.play-mode-payout:not(.play-settled) .play-option input[value="payout"] + span {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.06);
}

.play-option input:focus-visible + span {
  outline: 3px solid rgba(var(--color-secondary-rgb), 0.7);
  outline-offset: 2px;
}

.play-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* .btn sets display, which otherwise keeps a hidden button in the row. */
.play-actions > [hidden] {
  display: none;
}

/* Two buttons, from the class set in the head before the buttons exist:
   Resume game (a saved game in the selected mode) or New Game, and
   Learn to play, always the secondary one. */
#play-resume { display: none; }

html.play-has-save #play-resume { display: inline-flex; }

html.play-has-save #play-start { display: none; }

.play-start {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
  font-size: 1.1rem;
}

/* Color settles from storage before the first frame. Transitions wait so
   that correction doesn't fade a red Start into white. */
.play-actions .btn { transition: none; }

html.play-settled .play-actions .btn {
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

/* These swap colors and places when the game mode changes: no fade between them.
   Hover keeps its fade, except on phones, which have no hover to fade. */
html.play-swapping .play-actions .btn { transition: none; }

@media (max-width: 600px), (pointer: coarse) and (max-height: 599px) {
  html.play-settled .play-actions .btn { transition: none; }
}

/* Resume is white in the markup: a stored game paints it red before the
   script rewrites its class. */
html.play-has-save:not(.play-settled) #play-resume {
  background: var(--color-primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(var(--color-primary-rgb), 0.3);
}

/* A secondary action beside the red one. */
.btn-white {
  background: #fff;
  color: var(--color-text);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.btn-white:hover {
  background: #f6f1ea;
  color: var(--color-text);
}

.play-rules h2 {
  font-family: var(--font-heading);
  font-weight: 400;
  color: var(--color-primary);
  margin: 0 0 0.75rem;
}

.play-rules ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
}

/* Avenir Medium has no bold face, so a phone and a desktop were drawing
   <strong> differently. The system face has a real bold on both. */
.play-rules strong {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
}

/* Full-screen table */
.play-stage {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--theme-dark);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.play-stage[hidden] { display: none; }

.play-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.play-canvas:focus { outline: none; }

/* The game page has two: the game's table and the playback view's. */
.play-canvas[hidden] { display: none; }

html.is-playing,
html.is-playing body {
  background: var(--theme-dark);
  overflow: hidden;
  overscroll-behavior: none;
}

/* A phone held sideways: the page is one pixel taller than the screen, so
   scrolling it by that pixel makes the browser hide its toolbar (the game
   itself is fixed and doesn't move). */
html.is-playing.is-sideways {
  overflow-y: auto;
}

html.is-playing.is-sideways body {
  height: calc(100vh + 1px);
  overflow: hidden;
}

.rules-sheet {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 2px solid #F4A020;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 35%, var(--theme-light), var(--theme-dark) 75%);
  color: #FFF8F0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  overflow: auto;
}

.rules-sheet::backdrop { background: rgba(0, 0, 0, 0.6); }

.rules-sheet-inner { padding: 14px 22px 16px; }

.rules-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.rules-sheet-head h2 {
  margin: 0;
  font-family: "KN Yuanmo SC", var(--font-heading);
  font-size: 1.7rem;
  font-weight: normal;
  color: #ffd27a;
}

.rules-sheet-close {
  padding: 6px 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-family: "KN Yuanmo SC", var(--font-body);
  font-size: 0.92rem;
  font-weight: normal;
  cursor: pointer;
}

.rules-sheet-close:hover { background: rgba(255, 255, 255, 0.22); }

.rules-sheet-intro {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: rgba(255, 248, 240, 0.85);
}

.rules-sheet-body { display: grid; gap: 10px; }

.rules-section-title {
  display: inline-block;
  margin: 0 0 6px;
  padding: 2px 16px 3px;
  border: 2px solid #ffd27a;
  border-radius: 999px;
  background: var(--theme-primary);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  font-family: "KN Yuanmo SC", var(--font-heading);
  font-size: 1.05rem;
  font-weight: normal;
  color: #fff;
}

.rules-families {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.rules-families--flat .rules-family {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: 16px;
}

.rules-families--flat { grid-template-columns: 1fr; }

.rules-family {
  padding: 6px 12px 4px;
  border-top: 3px solid var(--theme-primary);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.26);
}

.rules-family h4 {
  margin: 0 0 2px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-accent);
}

.rules-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.rules-family h4 + .rules-row,
.rules-families--flat .rules-row { border-top: 0; }

.rules-row-text { flex: 1; min-width: 0; }

.rules-name {
  font-weight: bold;
  font-size: 0.86rem;
  line-height: 1.3;
  color: #FFF8F0;
}

.rules-desc {
  font-size: 0.74rem;
  line-height: 1.25;
  color: rgba(255, 248, 240, 0.7);
}

.rules-faan {
  flex: none;
  min-width: 50px;
  padding: 2px 7px;
  border: 1px solid rgba(255, 210, 122, 0.6);
  border-radius: 999px;
  background: var(--theme-primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: bold;
  text-align: center;
}

.rules-faan--limit {
  border-color: #ffd27a;
  background: #F4A020;
  color: #1A1A1A;
}

.rules-row--example { cursor: pointer; border-radius: 3px; }
.rules-row--example:focus { outline: none; }
.rules-row--example:focus-visible {
  outline: 2px solid #ffd27a;
  outline-offset: 2px;
}

.rules-sheet { position: fixed; }

.rules-example {
  display: none;
  position: absolute;
  z-index: 2;
  max-width: min(560px, calc(100% - 16px));
  padding: 10px 12px;
  border: 2px solid var(--theme-primary);
  border-radius: 6px;
  background: var(--theme-deep);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  .rules-example { cursor: default; }
}

.rules-example-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.rules-example-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: #ffd27a;
}

.rules-example-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.rules-set {
  display: inline-flex;
  gap: 1px;
  padding-bottom: 3px;
  border-bottom: 3px solid transparent;
}

.rules-set--open { border-bottom-color: var(--theme-primary); }

.rules-example-break { flex-basis: 100%; height: 0; }

.rules-set--flowers { margin-left: 6px; }

.rules-tile {
  width: 26px;
  height: auto;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.rules-example-note {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 248, 240, 0.8);
}

@media (max-width: 1000px) {
  .rules-families { grid-template-columns: 1fr 1fr; }
  .rules-families--flat .rules-family { grid-template-columns: 1fr 1fr; }
}

/* Tablets: Situational and Flowers & Seasons share a row, one column each. */
@media (min-width: 601px) and (max-width: 1000px) {
  .rules-sheet-body { grid-template-columns: 1fr 1fr; }
  .rules-sheet-body > * { grid-column: 1 / -1; min-width: 0; }
  .rules-sheet-body > .rules-section--half { grid-column: auto; display: flex; flex-direction: column; }
  .rules-section--half .rules-section-title { align-self: flex-start; }
  .rules-section--half .rules-families { flex: 1; grid-template-columns: 1fr; }
  .rules-section--half .rules-families--flat .rules-family { grid-template-columns: 1fr; height: 100%; box-sizing: border-box; }
}

@media (max-width: 600px) {
  .rules-families,
  .rules-families--flat .rules-family { grid-template-columns: 1fr; }

  .rules-example { max-width: calc(100% - 26px); }
}

@media (max-width: 600px), (pointer: coarse) and (max-height: 599px) {
  .rules-sheet {
    max-height: calc(100dvh - 48px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  .rules-sheet-inner { padding: 16px 22px 18px; }
}

/* View playback sheet: recent hands and the upload, each a row with Play and Download. */
.playbacks-sheet { width: min(680px, calc(100vw - 32px)); }

.playbacks-heading {
  margin: 14px 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-accent);
}

.playbacks-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.playbacks-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 3px solid var(--theme-primary);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.26);
}

.playbacks-row.is-showing { border-top-color: #F4A020; }

.playbacks-text { flex: 1; min-width: 0; }

.playbacks-name {
  font-weight: bold;
  font-size: 0.9rem;
  line-height: 1.3;
  color: #FFF8F0;
}

.playbacks-when {
  font-size: 0.78rem;
  color: rgba(255, 248, 240, 0.75);
}

.playbacks-empty {
  padding: 8px 10px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
  color: rgba(255, 248, 240, 0.75);
}

.playbacks-btn,
.playbacks-upload {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-family: "KN Yuanmo SC", var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  flex: none;
}

.playbacks-play {
  border-color: #ffd27a;
  background: #F4A020;
  color: #1A1A1A;
}

.playbacks-btn:hover:not(:disabled),
.playbacks-upload:hover { background: rgba(255, 255, 255, 0.22); }
.playbacks-play:hover:not(:disabled) { background: #ffd27a; }

/* The playback on screen: its Play button is the same size as the others, with a white
   border round the outside of it (a ring, so it takes no room from the button). */
.playbacks-play.is-showing {
  box-shadow: 0 0 0 3px #ffffff;
}
.playbacks-btn:disabled { opacity: 0.4; cursor: default; }

.playbacks-upload {
  display: block;
  margin: 14px auto 0;
  padding: 8px 22px;
  border-color: #ffd27a;
  background: var(--theme-primary);
}

.playbacks-upload:hover { background: #d8344f; }

/* Play and Download are rounded-square icon buttons, each with a tooltip. */
.playbacks-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 9px;
}

.playbacks-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 9px;
  border-radius: 6px;
  background: #1A1A1A;
  color: #FFF8F0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 2;
}

.playbacks-btn[data-tip]:hover::after,
.playbacks-btn[data-tip]:focus-visible::after,
.playbacks-btn.is-copied::after { opacity: 1; }

/* A phone has no Copy hand seed button on a saved playback: only Play and Download. */
@media (max-width: 600px), (pointer: coarse) and (max-height: 599px) {
  .playbacks-copy { display: none; }
}

/* Copy hand seed turns green with a check for a moment once it has copied. */
.playbacks-btn.is-copied { border-color: #7bd88f; background: #1f6b3c; }

/* The last button on a row keeps its tooltip inside the sheet. */
.playbacks-btn:last-child[data-tip]::after { left: auto; right: 0; transform: none; }

/* A disabled button still shows why on hover. */
.playbacks-btn:disabled { pointer-events: auto; }

.playbacks-btn svg { display: block; }
.playbacks-play svg { margin-left: 2px; } /* the triangle looks centered */

/* The popup for a playback that could not be uploaded. */
.upload-error-sheet { width: min(480px, calc(100vw - 32px)); }

.upload-error-lead {
  margin: 4px 0 8px;
  font-size: 1.05rem;
  font-weight: bold;
  color: #ffd27a;
}

/* Strategies sheet: the same look as the rules sheet. */
.strategies-sheet { width: min(1000px, calc(100vw - 32px)); }

.strategies-beta {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--theme-primary);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.strategies-assign {
  display: grid;
  grid-template-columns: 1fr;
  padding: 8px 12px;
}

.strategies-assign-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(160px, 1fr);
  align-items: center;
  gap: 4px 12px;
  padding: 5px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.strategies-assign-row:first-child { border-top: 0; }

.strategies-assign-row--read { grid-template-columns: 1fr; }

@media (min-width: 601px) {
  .strategies-assign {
    grid-template-columns: 1fr 1fr;
    column-gap: 28px;
  }

  .strategies-assign-row { border-top: 0; }
}

.strategies-assign-label {
  font-weight: bold;
  font-size: 0.86rem;
}

.strategies-assign-who {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.strategies-assign-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

/* What this seat is playing: at the right of its row on a phone, under its name on desktop. */
.strategies-assign-playing {
  font-size: 0.78rem;
  font-weight: normal;
  color: rgba(255, 248, 240, 0.62);
}

@media (min-width: 601px) {
  .strategies-assign-playing { display: block; }
}

@media (max-width: 600px) {
  .strategies-assign-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
  }

  .strategies-assign-playing {
    flex: none;
    text-align: right;
  }
}

.strategies-about-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.strategies-details-toggle {
  padding: 6px 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  font-family: "KN Yuanmo SC", var(--font-body);
  font-size: 0.86rem;
  font-weight: normal;
  color: #ffd27a;
}

/* A caret: down to expand, up to collapse. */
.strategies-details-toggle::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.strategies-details-toggle[aria-expanded="true"]::after {
  transform: translateY(1px) rotate(-135deg);
}

.strategies-details-toggle:focus-visible {
  outline: 2px solid #ffd27a;
  outline-offset: 2px;
}

.strategies-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

@media (min-width: 601px) {
  .strategies-cards { grid-template-columns: 1fr 1fr; }
}

.strategies-card { padding: 8px 12px 10px; }

.strategies-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.strategies-card .strategies-card-name {
  margin: 0;
  font-family: "KN Yuanmo SC", var(--font-heading);
  font-size: 1.15rem;
  font-weight: normal;
  letter-spacing: 0;
  text-transform: none;
  color: #ffd27a;
}

.strategies-card-id {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--theme-primary);
  color: #fff;
  font-size: 0.72rem;
}

.strategies-card-who {
  margin: 2px 0 6px;
  font-size: 0.76rem;
  color: var(--theme-accent);
}

.strategies-card-summary {
  margin: 0 0 6px;
  font-size: 0.86rem;
  line-height: 1.35;
}

.strategies-card-more { display: none; }

.strategies-cards.is-showing-details .strategies-card-more { display: block; }

.strategies-card-more p {
  margin: 6px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: rgba(255, 248, 240, 0.85);
}

/* Hand names, in the theme's colour for the dark sheet. */
.strategies-hand {
  color: var(--theme-accent);
  font-weight: 600;
}

@media (max-width: 600px) {
  .strategies-assign-row { grid-template-columns: 1fr; }
}

/* Results: the same sheet as the rules, with one row per finished hand. */
.results-sheet { width: min(720px, calc(100vw - 32px)); }

.results-empty {
  margin: 8px 0 4px;
  color: rgba(255, 248, 240, 0.75);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th,
.results-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  vertical-align: middle;
  font-size: 0.86rem;
  font-weight: normal;
}

.results-table thead th {
  position: sticky;
  top: 0;
  background: var(--theme-dark);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: bold;
}

.results-player {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}

.results-avatar {
  width: 14px;
  height: 14px;
  flex: none;
}

.results-table tbody th {
  color: #ffffff;
  font-weight: bold;
}

.results-draw {
  display: block;
  font-size: 0.72rem;
  font-weight: normal;
  color: #ffffff;
}

.results-faan,
.results-points { display: block; }

.results-faan { color: rgba(255, 248, 240, 0.7); }

.results-faan--scored { color: #fff8f0; font-weight: bold; }

.results-faan--loss { color: var(--theme-accent); font-weight: bold; }

.results-points { color: rgba(255, 248, 240, 0.55); }

.results-points--gain { color: #ffd27a; font-weight: bold; }

.results-points--loss { color: var(--theme-accent); font-weight: bold; }

.results-total th,
.results-total td {
  border-top: 1px solid rgba(255, 210, 122, 0.4);
  border-bottom: 0;
}

.results-total th { color: #ffffff; }

/* The results table is smaller on a phone so four players and a total fit without crowding. */
@media (max-width: 600px) {
  .results-table th,
  .results-table td {
    padding: 6px 3px;
    font-size: 0.72rem;
  }
  .results-table thead th { font-size: 0.66rem; }
  .results-draw { font-size: 0.62rem; }
  .results-avatar { width: 11px; height: 11px; }
  .results-player { gap: 3px; }
  .results-empty { font-size: 0.85rem; }
  .results-sheet .rules-sheet-head h2 { font-size: 1.3rem; }
  .results-sheet .rules-sheet-close { padding: 4px 12px; font-size: 0.8rem; }
  .results-sheet .rules-sheet-inner { padding: 12px 14px 14px; }
}

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

@media (max-width: 560px) {
  .play-card,
  .play-rules { padding: 1.4rem 1.1rem; }
  .play-options { grid-template-columns: 1fr; }
  .play-actions { flex-direction: column; }
  .play-start { flex: none; width: 100%; }
}

/* Coach settings: three choices, each with what it says and an example. */
.coach-settings-sheet { width: min(520px, calc(100vw - 32px)); }
.coach-options { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.coach-option {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 12px 14px; border: 2px solid rgba(255, 255, 255, 0.22); border-radius: 8px;
  background: rgba(0, 0, 0, 0.18); color: #FFF8F0; font: inherit; cursor: pointer;
}
.coach-option:hover { border-color: rgba(255, 210, 122, 0.6); }
.coach-option.is-selected { border-color: #F4A020; background: rgba(244, 160, 32, 0.14); }
.coach-option-name { font-weight: 700; color: #ffd27a; font-size: 1rem; }
.coach-option-example { font-size: 0.82rem; opacity: 0.75; font-style: italic; }

/* Keyboard shortcuts: each key, and what it does. */
.keys-sheet { width: min(760px, calc(100vw - 32px)); }
.keys-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 28px; margin-top: 14px; }
.keys-group h3 { margin: 0 0 8px; font-size: 0.95rem; color: #ffd27a; }
.keys-group dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; align-items: center; }
.keys-group dt { display: flex; flex-wrap: wrap; gap: 4px; }
.keys-group dd { margin: 0; font-size: 0.88rem; color: #FFF8F0; }
.keys-sheet kbd {
  display: inline-block; min-width: 1.7em; padding: 2px 7px; text-align: center;
  font: 700 0.78rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #3a3a3a;
  background: #FFF8F0; border-radius: 5px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
@media (max-width: 640px) { .keys-grid { grid-template-columns: 1fr; } }
