.account-button {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 82px;
  width: auto;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(229, 154, 60, .58);
  border-radius: 10px;
  color: #fff1cc;
  background: rgba(11, 18, 31, .94);
  font-weight: 800;
  z-index: 4;
}

.account-button:hover { border-color: #e59a3c; }
.account-menu-backdrop { position: fixed; inset: 0; z-index: 7000; background: transparent; }
.account-menu {
  position: absolute;
  z-index: 7001;
  top: calc(100% + 8px);
  right: 12px;
  width: 190px;
  padding: 7px;
  border: 1px solid rgba(229,154,60,.55);
  border-radius: 12px;
  background: linear-gradient(180deg, #111a2b, #070d18);
  box-shadow: 0 18px 48px rgba(0,0,0,.58);
}
.account-menu button { width: 100%; margin: 0; padding: 10px 11px; border: 0; border-radius: 8px; background: transparent; color: #eef2f8; text-align: left; font-size: 13px; }
.account-menu button:hover { background: rgba(229,154,60,.13); }
.account-menu .account-menu-danger { color: #ff8b92; }
.account-modal-panel { width: min(430px, calc(100vw - 30px)); }
.account-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 18px; }
.account-tab { margin: 0; background: #111a2c; border: 1px solid #33415c; color: #cbd5e1; }
.account-tab.active { color: #fff; border-color: #e6a145; background: linear-gradient(135deg, #dc8b36, #a64bd2); }
.account-form { display: grid; gap: 11px; }
.account-form input { width: 100%; min-height: 44px; }
.account-form .main-button { margin: 3px 0 0; }
.account-message { min-height: 21px; margin: 12px 0 0; color: #f2bd69; }
.account-user-view { display: grid; gap: 16px; }
.account-separator { display: flex; align-items: center; gap: 10px; margin: 4px 0; color: #dba660; font-size: 12px; font-weight: 800; text-transform: uppercase; }
.account-separator::before, .account-separator::after { content: ""; height: 1px; flex: 1; background: rgba(229,154,60,.28); }
.watchlist-modal-panel { display: block; width: min(980px, calc(100vw - 30px)); max-width: 100%; height: min(680px, 88dvh); min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.watchlist-modal-panel::-webkit-scrollbar { display: none; }
.watchlist-tabs { max-width: 360px; }
.watchlist-tools { display: grid; grid-template-columns: minmax(0,1fr) 190px; gap: 10px; margin: -6px 0 14px; }
.watchlist-tools label { min-width: 0; }
.watchlist-tools input, .watchlist-tools select { width: 100%; min-height: 42px; margin: 0; }
.watchlist-tools input { padding-inline: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.watchlist-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); align-content: start; gap: 14px; width: 100%; height: auto; min-height: 0; overflow: visible; }
.watchlist-grid::-webkit-scrollbar { display: none; }
.watchlist-card { position: relative; display: flex; flex-direction: column; align-items: stretch; width: 100%; min-width: 0; min-height: 0; overflow: hidden; border: 1px solid rgba(95,112,148,.45); border-radius: 13px; background: #0b1322; }
.watchlist-poster { display: block; flex: 0 0 auto; width: 100%; height: clamp(230px, 42dvh, 360px); overflow: hidden; background: #11192a; }
.watchlist-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.watchlist-card > strong { position: relative; display: block; flex: 0 0 auto; padding: 10px 10px 2px; color: #fff1d0; background: #0b1322; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.watchlist-card > span { position: relative; flex: 0 0 auto; padding: 0 10px; color: #9ba8bc; background: #0b1322; font-size: 11px; }
.watchlist-card-actions { position: relative; display: grid; flex: 0 0 auto; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; padding: 9px 10px 10px; background: #0b1322; }
.watchlist-card-actions.finished-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
.watchlist-card-actions button { width: 100%; min-width: 0; min-height: 34px; padding: 7px 4px; font-size: 11px; }
.watchlist-card-actions .danger { border-color: #ef5a66; color: #fff; background: linear-gradient(135deg, #8f2634, #d74453); box-shadow: none; }
.watchlist-card-actions .danger:hover, .watchlist-card-actions .danger:focus-visible { border-color: #ff9ca4; background: linear-gradient(135deg, #a92d3d, #ef5260); color: #fff; }
.watchlist-empty { grid-column: 1/-1; padding: 70px 20px; color: #9ba8bc; text-align: center; }

.history-swipe-row { position: relative; overflow: hidden; border-radius: 12px; touch-action: pan-y; }
.history-swipe-actions { position: absolute; inset: 0; font-size: 13px; font-weight: 900; text-transform: uppercase; }
.history-swipe-delete, .history-swipe-finish { position: absolute; inset: 0; display: flex; align-items: center; width: 100%; padding: 0 26px; color: #fff; opacity: 0; transition: opacity .08s linear; }
.history-swipe-delete { justify-content: flex-end; background: linear-gradient(90deg, #762431, #d44251); }
.history-swipe-finish { justify-content: flex-start; background: linear-gradient(90deg, #18834e, #2dad6d); }
.history-swipe-row.swipe-left .history-swipe-delete { opacity: 1; }
.history-swipe-row.swipe-right .history-swipe-finish { opacity: 1; }
.history-swipe-row .history-media-card { position: relative; z-index: 1; width: 100%; margin: 0; transition: transform .18s ease; will-change: transform; background: #101a2c; background-image: none; }
.history-swipe-row .history-media-card:hover { transform: none; }
.history-swipe-row.is-dragging .history-media-card { transition: none; }

@media (max-width: 860px) {
  .pirate-navbar { padding-right: 96px; }
  .account-button { right: 8px; }
}

@media (max-width: 560px) {
  .pirate-navbar { padding-right: 8px; padding-bottom: 50px; }
  .account-button { top: auto; right: 8px; bottom: 8px; left: 8px; transform: none; width: calc(100% - 16px); }
  .account-menu { position: fixed; top: auto; right: 10px; bottom: 10px; left: 10px; width: auto; padding: 10px; border-radius: 16px; }
  .account-menu button { min-height: 46px; text-align: center; }
  .account-menu-backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
  #watchListModal { padding: 8px; place-items: center; overflow: hidden; }
  .watchlist-modal-panel { display: block; width: 100%; max-width: 100%; height: calc(100dvh - 16px); max-height: calc(100dvh - 16px); padding: 14px 10px max(28px, env(safe-area-inset-bottom)); overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .watchlist-modal-panel::-webkit-scrollbar { display: none; }
  .watchlist-modal-panel .modal-heading,
  .watchlist-modal-panel .watchlist-tabs,
  .watchlist-modal-panel .watchlist-tools,
  .watchlist-modal-panel .watchlist-grid { width: 100%; min-width: 0; }
  .watchlist-tools { grid-template-columns: minmax(0,1fr) 118px; gap: 7px; margin-bottom: 10px; }
  .watchlist-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; height: auto; min-height: 0; padding-right: 1px; padding-bottom: 12px; overflow: visible; }
  .watchlist-card { min-height: 0; }
  .watchlist-poster { height: clamp(210px, 40dvh, 300px); }
  .watchlist-card > strong { padding-inline: 8px; }
  .watchlist-card > span { padding-inline: 8px; }
  .watchlist-card-actions { gap: 4px; padding: 8px 6px 9px; }
  .watchlist-card-actions button { padding-inline: 2px; font-size: 10px; }
}

@media (max-width: 390px) {
  .watchlist-grid { grid-template-columns: 1fr; }
  .watchlist-poster { height: min(52dvh, 390px); }
}

@media (min-width: 561px) and (max-width: 900px) {
  .watchlist-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
/* Watching dialog: keep the shell fixed and scroll only the card list. */
#historyModal {
  overflow: hidden;
}

#historyModal > .history-modal-panel {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(760px, calc(100vw - 32px));
  height: min(640px, calc(100dvh - 48px)) !important;
  max-height: min(640px, calc(100dvh - 48px)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

#historyModal > .history-modal-panel > .modal-heading {
  min-height: 0;
  margin-bottom: 14px;
}

#historyModal #historyList {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

/* A fixed scrolling viewport must never squeeze the Watching rows to fit. */
#historyModal #historyList > .history-swipe-row,
#historyModal #historyList > .history-media-card {
  flex: 0 0 auto !important;
  width: 100%;
  min-height: 82px;
}

#historyModal .history-swipe-row .history-media-card {
  height: auto !important;
  min-height: 82px;
}

#historyModal #historyList::-webkit-scrollbar {
  display: none;
}

@media (max-width: 560px) {
  #historyModal {
    padding: 8px;
  }

  #historyModal > .history-modal-panel {
    width: 100%;
    height: min(620px, calc(100dvh - 16px)) !important;
    max-height: calc(100dvh - 16px) !important;
  }
}

/* Watch List uses a fixed shell like Explore; only its cards scroll. */
#watchListModal {
  overflow: hidden;
}

#watchListModal > .watchlist-modal-panel {
  display: grid !important;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  width: min(980px, calc(100vw - 32px));
  height: min(760px, calc(100dvh - 48px)) !important;
  max-height: min(760px, calc(100dvh - 48px)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

#watchListModal .modal-heading,
#watchListModal .watchlist-tabs,
#watchListModal .watchlist-tools {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
}

#watchListModal #watchListGrid {
  width: 100%;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  padding-right: 3px;
  padding-bottom: 14px;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  align-content: start !important;
  grid-auto-rows: max-content !important;
}

/* Preserve the original portrait cards; overflow belongs to the grid viewport. */
#watchListModal #watchListGrid > .watchlist-card {
  align-self: start;
  height: max-content !important;
  min-height: 0 !important;
}

#watchListModal .watchlist-poster {
  flex: 0 0 clamp(230px, 42dvh, 360px) !important;
  height: clamp(230px, 42dvh, 360px) !important;
  min-height: 230px;
}

#watchListModal #watchListGrid::-webkit-scrollbar {
  display: none;
}

@media (max-width: 560px) {
  #watchListModal {
    padding: 8px;
  }

  #watchListModal > .watchlist-modal-panel {
    width: 100%;
    height: calc(100dvh - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    padding: 14px 10px max(14px, env(safe-area-inset-bottom));
  }

  #watchListModal #watchListGrid {
    height: 100% !important;
    overflow-y: auto !important;
    grid-auto-rows: max-content !important;
  }

  #watchListModal .watchlist-poster {
    flex-basis: clamp(210px, 40dvh, 300px) !important;
    height: clamp(210px, 40dvh, 300px) !important;
    min-height: 210px;
  }
}

@media (max-width: 390px) {
  #watchListModal .watchlist-poster {
    flex-basis: min(52dvh, 390px) !important;
    height: min(52dvh, 390px) !important;
  }
}
