/* Wspólny motyw Akademii MCHIM: nocny oraz jasny do rzutnika. */
:root,
html[data-mchim-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a !important;
  --panel: #1e293b !important;
  --panel2: #273449 !important;
  --line: #475569 !important;
  --text: #e2e8f0 !important;
  --muted: #a8b4c5 !important;
  --accent: #38bdf8 !important;
  --accent-d: #0ea5e9 !important;
  --gold: #38bdf8 !important;
  --gold-d: #0284c7 !important;
  --gold-l: #7dd3fc !important;
  --green: #22c55e !important;
  --red: #ef4444 !important;
  --yellow: #facc15 !important;
  --violet: #a78bfa !important;
  --orange: #f97316 !important;
  --theme-field: #0b1220;
  --theme-shadow: rgba(0, 0, 0, .36);
}

html[data-mchim-theme="light"] {
  color-scheme: light;
  --bg: #eef3f8 !important;
  --panel: #ffffff !important;
  --panel2: #e6eef7 !important;
  --line: #8da0b5 !important;
  --text: #172033 !important;
  --muted: #4a5b70 !important;
  --accent: #0369a1 !important;
  --accent-d: #075985 !important;
  --gold: #0369a1 !important;
  --gold-d: #075985 !important;
  --gold-l: #075985 !important;
  --green: #15803d !important;
  --red: #b91c1c !important;
  --yellow: #a16207 !important;
  --violet: #6d28d9 !important;
  --orange: #c2410c !important;
  --theme-field: #ffffff;
  --theme-shadow: rgba(30, 64, 96, .14);
}

html[data-mchim-theme] body {
  background:
    radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--accent) 17%, transparent) 0%, transparent 38%),
    radial-gradient(circle at 92% 100%, color-mix(in srgb, var(--violet) 12%, transparent) 0%, transparent 42%),
    var(--bg) !important;
  color: var(--text) !important;
  transition: background-color .2s ease, color .2s ease;
}

html[data-mchim-theme] header,
html[data-mchim-theme] .panel,
html[data-mchim-theme] .card,
html[data-mchim-theme] .tile,
html[data-mchim-theme] .container,
html[data-mchim-theme] .content,
html[data-mchim-theme] .quiz-card,
html[data-mchim-theme] .task-card,
html[data-mchim-theme] details {
  background-color: var(--panel) !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
  box-shadow: 0 10px 28px var(--theme-shadow) !important;
}

html[data-mchim-theme] header {
  background: linear-gradient(
    110deg,
    var(--panel) 0%,
    color-mix(in srgb, var(--panel2) 82%, var(--accent)) 100%
  ) !important;
  border: 1px solid var(--line) !important;
  border-left: 6px solid var(--accent) !important;
}

html[data-mchim-theme] .task-picker,
html[data-mchim-theme] .q,
html[data-mchim-theme] .question,
html[data-mchim-theme] .dane,
html[data-mchim-theme] .mode-switch,
html[data-mchim-theme] .ocena,
html[data-mchim-theme] .bar,
html[data-mchim-theme] .schemacik,
html[data-mchim-theme] .wzor-box,
html[data-mchim-theme] .answer-box,
html[data-mchim-theme] .info-box {
  background-color: var(--panel2) !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
}

html[data-mchim-theme] input,
html[data-mchim-theme] select,
html[data-mchim-theme] textarea {
  background: var(--theme-field) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

html[data-mchim-theme] .tresc,
html[data-mchim-theme] .task,
html[data-mchim-theme] .q label,
html[data-mchim-theme] .unit,
html[data-mchim-theme] td,
html[data-mchim-theme] th {
  color: var(--text) !important;
}

html[data-mchim-theme] a { color: var(--accent); }
html[data-mchim-theme] h1,
html[data-mchim-theme] h2,
html[data-mchim-theme] h3 { border-color: var(--accent) !important; }

html[data-mchim-theme="light"] .tile,
html[data-mchim-theme="light"] header,
html[data-mchim-theme="light"] .panel,
html[data-mchim-theme="light"] .container {
  background-image: linear-gradient(155deg, #ffffff, #eaf1f8) !important;
}

html[data-mchim-theme="light"] .tresc b,
html[data-mchim-theme="light"] .task h2,
html[data-mchim-theme="light"] .dane b,
html[data-mchim-theme="light"] header h1,
html[data-mchim-theme="light"] .tile-title,
html[data-mchim-theme="light"] .section-title h2 {
  color: #075985 !important;
}

/* Odpowiedzi jednokrotnego wyboru są tworzone dynamicznie z ciemnym tłem.
   W jasnym motywie nadajemy im jasne pole i ciemny, czytelny tekst. */
html[data-mchim-theme="light"] #opcjeWrap > label {
  background: #ffffff !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
  box-shadow: 0 2px 8px rgba(30, 64, 96, .08);
}

html[data-mchim-theme="light"] #opcjeWrap > label:hover,
html[data-mchim-theme="light"] #opcjeWrap > label:has(input:checked) {
  background: #e0f2fe !important;
  border-color: var(--accent) !important;
  color: #0c4a6e !important;
}

html[data-mchim-theme="light"] #opcjeWrap input[type="radio"] {
  accent-color: var(--accent);
}

html[data-mchim-theme="light"] input::placeholder,
html[data-mchim-theme="light"] textarea::placeholder {
  color: #64748b !important;
  opacity: 1;
}

/* Tolerancje i pasowania: opisy parametrów stoją na jasnych kartach pytań. */
html[data-mchim-theme="light"] body.page-pasowania .input-row,
html[data-mchim-theme="light"] body.page-pasowania .input-row sub,
html[data-mchim-theme="light"] body.page-pasowania .input-row sup {
  color: #334155 !important;
}

html[data-mchim-theme="light"] body.page-pasowania .radio-group label {
  background: #ffffff !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
}

html[data-mchim-theme="light"] body.page-pasowania .radio-group label:has(input:checked) {
  background: #e0f2fe !important;
  border-color: var(--accent) !important;
  color: #0c4a6e !important;
}

/* Obrabiarki: podpisy pozostają na ciemnych polach pod fotografiami. */
html[data-mchim-theme="light"] body.page-obrabiarki .obraz-box {
  color: #e2e8f0 !important;
}

html[data-mchim-theme="light"] body.page-obrabiarki .foto-podpis,
html[data-mchim-theme="light"] body.page-obrabiarki .cecha-box small {
  color: #cbd5e1 !important;
}

html[data-mchim-theme="light"] body.page-obrabiarki .obraz-box a,
html[data-mchim-theme="light"] body.page-obrabiarki .cecha-box,
html[data-mchim-theme="light"] body.page-obrabiarki .cecha-box b {
  color: #7dd3fc !important;
}

html[data-mchim-theme="light"] svg text[fill="#cbd5e1"],
html[data-mchim-theme="light"] svg text[fill="#e2e8f0"],
html[data-mchim-theme="light"] svg text[fill="#94a3b8"] {
  fill: #26364a !important;
}

/* Symulatory czujnikowe zachowują ciemne pola robocze także w jasnym motywie.
   Tekst w tych polach musi więc pozostać jasny i kontrastowy. */
html[data-mchim-theme="light"] .step-btn.active,
html[data-mchim-theme="light"] .step-btn.done {
  color: #f8fafc !important;
}

html[data-mchim-theme="light"] .step-btn.active .num {
  color: #ffffff !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .hint-box,
html[data-mchim-theme="light"] body.page-pomiary-gwintu .hint-box,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .stos-sum,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .obrot-box .kat,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .wychyl-box .info b,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .wychyl-box .status.warn {
  color: #fde047 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .hint-box {
  flex: 1 1 360px;
  width: auto;
  max-width: none;
  height: auto;
  min-height: 32px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .duze-pokretlo .wartosc {
  color: #fde047 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .dane span {
  background: #0b1220 !important;
  border-color: #64748b !important;
  color: #f8fafc !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .dane span b {
  color: #fde047 !important;
}

html[data-mchim-theme] body.page-pomiary-gwintu .scene-wrap .gwint-wnetrze {
  fill: url(#gwintWnetrze) !important;
}

html[data-mchim-theme] body.page-pomiary-gwintu .scene-wrap .gwint-gorny {
  fill: none !important;
  stroke: #facc15 !important;
}

html[data-mchim-theme] body.page-pomiary-gwintu .scene-wrap .gwint-dolny {
  fill: none !important;
  stroke: #fb923c !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .obrot-box label,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .wychyl-box .info {
  color: #cbd5e1 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .lift-badge,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .obrot-box .kat b,
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .wychyl-box .status.ok {
  color: #4ade80 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .dane span {
  background: #0b1220 !important;
  border-color: #64748b !important;
  color: #f8fafc !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .dane span b {
  color: #fde047 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .gwint-karta .nazwa {
  color: #38bdf8 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .gwint-karta .wiersz {
  color: #cbd5e1 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .gwint-karta .wiersz span:last-child {
  color: #e2e8f0 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-gwintu .gwint-karta b {
  color: #fde047 !important;
}

html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .scene-wrap svg text[fill="#cbd5e1"],
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .scene-wrap svg text[fill="#e2e8f0"],
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .scene-wrap svg text[fill="#94a3b8"],
html[data-mchim-theme="light"] body.page-pomiary-czujnikowe .scene-wrap svg text[fill="#64748b"] {
  fill: #e2e8f0 !important;
}

#mchim-theme-control {
  position: static;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 8px 24px var(--theme-shadow);
  backdrop-filter: blur(10px);
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  margin-left: auto;
  flex-shrink: 0;
}

#mchim-theme-control .theme-label {
  padding: 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}

#mchim-theme-control button {
  min-width: auto;
  width: auto;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: 700 13px/1.2 "Segoe UI", Roboto, system-ui, sans-serif;
  cursor: pointer;
  box-shadow: none;
}

#mchim-theme-control button:hover {
  color: var(--text);
  border-color: var(--line);
}

#mchim-theme-control button[aria-pressed="true"] {
  color: #ffffff;
  background: linear-gradient(180deg, var(--accent), var(--accent-d));
  border-color: var(--accent);
}

html[data-mchim-theme="light"] #mchim-theme-control button[aria-pressed="true"] {
  color: #ffffff;
}

@media (max-width: 700px) {
  #mchim-theme-control {
    width: 100%;
    margin: 4px 0 0;
    justify-content: center;
  }
  #mchim-theme-control .theme-label { display: inline; }
  #mchim-theme-control button { padding: 7px 9px; font-size: 12px; }
}

/* Obrazy dydaktyczne pokazujemy w całości — bez obcinania przez object-fit: cover. */
html[data-mchim-theme] .photo-fig img,
html[data-mchim-theme] .question-image img,
html[data-mchim-theme] .task-photo img,
html[data-mchim-theme] .tool-photo img,
html[data-mchim-theme] .photo-wrap img,
html[data-mchim-theme] .image-wrap img,
html[data-mchim-theme] img.foto,
html[data-mchim-theme] .foto img {
  object-fit: contain !important;
  object-position: center center !important;
  background: var(--theme-field) !important;
}

/* Rysunki znaków tolerancji muszą pozostać kontrastowe także w motywie nocnym. */
html[data-mchim-theme] body.page-odchylki .photo-fig .ph,
html[data-mchim-theme] body.page-odchylki .tolerance-frame,
html[data-mchim-theme] body.page-odchylki .tolerance-frame .tolerance-symbol {
  background: #f4f4f0 !important;
}

html[data-mchim-theme] body.page-odchylki .photo-fig img,
html[data-mchim-theme] body.page-odchylki .tolerance-frame .tolerance-symbol img {
  background: transparent !important;
}

/* Na stronie zjawisk fotografie wypełniają całe, równe pole ilustracji. */
html[data-mchim-theme] body.page-zjawiska .image-wrap img {
  object-fit: cover !important;
  object-position: center center !important;
  background: transparent !important;
}

/* Fotografie na tych stronach wypełniają całe, proporcjonalne pole. */
html[data-mchim-theme] body.page-obrobka-kol .task-photo img,
html[data-mchim-theme] body.page-materialy-konstrukcyjne .question-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center center !important;
  background: transparent !important;
}

html[data-mchim-theme] body.page-mechanizmy .photo-fig img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center center !important;
  background: transparent !important;
}

/* Obróbka plastyczna: równe kadry fotografii, z pełnym widokiem schematów. */
html[data-mchim-theme] body.page-obrobka-plastyczna .task-photo img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center center !important;
  background: transparent !important;
}

html[data-mchim-theme] body.page-obrobka-plastyczna .task-photo.is-diagram img {
  object-fit: contain !important;
  background: #edf3f8 !important;
}

html[data-mchim-theme] body.page-obrobka-plastyczna .task-photo.soft-fit img {
  object-fit: contain !important;
  background: transparent !important;
}

/* Układy napędowe: równe kadry bez wymuszonych pustych marginesów. */
html[data-mchim-theme] body.page-napedy .photo-fig img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center center !important;
  background: transparent !important;
}

html[data-mchim-theme] body.page-napedy .photo-fig .ph.soft-fit img {
  object-fit: contain !important;
  background: transparent !important;
}

@media (max-width: 640px) {
  html[data-mchim-theme] body.page-napedy .photo-fig .ph {
    aspect-ratio: 4 / 3;
  }
}

/* Wspólny ekran powitalny stron ćwiczeń. */
html[data-mchim-theme] #taskArea .mchim-start-screen {
  min-height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(22px, 4vw, 44px);
  text-align: center;
  color: var(--text);
}

html[data-mchim-theme] #taskArea.mchim-start-host {
  box-sizing: border-box !important;
  height: auto !important;
  min-height: 500px !important;
  overflow: hidden !important;
}

/* Na ekranie startowym lewy i prawy panel tworzą równy, schludny rząd. */
html[data-mchim-theme] main:has(> #taskArea.mchim-start-host),
html[data-mchim-theme] .layout:has(> #taskArea.mchim-start-host) {
  align-items: stretch !important;
}

html[data-mchim-theme] main:has(> #taskArea.mchim-start-host) > .panel,
html[data-mchim-theme] .layout:has(> #taskArea.mchim-start-host) > .panel {
  align-self: stretch !important;
}

/* Jawna klasa jest zgodnym wstecznie odpowiednikiem selektora :has(). */
html[data-mchim-theme] .mchim-start-layout {
  align-items: stretch !important;
}

html[data-mchim-theme] .mchim-start-layout > .panel {
  align-self: stretch !important;
}

html[data-mchim-theme] #taskArea .mchim-start-image {
  width: clamp(180px, 29vw, 300px) !important;
  height: auto !important;
  max-width: 72%;
  object-fit: contain !important;
  background: transparent !important;
  filter: drop-shadow(0 16px 18px rgba(0, 0, 0, .22));
  user-select: none;
}

html[data-mchim-theme] #taskArea .mchim-start-copy h2 {
  margin: 2px 0 7px;
  color: var(--accent) !important;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
}

html[data-mchim-theme] #taskArea .mchim-start-copy p {
  margin: 0;
  color: var(--text) !important;
  font-size: clamp(.96rem, 1.7vw, 1.08rem);
}

html[data-mchim-theme] #taskArea .mchim-start-copy span {
  display: block;
  margin-top: 7px;
  color: var(--muted) !important;
  font-size: .88rem;
}

@media (max-width: 640px) {
  html[data-mchim-theme] #taskArea.mchim-start-host {
    height: 420px !important;
    min-height: 420px !important;
  }

  html[data-mchim-theme] #taskArea .mchim-start-screen {
    min-height: 100%;
    padding: 24px 16px;
  }

  html[data-mchim-theme] #taskArea .mchim-start-image {
    max-width: 82%;
  }
}

@media print {
  #mchim-theme-control { display: none !important; }
}
