/* V6.5.0: device backup, working space and lesson completion controls. */

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.backup-actions > * {
  min-width: 170px;
}

.backup-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.backup-file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.backup-file-button:focus-within {
  outline: 3px solid rgba(116, 84, 232, 0.32);
  outline-offset: 3px;
}

@media (max-width: 520px) {
  .backup-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .backup-actions > * {
    width: 100%;
    min-width: 0;
  }
}

/* V6.5: optional in-card working space */
.question-tool-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.scratch-toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid #c9e9f7;
  border-radius: 999px;
  background: #f2fbff;
  color: #08658e;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.scratch-toggle-button:hover,
.scratch-toggle-button.active {
  border-color: #7bc9e8;
  background: #e4f7ff;
}

.scratch-pad[hidden] {
  display: none;
}

.scratch-pad {
  width: min(760px, 100%);
  margin: 18px auto 0;
  padding: 10px;
  border: 2px solid #dcd2f8;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: inset 0 0 0 1px rgba(116, 84, 232, 0.04);
}

.scratch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.scratch-toolbar > span {
  color: #3d3a58;
  font-weight: 800;
}

.scratch-toolbar > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.scratch-tool {
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid #d9d0f4;
  border-radius: 9px;
  background: #fff;
  color: #45356f;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.scratch-tool:hover,
.scratch-tool.active {
  border-color: #7c55ed;
  background: #eee9ff;
  color: #5b32d4;
}

.scratch-canvas-wrap {
  width: 100%;
  height: clamp(125px, 17vh, 175px);
  overflow: hidden;
  border: 1px solid #d9e2ef;
  border-radius: 11px;
  background-color: #fff;
  background-image:
    linear-gradient(#edf2f8 1px, transparent 1px),
    linear-gradient(90deg, #edf2f8 1px, transparent 1px);
  background-size: 24px 24px;
}

#scratchCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.paw-result.needs-practice {
  border-color: #f1c563;
  background: #fff8df;
  color: #704d00;
}

.needs-practice-result .result-score {
  border-color: #f1c563;
  background: #fff8df;
}

.lesson-completion-rule {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 13px;
  align-items: center;
}

.lesson-completion-rule > span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: #fff4c7;
  font-size: 24px;
}

.lesson-completion-rule h3,
.lesson-completion-rule p {
  margin: 0;
}

.lesson-completion-rule p {
  margin-top: 3px;
  color: #625d78;
}

.formal-attempt-row > strong {
  justify-self: end;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .read-question-button span,
  .scratch-toggle-button span {
    display: none;
  }

  .read-question-button,
  .scratch-toggle-button {
    width: 44px;
    min-width: 44px;
    padding: 8px;
  }

  .scratch-canvas-wrap {
    height: 145px;
  }
}

@media (max-width: 520px) {
  .scratch-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .scratch-toolbar > div {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .scratch-tool {
    min-width: 0;
    padding-inline: 5px;
  }

  .formal-attempt-row {
    align-items: flex-start;
  }

  .formal-attempt-row > strong {
    justify-self: start;
  }
}
