#study-dialog { width: min(972px,calc(100% - 40px)); height: min(704px,88dvh); max-height: 92dvh; border: 1px solid #cfc5d4; border-radius: 19px; }
#study-dialog .dialog-head { flex: none; padding: 14px 22px; background: #f9f7f4; border-color: #ded7df; }
#study-dialog .dialog-head h2 { font: 540 27px/1.2 var(--serif); letter-spacing: -.9px; }
#study-dialog .dialog-head .mini-icon { width: 32px; height: 32px; }
.study-layout { display: grid; grid-template-columns: 230px minmax(0,1fr); flex: 1; min-height: 0; }
.contents { position: relative; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #cbbdd6 transparent; padding: 16px 12px 24px; border-right: 1px solid #e0dbe1; background: #faf9f7; overscroll-behavior: contain; }
.contents > p, .mobile-picker { font: 700 11px var(--mono); text-transform: uppercase; letter-spacing: 1px; color: #65566a; }
.contents > p { padding: 3px 9px 7px; }
.index-group { padding: 12px 0 5px; }
.index-group h3 { color: #62576a; font: 650 13px var(--body); margin: 0 9px 4px; }
.contents button { display: block; width: 100%; border: 1px solid transparent; border-radius: 7px; padding: 6px 8px; background: transparent; color: #655c68; text-align: left; font-size: 13px; line-height: 1.35; font-weight: 520; }
.contents button:hover { background: #f1edf2; }
.contents button[aria-current="page"] { color: #4e366a; background: #eee6f5; border-color: #d8c9e3; font-weight: 700; }
.contents .source-link { margin-top: 14px; color: var(--violet-dark); }
.study-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.mobile-picker { display: none; }
.study-main .dialog-body { flex: 1; padding: 24px 28px; scrollbar-width: thin; }
.chapter-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; font: 600 11px var(--mono); color: #756579; }
#chapter { color: #6c5283; }
#lesson-heading, .dialog-body .sources h3 { font: 550 clamp(26px,2.7vw,37px)/1.06 var(--serif); color: #392b42; margin: 12px 0 8px; letter-spacing: -.04em; }
#lesson-summary { color: #665b6a; line-height: 1.45; font-size: 15px; }
.study-figure { overflow: hidden; margin: 17px 0 0; border: 1px solid #dcd3e2; border-radius: 13px; background: #f9f6fa; }
#diagram { display: block; width: 100%; height: clamp(160px,24vh,219px); font-family: var(--body); background-color: #f5f1f6; background-image: radial-gradient(#c2b4ca 0.65px,transparent 0.8px); background-size: 14px 14px; }
.study-figure figcaption { min-height: 100px; padding: 13px 17px 15px; background: #fcfbfa; border-top: 1px solid #e1d8e4; }
.step-counter { display: block; font: 600 10px var(--mono); color: #726478; margin-bottom: 5px; }
.study-figure figcaption strong { font: 700 17px var(--display); color: #493753; }
.study-figure figcaption p { margin: 5px 0 0; font-size: 14px; color: #534d56; line-height: 1.45; }
#frame-captions { display: grid; }
#frame-captions > div { grid-area: 1 / 1; }
#frame-captions > [aria-hidden="true"] { visibility: hidden; }
#film-seek { --played: 0%; display: block; width: 100%; height: 30px; margin: 2px 0 0; appearance: none; background: transparent; cursor: pointer; }
#film-seek::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, #785991 var(--played), #ded5e3 var(--played)); }
#film-seek::-moz-range-track { height: 4px; border-radius: 4px; background: #ded5e3; }
#film-seek::-moz-range-progress { height: 4px; border-radius: 4px; background: #785991; }
#film-seek::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -5px; border: 2px solid #fff; border-radius: 50%; background: #77558e; box-shadow: 0 0 0 1px #bba9c7; }
#film-seek::-moz-range-thumb { width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; background: #77558e; box-shadow: 0 0 0 1px #bba9c7; }
.player { display: flex; align-items: center; gap: 6px; }
.player button { border: 1px solid #d6cbdc; background: #fff; color: #5f426e; border-radius: 7px; }
.player #animate { display: inline-flex; gap: 6px; align-items: center; min-height: 36px; padding: 5px 10px; background: #f3edf6; font-size: 13px; font-weight: 650; }
#animate .icon { width: 14px; height: 14px; }
#frame-prev, #frame-next { width: 34px; height: 34px; display: grid; place-content: center; font: 500 23px/1 var(--body); }
.player button:disabled { opacity: .42; }
#frame-dots { display: flex; align-items: center; margin: 0 auto 0 3px; }
#frame-dots button { width: 19px; height: 32px; background: transparent; border: 0; padding: 0; display: grid; place-items: center; }
#frame-dots button::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #d1c7d5; }
#frame-dots button[aria-current="step"]::before { width: 14px; border-radius: 9px; background: #7d5d92; }
.turn-page { border-top: 1px solid #e7e1e7; margin-top: 20px; padding-top: 11px; display: flex; justify-content: space-between; gap: 8px; }
.turn-page button { border: 0; padding: 5px 0; background: none; color: #644679; font-weight: 650; font-size: 13px; }
.turn-page button:disabled { visibility: hidden; }
.dialog-body .sources { margin: 0; border: 0; padding: 0; }
.sources li { margin-block: 8px; }
#lesson[hidden], #sources[hidden] { display: none; }

.figure-viewport { overflow-x: auto; overscroll-behavior-x: contain; }
.caption-tools { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 5px; }
.caption-tools .step-counter { margin-bottom: 0; }
#zoom-figure, #frame-select { display: none; }

@media (max-width: 730px), (pointer: coarse) and (max-height: 540px) {
  #study-dialog {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  #study-dialog .dialog-head { padding: 7px 16px; }
  #study-dialog .dialog-head h2 { font-size: 23px; }
  #study-dialog .close { width: 44px; height: 44px; }
  .study-layout { display: flex; }
  .study-main { width: 100%; }
  .contents { display: none; }
  .mobile-picker { display: flex; flex: none; align-items: center; gap: 10px; padding: 6px 16px; border-bottom: 1px solid #e8e1e8; background: #fcfafc; }
  .mobile-picker select, #frame-select {
    appearance: none;
    height: 44px;
    padding: 5px 28px 5px 8px;
    font: 600 16px/1.2 var(--body);
    border: 1px solid #d7cadf;
    border-radius: 7px;
    color: #4e3c5a;
    background: linear-gradient(45deg,transparent 50%,currentColor 50%) right 13px center / 5px 5px no-repeat,
                linear-gradient(-45deg,transparent 50%,currentColor 50%) right 8px center / 5px 5px no-repeat, white;
  }
  .mobile-picker select { flex: 1; min-width: 0; }
  .study-main .dialog-body { min-height: 0; padding: 16px 16px max(16px,env(safe-area-inset-bottom)); }
  #diagram { height: auto; aspect-ratio: 400/192; }
  #lesson-heading { font-size: 29px; }
  .study-figure figcaption p { font-size: 15px; }
  .caption-tools .step-counter, #frame-dots { display: none; }
  #frame-select { display: block; max-width: 100%; }
  .player #animate { min-height: 44px; padding-inline: 14px; margin-right: auto; font-size: 15px; }
  #film-seek { height: 44px; }
  #frame-prev, #frame-next { width: 48px; height: 44px; }
  .turn-page { margin-top: 14px; }
  .turn-page button { min-height: 44px; font-size: 14px; }
  .sources a { display: inline-flex; align-items: center; min-height: 44px; }
}
@media (max-width: 540px) {
  #zoom-figure { display: inline-block; min-height: 44px; padding: 4px; background: none; color: var(--violet-dark); border: 0; font: 650 13px var(--body); text-decoration: underline; text-underline-offset: 2px; }
  .figure-viewport.zoomed #diagram { min-width: 540px; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) and (min-width: 600px) {
  .study-figure { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(0,1fr); }
  .figure-viewport { display: grid; align-content: center; background: #f5f1f6; }
  .study-figure figcaption { border-top: 0; border-left: 1px solid #e1d8e4; }
}
