/* Dialogs, reference previews, image enlargement and status toast. */
.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: white;
  z-index: 60;
  padding: 13px 20px;
  border-radius: 9px;
  box-shadow: 0 5px 25px #40346420;
  font-size: 14px;
}

dialog {
  border: 0;
  border-radius: 12px;
  max-width: calc(100vw - 24px);
  width: 1000px;
  padding: 20px;
  max-height: calc(100dvh - 30px);
  color: var(--text);
}

dialog::backdrop {
  background: #26203ec9;
}

.reference-modal {
  overflow: hidden;
}

.editorial-reference {
  text-underline-offset: .2em;
  text-decoration-thickness: 1px;
  overflow-wrap: anywhere;
}

.editorial-reference[aria-haspopup="dialog"]::after {
  content: "查看";
  display: inline-block;
  margin-inline-start: .35em;
  padding: 0 .3em;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: .72em;
  line-height: 1.45;
  vertical-align: .08em;
  white-space: nowrap;
}

.editorial-reference--external::after {
  content: "↗";
  display: inline-block;
  margin-inline-start: .18em;
  font-size: .85em;
  white-space: nowrap;
}

.reference-dialog {
  width: min(820px,100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-top: calc(var(--drawer-header-height,68px) + 18px);
  scroll-padding-bottom: 20px;
}

.reference-dialog::backdrop {
  background: #211b3c66;
}

.reference-dialog .reference-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--space-4) var(--space-6);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.reference-dialog .reference-header h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
}

.reference-body {
  min-width: 0;
  padding: var(--space-6);
}

.reference-lesson .book-concept {
  padding: 0;
  border: 0;
}

.reference-lesson .concept-number {
  display: none;
}

.reference-lesson .book-rule {
  font-size: 18px;
  line-height: 1.85;
}

.reference-lesson .book-concept>h2 {
  font-size: 24px;
  line-height: 1.5;
  margin: 0 0 18px;
}

.reference-lesson p,.reference-lesson li {
  line-height: 1.85;
}

.reference-lesson .book-diagram {
  margin-block: var(--space-6);
}

.reference-lesson a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.reference-body [hidden] {
  display: none !important;
}

.reference-body h3 {
  font-size: 23px;
  line-height: 1.65;
  margin: var(--space-3) 0 20px;
}

.reference-options {
  display: grid;
  gap: 10px;
  list-style: decimal;
  padding-left: 1.6em;
  margin: 14px 0 var(--space-6);
}

.reference-options>li {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}

.reference-answer {
  border-top: 1px solid var(--line);
  padding: var(--space-4) 0;
  margin-top: 20px;
}

.reference-answer>summary {
  font-weight: 650;
  cursor: pointer;
}

.reference-answer>p {
  margin-top: 18px;
}

.reference-source-links {
  margin-top: var(--space-6);
}

.reference-pictures {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(min(240px,100%),1fr));
  gap: var(--space-4);
}

.reference-dialog .reference-body .picture {
  min-height: 0;
}

.reference-dialog .reference-body .picture img {
  max-height: max(44px,min(360px,calc(100dvh - var(--drawer-header-height,77px) - 80px)));
}

.reference-guidance {
  display: grid;
  gap: 18px;
  margin: var(--space-6) 0;
}

.reference-guidance dt {
  font-weight: 650;
}

.reference-guidance dd {
  margin: 6px 0 0;
}

@media (max-width:600px) {
  .reference-dialog .reference-header {
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
  }

  .reference-dialog .reference-header h2 {
    font-size: 16px;
  }

  .reference-body {
    padding: 18px var(--space-4);
  }

  .reference-body h3 {
    font-size: 20px;
  }
}

#zoom[open] {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: var(--space-3);
  height: min(860px, calc(100dvh - 30px));
}

.dialog-top {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
}

.dialog-top button {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
}

.zoom-stage {
  overflow: auto;
  min-height: 0;
  height: 100%;
  margin: 0;
  background: var(--surface-subtle);
  text-align: center;
  padding: var(--space-4);
}

.zoom-canvas {
  width: max-content;
  height: max-content;
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
}

.zoom-stage img {
  display: block;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

.zoom-stage img[hidden] {
  display: none;
}

.zoom-description p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

#zoom-status:not([hidden]) + #zoom-note {
  margin-top: 4px;
}

@media (max-height: 600px) {
  #zoom[open] {
    padding: var(--space-3);
    gap: var(--space-2);
  }

  .zoom-stage {
    padding: var(--space-2);
  }
}

@media (max-height: 320px) {
  #zoom[open] {
    inset: 0;
    margin: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 6px;
    gap: var(--space-1);
  }

  #zoom .dialog-top {
    gap: var(--space-2);
    align-items: center;
  }

  #zoom .zoom-stage {
    padding: var(--space-1);
  }

  #zoom .zoom-description p {
    line-height: 1.25;
    font-size: 12px;
  }
}

@media (max-width: 600px) {
  .toast {
    width: calc(100% - 32px);
    text-align: center;
  }

  .dialog-top {
    align-items: flex-start;
    font-size: 14px;
  }

  .dialog-top button {
    font-size: 12px;
    padding: var(--space-2) 10px;
  }

  .zoom-stage {
    padding: 10px;
  }
}

@media print {
  .sidebar,
button,
.button,
.local-nav,
.toast,
.review-mark {
    display: none !important;
  }
}

.zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin: 0;
}

#zoom-level {
  font-size: 13px;
  min-width: 68px;
  text-align: center;
}

#zoom-original {
  width: auto;
  padding-inline: 12px;
}

.zoom-controls button {
  width: 112px;
  min-width: 0;
  font-size: 13px;
  min-height: 44px;
}

@media (max-width: 600px) {
  .zoom-controls {
    gap: 6px;
  }

  .zoom-controls button {
    flex: 1 1 calc((100% - 12px)/3);
    padding: var(--space-2);
  }

  .zoom-controls #zoom-original {
    flex: 0 1 auto;
    padding-inline: 12px;
  }
}

.reference-dialog .reference-header button {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 auto;
  white-space: nowrap;
}

@media (max-width:600px) {
  .reference-dialog .reference-header button {
    font-size: 13px;
    padding-inline: 10px;
  }
}
