/* Handy und Tablet: greift nur bei schmalem/niedrigem Fenster oder bei Touch-Bedienung (pointer: coarse).
   Breakpoints Trainingsbildschirm: Desktop ab 1024 px, Tablet 600–1023 px (und Handy quer), Handy unter 600 px. */

/* ---------- Immer: neue Elemente ---------- */
#banners:empty { display: none; }
.banner { display: flex; align-items: center; gap: var(--a-2); flex-wrap: wrap; padding: var(--a-2) var(--a-4); background: var(--weich-hinweis); border-bottom: 1px solid var(--hinweis); font-size: var(--t-1); color: var(--hinweis); }
.banner span { flex: 1 1 240px; }
.banner button { margin: 0; padding: var(--a-1) var(--a-3); }
.banner .banner-x { border: none; background: none; }
#chartBtns { position: absolute; left: 8px; top: 8px; z-index: 6; display: flex; gap: var(--a-2); align-items: center; }
#chartBtns button { margin: 0; padding: var(--a-1) var(--a-3); font-size: var(--t-1); background: var(--flaeche); }
#chartBtns, #chartBtns > div { pointer-events: none; } /* Lücken zwischen den Knöpfen gehören dem Chart (sonst verschluckte Taps) */
#chartBtns button { pointer-events: auto; }
#modeSwitch { display: none; background: var(--papier-tief); padding: var(--a-1); border-radius: var(--r-bedien); }
#modeSwitch button { border: none; border-radius: var(--r-bedien); background: transparent; font-weight: 600; color: var(--untiefe); }
#modeSwitch button.on { background: var(--flaeche); color: var(--tinte); box-shadow: inset 0 -2px 0 var(--messing); }
body.draw-mode #modeSwitch button.on[data-mode="draw"] { background: var(--accent); color: var(--auf-messing); }
#loupe { position: fixed; z-index: 200; pointer-events: none; border-radius: 50%; box-shadow: 0 0 0 3px var(--flaeche), 0 6px 20px var(--schatten); }
.filebtn { display: inline-block; position: relative; padding: var(--a-2) var(--a-4); border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent); color: var(--auf-messing); font-weight: 600; cursor: pointer; margin: var(--a-1) 0; }
.filebtn input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
#appData h3.sub, #infoPage h3.sub { font-size: var(--t-1); text-transform: none; letter-spacing: normal; color: var(--muted); margin: var(--a-4) 0 var(--a-1); }
#appData details { margin-top: var(--a-1); }
.tbl-scroll { max-height: 40vh; overflow: auto; -webkit-overflow-scrolling: touch; }
#infoPage { position: fixed; inset: 0; z-index: 120; background: var(--bg); overflow-y: auto; padding: var(--a-4) var(--a-5); }
#infoPage section { max-width: 760px; margin-top: var(--a-3); }
/* Trade-Management */
#chartBtns { flex-wrap: wrap; max-width: calc(100% - 80px); }
#btnChartPause { font-weight: 700; }
#tmLive { padding: var(--a-1) var(--a-3); border-radius: var(--r-bedien); background: var(--flaeche); font-weight: 600; font-size: var(--t-1); box-shadow: 0 1px 3px var(--schatten); }
#tmInfo { position: absolute; left: 8px; top: 64px; z-index: 7; max-width: min(440px, 90%); padding: var(--a-2) var(--a-6) var(--a-2) var(--a-3); font-size: var(--t-1); line-height: 1.5;
  background: var(--flaeche); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 4px 14px var(--schatten); }
.tm-x { position: absolute; right: 2px; top: 2px; margin: 0; padding: 2px var(--a-2); border: none; background: none; }
.tm-row { display: flex; flex-wrap: wrap; gap: var(--a-2); align-items: center; margin: var(--a-2) 0; }
.tm-why { display: block; margin: var(--a-2) 0; } .tm-why input { display: block; width: 100%; box-sizing: border-box; min-height: 44px; margin-top: var(--a-1); }
.tm-row label { display: flex; gap: var(--a-2); align-items: center; margin: 0; }
.tm-row button { margin: 0; }
#tmStop, #tmTarget { width: 110px; }
#tmPartPct { width: 70px; }
#tmLog { font-size: var(--t-1); }
.tm-result { margin-bottom: var(--a-4); }
#tmDialog { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: var(--a-4); background: var(--schleier); }
.tm-box { width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; padding: var(--a-4); border-radius: var(--r-panel); background: var(--card, var(--flaeche)); box-shadow: 0 12px 40px var(--schatten); }
.tm-box input[type=text], .tm-box textarea { width: 100%; box-sizing: border-box; margin-top: var(--a-2); }
.tm-btns { display: flex; flex-wrap: wrap; gap: var(--a-2); margin-top: var(--a-3); }
.tm-btns button { margin: 0; }
.an-blocks { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--a-3); margin: var(--a-2) 0; }
.an-block { padding: var(--a-3) var(--a-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card, var(--flaeche)); line-height: 1.7; }
.an-block h4 { margin: 0 0 var(--a-1); }
.an-warn { padding: var(--a-2) var(--a-3); border-radius: var(--radius-sm); background: var(--weich-gefahr); border: 1px solid var(--gefahr); color: var(--gefahr); font-weight: 600; }
.gal-excl { margin-top: var(--a-4); padding: var(--a-3) var(--a-3); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.gal-excl select, .gal-excl input { margin: var(--a-1) var(--a-2) var(--a-1) 0; }
/* Trade-Auswertung */
#review { position: fixed; inset: 0; z-index: 130; background: var(--bg); overflow-y: auto; padding: var(--a-4) var(--a-5); box-sizing: border-box; }
#review[hidden] { display: none; }
#rvHead { position: sticky; top: 0; z-index: 3; margin: var(--a-2) 0 var(--a-3); padding: var(--a-2) 0; background: var(--bg); box-shadow: 0 4px 8px -6px var(--schatten); }
.rv-meta { font-size: var(--t-1); color: var(--muted); }
.rv-meta b { color: var(--text); font-size: var(--t-2); }
.rv-kpis { display: flex; flex-wrap: wrap; gap: var(--a-2) var(--a-4); margin: var(--a-2) 0; font-size: var(--t-2); }
.rv-matrix { border-left: 6px solid var(--c); background: color-mix(in srgb, var(--c) 12%, var(--flaeche)); border-radius: var(--radius-sm); padding: var(--a-2) var(--a-3); font-size: var(--t-1); }
.rv-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr); gap: var(--a-4); align-items: start; }
.rv-chart { position: sticky; top: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--a-2); }
.rv-views { display: flex; flex-wrap: wrap; gap: var(--a-2); margin-bottom: var(--a-2); }
.rv-views button { margin: 0; padding: var(--a-1) var(--a-3); font-size: var(--t-1); }
.rv-views button.on { background: var(--accent); color: var(--auf-messing); border-color: var(--accent); }
#rvSlider { width: 100%; min-height: 44px; margin: var(--a-1) 0 0; }
.rv-card { background: var(--card); border: 1px solid var(--rand-karte); box-shadow: var(--karte); border-radius: var(--radius); margin-bottom: var(--a-3); }
.rv-card summary { cursor: pointer; padding: var(--a-3) var(--a-3); font-weight: 600; }
.rv-in { padding: 0 var(--a-3) var(--a-3); overflow-x: auto; }
.rv-checks td:first-child { width: 28px; text-align: center; }
.rv-you td { font-weight: 600; background: var(--flaeche); }
.rv-lights { list-style: none; padding: 0; margin: var(--a-1) 0; }
.rv-lights .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: var(--a-2); }
/* Schreibmodus (Nachbetrachtung offen): Kopf scrollt mit, der Chart bleibt oben stehen */
#review.rv-writing #rvHead { position: static; box-shadow: none; }
#review.rv-writing .rv-chart { position: sticky; top: 0; z-index: 2; }
.rv-q { display: block; margin: var(--a-2) 0; }
.rv-q textarea, .rv-q input { width: 100%; box-sizing: border-box; }
.rv-sim { list-style: none; padding: 0; }
.rv-sim button { margin: 2px 0; text-align: left; }
#rvReport { width: 100%; box-sizing: border-box; font-family: var(--schrift-mono); font-size: var(--t-1); }
.an-matrix { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--a-2); }
.an-matrix div { border-left: 6px solid var(--c); background: var(--flaeche); border-radius: var(--radius-sm); padding: var(--a-2) var(--a-3); }
#noticeText { white-space: pre-wrap; background: var(--flaeche); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--a-3) var(--a-3); font-size: var(--t-1); }

/* ---------- Touch-Geräte: große Bedienflächen (mind. 44 × 44 px), Modus-Schalter sichtbar ---------- */
@media (pointer: coarse) {
  #modeSwitch { display: flex; }
  button, select, input[type=number], input[type=text], input[type=search], .filebtn, .hdr-btn { min-height: 44px; }
  button, .hdr-btn { min-width: 44px; }
  #chartBtns button { min-height: 40px; font-size: var(--t-1); }
  label:has(> input[type=checkbox]) { min-height: 44px; display: flex; align-items: center; }
  input[type=range] { height: 44px; }
  .skiprow button { min-width: 48px; }
  #tfSwitch button { min-height: 40px; }
  #chart { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  body.draw-mode #chart { touch-action: none; } /* Zeichnen: Finger verschiebt weder Chart noch Seite */
  #zoneMenu button { min-height: 48px; min-width: 180px; }
}

/* ---------- Andere Bildschirme auf schmalen Fenstern (unverändert, Umbau in Phase 3) ---------- */
@media (max-width: 900px), (max-height: 520px) {
  /* Galerie, Analyse, Info: lesbar, Tabellen horizontal scrollbar */
  #gallery, #analyse, #infoPage { padding: var(--a-3) var(--a-3) var(--a-6); padding-top: max(var(--a-3), env(safe-area-inset-top)); }
  .an-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .an-charts, .an-blocks { grid-template-columns: 1fr; }
  #review { padding: 0 var(--a-2) var(--a-6); }
  #review .gal-top { padding-top: max(var(--a-2), env(safe-area-inset-top)); }
  #rvHead { margin: 0 -8px var(--a-2); padding: var(--a-2) var(--a-2); background: var(--bg); box-shadow: 0 4px 8px -6px var(--schatten); }
  .rv-kpis { font-size: var(--t-1); gap: 2px var(--a-3); }
  .rv-grid { grid-template-columns: 1fr; }
  .rv-chart { position: static; }
  #review.rv-writing #rvViews { display: none; }  .an-matrix { grid-template-columns: repeat(2, 1fr); }
  #galGrid { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
  #galFilters, #anFilters { gap: var(--a-1); }
  #galFilters select, #galFilters input, #anFilters select { flex: 1 1 140px; }
  #anSettings label { display: block; }
  .gal-detail-box { padding: var(--a-4) var(--a-3); }
  #galDetail { padding: var(--a-2); }
}

/* ---------- Trainingsbildschirm, Tablet (600–1023 px) und Handy quer: Werkzeuge links, Peilung als Overlay von rechts ---------- */
@media (max-width: 1023px), (max-height: 520px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  #statusbar { gap: var(--a-2); padding: var(--a-1) var(--a-3); padding-top: max(var(--a-1), env(safe-area-inset-top)); }
  #statusbar .h1-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } /* bleibt für Screenreader */
  #saveStatus { display: none; }
  main { padding: var(--a-2) var(--a-3); padding-left: max(var(--a-2), env(safe-area-inset-left)); }
  #toolOptions { overflow-x: auto; flex-wrap: nowrap; white-space: nowrap; }
  #toolHint { white-space: normal; min-width: 200px; }
  .tb[data-tip]:hover::after { display: none; } /* Tooltip würde vom Scrollbereich abgeschnitten; Name steht im aria-label */
  #peilung { position: fixed; z-index: 80; top: 0; right: 0; bottom: 0; width: min(380px, 86vw); max-height: none; padding: 0 var(--a-3) var(--a-5);
    background: var(--papier); box-shadow: var(--schwebe); transform: translateX(105%); transition: transform .22s ease-out; visibility: hidden; }
  body[data-peil="zu"] #peilung { display: flex; }
  body:not([data-peil="zu"]) #peilung { transform: none; visibility: visible; }
  #sheetHead { padding-top: max(var(--a-2), env(safe-area-inset-top)); }
  body[data-peil="zu"] #peilOpen { position: fixed; z-index: 70; right: 0; top: 50%; transform: translateY(-50%); border-radius: var(--r-bedien) 0 0 var(--r-bedien); border-right: none; }
  #tradePanel { order: -1; scroll-margin-top: 52px; } /* Pause: Eingriffe oben in der Peilung */
}
@media (max-height: 520px) and (orientation: landscape) {
  #chart { height: calc(100dvh - 150px); min-height: 200px; }
  #info { display: none; }
}

/* ---------- Trainingsbildschirm, Handy (< 600 px): Chart oben, Werkzeuge unten wischbar, Peilung als Bottom-Sheet ---------- */
@media (max-width: 599px) {
  button, select, input[type=number], input[type=text], .hdr-btn { min-height: 44px; }
  button, .hdr-btn { min-width: 44px; }
  label:has(> input[type=checkbox]) { min-height: 44px; display: flex; align-items: center; }
  #statusbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: var(--a-2); padding: var(--a-1) var(--a-2); min-height: 52px; } /* eine Zeile, wischbar */
  #statusbar > * { flex: none; }
  .acc-kpi { padding: 2px var(--a-2); } .acc-kpi b { font-size: var(--t-2); } .acc-kpi span { display: none; } /* Kontostand: beide Beträge ohne Wischen sichtbar; Prozent steht am Desktop */
  #statusbar h1 { margin: 0; }
  #tfSwitch button, #draw-color { min-height: 44px; min-width: 44px; }
  #btnNew { padding: var(--a-2) var(--a-3); }
  .pop { position: static; }
  .pop-panel { position: fixed; top: 56px; left: var(--a-2); right: var(--a-2); max-width: none; width: auto; } /* fixed: entkommt dem Scrollbereich der Statuszeile */
  #toolHint { white-space: nowrap; min-width: 0; } /* eine Zeile, wischbar */
  main { display: block; padding: var(--a-1) var(--a-2) calc(56px + 53px + 56px + 48px + var(--a-4) + env(safe-area-inset-bottom)); }
  .left { gap: var(--a-1); }
  #chart { height: max(60vh, 320px); height: max(60dvh, 320px); min-height: 0; }
  body.full #chart { height: calc(100dvh - 200px); }
  /* Bewegen / Zeichnen groß und immer sichtbar */
  #modeSwitch { display: flex; }
  #modeSwitch button { min-height: 48px; min-width: 88px; font-size: var(--t-2); }
  #chartBtns button { min-height: 48px; }
  /* Player fest über der Werkzeugleiste: Abspielen bleibt auch bei offener Peilung erreichbar; Rest wischbar */
  #player { position: fixed; z-index: 90; left: 0; right: 0; bottom: calc(109px + env(safe-area-inset-bottom)); height: 56px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    gap: var(--a-2); padding: var(--a-1) var(--a-2); border-radius: 0; border-top: 1px solid var(--linie); }
  #player > * { flex: none; }
  #player > .skiprow, #player > .speed, #playNote, #skipInfo { order: 2; }
  #player .skiprow { flex-wrap: nowrap; }
  .skiprow > span { display: none; } /* Gruppe trägt den Namen „Schritt vor“ */
  #player .speed input { width: 100px; }
  /* Werkzeuge: waagerechte, wischbare Leiste unten */
  #toolbar { position: fixed; z-index: 91; left: 0; right: 0; top: auto; bottom: calc(56px + env(safe-area-inset-bottom)); max-height: none; display: flex; flex-direction: row; align-items: center; justify-content: space-between; overflow: visible;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; border-radius: 0; border-top: 1px solid var(--linie); padding: var(--a-1) var(--a-2); }
  .tb { flex: none; }
  .tb.active { box-shadow: inset 0 -3px 0 var(--messing); }
  .tb-gap { display: none; } /* 8 Knöpfe passen nur ohne Lücke auf 375 px */
  .flyout { position: fixed; left: var(--a-2); right: var(--a-2); top: auto; bottom: calc(56px + 53px + var(--a-2) + env(safe-area-inset-bottom)); min-width: 0; } /* öffnet nach oben über der Leiste */
  /* Peilung: Bottom-Sheet über der Werkzeugleiste, Stufen zu / halb / voll */
  #peilung { left: 0; right: 0; top: auto; bottom: calc(165px + env(safe-area-inset-bottom)); width: auto; height: 48px; padding: 0 var(--a-3) var(--a-4);
    transform: none; visibility: visible; transition: height .22s ease-out; border-radius: var(--r-panel) var(--r-panel) 0 0; overflow-y: hidden; z-index: 85; }
  body[data-peil="halb"] #peilung { height: 50vh; height: 50dvh; overflow-y: auto; }
  body[data-peil="voll"] #peilung { height: calc(100dvh - 165px - 60px - env(safe-area-inset-bottom)); overflow-y: auto; }
  body[data-peil="zu"] #peilOpen { display: none; }
  #sheetHead { margin: 0 calc(-1 * var(--a-3)); padding: 0 var(--a-2); touch-action: none; background: var(--papier); border-radius: var(--r-panel) var(--r-panel) 0 0; }
  #sheetGrip { flex: 1; flex-direction: column; gap: 2px; min-height: 48px; justify-content: center; font-size: var(--t-1); }
  #sheetGrip .grip { display: block; width: 40px; height: 4px; border-radius: var(--r-bedien); background: var(--rahmen); }
  body[data-peil="zu"] #sheetClose { display: none; }
}

@media (max-width: 599px) {
  :is(.pv-table, .vr-table, .ev-table, .mp-table) :is(td, th):first-child { position: sticky; left: 0; z-index: 1; background: var(--flaeche); box-shadow: 1px 0 0 var(--linie); }
}
/* Handy: Navigation als untere Leiste mit 5 Einträgen; „Daten“ öffnet die übrigen Bildschirme */
@media (max-width: 599px) {
  body { padding-left: 0; }
  #appNav { top: auto; right: 0; width: auto; height: calc(56px + env(safe-area-inset-bottom)); flex-direction: row; gap: 0; overflow: visible;
    padding: 0 0 env(safe-area-inset-bottom); border-right: none; border-top: 1px solid var(--linie); }
  .nav-item { flex: 1 1 0; min-width: 0; min-height: 56px; padding: var(--a-1) 0; gap: 1px; font-size: 11px; line-height: 1.1; } /* zwei Zeilen passen in 56 px */
  .nav-item svg { width: 20px; height: 20px; }
  .nav-item[aria-current="page"] { box-shadow: inset 0 3px 0 var(--messing); }
  #navData { display: flex; }
  #navDataItems { display: none; }
  body.data-open #navDataItems { display: flex; flex-direction: column; position: fixed; z-index: 141; right: var(--a-2); bottom: calc(56px + var(--a-2) + env(safe-area-inset-bottom));
    width: min(260px, calc(100vw - 16px)); padding: var(--a-2); background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--r-panel); box-shadow: var(--schwebe); }
  #navDataItems .nav-item { flex: none; flex-direction: row; gap: var(--a-3); min-height: 48px; padding: var(--a-2) var(--a-3); text-align: left; font-size: var(--t-2); }
  #navDataItems .nav-item[aria-current="page"] { box-shadow: inset 3px 0 0 var(--messing); }
  #navDataItems .nav-item span { white-space: nowrap; }
  #btnInfo { margin-top: 0; }
  body > :is(#gallery, #analyse, #peers, #mp, #ch, #rm, #sim, #ev, #vr, #review, #infoPage, #rp, #lp) { left: 0; bottom: calc(56px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  #peilung, #curtain { transition: none !important; }
}
