/* ==========================================================================
   Zahlensysteme – interaktive Werkzeuge (tools.js)

   Aufbau:
     1. Rahmen und gemeinsame Bausteine
     2. Stellenwerttafel
     3. Umrechner und Rechenweg
     4. Trainer
     5. Farbmischer
     6. Aufgaben mit Kontrolle
     7. Responsive & Druck
   ========================================================================== */

/* 1. Rahmen und gemeinsame Bausteine -------------------------------------- */
.tool {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-top: 4px solid var(--icon-interface);
  border-radius: var(--radius);
  background: var(--bg-light);
  box-shadow: var(--shadow);
}

.tool-title {
  margin: 0 0 .25rem;
  font-weight: 700;
  color: #6b46c1;
}

.tool-hint {
  margin: 0 0 .75rem;
  font-size: .875rem;
  color: var(--text-muted);
}

.tool-result {
  margin-top: .75rem;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

.tool-result > :first-child {
  margin-top: 0;
}

.tool-result > :last-child {
  margin-bottom: 0;
}

.tool-big {
  margin: 0 0 .25rem;
  font-size: 1.375rem;
  font-weight: 700;
}

.tool-calc {
  margin: 0;
  color: var(--text-muted);
}

.tool-placeholder {
  margin: 0;
  color: var(--text-muted);
  font-style: italic;
}

.tool-error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

.tool-success {
  margin: 0;
  color: var(--success);
  font-weight: 600;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin-top: .75rem;
}

.tool input[type="text"],
.tool input[type="number"] {
  padding: .375rem .5rem;
  border: 1px solid #8f959e;
  border-radius: .375rem;
  background: var(--bg);
  font: inherit;
  font-size: 1rem;
  color: var(--text);
}

.tool input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.tool input.is-invalid {
  border-color: var(--danger);
  background: var(--danger-light);
  animation: shake .25s;
}

.tool input.is-valid {
  border-color: var(--success);
  background: var(--success-light);
}

@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.text-muted {
  color: var(--text-muted);
}

/* 2. Stellenwerttafel ----------------------------------------------------- */
.chapter table.pv-table {
  width: auto;
  margin: 0 auto;
  background: var(--bg);
}

.chapter .pv-table th,
.chapter .pv-table td {
  min-width: 3.25rem;
  padding: .375rem;
  text-align: center;
}

.chapter .pv-table .pv-power th {
  font-weight: 400;
  color: var(--text-muted);
}

.chapter .pv-table .pv-weight th {
  background: var(--primary-light);
}

.pv-table input[type="text"] {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 1.375rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
}

/* 3. Umrechner und Rechenweg ---------------------------------------------- */
.conv-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem;
}

.conv-field label {
  display: block;
  margin-bottom: .25rem;
  font-size: .8125rem;
  font-weight: 600;
}

.conv-input {
  display: flex;
  align-items: baseline;
  gap: .25rem;
}

.conv-input input[type="text"] {
  width: 12rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.conv-input .affix {
  font-size: 1.125rem;
  color: var(--text-muted);
}

.conv-arrow {
  padding-bottom: .375rem;
  font-size: 1.5rem;
  color: var(--text-muted);
}

.steps-title {
  font-weight: 700;
}

.steps-result {
  font-weight: 700;
}

.steps-note {
  font-size: .875rem;
  color: var(--text-muted);
}

.steps-list {
  padding-left: 1.25rem;
}

.chapter table.steps-table,
.chapter table.steps-division {
  width: auto;
}

.chapter .steps-table td,
.chapter .steps-table th {
  min-width: 3rem;
  text-align: center;
}

.chapter .steps-table th {
  font-weight: 400;
}

.chapter .steps-division td {
  padding: .125rem .75rem;
  border: 0;
}

/* 4. Trainer -------------------------------------------------------------- */
.trainer-question {
  margin: .5rem 0 .75rem;
  font-size: 1.125rem;
}

.trainer-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .5rem;
}

.trainer-form .btn {
  padding-top: .375rem;
  padding-bottom: .375rem;
}

.trainer-feedback {
  margin-top: .75rem;
}

.trainer-feedback:empty {
  display: none;
}

.trainer-score {
  margin-left: auto;
  font-size: .875rem;
  color: var(--text-muted);
}

.btn[disabled] {
  opacity: .5;
  cursor: default;
}

/* 5. Farbmischer ---------------------------------------------------------- */
.mixer {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: 1rem;
}

.mixer-preview {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 180px;
  padding: .75rem;
  border: 1px solid rgba(0, 0, 0, .25);
  border-radius: var(--radius);
  color: #fff;
  transition: background-color .1s;
}

.mixer-preview.is-light {
  color: #1d2125;
}

.mixer-preview-code {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
}

.mixer-channel {
  display: grid;
  grid-template-columns: 4.75rem 1fr 4.75rem;
  align-items: center;
  gap: .25rem .75rem;
  margin-bottom: .5rem;
}

.mixer-label {
  font-weight: 700;
  color: var(--channel);
}

.mixer-channel input[type="range"] {
  width: 100%;
  accent-color: var(--channel);
}

.mixer-channel input[type="number"] {
  width: 100%;
}

.mixer-info {
  grid-column: 2 / -1;
  margin-top: -.25rem;
  font-size: .8125rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mixer-code {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .75rem;
}

.mixer-code label {
  width: 4.75rem;
  font-weight: 700;
}

.mixer-code input[type="text"] {
  width: 7.5rem;
  text-transform: uppercase;
}

.mixer-code input[type="color"] {
  width: 3rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid #8f959e;
  border-radius: .375rem;
  background: none;
  cursor: pointer;
}

.mixer-summary {
  margin: .75rem 0 0;
}

.mixer-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .375rem;
  margin-top: 1rem;
}

.mixer-presets-label {
  margin-right: .25rem;
  font-size: .875rem;
  font-weight: 600;
}

/* 6. Aufgaben mit Kontrolle ----------------------------------------------- */
.challenge {
  margin-top: 1rem;
  padding: .75rem 1rem;
  border: 1px solid var(--task);
  border-radius: var(--radius);
  background: var(--task-light);
}

.challenge-title {
  margin: 0 0 .5rem;
  font-weight: 700;
  color: var(--task);
}

.challenge .tool-targets {
  margin: 0;
  padding-left: 1.75rem;
}

.challenge .tool-targets li {
  margin: .125rem 0;
  padding: .125rem .375rem;
  border-radius: .25rem;
  cursor: pointer;
}

.challenge .tool-targets li.is-current {
  background: var(--bg);
  outline: 2px solid var(--task);
  font-weight: 600;
}

.challenge .tool-targets li.is-done {
  color: var(--success);
}

.challenge .tool-targets li.is-done::after {
  content: " ✓";
  font-weight: 700;
}

.challenge-status {
  min-height: 1.5em;
  margin: .5rem 0;
  font-weight: 600;
  color: var(--success);
}

/* Ohne JavaScript bleibt die Aufgabenliste als normale Liste lesbar. */
.tool-targets {
  margin: .5rem 0;
}

/* 7. Responsive & Druck --------------------------------------------------- */
@media (max-width: 575.98px) {
  .mixer {
    grid-template-columns: 1fr;
  }

  .mixer-preview {
    min-height: 100px;
  }

  .conv-arrow {
    display: none;
  }

  .conv-input input[type="text"] {
    width: 100%;
  }
}

@media print {
  .tool {
    box-shadow: none;
  }

  .tool-actions,
  .challenge-reset,
  .mixer-presets {
    display: none;
  }
}
