/* Training in the app layout (phones and touch tablets, html.gt-app). Shared frame: assets/css/mode-app.css.
   Two phases in the same page, told apart in CSS only:
     - preparing the list (#training-panel.d-none): a page that scrolls, compact; presets in a row that scrolls
       sideways; Export / Import in the "⋯" sheet; "Start training" stays at the bottom while the list is in view;
     - session (#training-panel visible): a game frame (banner, map, answer dock) as in SpotCity, the HUD's own
       counters (Remaining, Correct, Errors) and the last answer on the map, "Get a hint" above the dock.
   The intro, the session heading, the map toolbar, the progress and the guide are moved under the frame by
   data-gtm-move (mode-app.js): nothing is hidden. Fullscreen (.geotrainer-fullscreen) keeps its own rules. */

.gt-app { --gtm-accent: #9b6cff; --gtm-accent-ink: color-mix(in srgb, #9b6cff 72%, #101820); --trn-good: #138a5e; }
.gt-app[data-bs-theme="dark"] { --gtm-accent-ink: #b896ff; --trn-good: #34d399; }

/* overflow: clip instead of hidden keeps position: sticky working (the "Start training" bar). */
.gt-app .gt-training-page { overflow: clip; }
.gt-app .gt-game-section { padding: 0; }
.gt-app .gt-game-section > .container { max-width: none; padding: 0; }

.gt-app #training-container:not(.geotrainer-fullscreen) {
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transition: none;
}
.gt-app #training-container:not(.geotrainer-fullscreen)::before { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-game-body { padding: 0; transition: none; }
.gt-app #training-container.geotrainer-fullscreen #training-more-btn { display: none; }

/* ------------------------------------------------------------ banner (both phases): kicker, real h1, count, "⋯" */
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas:
    "kicker stat more"
    "title  stat more";
  align-items: center;
  column-gap: 10px;
  margin: 0;
  padding: 10px var(--gtm-gutter, 16px);
  border-bottom: 1px solid var(--sh-border-soft);
}
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-game-heading { display: contents; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-kicker {
  grid-area: kicker;
  align-self: end;
  color: var(--gtm-accent-ink);
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .1em;
}
.gt-app #training-container:not(.geotrainer-fullscreen) #training-title {
  grid-area: title;
  align-self: start;
  min-width: 0;
  margin: 3px 0 0;
  font-size: 1.19rem;
  font-weight: 850;
  letter-spacing: -.02em;
  line-height: 1.15;
}
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-primary-stat {
  grid-area: stat;
  min-width: 0;
  width: auto;
  padding: 6px 12px;
  gap: 0;
  border: 0;
  border-radius: 14px;
  background: var(--sh-surface);
}
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-primary-stat-icon { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-primary-stat > span:last-child { display: flex; flex-direction: column-reverse; align-items: flex-end; line-height: 1.1; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-primary-stat strong { margin: 0; font-size: 1.1rem; font-weight: 900; line-height: 1; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar .gt-primary-stat small { font-size: .69rem; font-weight: 600; white-space: nowrap; }
.gt-app #training-container:not(.geotrainer-fullscreen) #training-more-btn { grid-area: more; }

/* ------------------------------------------------------------ preparing the list */
.gt-app #training-setup:not(.d-none) { gap: 16px; padding: 16px var(--gtm-gutter, 16px) 0; }
.gt-app #training-setup .gt-training-builder-head { display: block; padding-top: 0; border-top: 0; }
.gt-app #training-setup .gt-training-builder-head h2 { margin: 4px 0 0; font-size: 1.15rem; }
.gt-app #training-setup .gt-training-builder-head p { margin: 6px 0 0; color: var(--gt-muted); font-size: .9rem; }
.gt-app #training-setup .gt-training-builder-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.gt-app #training-setup .gt-training-builder-card { padding: 14px; border-radius: 18px; }
.gt-app #training-setup .gt-training-input .form-control { min-height: 52px; font-size: 16px; }
/* Presets: one row that scrolls sideways (buttons keep their order for the keyboard). */
.gt-app #training-setup .gt-training-preset-grid {
  display: flex;
  gap: 8px;
  margin: 0 -14px;
  padding: 2px 14px 6px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.gt-app #training-setup .gt-training-preset-grid::-webkit-scrollbar { display: none; }
.gt-app #training-setup .gt-training-preset { flex: none; min-height: 44px; scroll-snap-align: start; }
.gt-app #training-setup .gt-training-preset strong { font-size: .8rem; white-space: nowrap; }
.gt-app #training-setup .gt-training-favorites { min-height: 44px; }
.gt-app #training-setup .gt-training-selection { padding: 14px; border-radius: 18px; }
.gt-app #training-setup .gt-training-selected-list .list-group-item { min-height: 48px; }
/* Export / Import live in the "⋯" sheet; "Start training" stays at the bottom while the list is in view. */
.gt-app #training-setup #training-import-export { display: none; }
.gt-app #training-setup .gt-training-selection-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 12px -14px -14px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--sh-border-soft);
  border-radius: 0 0 18px 18px;
  background: var(--sh-card);
}
.gt-app #training-setup .gt-training-start { width: 100%; min-height: 52px; font-weight: 800; }

/* The map of the list, under the preparation. */
.gt-app #training-container:not(.geotrainer-fullscreen):not(:has(#training-panel:not(.d-none))) .gt-training-map-frame {
  margin: 16px var(--gtm-gutter, 16px) 0;
  padding: 0;
  border-radius: 20px;
}
.gt-app #training-container:not(.geotrainer-fullscreen):not(:has(#training-panel:not(.d-none))) .gt-training-map-frame #map { height: 56vh; min-height: 320px; border-radius: 20px; }

/* ------------------------------------------------------------ session: the game frame */
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-game-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "banner"
    "map"
    "dock";
  height: var(--gtm-game-h);
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) :is(#training-panel, #training-fullscreen-hud) { display: contents; }
.gt-app #training-container:not(.geotrainer-fullscreen) .gt-training-topbar { grid-area: banner; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) :is(.gt-training-fs-identity, #training-hud-form) { display: none; }

.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-map-frame {
  grid-area: map;
  position: relative;
  z-index: 0; /* keeps Leaflet's panes under the dock, the counters and "Get a hint" */
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-map-frame #map { height: 100%; min-height: 0; border-radius: 0; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-hint-card {
  top: 12px;
  right: 12px;
  bottom: auto;
  left: 12px;
  width: auto;
}

/* The HUD's own counters (already kept up to date outside fullscreen), bottom left of the map. */
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats {
  grid-area: map;
  align-self: end;
  justify-self: start;
  position: relative;
  z-index: 600;
  max-width: calc(100% - 140px);
  margin: 0 0 30px 12px; /* above the map credits */
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span {
  min-height: 32px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--sh-border);
  border-radius: 999px;
  background: var(--sh-navbar-bg);
  color: var(--sh-text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats small { color: var(--sh-muted); font-size: .72rem; font-weight: 700; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats strong { font-size: .82rem; font-weight: 800; }
/* Selection = the banner's count; Correct / Errors as ✓ / ✕, their words kept for screen readers. */
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:first-child { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:nth-child(n+3) small {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:nth-child(3)::before { content: "\2713"; color: var(--trn-good); font-weight: 900; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:nth-child(4)::before { content: "\2715"; color: var(--gtm-danger); font-weight: 900; }

/* Last answer only, above the counters. */
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-history-wrap {
  grid-area: map;
  align-self: end;
  justify-self: start;
  position: relative;
  z-index: 600;
  max-width: calc(100% - 24px);
  margin: 0 12px 80px; /* above the counters and "Get a hint" */
  border: 0;
  background: none;
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-history-head { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-history li + li { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-history li {
  max-width: 100%;
  overflow: hidden;
  padding: 6px 12px;
  border: 1px solid var(--sh-border);
  border-radius: 999px;
  background: var(--sh-navbar-bg);
  font-size: .8rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
/* The legend is the same as the dots: room on the phone goes to the counters and the last answer. */
@media (max-width: 759.98px) {
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) :is(.gt-training-map-legend, .gt-map-badge, .leaflet-control-zoom) { display: none; }
}

/* Dock: answer field and Validate; "Get a hint" above it on the map; End session in the sheet. */
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-form {
  grid-area: dock;
  position: relative;
  z-index: 3;
  display: block;
  margin: 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--sh-border-soft);
  background: var(--sh-card);
}
.gt-app.gtm-kb-open #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-form { padding-bottom: 10px; }
.gt-app #training-container:not(.geotrainer-fullscreen) #training-form .gt-input-group { min-height: 52px; box-shadow: none; }
.gt-app #training-container:not(.geotrainer-fullscreen) #training-answer { font-size: 16px; }
.gt-app #training-container:not(.geotrainer-fullscreen) #training-form .gt-btn-validate { min-width: 0; padding-inline: 18px; font-weight: 800; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-session-actions {
  position: absolute;
  right: 12px;
  bottom: calc(100% + 30px);
  margin: 0;
  display: flex;
  gap: 8px;
}
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #end-training { display: none; }
.gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-session-actions [data-gt-training-hint] {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Keyboard up: banner on one line, the map keeps the rest. */
.gt-app.gtm-kb-open #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-topbar .gt-kicker { display: none; }
.gt-app.gtm-kb-open #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-title {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gt-app.gtm-kb-open #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-topbar .gt-primary-stat small {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ------------------------------------------------------------ under the frame (moved): intro, session heading, map toolbar,
   progress and guide, in the page order */
.gt-app .gt-game-section > .container > p[data-gtm-move] {
  max-width: 680px;
  margin: 18px var(--gtm-gutter, 16px) 0;
  color: var(--gt-muted);
  font-size: .95rem;
  line-height: 1.6;
}
/* The session heading belongs to the session: hidden while the list is prepared, as inside its panel today. */
.gt-app .gt-game-section > .container:has(#training-panel.d-none) > .gt-training-session-head { display: none; }
.gt-app .gt-game-section > .container > .gt-training-session-head { margin: 18px var(--gtm-gutter, 16px) 0; }
.gt-app .gt-game-section > .container > .gt-training-map-toolbar { margin: 18px var(--gtm-gutter, 16px) 0; flex-wrap: wrap; }
.gt-app .gt-game-section > .container > .gt-training-map-toolbar #toggle-fullscreen { display: none; }
.gt-app .gt-game-section > .container > #training-found-card,
.gt-app .gt-game-section > .container > #training-howto { margin: 24px var(--gtm-gutter, 16px) 0; }
.gt-app .gt-game-section > .container > :last-child { margin-bottom: 32px; }

/* Sheet: the actions of the current phase. */
.gt-app #training-more .gtm-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.gt-app body:has(#training-panel.d-none) #training-more .gtm-session-only,
.gt-app body:has(#training-panel:not(.d-none)) #training-more .gtm-setup-only { display: none; }

/* ------------------------------------------------------------ touch tablets in landscape: session = map left, panel right */
@media (min-width: 1000px) {
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-game-body {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas:
      "map banner"
      "map dock"
      "map stats"
      "map history";
    column-gap: 16px;
    padding: 16px var(--gtm-gutter, 32px) 20px;
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-game-body::before {
    content: "";
    grid-row: 1 / -1;
    grid-column: 2;
    border: 1px solid var(--sh-border-soft);
    border-radius: 22px;
    background: var(--sh-card);
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-topbar { padding: 16px 16px 12px 20px; border-bottom: 0; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-title { font-size: 1.25rem; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-map-frame {
    grid-area: auto;
    grid-row: 1 / -1;
    grid-column: 1;
    border: 1px solid var(--sh-border-soft);
    border-radius: 22px;
    overflow: hidden;
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-form { margin: 0 20px; padding: 0; border: 0; background: transparent; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-session-actions {
    position: static;
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #end-training { display: inline-flex; min-height: 44px; border-radius: 999px; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats {
    grid-area: stats;
    align-self: start;
    justify-self: stretch;
    max-width: none;
    margin: 14px 20px 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:first-child { display: inline-flex; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span {
    justify-content: space-between;
    min-height: 40px;
    border-radius: 14px;
    background: var(--sh-surface);
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:nth-child(n+3) small { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-fs-stats > span:nth-child(n+3)::before { content: none; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-history-wrap {
    grid-area: history;
    align-self: stretch;
    justify-self: stretch;
    max-width: none;
    min-height: 0;
    margin: 14px 20px 20px;
    overflow: auto;
    border: 1px solid var(--sh-border-soft);
    background: var(--sh-surface);
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-history-head { display: flex; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-history li + li { display: block; }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) #training-history li {
    border: 0;
    border-bottom: 1px solid var(--sh-border-soft);
    border-radius: 0;
    background: none;
    white-space: normal;
    backdrop-filter: none;
  }
  .gt-app #training-container:not(.geotrainer-fullscreen):has(#training-panel:not(.d-none)) .gt-training-hint-card { right: 12px; left: 68px; } /* right of the 44 px zoom buttons */
}

/* Touch sizes: zoom buttons (list map, tablets) and "Clear all". */
.gt-app #training-container:not(.geotrainer-fullscreen) .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; font-size: 20px; }
.gt-app #training-setup #training-clear-selection { min-height: 44px; }
