/* ==========================================================================
   Field Setter — styles
   Built for a phone first, then a tablet: light theme with high contrast
   (readable in sunlight), nothing under 16 px, touch targets of 44 px, dark
   mode via prefers-color-scheme. Sections:
     1. Tokens          2. Base & typography    3. Header & sections switch
     4. Buttons         5. Field layout         6. Oval (SVG)
     7. Situation & toolbar                     8. Controls
     9. Players, warnings & notes              10. Fielder sheet
    11. Dialogs        12. Change field        13. Share
    14. Learn          15. Toast               16. Utilities & motion

   Four layouts (section 5):
     phone            one column; the oval runs edge to edge
     tablet, upright  one column, more room round a bigger oval
     wide             two panes that fill the screen: the oval on the left,
                      everything about it in a column of its own on the right
     phone, sideways  the oval pinned on the left as tall as the screen, the
                      rest of the page scrolling beside it
   In the last two the oval has a pane to itself ("side by side"): sheets
   and panels open in the other column instead of over the oval.
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  color-scheme: light dark;
  --bg: #f4f6f0;
  --surface: #ffffff;
  --surface-2: #eaf0e6;
  --text: #14231b;
  --muted: #4b5a52;
  --border: #c9d4cb;          /* card outlines (decorative) */
  --border-strong: #6f8276;   /* control edges: ≥ 3:1 against white and --surface-2 */
  --primary: #1f6f3f;
  --primary-strong: #175530;
  --primary-soft: #d9ecdf;
  --on-primary: #ffffff;
  --accent: #e8731a;          /* selection / focus on the oval */
  --focus: #1a5fb4;
  --danger: #b3261e;
  --danger-bg: #fbe4e2;
  --warn: #7a4f00;
  --warn-bg: #fff1cf;
  --good: #1f6f3f;
  --good-bg: #dff1e4;
  --surround: #123d27;        /* the dark frame the ground sits in */
  --grass: #2b8046;           /* white text on it reads at ≥ 4.5:1 */
  --pitch: #d8c49b;
  --keeper: #f2c14e;
  --bowler: #b9c2bc;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 14px rgba(0, 0, 0, 0.06);
  --shadow-up: 0 -8px 28px rgba(0, 0, 0, 0.22);
  --radius: 14px;
  --radius-s: 10px;

  --header-h: 52px;
  --gutter: 12px;
  /* The gutter, but never inside a notch or a rounded corner. */
  --gutter-l: max(var(--gutter), env(safe-area-inset-left, 0px));
  --gutter-r: max(var(--gutter), env(safe-area-inset-right, 0px));
  /* The tallest the oval may be: it must fit under the header with its
     title, so the whole ground is on screen at once. */
  --oval-max-h: calc(100vh - var(--header-h) - 76px);
}
@supports (height: 100dvh) {
  :root { --oval-max-h: calc(100dvh - var(--header-h) - 76px); }
}

@media screen and (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1816;
    --surface: #1a2522;
    --surface-2: #22302b;
    --text: #edf3ee;
    --muted: #a8b6ad;
    --border: #35463d;
    --border-strong: #8a9c90;
    --primary: #3da96a;
    --primary-strong: #57c184;
    --primary-soft: #1f4a31;
    --on-primary: #06140b;
    --accent: #ffa052;
    --focus: #7fb4ff;
    --danger: #ff8a80;
    --danger-bg: #40201e;
    --warn: #ffd27a;
    --warn-bg: #3d2f10;
    --good: #7fd49c;
    --good-bg: #173524;
    --surround: #0b2417;
    --grass: #256b3d;
    --pitch: #b8a070;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
    --shadow-up: 0 -8px 28px rgba(0, 0, 0, 0.5);
  }
}

/* 2. Base & typography ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

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

/* An author `display` (.toast { display: flex }, .warnings { display: grid })
   outranks the browser's own [hidden] { display: none }, which left the toast
   on screen for good: neither its × nor its timer could hide it. */
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.sprite { position: absolute; }
.icon { flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.noscript { padding: 16px; background: var(--warn-bg); color: var(--warn); }
.section-title { margin: 0 0 8px; font-size: 1.15rem; }

/* 3. Header & sections switch ----------------------------------------------------
   The mark on the left (with the name where there is room), the switch
   between the two halves of the app in the middle, Settings on the right. */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: var(--header-h);
  background: var(--primary);
  color: #ffffff;
  padding: 4px var(--gutter-r) 4px var(--gutter-l);
  box-shadow: var(--shadow);
}
.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  border-radius: 10px;
}
.brand-mark { flex: 0 0 auto; display: block; }
/* The name needs room the sections switch has first call on. */
.brand-name { display: none; }
@media (min-width: 520px) { .brand-name { display: inline; } }

.modes {
  display: inline-flex;
  padding: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.24);
}
.mode {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.mode[aria-current="page"] { background: #ffffff; color: #175530; }
.mode:focus-visible, .brand:focus-visible, .btn-header:focus-visible { outline-color: #ffd166; }

@media (max-width: 519px) {
  .app-header { gap: 4px; }
  .mode { padding-inline: clamp(6px, 2vw, 12px); }
}

.btn-header {
  justify-self: end;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  cursor: pointer;
}
.btn-header:hover, .btn-header[aria-expanded="true"] { background: rgba(255, 255, 255, 0.22); border-color: #ffffff; }

@media screen and (prefers-color-scheme: dark) {
  .app-header { background: #163d27; color: #edf3ee; }
}

/* 4. Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-danger { color: var(--danger); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-compact { padding: 0 14px; }
.btn-block { width: 100%; }

/* A square button that is only an icon (close, back). */
.icon-btn {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* One labelled text box. 16 px or more, or iOS zooms the page on focus. */
.text-field { display: grid; gap: 6px; }
.text-field-label { font-weight: 600; }
.text-field input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 1rem;
}

/* 5. Field layout ----------------------------------------------------------------
   Phone: title, warnings, the oval edge to edge, the three situation
   buttons, the tools, then who is where and why. */
.view { display: block; }

.field-layout {
  display: grid;
  gap: 20px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}
.stage { display: grid; gap: 10px; }

/* The heading above the oval: what the field is called, with the Change
   field button beside it. Long names are cut with an ellipsis rather than
   pushing the oval down on a phone. */
.field-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  min-width: 0;
  padding: 10px var(--gutter-r) 0 var(--gutter-l);
}
/* Reserve two lines (a two-line title, or a title and its subtitle) before
   app.js writes the text, so the oval does not move on the first render. */
.field-heading-text { display: grid; gap: 1px; min-width: 0; min-height: 2.9rem; align-content: center; }
/* (The padding is room for descenders: a clamped line is clipped at its
   box, and Safari's system font hangs a little below it.) */
.field-title {
  margin: 0 0 -0.12em;
  padding-bottom: 0.12em;
  font-size: 1.15rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}
.field-subtitle {
  margin: 0 0 -0.12em;
  padding-bottom: 0.12em;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}
/* The device's safety profile ("Under 13 safety on"), under the title.
   Amber like the "Check" warnings: a condition the field is built under. */
.safety-badge {
  justify-self: start;
  margin: 3px 0 0;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.au-ground-note { margin: 3px 0 0; font-size: .875rem; line-height: 1.35; }
.au-ground-note a { color: inherit; }
.warnings, .oval-hint, .situation, .toolbar { margin: 0 var(--gutter-r) 0 var(--gutter-l); }

/* The ground sits in a dark frame, the full width of a phone. The oval is
   as wide as the screen unless that would make it taller than the screen. */
.oval-frame {
  display: grid;
  place-items: center;
  background: var(--surround);
}
.oval {
  display: block;
  width: min(100%, calc(var(--oval-fit, var(--oval-max-h)) * 128 / 140));
  aspect-ratio: 128 / 140;
  height: auto;
}

.oval-hint { margin-top: -2px; color: var(--muted); font-size: 1rem; line-height: 1.35; }
.oval-hint:empty { display: none; }

.panel {
  display: grid;
  gap: 22px;
  align-content: start;
  min-width: 0;
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
}
.panel-foot { margin: 0; font-size: 1rem; }

/* Tablet, upright: the same single column with more air, the ground in a
   rounded frame of its own, and the oval kept short enough that the buttons
   under it are on screen too. */
@media (min-width: 700px) {
  :root { --gutter: 20px; }
  @supports (height: 100dvh) {
    :root { --oval-max-h: calc(100dvh - var(--header-h) - 262px); }
  }
  .field-heading { padding-top: 14px; }
  .field-title { font-size: 1.35rem; }
  .oval-frame { margin: 0 var(--gutter-r) 0 var(--gutter-l); border-radius: 22px; padding: 6px; }
}

/* Wide (a tablet on its side, a laptop): two panes that fill the screen.
   The stage's parts become cells of one grid: the title and the oval on the
   left; the situation, the tools, any warnings and the scrolling column
   about the field on the right. Nothing is ever cut off: the oval takes
   whatever height is left and the right-hand column scrolls by itself. */
@media (min-width: 900px) and (min-height: 560px) and (min-aspect-ratio: 11/10) {
  .view-field { height: calc(100vh - var(--header-h)); overflow: hidden; }
  @supports (height: 100dvh) {
    .view-field { height: calc(100dvh - var(--header-h)); }
  }
  .field-layout {
    height: 100%;
    gap: 0 20px;
    padding: 12px var(--gutter-r) max(14px, env(safe-area-inset-bottom, 0px)) var(--gutter-l);
    grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "heading situation"
      "oval    toolbar"
      "oval    warnings"
      "oval    panel"
      "hint    panel";
  }
  .stage { display: contents; }
  .field-heading { grid-area: heading; padding: 0 0 10px; align-self: end; }
  /* (Both halves of the app: the Learn stage has an oval pane of its own.) */
  .oval-frame {
    margin: 0;
    padding: 6px;
    min-height: 0;
    border-radius: 22px;
    container-type: size;
  }
  .stage > .oval-frame { grid-area: oval; }
  /* As big as the pane allows, in whichever direction runs out first. */
  .oval { width: 100%; max-height: 100%; }
  @supports (width: 1cqw) {
    .oval { width: min(100cqw, calc(100cqh * 128 / 140)); max-height: none; }
  }
  .oval-hint { grid-area: hint; margin: 8px 0 0; text-align: center; }
  .situation { grid-area: situation; margin: 0; align-self: end; padding-bottom: 10px; }
  .toolbar { grid-area: toolbar; margin: 0; }
  /* (Two classes each, to outrank the upright-tablet rules further down.) */
  .toolbar .tool { grid-auto-flow: row; gap: 1px; min-height: 56px; }
  .warnings { grid-area: warnings; margin: 10px 0 0; }
  /* A flex column, not a grid: a grid row holding something that scrolls
     (the fielder sheet) may be squeezed to nothing once the column is full. */
  .panel {
    grid-area: panel;
    display: flex;
    flex-direction: column;
    margin-top: 12px;
    padding: 2px 6px 4px 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .panel > * { flex: none; }
  .panel > * + * { margin-top: 22px; }
  .panel .players { grid-template-columns: minmax(0, 1fr); }
}

/* A phone on its side: wide but short. The oval is pinned on the left, as
   tall as the screen allows, and the page scrolls beside it: heading,
   situation, tools and the lists, all in the right-hand column. */
@media (min-width: 600px) and (max-height: 559px) and (min-aspect-ratio: 11/10) {
  :root { --gutter: 14px; --oval-max-h: calc(100vh - var(--header-h) - 20px); }
  @supports (height: 100dvh) {
    :root { --oval-max-h: calc(100dvh - var(--header-h) - 20px); }
  }
  .field-layout {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0 16px;
    align-items: start;
    padding: 10px var(--gutter-r) calc(20px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
    grid-template-areas:
      "oval heading"
      "oval situation"
      "oval toolbar"
      "oval hint"
      "oval warnings"
      "oval panel";
  }
  .stage { display: contents; }
  .oval-frame {
    grid-area: oval;
    position: sticky;
    top: calc(var(--header-h) + 10px);
    margin: 0;
    padding: 0;
    border-radius: 16px;
  }
  .oval { width: calc(var(--oval-max-h) * 128 / 140); }
  .field-heading { grid-area: heading; padding: 0 0 8px; }
  .situation { grid-area: situation; margin: 0 0 8px; }
  .toolbar { grid-area: toolbar; margin: 0 0 8px; }
  .oval-hint { grid-area: hint; margin: 0 0 8px; }
  .warnings { grid-area: warnings; margin: 0 0 10px; }
  .panel { grid-area: panel; padding: 0; }
  /* (Learn's half of this layout is with the rest of Learn, section 14.) */
}

/* 6. Oval (SVG) --------------------------------------------------------------- */
.oval {
  /* The oval fills a phone screen, so the grass must still scroll the page;
     only the draggable fielders (below) take the touch for themselves. */
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: inherit;
  overflow: visible;
}
/* Text a few user units tall: without this Chrome spaces the letters as if
   they were whole pixels wide. */
.oval text { text-rendering: geometricPrecision; }

.ov-grass { fill: var(--grass); }
.ov-pitch { fill: var(--pitch); }
.ov-batter { fill: #1d3557; stroke: #ffffff; }
.ov-bat { stroke: #f3e2b3; }
/* Side captions, in the corners of the dark frame. Font size is set by
   oval.js so it scales with the labels. */
.ov-side {
  fill: #ffffff;
  fill-opacity: 0.82;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.ov-hit { fill: transparent; }   /* transparent (not none) so it still takes pointer events */
.ov-hit.is-draggable { cursor: grab; }
.ov-player { cursor: pointer; }
.ov-player:focus { outline: none; }
.ov-player.is-draggable { cursor: grab; }
.ov-player.is-dragging { cursor: grabbing; }
/* Only a draggable fielder takes the touch away from the page scroll. */
.ov-hit.is-draggable, .ov-player.is-draggable { touch-action: none; }
.ov-dot { fill: #ffffff; stroke: #14231b; stroke-width: 0.55; }
.ov-player.is-keeper .ov-dot { fill: var(--keeper); }
.ov-player.is-bowler .ov-dot { fill: var(--bowler); }
.ov-deep-ring { fill: none; stroke: #ffffff; stroke-width: 0.45; opacity: 0.9; }
.ov-player.is-moved .ov-dot { stroke-dasharray: 1.3 0.9; stroke-width: 0.7; }
.ov-player.is-selected .ov-dot,
.ov-player:focus-visible .ov-dot { stroke: var(--accent); stroke-width: 1.2; }
.ov-leader { stroke: #ffffff; stroke-width: 0.4; opacity: 0.85; pointer-events: none; }
.ov-label-bg { fill: #ffffff; opacity: 0.93; pointer-events: none; }
.ov-label { fill: #14231b; font-weight: 600; pointer-events: none; }
/* Selected label: dark text on the orange backing (5.3:1); white on it was 3:1. */
.ov-player.is-selected .ov-label-bg,
.ov-player:focus-visible .ov-label-bg { fill: var(--accent); opacity: 1; }
.ov-player.is-selected .ov-label,
.ov-player:focus-visible .ov-label { fill: #14231b; }
.ov-player.is-selected .ov-leader { stroke: var(--accent); opacity: 1; }

/* While dragging: faint dots on every standard spot the fielder could go
   to (a hint of where the places are, well under the real players), a ring
   on the spot the fielder will be pulled onto, and a tag above the finger
   that names where it is heading and turns green to say "this will snap".
   The fielder's own name is hidden meanwhile: the tag has taken over. */
.ov-snap, .ov-overlay { pointer-events: none; }
.ov-ghost { fill: #ffffff; opacity: 0.38; }
.ov-snap-ring {
  fill: rgba(255, 255, 255, 0.18);
  stroke: #ffffff;
  stroke-width: 0.6;
  stroke-dasharray: 1.2 0.8;
  opacity: 0.95;
}
.ov-player.is-dragging .ov-label,
.ov-player.is-dragging .ov-label-bg,
.ov-player.is-dragging .ov-leader { display: none; }
.ov-player.is-dragging .ov-dot { stroke: var(--accent); stroke-width: 1; }
.ov-player.is-snapping .ov-dot { stroke: #1f6f3f; stroke-width: 1.1; }
.oval.is-dragging .ov-player:not(.is-dragging) { opacity: 0.72; }
.ov-dragtag-bg { fill: #14231b; stroke: #ffffff; stroke-width: 0.35; }
.ov-dragtag-text { fill: #ffffff; font-weight: 700; }
.ov-dragtag.is-snapping .ov-dragtag-bg { fill: #d9ecdf; stroke: #1f6f3f; }
.ov-dragtag.is-snapping .ov-dragtag-text { fill: #14231b; }

/* A fielder breaking a Law (red) or a playing condition (amber): a bold
   ring round the dot and a coloured label backing. Fixed colours: the
   grass is the same in both themes, and white on #b3261e is 6.5:1, dark
   text on #ffb300 is 9:1. */
.ov-warn-ring { fill: none; stroke: #ff6b5e; stroke-width: 0.9; }
.ov-player.is-warned-law .ov-dot { stroke: #b3261e; stroke-width: 0.9; }
.ov-player.is-warned-law .ov-label-bg { fill: #b3261e; opacity: 1; }
.ov-player.is-warned-law .ov-label { fill: #ffffff; }
.ov-player.is-warned-rule .ov-warn-ring { stroke: #ffb300; }
.ov-player.is-warned-rule .ov-label-bg { fill: #ffb300; opacity: 1; }
.ov-player.is-warned-rule .ov-label { fill: #14231b; }
/* Selected AND warned: the orange selection stays on the dot, the label keeps its colour. */
.ov-player.is-warned.is-selected .ov-dot,
.ov-player.is-warned:focus-visible .ov-dot { stroke: var(--accent); stroke-width: 1.2; }

/* Learn: the answer to a question, right or wrong. */
.ov-player.is-correct .ov-warn-ring { stroke: #7dffa8; stroke-width: 1.1; }
.ov-player.is-correct .ov-dot { fill: #b9f5cd; stroke: #0e5a2c; stroke-width: 0.9; }
.ov-player.is-correct .ov-label-bg { fill: #b9f5cd; opacity: 1; }
.ov-player.is-wrong .ov-warn-ring { stroke: #ff6b5e; stroke-width: 1.1; }
.ov-player.is-wrong .ov-dot { fill: #ffd2cd; stroke: #b3261e; stroke-width: 0.9; }
.ov-player.is-wrong .ov-label-bg { fill: #ffd2cd; opacity: 1; }
.ov-player.is-dim { opacity: 0.45; }

/* 7. Situation & toolbar --------------------------------------------------------
   The three things a field is set for, as three buttons that say what is
   chosen; then the tools. */
.situation { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sit {
  display: grid;
  gap: 0;
  align-content: center;
  min-width: 0;
  min-height: 58px;
  padding: 7px 10px 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.sit:hover { border-color: var(--primary); }
.sit[aria-expanded="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; background: var(--primary-soft); }
/* What it is, with a chevron to say it opens. */
.sit-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.25;
}
.sit-label::after {
  content: "";
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  background: no-repeat center / contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f8276' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.sit-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; line-height: 1.3; }
.sit-value, .sit-detail { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sit-value { flex: 0 1 auto; font-weight: 700; font-size: clamp(0.875rem, 3.9vw, 1rem); }
/* The detail ("right arm, outswing") beside the value, where there is room. */
.sit-detail { display: none; flex: 1 1 0; min-width: 0; color: var(--muted); font-size: 1rem; }
.sit-detail:empty { display: none !important; }
@media (min-width: 560px) { .sit-detail { display: block; } }

.toolbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.tool {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 56px;
  padding: 5px 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}
.tool:hover { border-color: var(--primary); }
.tool:disabled { opacity: 0.45; cursor: default; border-color: var(--border); }
.tool[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-strong); }
.tool-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tool-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
@media (min-width: 700px) {
  .tool { grid-auto-flow: column; justify-content: center; gap: 8px; min-height: 48px; }
}

/* 8. Controls (the Situation sheet and the Settings panel) ------------------- */
.controls { display: grid; gap: 18px; }

.ctrl-group { display: grid; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.ctrl-group:last-child { border-bottom: 0; padding-bottom: 0; }
.ctrl-group-title { margin: 0; font-size: 1.05rem; color: var(--primary-strong); }
.ctrl-body { display: grid; gap: 16px; }

.seg { border: 0; padding: 0; margin: 0; min-width: 0; }
.seg-legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-option { position: relative; }
.seg-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.seg-label {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
}
.seg-option input:checked + .seg-label {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.seg-option input:focus-visible + .seg-label { outline: 3px solid var(--focus); outline-offset: 2px; }
.ctrl-help { margin: 6px 0 0; color: var(--muted); font-size: 1rem; min-height: 1.3em; }

.switch { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch-track {
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
  margin-top: 2px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.15s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked ~ .switch-track { background: var(--primary); }
.switch input:checked ~ .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible ~ .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch-text small { display: block; color: var(--muted); font-size: 1rem; }

/* 9. Players, warnings & notes --------------------------------------------- */
.warnings { display: grid; gap: 8px; }
.warning { padding: 10px 12px; border-radius: var(--radius-s); border-left: 5px solid; }
.warning-law { background: var(--danger-bg); border-color: var(--danger); color: var(--text); }
.warning-rule { background: var(--warn-bg); border-color: var(--warn); color: var(--text); }
.warning strong { color: inherit; }

.players { display: grid; gap: 8px; }
@media (min-width: 700px) {
  .players { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.player {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: start;
  gap: 2px 8px;
  text-align: left;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  cursor: pointer;
}
.player:hover { border-color: var(--border-strong); }
.player[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.player-name { font-weight: 700; }
.player-reason { grid-column: 1 / -1; color: var(--muted); font-size: 1rem; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-keeper { background: var(--keeper); color: #14231b; border-color: transparent; }
.badge-deep { background: var(--primary-soft); color: var(--primary-strong); }
.badge-moved { background: var(--warn-bg); color: var(--warn); }
.badge-law { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.badge-rule { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }

/* Why this field: the first note says what the field is; the rest open. */
.notes-lead { margin: 0; }
.notes-more { margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); }
.notes-more > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.notes-more > summary::-webkit-details-marker { display: none; }
.notes-more > summary::after { content: "+"; margin-left: auto; font-size: 1.3rem; color: var(--muted); }
.notes-more[open] > summary::after { content: "–"; }
.notes { display: grid; gap: 8px; padding: 0 12px 12px 30px; list-style: disc; }

/* 10. Fielder sheet -------------------------------------------------------------
   The tapped fielder: who they are, where they stand and why. On a phone a
   non-modal panel fixed to the bottom of the viewport: fixed, so opening it
   never jumps the page; capped at 42 % of the viewport so the oval stays in
   view; scrolls inside itself. On a wide screen a card at the top of the
   right-hand column. */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 42vh;
  max-height: 42dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* The full width of the screen; the words kept to a readable measure. */
  padding: 6px max(16px, calc(50% - 340px)) calc(16px + env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-up);
  animation: sheet-in 0.22s ease-out;
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
/* The panel itself takes focus when opened from the keyboard; the ring would
   be clipped by the viewport edge, so draw it inside. */
.sheet:focus-visible { outline-offset: -3px; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sheet-header .icon-btn { margin-right: -8px; }
.sheet-title { margin: 0; padding-top: 10px; font-size: 1.25rem; }
.sheet-meta { margin: 0 0 8px; color: var(--muted); }
.sheet-reason { margin: 0 0 10px; padding: 8px 12px; border-radius: var(--radius-s); background: var(--surface-2); }
.sheet-facts { margin: 0; display: grid; gap: 2px 0; }
.sheet-facts dt { font-weight: 700; }
.sheet-facts dd { margin: 0 0 10px; }
.sheet-facts dd:last-child { margin-bottom: 0; }
.position-guide-link, .position-guide-index { display: inline-flex; align-items: center; min-height: 44px; color: var(--primary-strong); text-underline-offset: .17em; }
.position-guide-link { margin-top: .4rem; }
/* The same warning line in the fielder sheet, for a player the box points at. */
.sheet-warning {
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: var(--radius-s);
  border-left: 5px solid;
  font-weight: 600;
}
.sheet-warning.is-law { background: var(--danger-bg); border-color: var(--danger); }
.sheet-warning.is-rule { background: var(--warn-bg); border-color: var(--warn); }

/* One column (phone, upright tablet): room to scroll the page out from under
   the open sheet, and the warnings float just above it. On a phone the
   warnings box above the oval can be scrolled out of view, and every drop
   opens the sheet: a no-ball could vanish the moment it was created. While
   the sheet is open the box floats just above it instead, and goes back
   above the oval when the sheet closes. Fixed rather than sticky: .stage is
   a grid, and a sticky grid item cannot leave its own row. */
body.has-sheet .field-layout { padding-bottom: calc(42vh + 28px); }
body.has-sheet #warnings {
  position: fixed;
  left: var(--gutter-l);
  right: var(--gutter-r);
  bottom: calc(42vh + 8px);
  bottom: calc(42dvh + 8px);
  z-index: 51;
  max-width: 656px;
  margin: 0 auto;
  box-shadow: var(--shadow);
}

/* Side by side (wide, or a phone on its side): the sheet is a card in the
   column beside the oval, never over it. */
@media (min-width: 900px) and (min-height: 560px) and (min-aspect-ratio: 11/10), (min-width: 600px) and (max-height: 559px) and (min-aspect-ratio: 11/10) {
  .sheet {
    position: sticky;
    top: 0;
    z-index: 3;
    max-height: 56vh;
    padding: 4px 16px 14px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: sheet-fade 0.18s ease-out;
  }
  @keyframes sheet-fade {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  body.has-sheet .field-layout { padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); }
  body.has-sheet #warnings {
    position: static;
    max-width: none;
    margin: 10px 0 0;
    box-shadow: none;
  }
}
/* A phone on its side: the page itself scrolls, so the card sticks under
   the header (and is scrolled into view when it opens: app.js). */
@media (min-width: 600px) and (max-height: 559px) and (min-aspect-ratio: 11/10) {
  .sheet {
    top: calc(var(--header-h) + 10px);
    max-height: calc(100vh - var(--header-h) - 20px);
    scroll-margin-top: calc(var(--header-h) + 10px);
    margin-bottom: 14px;
  }
  body.has-sheet .field-layout, body.has-sheet .learn-layout { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  body.has-sheet #warnings { margin: 0 0 10px; }
}

/* 11. Dialogs ---------------------------------------------------------------------
   All modal <dialog>s (src/ui/dialog.js). On a phone each is a bottom sheet.
   On a bigger screen the Situation sheet and Settings (.dialog-side) are a
   panel on the right, over the column they change, and the chooser and
   Share (.dialog-centred) sit in the middle. The dialog itself has no
   padding so a tap on it (outside .dialog-body) can only mean the backdrop. */
.dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-body {
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-up);
  animation: dialog-up 0.22s ease-out;
}
@keyframes dialog-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 60px;
  margin: 0 -16px 14px;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.dialog-title { margin: 0; font-size: 1.25rem; }
.dialog-title:focus-visible { outline-offset: 4px; border-radius: 4px; }

/* The page behind a dialog must not scroll under it. */
body.has-dialog { overflow: hidden; }

/* The Situation sheet: short, and with nothing drawn over the page behind
   it, so the field can be watched changing as the options are tapped. */
.dialog-situation::backdrop { background: transparent; }
.dialog-situation .dialog-body { max-height: min(54vh, 470px); max-height: min(54dvh, 470px); }
.dialog-header-tabs { padding-right: 12px; }
.tabs { display: inline-flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.tab {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--primary); color: var(--on-primary); }

/* An upright tablet: still a bottom sheet the width of the screen, with its
   contents kept to a comfortable measure in the middle. */
@media (min-width: 700px) {
  .dialog-side .dialog-body { padding-left: max(16px, calc(50% - 360px)); padding-right: max(16px, calc(50% - 360px)); }
  .dialog-side .dialog-header { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
}
/* A panel down the right-hand side, where the oval has a pane of its own
   and stays in view beside it (wide, or a phone on its side). */
@media (min-width: 900px) and (min-height: 560px) and (min-aspect-ratio: 11/10), (min-width: 600px) and (max-height: 559px) and (min-aspect-ratio: 11/10) {
  .dialog-side { margin: 0 0 0 auto; width: min(480px, 62%); height: 100%; border-radius: 0; }
  .dialog-side .dialog-header { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 8px; }
  .dialog-side .dialog-body {
    height: 100%;
    max-height: 100%;
    padding: 0 16px 24px;
    border: 0;
    border-left: 1px solid var(--border-strong);
    border-radius: 0;
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.25);
    animation-name: dialog-in-right;
  }
  @keyframes dialog-in-right {
    from { transform: translateX(32px); opacity: 0.6; }
    to { transform: translateX(0); opacity: 1; }
  }
}

/* A box in the middle of a bigger screen. */
@media (min-width: 600px) {
  .dialog-centred { margin: auto; width: min(640px, calc(100% - 48px)); border-radius: 18px; }
  .dialog-centred .dialog-body {
    max-height: 88vh;
    max-height: 88dvh;
    padding-bottom: 20px;
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    box-shadow: var(--shadow);
  }
}

/* A small question box (src/ui/prompt.js): name a field, confirm a delete.
   Centred on every screen, above the keyboard on a phone. */
.dialog-prompt { margin: auto; width: min(440px, calc(100% - 32px)); border-radius: 18px; }
.dialog-prompt .dialog-body {
  padding: 18px 16px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.prompt-title { margin: 0 0 10px; font-size: 1.2rem; }
.prompt-message { margin: 0 0 14px; }
.prompt-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* 12. Change field ---------------------------------------------------------------- */
.chooser-section { margin-bottom: 22px; }
.chooser-section:last-child { margin-bottom: 0; }
.chooser-heading { margin: 0 0 8px; font-size: 1.05rem; }
.chooser-heading:focus-visible { outline-offset: 4px; border-radius: 4px; }
.chooser-heading-note { margin-left: 6px; color: var(--muted); font-size: 1rem; font-weight: 500; }

/* Ready-made fields: one row per preset — the name (tap to load) and a
   chevron that opens what the field is for underneath. The description is
   closed to start with so the list is a list of names, not a wall of text. */
.preset-list { display: grid; gap: 8px; }
.preset-item { display: grid; }
.preset-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  overflow: hidden;
}
.preset-row:hover { border-color: var(--primary); }
.preset-item.is-current .preset-row { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.preset-card {
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.preset-card-name { font-weight: 700; }
.preset-more {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.preset-more:hover { color: var(--text); }
.preset-more .icon { transition: transform 0.15s ease-out; }
.preset-more[aria-expanded="true"] .icon { transform: rotate(180deg); }
.preset-card:focus-visible, .preset-more:focus-visible { outline-offset: -3px; }
.preset-about {
  display: grid;
  gap: 6px;
  padding: 8px 12px 2px;
  color: var(--muted);
  font-size: 1rem;
}
.preset-about p { margin: 0; }
.preset-about-lead { color: var(--text); }
.preset-about-notes { margin: 0; padding-left: 18px; list-style: disc; }
.preset-about-notes li { margin: 0 0 2px; }

/* Your saved fields. */
.saved-list { display: grid; gap: 10px; }
.saved-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.saved-name { margin: 0 0 2px; }
.saved-meta { margin: 0; color: var(--muted); font-size: 1rem; }
.saved-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.saved-empty { padding: 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.saved-empty p { margin: 0; }
@media (min-width: 600px) {
  .saved-item { grid-template-columns: 1fr auto; align-items: center; }
}

/* 13. Share ------------------------------------------------------------------------ */
.share-form { display: grid; gap: 14px; }
.share-preview { margin: 0; display: grid; gap: 6px; }
.share-preview img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 630;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surround);
}
.share-preview figcaption { font-size: 1rem; }
.share-actions { display: grid; gap: 8px; }
@media (min-width: 480px) {
  .share-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share-actions:has(#share-copy[hidden]) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.share-status { margin: 0; min-height: 1.45em; overflow-wrap: anywhere; }

/* 14. Learn ------------------------------------------------------------------------
   The other half of the app: the same oval, with lessons under it. Laid out
   like "Set a field": one column on a phone, two panes on a wide screen. */
.learn-layout { display: grid; gap: 14px; padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
.lesson-reading { box-sizing: border-box; max-height: 100%; overflow-y: auto; max-width: 72ch; margin-inline: auto; padding: 1.5rem var(--gutter-l); }
.lesson-reading a { color: var(--primary-strong); }
.lesson-reading details { margin-bottom: 1rem; }
.lesson-reading details li { padding-block: .2rem; }
.lesson-reading section[id] { scroll-margin-top: var(--header-h); }
.lesson-sources a { display: inline-block; padding-block: .45rem; color: var(--primary-strong); text-underline-offset: .15em; }
.position-finder { margin: 0 var(--gutter-r) 4px var(--gutter-l); }
.position-finder label { display: block; margin-bottom: .25rem; font-weight: 650; }
.position-directory summary { width: fit-content; padding-block: .5rem; cursor: pointer; color: var(--primary-strong); }
.position-finder .position-directory ul { max-height: min(24vh, 13rem); overflow-y: auto; padding-inline: .75rem; border: 1px solid var(--border); border-radius: var(--radius); }
.position-finder .position-directory li { color: var(--muted); }
.position-finder .position-directory a { display: inline-block; padding-block: .5rem; color: var(--primary-strong); }
.position-finder input {
  width: 100%; min-height: 44px; padding: .5rem .75rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.finder-status { margin: .3rem 0; color: var(--muted); font-size: .9rem; }
.finder-status:empty { margin: 0; }
.finder-results { max-height: min(24vh, 13rem); overflow: auto; }
.finder-results:not(:empty) { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.finder-results a { display: flex; flex-wrap: wrap; align-items: center; gap: .3em; min-height: 44px; padding: .4rem .75rem; color: var(--primary-strong); font-weight: 650; }
.finder-results a:focus-visible { outline-offset: -3px; }
.finder-results a span { color: var(--muted); font-weight: 400; }
.finder-depth { margin-inline-start: auto; font-size: .9rem; }
.learn-stage { display: grid; gap: 10px; min-width: 0; }
.learn-heading {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 3.4rem;
  padding: 10px var(--gutter-r) 0 var(--gutter-l);
}
.learn-back { margin-left: -8px; text-decoration: none; }
.learn-heading-text { min-width: 0; }
.learn-kicker { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.25; }
.learn-title { margin: 0; font-size: 1.25rem; line-height: 1.2; overflow-wrap: anywhere; }
.learn-title:focus-visible { outline-offset: 4px; border-radius: 4px; }

.learn-switches { display: flex; flex-wrap: wrap; gap: 10px 20px; padding: 0 var(--gutter-r) 0 var(--gutter-l); }
.learn-sheet .learn-switches { padding: 0 0 .75rem; }
.chip-group { display: grid; gap: 4px; }
.chip-group-label { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }

.learn-panel { display: grid; gap: 16px; align-content: start; min-width: 0; padding: 0 var(--gutter-r) 0 var(--gutter-l); }
.learn-body { display: grid; gap: 16px; align-content: start; min-width: 0; }
.learn-intro { margin: 0; font-size: 1.05rem; }
.learn-progress { margin: 0; color: var(--primary-strong); font-weight: 600; }
.learn-section { display: grid; gap: 0; }
.learn-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.learn-card > p { margin: 0 0 10px; }
.word-list { margin: 0; display: grid; gap: 2px 0; }
.word-list dt { font-weight: 700; }
.word-list dd { margin: 0 0 10px; }
.word-list dd:last-child { margin-bottom: 0; }

/* The list of lessons: a number (a tick once its test is done), what the
   lesson is about and how it went. */
.lesson-list { display: grid; gap: 8px; }
.lesson-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.lesson-card:hover { border-color: var(--primary); }
.lesson-number {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-weight: 700;
}
.lesson-card.is-done .lesson-number { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.lesson-text { display: grid; gap: 1px; min-width: 0; }
.lesson-title { font-weight: 700; font-size: 1.05rem; }
.lesson-blurb { color: var(--text); }
.lesson-meta { color: var(--muted); }
.lesson-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* A lesson's positions: tap one to find it on the ground and read about it. */
.pos-list { display: grid; gap: 8px; }
.pos-item {
  width: 100%;
  height: 100%;
  display: grid;
  align-content: start;
  gap: 2px;
  text-align: left;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.pos-item:hover { border-color: var(--border-strong); }
.pos-item[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.pos-item-name { font-weight: 700; }
.pos-item-meta { color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tag { padding: 1px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.tag-off { background: var(--primary-soft); }
.tag-leg { background: var(--warn-bg); }
.learn-sheet-link { margin-top: 12px; }

/* Test yourself: the question takes the sheet's place. */
.learn-sheet.is-quiz { padding-top: 12px; }
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.quiz-count { margin: 0; color: var(--muted); }
.quiz-ask { margin: 0 0 6px; font-size: 1.35rem; font-weight: 600; }
.quiz-ask strong { font-weight: 800; color: var(--primary-strong); }
.quiz-feedback { margin: 0 0 12px; min-height: 2.9em; }
.quiz-feedback.is-right, .quiz-feedback.is-wrong {
  padding: 8px 12px;
  border-radius: var(--radius-s);
  border-left: 5px solid;
}
.quiz-feedback.is-right { background: var(--good-bg); border-color: var(--good); }
.quiz-feedback.is-wrong { background: var(--danger-bg); border-color: var(--danger); }
.quiz-actions { display: grid; gap: 8px; }

/* The sheet's place in the page is the same as on "Set a field". */
body.has-sheet .learn-layout { padding-bottom: calc(42vh + 28px); }

@media (min-width: 700px) {
  .learn-title { font-size: 1.45rem; }
  .lesson-list, .pos-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quiz-actions { grid-template-columns: repeat(3, auto); justify-content: start; }
}

@media (min-width: 900px) and (min-height: 560px) and (min-aspect-ratio: 11/10) {
  .view-learn { height: calc(100vh - var(--header-h)); overflow: hidden; }
  @supports (height: 100dvh) {
    .view-learn { height: calc(100dvh - var(--header-h)); }
  }
  .learn-layout {
    height: 100%;
    gap: 0 20px;
    padding: 12px var(--gutter-r) max(14px, env(safe-area-inset-bottom, 0px)) var(--gutter-l);
    grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
    grid-template-rows: minmax(0, 1fr);
  }
  .learn-stage { grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; min-height: 0; }
  .learn-heading { padding: 0 0 6px; }
  .position-finder { margin-inline: 0; }
  .learn-switches { padding: 0; }
  .learn-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 2px 6px 4px 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .learn-panel > * { flex: none; }
  .learn-panel > * + * { margin-top: 16px; }
  .learn-panel .lesson-list, .learn-panel .pos-list { grid-template-columns: minmax(0, 1fr); }
  body.has-sheet .learn-layout { padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); }
  .learn-sheet.is-quiz { border-color: var(--primary); }
}

/* A phone on its side: the oval pinned on the left, the lesson scrolling
   beside it (the frame and the oval themselves are sized in section 5). */
@media (min-width: 600px) and (max-height: 559px) and (min-aspect-ratio: 11/10) {
  .learn-layout {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0 16px;
    align-items: start;
    padding: 10px var(--gutter-r) calc(20px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
    grid-template-areas:
      "oval heading"
      "oval switches"
      "oval panel";
  }
  .learn-stage { display: contents; }
  .learn-stage-header { grid-area: heading; }
  .learn-heading { min-height: 0; padding: 0 0 8px; }
  .position-finder { margin: 0 0 12px; }
  .learn-switches { grid-area: switches; padding: 0 0 12px; }
  .learn-panel { grid-area: panel; padding: 0; }
  .learn-panel .lesson-list, .learn-panel .pos-list { grid-template-columns: minmax(0, 1fr); }
  /* The sheet is a card in the column here, so it needs no room under the page. */
  body.has-sheet .learn-layout { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}

/* Settings are about setting a field: nothing for them to do here. */
body[data-view="learn"] .btn-header { visibility: hidden; }

/* 15. Toast -------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  /* Sit above the iPhone home indicator; its Reload button must stay tappable. */
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 6px 6px 6px 16px;
  border-radius: 12px;
  background: #14231b;
  color: #ffffff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.toast-text { padding: 8px 0; }
.toast-action, .toast-close {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffd166;
  font-weight: 700;
  cursor: pointer;
}
.toast-close { color: #ffffff; opacity: 0.8; font-size: 1.4rem; }
.toast:focus-within, .toast-action:focus-visible, .toast-close:focus-visible { outline-color: #ffd166; }

/* 16. Utilities & motion ------------------------------------------------------ */
.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 (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* A captain's sheet for paper or Save as PDF. The named page applies only
   to the field planner, so lesson and training print layouts keep their size. */
#field-print { display: none; }
@page field-plan { size: A4 portrait; margin: 12mm 15mm; }
@media print {
  body.printing-field {
    page: field-plan;
    display: block;
    min-height: 0;
    height: auto;
    overflow: visible;
    margin: 0;
    padding: 0;
    color-scheme: light;
    background: #fff;
    color: #111;
  }
  body.printing-field > :not(#field-print),
  body.printing-field dialog::backdrop { display: none !important; }
  body.printing-field #field-print {
    display: block;
    font: 11pt/1.3 system-ui, sans-serif;
    break-inside: avoid;
  }
  #field-print h1 { margin: 0 0 2mm; font-size: 21pt; line-height: 1.15; overflow-wrap: anywhere; }
  #field-print p { margin: 0; }
  #field-print .print-diagram { margin: 3mm 0; }
  #field-print svg { display: block; width: 100%; height: 158mm; }
  #field-print h2 { margin: 0 0 1mm; padding-top: 2mm; border-top: .35mm solid #222; font-size: 13pt; }
  #field-print ol {
    margin: 0; padding: 0; list-style: none;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 7mm;
  }
  #field-print li { display: flex; align-items: baseline; gap: 2mm; min-height: 7.5mm; padding-top: 1mm; }
  #field-print li b { min-width: 5mm; text-align: right; }
  #field-print li::after { content: ''; flex: 1 0 7mm; border-bottom: .2mm solid #666; }
  #field-print .print-warning { margin-top: 3mm; padding-left: 2mm; border-left: .6mm solid; font-size: 10pt; }
}

.cookie-notice {
  position: fixed;
  z-index: 101;
  inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto;
  width: min(26rem, calc(100% - 24px));
  max-height: 70dvh;
  overflow: auto;
  padding: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 3px 22px #0003;
}
.cookie-notice h2 { margin: 0; font-size: 1.05rem; }
.cookie-notice p { margin: .45rem 0 .8rem; line-height: 1.45; }
.cookie-notice a, .privacy-link { color: var(--primary-strong); }
.cookie-notice div { display: flex; flex-wrap: wrap; gap: .5rem; }
.cookie-notice button { flex: 1 1 8rem; }
.privacy-footer { padding: .6rem var(--gutter-l); }
.privacy-copy { max-width: 48rem; padding-bottom: 2.5rem; }
.privacy-copy h2 { margin: 1.6rem 0 .35rem; font-size: 1.35rem; }
.privacy-copy p { line-height: 1.6; }
@media print { .cookie-notice, .privacy-footer { display: none !important; } }

.measurement-frame { position: fixed; inset: 0 auto auto 0; width: 1px; height: 1px; border: 0; opacity: 0; pointer-events: none; }
@media print { .measurement-frame { display: none; } }
