html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

img {
  max-width: 100%;
  height: auto;
}

iframe {
  max-width: 100%;
}

/* Keep legacy look, but let the main canvas scale down on smaller screens */
#main,
#boxtop,
#boxbottom {
  max-width: 1000px;
  width: 100%;
}

#middle {
  margin-left: 20px;
  padding: 0;
}

.mobile-nav-toggle {
  display: none;
}

.mobile-nav-icon {
  font-size: 1.1rem;
  line-height: 1;
  margin-right: 4px;
}

/* Desktop/tablet polish that preserves legacy style */
@media (min-width: 769px) {
  #middle {
    margin-left: 20px;
    padding: 0;
  }

  #menuLeft {
    float: left;
    width: 200px;
    margin: 10px 0 0 0;
    padding: 0;
  }

  #contentWrapper {
    float: left;
    width: 538px;
    margin: 0 10px 0 0;
    padding: 0;
    display: block;
  }

  #menuRight {
    float: left;
    width: 200px;
    margin: 0 0 0 8px;
    padding: 0;
  }

  #raf {
    clear: both;
    float: right;
    margin-top: 0;
  }

  #menuRight .sideBarText {
    text-align: center;
    line-height: 1.45;
  }

  #menuRight .book175 {
    display: block;
    margin-left: auto;
    margin-right: auto;
  }

  .bookListing {
    display: inline-block;
    vertical-align: top;
    margin: 6px 4px;
  }

  .content h1 + p,
  .content h2 + p,
  .content h3 + p {
    margin-top: 6px;
  }

  .content table.booklist td {
    vertical-align: top;
  }
}

.content {
  overflow: hidden;
}

.content p,
.content li {
  line-height: 1.5;
}

.content p {
  margin-top: 0;
  margin-bottom: 0.9em;
}

.menuTop,
.menuBottom,
.contentTop,
.contentBottom {
  background-repeat: no-repeat;
}

.bookList {
  position: relative;
  z-index: 2;
}

/* Tablet breakpoint */
@media (max-width: 1024px) {
  html body {
    margin: 0;
    padding: 0 0 12px 0;
  }

  #middle {
    margin-left: 0;
    padding: 0 10px;
  }

  #main {
    background-color: #C9B5A0;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  #boxtop,
  #boxbottom {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  #boxRight,
  #boxright {
    display: none;
  }

  #logo {
    width: auto;
    height: auto;
    padding: 8px 10px 0 10px;
  }

  #logo img {
    max-width: 280px;
  }

  #loginTop {
    width: 260px;
    margin: 10px;
  }

  #menuLeft,
  #menuRight {
    width: 200px;
  }

  #contentWrapper {
    width: calc(100% - 428px);
    max-width: 538px;
    min-width: 0;
  }

  /* Anchor absolute book hero layers inside the content box */
  .content > div[style*="padding:20px"],
  .content > div[style*="padding:10px"] {
    position: relative;
    overflow: hidden;
  }

  #top-stuff {
    width: 100%;
  }

  /* Disable absolute blur layer on tablet to prevent overlap into side columns */
  #background-cel,
  .background-cel-list {
    display: none;
  }

  #top-stuff,
  .top-stuff-list {
    width: 100%;
    max-width: 100%;
    position: static;
    display: block;
    padding-top: 0;
  }

  #precis {
    margin-top: 12px;
    padding: 0;
  }

  #fokkerBox {
    width: 100%;
    max-width: 300px;
  }

  .content,
  .contentTop,
  .contentBottom {
    width: 100%;
    margin-left: 0;
  }
}

/* Mobile breakpoint */
@media (max-width: 768px) {
  body {
    position: relative;
    overflow-x: hidden;
  }

  .mobile-nav-toggle {
    display: inline-block;
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 1201;
    border: 1px solid #000066;
    background: #E4E0CE;
    color: #000066;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1;
    padding: 8px 10px;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body.mobile-nav-open .mobile-nav-toggle .mobile-nav-label {
    display: none;
  }

  #boxtop,
  #boxbottom,
  #raf {
    display: none;
  }

  #main {
    width: 100%;
    margin: 0;
    background-color: #C9B5A0;
  }

  #masthead {
    position: relative;
    padding: 6px 8px 4px 8px;
    min-height: 64px;
  }

  #logo {
    text-align: left;
    padding: 2px 56px 6px 8px;
  }

  #logo img {
    max-width: 230px;
    width: min(64vw, 230px);
  }

  #loginTop {
    float: none;
    width: 100%;
    margin: 0;
    box-shadow: none;
    background-image: none;
  }

  #menuLeft,
  #contentWrapper {
    float: none;
    width: 100%;
    margin: 0 0 12px 0;
  }

  /* Pull the middle white panel slightly right on narrow screens */
  #contentWrapper {
    width: calc(100% - 12px);
    margin: 0 0 12px 12px;
  }

  #contentWrapper,
  #menuRight {
    box-sizing: border-box;
    width: min(538px, calc(100% - 12px));
    margin: 0 0 12px 12px;
    padding: 0;
  }

  #menuRight {
    float: none;
    background-image: url("/graphics/contentBar.gif");
    background-repeat: repeat-y;
    background-size: 100% auto;
  }

  #menuRight .menuTop {
    background-image: url("/graphics/tab.gif");
    background-repeat: no-repeat;
    background-position: top right;
    height: 19px;
  }

  #menuRight .menuBottom {
    background-image: url("/graphics/contentBarBottom.gif");
    background-repeat: no-repeat;
    background-position: bottom right;
    height: 5px;
  }

  #menuRight .sideBarText {
    width: 100% !important;
    padding: 6px 12px 0 12px;
    box-sizing: border-box;
  }

  #menuRight > div[style*="text-align: center"] {
    padding: 0 12px 10px 12px;
    box-sizing: border-box;
  }

  /* Keep blur layer disabled on mobile too */
  #background-cel,
  .background-cel-list,
  #top-stuff,
  .top-stuff-list {
    position: static;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0;
    left: auto;
  }

  .blur-image {
    position: static;
    display: block;
    width: 100%;
    max-width: 260px;
    height: auto;
    margin: 0 auto 10px auto;
    filter: none;
    -webkit-filter: none;
    -moz-filter: none;
    -o-filter: none;
    -ms-filter: none;
  }

  /* Off-canvas drawer with existing left and top blocks */
  #menuLeft,
  #loginTop {
    position: fixed;
    left: 0;
    width: 80vw;
    max-width: 360px;
    z-index: 1200;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    margin: 0;
  }

  #loginTop {
    top: auto;
    bottom: 0;
    padding: 10px;
    background: #ffffff;
    border-right: 1px solid #000066;
    border-top: 1px solid #000066;
    border-bottom: 0;
    z-index: 1202;
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.24);
  }

  #menuLeft {
    top: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 170px;
    background: #ffffff;
    border-right: 1px solid #000066;
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.24);
  }

  /* Hide release promo block in mobile drawer */
  #menuLeft .upcoming-releases-block {
    display: none !important;
  }

  body.mobile-nav-open #loginTop,
  body.mobile-nav-open #menuLeft {
    transform: translateX(0);
  }

  body.mobile-nav-open:before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.22);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    z-index: 1100;
  }

  body.mobile-nav-open #contentWrapper,
  body.mobile-nav-open #menuRight {
    pointer-events: none;
  }

  #middle {
    padding-top: 2px;
  }

  .menuTop,
  .menuTop,
  .menuBottom,
  .contentTop,
  .contentBottom,
  .content,
  #menuLeft {
    width: 100%;
  }

  .content {
    margin-left: 0;
  }

  .menuTop {
    height: 16px;
  }

  .menuBottom,
  .contentBottom {
    height: 4px;
  }

  .content > div[style*="padding:20px"] {
    padding: 14px !important;
  }

  .content > div[style*="padding:10px"] {
    padding: 12px !important;
  }

  .sideBarText,
  .registration-form,
  .advanced-search-form,
  .details-table,
  #fokkerBox,
  .ownbox {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  #menuLeft .sideBarText {
    width: 100% !important;
    padding-left: 8px;
    padding-right: 8px;
    box-sizing: border-box;
  }

  #menuLeft form,
  #menuLeft select,
  #menuLeft input,
  #menuLeft .inputbox,
  #menuLeft .inputbox2,
  #menuLeft .inputbox3,
  #menuLeft .btn {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .inputbox,
  .inputbox2,
  .inputbox3,
  .masthead-input,
  input.btn,
  .gallery-btn {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .sideBarText form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    text-align: left;
  }

  .sideBarText form div[style*="float:left"] {
    float: none !important;
    margin: 0 !important;
    font-weight: 700;
    text-align: left;
  }

  .sideBarText form input[type="submit"] {
    float: none !important;
    margin: 0 !important;
  }

  .sideBarText form div[style*="padding-top:7px"] {
    padding-top: 0 !important;
  }

  #loginTop form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #loginTop input[type="submit"] {
    width: 100%;
  }

  #register-top {
    float: none;
    margin-top: 2px;
    text-align: left;
  }

  .bookPageCover,
  .book175,
  .bookListing {
    width: 100%;
    max-width: 260px;
    height: auto !important;
  }

  .content .cover {
    float: none;
    margin: 0 auto 12px auto;
    display: block;
  }

  #top-stuff {
    position: static;
    display: block;
    padding-top: 0;
  }

  .details-table {
    margin: 8px auto 0 auto;
    table-layout: fixed;
  }

  .details-table td {
    padding: 3px !important;
  }

  .details-table td:first-child {
    width: 30%;
    white-space: nowrap;
  }

  .details-table td:nth-child(2) {
    width: 70%;
  }

  /* Override old align="right" image behavior in article/news text */
  .content img[align="right"],
  .content img[style*="float:right"],
  .content img[style*="float: right"] {
    float: none !important;
    display: block;
    margin: 0 auto 10px auto !important;
  }

  .content img[align="left"],
  .content img[style*="float:left"],
  .content img[style*="float: left"] {
    float: none !important;
    display: block;
    margin: 0 auto 10px auto !important;
  }

  /* Normalize right-floated utility wrappers from inline styles */
  .content [style*="float:right"],
  .content [style*="float: right"] {
    float: none !important;
    margin-left: 0 !important;
    text-align: left;
  }

  .content [style*="float:left"],
  .content [style*="float: left"] {
    float: none !important;
    margin-left: 0 !important;
  }

  /* Keep action rows usable when legacy table align attributes are present */
  .content td[align="right"] {
    text-align: left;
    padding-top: 6px;
  }

  /* ABE widget and similar fixed-width promo tables */
  .content table[width="150"],
  .content table[width="148"],
  .content table[width="136"],
  .content table[width="190"] {
    width: 100% !important;
    max-width: 320px;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .content td[width="148"],
  .content td[width="136"],
  .content td[width="190"] {
    width: auto !important;
  }

  .content input[style*="width:123px"],
  .content input[style*="width: 123px"],
  .content input[size="17"] {
    width: 100% !important;
    max-width: 100%;
  }

  .content [style*="margin-left: 2pt"],
  .content [style*="margin-left:2pt"] {
    margin-left: 0 !important;
  }

  /* Goodreads and external embed widgets */
  .gr_custom_container,
  .gr_custom_each_container,
  #gr_add_to_books,
  .gr_review_container {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Slightly calmer rhythm for long text-heavy pages */
  .content h2,
  .content h3 {
    margin-top: 10px;
    margin-bottom: 6px;
  }

  .content br + br {
    display: none;
  }

  #background-cel,
  .background-cel-list,
  #top-stuff,
  .top-stuff-list {
    position: static;
    width: 100%;
    height: auto;
    margin: 0;
  }

  #precis {
    margin-top: 12px;
    padding: 0;
  }

  .gallerybox {
    width: calc(50% - 18px);
    margin: 6px 9px;
    float: left;
  }

  .gallerybox .placard {
    margin-left: auto;
    margin-right: auto;
  }

  table,
  table.booklist,
  table.booklist tbody,
  table.booklist tr,
  table.booklist td,
  table.booklist th {
    width: 100% !important;
    display: block;
  }

  table.booklist tr {
    border-bottom: 1px solid #b9b29c;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  table.booklist img.bookListing {
    display: inline-block;
    height: auto !important;
    width: auto;
    max-width: 100%;
  }

  .content iframe,
  .content object,
  .content embed {
    max-width: 100% !important;
  }

  .content table {
    overflow-wrap: anywhere;
  }
}

/* Narrow phones */
@media (max-width: 420px) {
  html body {
    font-size: 14px;
  }

  h1 {
    font-size: 1.35em;
  }

  h2,
  h3 {
    font-size: 1.05em;
  }

  #middle {
    padding: 0 6px;
  }

  .gallerybox {
    width: 100%;
    margin: 6px 0;
    float: none;
  }
}