.dd-app {
  grid-template-rows: auto auto 1fr;
}

.dd-app:has(> .curriculum-tool-context) {
  grid-template-rows: auto auto auto 1fr;
}

.dd-app .icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dd-app .toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.dd-activity {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-width: 0;
  margin-inline: auto;
  padding: 12px clamp(12px, 2vw, 30px) 18px;
}

.dd-activity h2 {
  margin: 0;
  color: #123c52;
  font-size: clamp(2rem, 4.3vw, 3.3rem);
  line-height: 1.1;
  text-align: center;
}

.dd-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(302px, 2fr);
  gap: 14px;
  min-height: 0;
}

.dd-card {
  display: grid;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  padding: 10px 14px;
  border: 1px solid #d0dee8;
  border-radius: 14px;
  background: #fff;
}

.dd-card h3 {
  margin: 0 0 4px;
  font-size: 1.12rem;
  text-align: center;
}

.dd-counters {
  grid-template-rows: auto minmax(0, 1fr);
}

.dd-working {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 5px;
}

.dd-model,
.dd-model .question-visual {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
}

.dd-model .diagram-visual {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

.dd-working .dd-model {
  max-height: 240px;
  align-self: center;
}

.dd-app .place-value-highlight-cell,
.dd-app .dd-active-cell {
  fill: #fff0c2;
  stroke: #855400;
  stroke-width: 2;
}

.dd-stage {
  min-height: 142px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  text-align: center;
}

.dd-prompt,
.dd-feedback {
  margin: 0;
  line-height: 1.26;
}

.dd-prompt {
  min-height: 2.55em;
  max-width: 35ch;
  font-weight: 700;
}

.dd-feedback {
  min-height: 1.26em;
  color: #8b2730;
  font-weight: 600;
}

#ddShareForm {
  display: grid;
  justify-items: center;
  gap: 3px;
}

#ddShareForm[hidden] { display: none; }

.dd-answer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.dd-answer-line label {
  font-weight: 700;
}

#ddAnswer {
  width: 2.65rem;
  min-height: 44px;
  padding: 2px;
  border: 1px solid #50738a;
  border-radius: 7px;
  font-size: 1.3rem;
  text-align: center;
}

#ddAnswer[aria-invalid="true"] { border: 2px solid #a72835; }

.dd-card button {
  min-height: 44px;
  border-radius: 8px;
}

.dd-primary {
  border: 1px solid #075679;
  padding-inline: 12px;
  background: #075679;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.dd-reveal, .dd-back {
  border: 1px solid #adc2d1;
  padding-inline: 12px;
  color: #143b55;
  background: #f4f8fb;
  cursor: pointer;
}

.dd-reveal { background: transparent; border-color: transparent; text-decoration: underline; }
.dd-back { justify-self: center; }
.dd-back:disabled { opacity: .5; cursor: default; }
.dd-app :focus-visible { outline: 3px solid #0b79aa; outline-offset: 3px; }

@media (min-width: 850px) and (min-height: 590px) {
  .dd-app { height: 100dvh; min-height: 0; }
  .dd-activity { min-height: 0; }
}

@media (max-width: 849px), (max-height: 589px) {
  .dd-counters .dd-model { min-height: clamp(240px, 53vw, 440px); }
  .dd-working .dd-model { min-height: 126px; }
}

@media (max-width: 720px) {
  .dd-grid { grid-template-columns: minmax(0, 1fr); }
  .dd-app .toolbar { padding-inline: 10px; }
  .dd-card { padding-inline: 8px; }
}

@media print {
  @page { size: A4 landscape; margin: 6mm; }
  .dd-app { min-height: 0; height: auto; display: block; }
  .dd-app .toolbar, .dd-app button, .dd-app #ddShareForm, .dd-app .top-actions, .dd-feedback {
    display: none !important;
  }
  .dd-activity { display: block; padding: 0; }
  .dd-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    height: 150mm;
    gap: 3mm;
    break-inside: avoid;
    margin-top: 3mm;
  }
  .dd-model, .dd-working .dd-model, .dd-counters .dd-model { min-height: 0; }
  .dd-stage { min-height: 14mm; }
  .dd-app .place-value-highlight-cell, .dd-app .dd-active-cell { print-color-adjust: exact; }
}
