:root {
    --route-library-orange: #ff4e25;
    --route-library-ink: #111827;
    --route-library-muted: #8b95a5;
    --route-library-border: #e6e9ee;
    --route-library-soft: #f8fafc;
}

.route-library { position: fixed; z-index: 1450; inset: 0; display: grid; place-items: center; padding: 16px; font-family: Inter, system-ui, sans-serif; color: var(--route-library-ink); }
.route-library[hidden] { display: none; }
.route-library__backdrop { position: absolute; inset: 0; border: 0; background: rgba(25, 34, 49, .72); backdrop-filter: blur(8px); }
.route-library__dialog { position: relative; display: flex; width: min(1240px, 100%); height: min(870px, calc(100dvh - 32px)); flex-direction: column; overflow: hidden; border: 1px solid rgba(255,255,255,.55); border-radius: 28px; background: #fff; box-shadow: 0 32px 88px rgba(15, 23, 42, .32); }
.route-library__header { display: flex; min-height: 116px; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 26px; border-bottom: 1px solid var(--route-library-border); }
.route-library__header p, .route-library-editor__heading p { margin: 0 0 4px; color: var(--route-library-orange); font-size: 10px; font-weight: 900; line-height: 1.2; letter-spacing: .12em; text-transform: uppercase; }
.route-library__header h2 { margin: 0; font-size: clamp(28px, 3vw, 38px); font-weight: 900; letter-spacing: -.045em; line-height: 1; }
.route-library__header span { display: block; margin-top: 7px; color: var(--route-library-muted); font-size: 13px; font-weight: 700; line-height: 1.2; }
.route-library__close, .route-library-editor__heading > button { display: grid; width: 48px; height: 48px; flex: 0 0 48px; place-items: center; border: 1px solid var(--route-library-border); border-radius: 50%; background: var(--route-library-soft); transition: 160ms ease; }
.route-library__close:hover, .route-library-editor__heading > button:hover { border-color: #ffcbbb; background: #fff4ef; transform: rotate(5deg); }
.route-library__close img, .route-library-editor__heading button img { width: 19px; height: 19px; }
.route-library__layout { display: grid; min-height: 0; flex: 1; grid-template-columns: 300px minmax(0, 1fr); }
.route-library__sidebar { position: relative; display: flex; min-height: 0; flex-direction: column; padding: 22px 16px 22px 24px; border-right: 1px solid var(--route-library-border); }
.route-library__sidebar-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.route-library__sidebar-title h3 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -.02em; }
.route-library__sidebar-title button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--route-library-border); border-radius: 50%; background: var(--route-library-soft); color: #526074; font-size: 22px; }
.route-library__folder-tree { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 5px; overflow-y: auto; padding-right: 8px; scrollbar-width: thin; }
.route-library__folder-group-label { margin: 13px 9px 5px; color: #a0a9b7; font-size: 9px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.route-library__folder-row { display: grid; min-height: 47px; grid-template-columns: 1fr auto; align-items: center; gap: 8px; margin-left: calc(var(--route-folder-depth, 0) * 18px); border-radius: 13px; color: #39465a; }
.route-library__folder-row.is-active { background: #fff0eb; color: #c83a19; }
.route-library__folder-select { display: flex; min-width: 0; height: 100%; align-items: center; gap: 10px; border: 0; background: transparent; padding: 0 10px; color: inherit; text-align: left; }
.route-library__folder-select img { width: 21px; height: 21px; opacity: .9; }
.route-library__folder-select img, .route-library__subfolder img, .route-library__folder-mark img { filter: invert(41%) sepia(99%) saturate(3122%) hue-rotate(347deg) brightness(101%) contrast(101%); }
.route-library__folder-select strong { overflow: hidden; flex: 1; font-size: 13px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.route-library__folder-row small { padding-right: 10px; color: #929cab; font-size: 11px; font-weight: 800; }
.route-library__new-folder { display: flex; min-height: 43px; flex: 0 0 auto; align-items: center; gap: 8px; margin-top: 8px; border: 0; background: transparent; padding: 0 8px; color: #e84924; font-size: 13px; font-weight: 850; text-align: left; }
.route-library__new-folder span { font-size: 24px; font-weight: 400; }
.route-library__hint { margin: auto 8px 0; padding-top: 24px; color: #9aa4b3; font-size: 11px; line-height: 1.4; }
.route-library__content { display: flex; min-width: 0; min-height: 0; flex-direction: column; padding: 19px 25px 22px; }
.route-library__breadcrumb { min-height: 18px; color: #98a2b2; font-size: 11px; font-weight: 700; }
.route-library__folder-heading { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 20px; margin-top: 6px; }
.route-library__folder-copy { display: flex; min-width: 0; align-items: center; gap: 14px; }
.route-library__folder-mark { display: grid; width: 54px; height: 54px; flex: 0 0 54px; place-items: center; border: 2px solid var(--route-library-orange); border-radius: 15px; background: #fff8f5; }
.route-library__folder-mark img { width: 25px; height: 25px; }
.route-library__folder-copy h3 { overflow: hidden; margin: 0; font-size: clamp(24px, 2.3vw, 33px); font-weight: 900; letter-spacing: -.04em; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.route-library__folder-copy p { margin: 6px 0 0; color: var(--route-library-muted); font-size: 12px; font-weight: 700; }
.route-library__folder-heading-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; }
.route-library__map-button { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 14px; background: var(--route-library-orange); padding: 0 22px; color: #fff; font-size: 13px; font-weight: 850; box-shadow: 0 10px 24px rgba(255,78,37,.2); transition: 160ms ease; }
.route-library__map-button:hover { background: #ef431d; transform: translateY(-1px); }
.route-library__map-button img { width: 21px; height: 21px; filter: brightness(0) invert(1); }
.route-library__more, .route-library__mobile-back-row > button:last-child { display: grid; width: 48px; height: 48px; place-items: center; border: 1px solid var(--route-library-border); border-radius: 14px; background: #fff; color: #4b5769; font-size: 15px; font-weight: 900; }
.route-library__subfolders { display: flex; min-height: 0; flex: 0 0 auto; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.route-library__subfolder { display: flex; min-width: 160px; min-height: 42px; align-items: center; gap: 9px; border: 1px solid var(--route-library-border); border-radius: 12px; background: #fff; padding: 0 13px; color: #344054; font-size: 12px; font-weight: 800; }
.route-library__subfolder img { width: 18px; height: 18px; }
.route-library__subfolder small { margin-left: auto; color: #8e98a8; }
.route-library__add-subfolder { border: 0; background: transparent; color: #e84924; }
.route-library__toolbar { display: grid; flex: 0 0 auto; grid-template-columns: minmax(0, 1fr) minmax(220px, 240px); gap: 10px; margin-top: 14px; }
.route-library__search, .route-library__sort { display: flex; min-height: 44px; align-items: center; border: 1px solid var(--route-library-border); border-radius: 12px; background: var(--route-library-soft); }
.route-library__search input, .route-library__sort select { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0 15px; color: #253044; font-size: 12px; font-weight: 700; }
.route-library__sort select { cursor: pointer; padding-right: 38px; white-space: nowrap; }
.route-library__status { flex: 0 0 auto; padding: 18px 2px 6px; color: #8f99a7; font-size: 11px; font-weight: 750; }
.route-library__status:empty { display: none; }
.route-library__grid { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: max-content; align-content: start; align-items: start; gap: 15px; overflow-y: auto; margin-top: 12px; padding: 3px 4px 8px 0; scrollbar-width: thin; }
.route-library-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--route-library-border); border-radius: 16px; background: #fff; box-shadow: 0 3px 12px rgba(15,23,42,.04); transition: 180ms ease; }
.route-library-card:hover { border-color: #ffc8b8; box-shadow: 0 13px 30px rgba(15,23,42,.1); transform: translateY(-2px); }
.route-library-card__open { display: block; width: 100%; border: 0; background: transparent; padding: 0; color: inherit; text-align: left; }
.route-library-card__media { position: relative; height: 136px; overflow: hidden; background: #edf2f5; }
.route-library-card__media > img { width: 100%; height: 100%; object-fit: cover; transition: filter 180ms ease, transform 180ms ease; }
.route-library-card__media--empty { display: grid; place-items: center; background: #edf3ee; }
.route-library-card__media--empty > img { width: 42px; height: 42px; object-fit: contain; opacity: .75; }
.route-library-card__activity { position: absolute; left: 10px; bottom: 9px; display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: #fff; box-shadow: 0 5px 14px rgba(15,23,42,.16); }
.route-library-card__activity img { width: 18px; height: 18px; }
.route-library-card__folder { position: absolute; z-index: 5; top: 10px; right: 10px; display: grid; width: 35px; height: 35px; place-items: center; border: 1px solid rgba(255,255,255,.45); border-radius: 50%; background: rgba(29,39,53,.75); backdrop-filter: blur(8px); }
.route-library-card__folder img { width: 17px; height: 17px; filter: brightness(0) invert(1); }
.route-library-card__body { padding: 10px 12px 11px; }
.route-library-card__body h4 { overflow: hidden; margin: 0; color: #152033; font-size: 13px; font-weight: 900; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.route-library-card__meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 7px; color: #8c96a5; font-size: 10px; font-weight: 750; }
.route-library-card__spark { width: 100%; height: 33px; margin-top: 5px; overflow: visible; }
.route-library-card__spark polyline { fill: none; stroke: var(--route-library-orange); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.route-library-card__difficulty { display: block; margin-top: 1px; color: #f05a2a; font-size: 10px; font-weight: 900; }
.route-library-card__difficulty[data-tone="easy"] { color: #20a451; }
.route-library-card__difficulty[data-tone="medium"] { color: #d88a12; }
.route-library-card__map-overlay { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; background: rgba(20,29,42,.26); opacity: 0; pointer-events: none; transition: 180ms ease; }
.route-library-card__map-overlay a { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; border-radius: 13px; background: #fff; padding: 0 17px; color: #111827; font-size: 12px; font-weight: 900; box-shadow: 0 12px 28px rgba(15,23,42,.2); pointer-events: auto; }
.route-library-card__map-overlay a img { width: 18px; height: 18px; flex: 0 0 18px; object-fit: contain; }
.route-library:not(.is-map-page) .route-library-card:hover .route-library-card__open { filter: blur(3px); }
.route-library:not(.is-map-page) .route-library-card:hover .route-library-card__map-overlay,
.route-library:not(.is-map-page) .route-library-card:focus-within .route-library-card__map-overlay { opacity: 1; pointer-events: auto; }
.route-library__empty { grid-column: 1 / -1; display: grid; min-height: 250px; place-items: center; align-content: center; gap: 7px; border: 1px dashed #d9dfe7; border-radius: 20px; color: #8b95a5; text-align: center; }
.route-library__empty strong { color: #263247; font-size: 15px; }
.route-library__empty p { max-width: 360px; margin: 0; font-size: 11px; }
.route-library__mobile-back-row, .route-library__mobile-footer { display: none; }
body.route-library-open { overflow: hidden !important; }

.route-library-editor { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; padding: 20px; }
.route-library-editor[hidden] { display: none; }
.route-library-editor__backdrop { position: absolute; inset: 0; border: 0; background: rgba(15,23,42,.46); backdrop-filter: blur(5px); }
.route-library-editor__dialog { position: relative; width: min(460px, 100%); overflow: hidden; border: 1px solid rgba(255,255,255,.6); border-radius: 22px; background: #fff; box-shadow: 0 24px 68px rgba(15,23,42,.3); }
.route-library-editor__heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 21px 15px; border-bottom: 1px solid var(--route-library-border); }
.route-library-editor__heading h3 { margin: 0; font-size: 21px; font-weight: 900; letter-spacing: -.025em; }
.route-library-editor__heading > button { width: 38px; height: 38px; flex-basis: 38px; }
.route-library-editor form { padding: 18px 21px 21px; }
.route-library-editor label { display: grid; gap: 7px; color: #637084; font-size: 11px; font-weight: 850; }
.route-library-editor input { min-height: 48px; border: 1px solid var(--route-library-border); border-radius: 14px; outline: 0; padding: 0 14px; color: #172033; font-size: 14px; font-weight: 750; }
.route-library-editor input:focus { border-color: #ff9b7f; box-shadow: 0 0 0 3px rgba(255,78,37,.1); }
.route-library-editor__actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.route-library-editor__actions button { min-height: 43px; border-radius: 12px; padding: 0 15px; font-size: 11px; font-weight: 900; }
.route-library-editor__delete { margin-right: auto; border: 1px solid #ffd0d0; background: #fff3f3; color: #dc3345; }
.route-library-editor__cancel { border: 1px solid var(--route-library-border); background: #fff; color: #637084; }
.route-library-editor__save { border: 0; background: var(--route-library-orange); color: #fff; }

html[data-theme="dark"] .route-library__dialog, html[data-theme="dark"] .route-library-editor__dialog { border-color: #344154; background: #111a28; color: #f8fafc; }
html[data-theme="dark"] .route-library__header, html[data-theme="dark"] .route-library__sidebar, html[data-theme="dark"] .route-library-editor__heading { border-color: #2c3748; }
html[data-theme="dark"] .route-library__content, html[data-theme="dark"] .route-library-card, html[data-theme="dark"] .route-library__more, html[data-theme="dark"] .route-library__subfolder { background: #111a28; }
html[data-theme="dark"] .route-library__search, html[data-theme="dark"] .route-library__sort, html[data-theme="dark"] .route-library-editor input { border-color: #344154; background: #182334; color: #f8fafc; }
html[data-theme="dark"] .route-library-card__body h4, html[data-theme="dark"] .route-library__folder-copy h3, html[data-theme="dark"] .route-library-editor__heading h3 { color: #f8fafc; }

/* Keep this global overlay visually aligned with the compact desktop shell. */
@media (min-width: 981px) {
    .route-library__dialog { transform: scale(.9); transform-origin: center; }
}

@media (max-width: 980px) {
    .route-library__dialog { height: min(900px, calc(100dvh - 20px)); }
    .route-library__layout { grid-template-columns: 245px minmax(0, 1fr); }
    .route-library__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .route-library { align-items: end; padding: 0; }
    .route-library__dialog { width: 100%; height: 94dvh; max-height: none; border-radius: 26px 26px 0 0; }
    .route-library__header { min-height: 112px; padding: 17px 20px 14px; }
    .route-library__header h2 { font-size: 30px; }
    .route-library__header span { font-size: 12px; }
    .route-library__layout { display: block; overflow: hidden; }
    .route-library__sidebar { position: absolute; z-index: 6; inset: 112px 0 0; display: none; border: 0; background: #fff; padding: 20px; }
    .route-library.is-folder-list-open .route-library__sidebar { display: flex; }
    .route-library__sidebar-title h3 { font-size: 24px; }
    .route-library__content { height: 100%; padding: 13px 18px 96px; }
    .route-library__mobile-back-row { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; }
    .route-library__mobile-back-row > button:first-child { display: flex; min-height: 45px; align-items: center; gap: 9px; border: 0; background: transparent; color: #263247; font-size: 23px; }
    .route-library__mobile-back-row > button:first-child span { font-size: 16px; font-weight: 850; }
    .route-library__breadcrumb { display: none; }
    .route-library__folder-heading { margin-top: 9px; }
    .route-library__folder-mark { width: 55px; height: 55px; flex-basis: 55px; }
    .route-library__folder-copy h3 { font-size: 25px; }
    .route-library__folder-heading-actions { display: none; }
    .route-library__subfolders { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 17px; }
    .route-library__subfolder { min-width: 0; min-height: 48px; }
    .route-library__toolbar { grid-template-columns: minmax(0, 1fr); margin-top: 16px; }
    .route-library__sort { width: 100%; background: #fff; }
    .route-library__status { padding-top: 13px; }
    .route-library__grid { display: flex; flex-direction: column; gap: 10px; padding-bottom: 18px; }
    .route-library-card { display: grid; min-height: 130px; grid-template-columns: 136px minmax(0, 1fr); overflow: visible; }
    .route-library-card__open { display: contents; }
    .route-library-card__media { height: 130px; border-radius: 15px; }
    .route-library-card__body { min-width: 0; padding: 12px 11px; }
    .route-library-card__body h4 { font-size: 14px; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
    .route-library-card__spark { height: 37px; margin-top: 9px; }
    .route-library-card__folder { top: 9px; left: 95px; right: auto; }
    .route-library-card__map-overlay { display: none; }
    .route-library:not(.is-map-page) .route-library-card:hover .route-library-card__open { filter: none; }
    .route-library__mobile-footer { position: absolute; z-index: 7; right: 0; bottom: 0; left: 0; display: block; padding: 12px 18px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--route-library-border); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
    .route-library__mobile-footer .route-library__map-button { width: 100%; min-height: 58px; font-size: 15px; }
    .route-library-editor { align-items: end; padding: 0; }
    .route-library-editor__dialog { width: 100%; border-radius: 24px 24px 0 0; }
}

/* The retired map collection panel remains as a data compatibility host only. */
.page-map #left-collection-menu { display: none !important; }
