.textbooks-open-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.textbook-grid {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: clamp(12px,2vw,24px);
}

.textbook-card {
  min-width: 0;
}

.textbook-cover {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #23344c;
  cursor: pointer;
  transition: scale .16s ease, filter .16s ease;
}

.textbook-cover:hover {
  filter: brightness(1.08);
}

.textbook-cover:active {
  scale: .98;
}

.textbook-cover:focus-visible {
  outline: 2px solid #b6d2fa;
  outline-offset: 3px;
}

.textbook-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.textbook-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px 0;
  overflow-wrap: anywhere;
}

.textbook-caption .subject-icon {
  flex: none;
}

.textbook-caption small {
  display: block;
  color: #adc2dc;
  margin-top: 3px;
}

.textbook-form,
.textbook-form label,
.textbook-reader {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.textbook-form label {
  gap: 6px;
}

.textbook-form input {
  box-sizing: border-box;
  width: 100%;
}

.textbook-form input::file-selector-button {
  border: 0;
  border-radius: 16px;
  background: #304965;
  color: #e6efff;
  padding: 8px 12px;
  margin-inline-end: 8px;
  cursor: pointer;
}

.textbook-reader > a {
  justify-self: start;
  text-decoration: none;
}

@media (min-width:721px) and (pointer:fine), (min-width:901px) {
  body dialog.modal.material-modal.textbook-library-panel {
    width: min(900px, calc(100vw - 32px));
  }
}

@media (max-width:720px), (pointer:coarse) and (max-width:900px) {
  body dialog.modal.material-modal.textbook-library-panel {
    --sheet-max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
    height: var(--sheet-height, var(--sheet-max-height)) !important;
    max-height: var(--sheet-max-height) !important;
  }

  .textbook-grid {
    grid-template-columns: minmax(0,1fr);
    max-width: 420px;
    margin-inline: auto;
    gap: 24px;
  }

  .textbook-cover {
    aspect-ratio: 4 / 5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .textbook-cover { transition: none; }
}

body dialog.modal.textbook-desktop-panel {
  height: calc(100dvh - 24px);
  max-height: calc(100dvh - 24px);
}

body dialog.modal.textbook-desktop-panel > .modal-scroll {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
}

body dialog.modal.textbook-desktop-panel :is(.scroll-viewport, .modal-inner, .textbook-reader) {
  height: 100%;
  box-sizing: border-box;
}

.textbook-open-tab {
  text-decoration: none;
  white-space: nowrap;
}

.textbook-mobile-reader[open] {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: #0d1929;
  color: #e6efff;
}

.textbook-mobile-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  background: #17273a;
}

.textbook-mobile-bar form {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
}

.textbook-mobile-bar input {
  box-sizing: border-box;
  width: 68px;
  min-width: 0;
  height: 42px;
  padding: 4px 6px;
  border: 1px solid #617691;
  border-radius: 12px;
  background: #101e30;
  color: inherit;
  font-size: 16px;
  appearance: textfield;
}

.textbook-mobile-bar input::-webkit-inner-spin-button {
  appearance: none;
}

.textbook-mobile-bar button {
  min-height: 42px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  color: inherit;
  background: #2b415d;
  font-size: .85rem;
}

.textbook-mobile-bar .textbook-mobile-close {
  width: 42px;
  padding: 0;
  font-size: 1.5rem;
}

.textbook-mobile-count {
  white-space: nowrap;
  font-size: .875rem;
}

.textbook-mobile-pages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 4px env(safe-area-inset-bottom);
}

.textbook-mobile-pages > div {
  position: relative;
  margin: 0 auto 6px;
  width: min(100%, 850px);
  background: #fff;
}

.textbook-mobile-pages canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.textbook-mobile-pages [data-failed]::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  content: 'Не удалось показать страницу';
  color: #334155;
}

.textbook-mobile-status {
  padding: 12px;
}

.textbook-mobile-status a {
  color: #b6d2fa;
}

.textbook-mobile-pages canvas {
  position: absolute;
  inset: 0;
}

.textbook-homework-mark {
  position: absolute;
  box-sizing: border-box;
  border-radius: 6px;
  background: rgb(66 145 247 / .25);
  box-shadow: 0 0 0 1px rgb(42 113 220 / .42);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}

[data-rendered] > .textbook-homework-mark {
  opacity: 1;
}

.textbook-homework-mark.is-current {
  background: rgb(66 145 247 / .36);
}

.textbook-placeholder {
  display: grid;
  place-items: center;
  align-self: start;
  box-sizing: border-box;
  aspect-ratio: 3 / 4;
  padding: 16px;
  border: 2px dashed #59708d;
  border-radius: 18px;
  color: #bdcfe6;
  text-align: center;
}

@media (max-width:720px), (pointer:coarse) and (max-width:900px) {
  .textbook-placeholder { aspect-ratio: 4 / 5; }
}

.homework-book-link {
  position: relative;
  z-index: 7;
  width: fit-content;
  max-width: 100%;
  margin-block-start: 8px;
}

body dialog.material-modal .homework-book-link > button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 44px;
  padding: 8px 16px;
  font-size: .95rem;
}

body dialog.material-modal :is(.task-card,.homework-card).is-completed .homework-book-link > button {
  background: #24483e;
  color: #c2f3da;
}

body dialog.material-modal :is(.task-card,.homework-card).is-completed .homework-book-link > button:hover {
  background: #2e574a;
}

:is(.task-card, .homework-unit):has(.homework-book-link > button:is(:hover, :focus-visible)) .completion-button {
  opacity: 0 !important;
}

.homework-book-link > button svg {
  flex: none;
}

.homework-book-options {
  display: grid;
  gap: 8px;
}

body dialog.material-modal .homework-book-options > .homework-book-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  border-radius: 18px;
  padding: 8px 14px 8px 8px;
  text-align: left;
  white-space: normal;
}

.homework-book-option img {
  flex: none;
  width: 42px;
  height: 56px;
  object-fit: cover;
  border-radius: 7px;
}

.homework-book-option span {
  display: grid;
  gap: 3px;
  overflow-wrap: anywhere;
}

.homework-book-option small {
  opacity: .8;
}

.lesson-no-textbook {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  font-size: .85rem;
}

body dialog.material-modal .lesson-no-textbook input {
  appearance: auto;
  accent-color: #b6d2fa;
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
}

@media (max-width: 720px) {
  body dialog.material-modal .cabinet-account-actions:has(> .textbooks-open-button) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body dialog.material-modal .cabinet-account-actions > .textbooks-open-button {
    grid-column: 1 / -1;
    white-space: nowrap;
  }
}

.textbook-cover.is-editable {
  outline: 2px solid #9ebeea;
  outline-offset: 3px;
}

body dialog.modal .textbook-edit-mode[aria-pressed="true"] {
  background: #b6d2fa;
  color: #16283e;
}

.textbook-edition-warning {
  margin: 6px 2px 0;
  color: #ffdc9c;
  font-size: .85rem;
}

.textbook-reader-warning {
  margin: 0;
  padding: 6px 10px;
  background: #273348;
}

.textbook-form .textbook-warning-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

body dialog.material-modal .textbook-warning-toggle input {
  appearance: auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #b6d2fa;
}

.textbook-delete-confirm {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.textbook-delete-confirm p {
  width: 100%;
  margin: 0;
}

.textbook-group-cover {
  position: relative;
}

.textbook-group-cover img {
  filter: brightness(.48);
}

.textbook-group-count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 700;
  pointer-events: none;
}

.textbook-context-menu {
  position: fixed;
  inset: auto;
  margin: 0;
  width: 184px;
  padding: 6px;
  border: 1px solid #4a6684;
  border-radius: 14px;
  background: #20334b;
  color: #e4efff;
  box-shadow: 0 8px 22px #0006;
}

.textbook-context-menu:popover-open {
  display: grid;
  gap: 4px;
}

.textbook-context-menu button {
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.textbook-context-menu button:hover,
.textbook-context-menu button:focus-visible {
  background: #314a68;
}

.textbook-context-menu .danger-button {
  color: #ffbdc9;
}

.textbook-group-options {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: 1px solid #536b87;
  border-radius: 14px;
}

.textbook-group-options label {
  overflow-wrap: anywhere;
}

body dialog.modal.textbook-desktop-panel .textbook-pdf-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

body dialog.modal.textbook-desktop-panel,
.textbook-mobile-reader {
  --textbook-controls: #243b55;
  --textbook-button: #365473;
}

body dialog.modal.textbook-desktop-panel .modal-heading {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: clamp(12px,2vw,30px);
}

.textbook-mobile-bar {
  background: var(--textbook-controls);
  color: #e6efff;
  border-radius: 22px;
}

.textbook-pdf-content .textbook-mobile-bar {
  padding: 8px 16px;
}

.textbook-pdf-content .textbook-mobile-count {
  font-size: 1rem;
  font-weight: 500;
}

.textbook-mobile-bar .textbook-page-jump {
  gap: 4px;
  padding: 4px;
  border: 0;
  border-radius: 999px;
  background: var(--textbook-controls);
}

.textbook-mobile-reader .textbook-page-jump input[type="number"],
body dialog.modal.textbook-desktop-panel .textbook-page-jump input[type="number"] {
  width: 72px;
  height: 36px;
  padding: 0 4px 0 10px;
  border: 0;
  outline: none;
  border-radius: 999px;
  background: transparent;
  color: inherit;
}

body dialog.modal.textbook-desktop-panel .textbook-page-jump input[type="number"] {
  width: 132px;
}

.textbook-page-jump input::placeholder {
  color: #c5d6e9;
}

.textbook-page-jump:focus-within {
  background: #2d4865;
}

.textbook-mobile-bar .textbook-page-jump button,
.textbook-zoom button {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #e6efff;
  background: var(--textbook-button);
}

.textbook-homework {
  box-sizing: border-box;
  max-height: min(22dvh,8rem);
  overflow: auto;
  padding: 9px 14px;
  border-radius: 20px;
  background: var(--textbook-controls);
  color: #e6efff;
  overflow-wrap: anywhere;
}

.textbook-homework strong {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .95rem;
  color: #bdd3ec;
}

.textbook-homework strong svg {
  flex: none;
}

.textbook-homework p {
  margin: 2px 0 0;
  white-space: pre-wrap;
}

.textbook-homework .textbook-inline-jump {
  display: inline;
  min-height: 0;
  padding: 3px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #c7e1ff;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: .16em;
  cursor: pointer;
}

.textbook-homework .textbook-inline-jump[aria-pressed="true"] {
  background: #395b83;
  color: #fff;
}

.textbook-mobile-reader[open] {
  gap: 6px;
  padding: max(6px,env(safe-area-inset-top)) 6px max(6px,env(safe-area-inset-bottom));
  border-radius: 24px;
  background: #142235;
  animation: textbook-sheet-in 240ms cubic-bezier(.2,.75,.25,1) both;
}

@keyframes textbook-sheet-in {
  from { transform: translateY(46px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .textbook-mobile-reader[open] { animation: none; }
}

.textbook-mobile-reader .textbook-mobile-bar {
  padding: 4px 8px;
}

.textbook-mobile-reader .textbook-homework {
  max-width: 100%;
  font-size: .9rem;
}

.textbook-stage-navigation {
  position: absolute;
  z-index: 1;
  inset-block-start: 8px;
  inset-inline-start: 10px;
  inset-inline-end: calc(10px + var(--textbook-scrollbar,0px));
  display: grid;
  justify-items: center;
  justify-self: center;
  margin-inline: auto;
  gap: 6px;
  width: fit-content;
  max-width: calc(100% - 20px - var(--textbook-scrollbar,0px));
  pointer-events: none;
}

.textbook-stage-navigation > * {
  pointer-events: auto;
}

.textbook-pdf-content .textbook-stage-navigation {
  inset-inline-start: var(--textbook-corner-inset);
  inset-inline-end: auto;
  justify-items: start;
  margin-inline: 0;
  max-block-size: min(calc(100% - 16px), 45%);
}

.textbook-pdf-content .textbook-reference-jumps {
  flex-direction: column;
  min-block-size: 0;
  padding: 2px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 0;
}

.textbook-pdf-content .textbook-stage > .textbook-homework {
  position: absolute;
  z-index: 1;
  inset-inline-start: var(--textbook-corner-inset);
  inset-block-end: var(--textbook-corner-inset);
  width: clamp(12rem, calc((100% - 850px) / 2 - 24px), 19rem);
  max-width: calc(100% - 2 * var(--textbook-corner-inset));
  border-radius: var(--textbook-stage-radius);
  overscroll-behavior: contain;
}

.textbook-stage {
  --textbook-stage-radius: 20px;
  --textbook-corner-inset: 12px;
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--textbook-stage-radius);
  background: #0d1929;
}

.textbook-stage .textbook-mobile-pages {
  position: relative;
  min-width: 0;
  overflow: auto;
  touch-action: pan-x pan-y;
  overflow-anchor: none;
  padding-block-start: max(6px, var(--textbook-navigation-clearance, 0px));
}

.textbook-mobile-pages[data-pannable] {
  cursor: grab;
  user-select: none;
}

.textbook-mobile-pages[data-dragging] {
  cursor: grabbing;
}

.textbook-stage .textbook-mobile-pages > div {
  width: min(var(--textbook-page-zoom,100%), var(--textbook-page-max,850px));
}

.textbook-mobile-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 16px;
  text-align: center;
  font-size: clamp(1.1rem,2.1vw,1.4rem);
  font-weight: 600;
}

.textbook-loading {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.textbook-loading > svg {
  color: #b7d4fc;
}

.textbook-loading-dots > :nth-child(2) {
  animation: textbook-loading-second-dot 1.5s steps(1,end) infinite;
}

.textbook-loading-dots > :nth-child(3) {
  animation: textbook-loading-third-dot 1.5s steps(1,end) infinite;
}

@keyframes textbook-loading-second-dot {
  0%, 80%, 100% { opacity: 0; }
  20% { opacity: 1; }
}

@keyframes textbook-loading-third-dot {
  0%, 60%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .textbook-loading-dots > span { animation: none; }
}

.textbook-actions {
  position: absolute;
  inset-inline-end: calc(12px + var(--textbook-scrollbar,16px));
  inset-block-end: 22px;
  display: flex;
  align-items: center;
  max-width: calc(100% - 42px - var(--textbook-scrollbar,16px));
  gap: 12px;
}

.textbook-zoom,
.textbook-reference-jumps {
  display: flex;
  gap: 8px;
}

.textbook-reference-jumps {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  border-radius: 999px;
  scrollbar-width: thin;
}

.textbook-reference-jumps button {
  flex: none;
  min-height: 42px;
  padding: 8px 15px;
  border: 0;
  border-radius: 999px;
  background: var(--textbook-button);
  color: #edf5ff;
}

.textbook-pdf-content .textbook-reference-jumps button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--textbook-stage-radius);
}

.textbook-reference-jumps button svg {
  flex: none;
}

.textbook-reference-jumps button[aria-pressed="true"] {
  background: #b7d4fc;
  color: #142d46;
}

.textbook-zoom button {
  width: 42px;
  height: 42px;
  font-size: 1.35rem;
}

.textbook-zoom button:disabled,
.textbook-reference-jumps button:disabled,
.textbook-mobile-bar button:disabled {
  opacity: .55;
}
