@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #101014; --panel: #18181e; --panel2: #202027; --line: #303038;
  --text: #f3f1ed; --muted: #96949f; --accent: #ffc857; --accent2: #ffdf93;
  --reader: #09090b; --font: 'DM Sans', system-ui, sans-serif; --mono: 'DM Mono', ui-monospace, monospace;
  --gutter: 22px; --zoom: 1; --page-filter: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); height: 100dvh; overflow: hidden; max-width: 100vw; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.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; }

/* Shell */
.app { height: 100dvh; width: 100%; display: grid; grid-template-rows: 64px 1fr auto; grid-template-columns: minmax(0, 1fr); }

/* Base strip: Adaptor House mark, legal marks, citation + terms */
.base { display: flex; align-items: center; gap: 14px; padding: 5px 16px calc(5px + env(safe-area-inset-bottom)); background: #0d0d10; border-top: 1px solid #222228; font: 9px var(--mono); letter-spacing: .8px; color: #7d7b86; white-space: nowrap; overflow: hidden; }
.base a { color: inherit; text-decoration: none; }
.base a:hover, .base a:focus-visible { color: var(--accent); }
.base-mark { display: inline-flex; align-items: center; gap: 8px; color: #b9b7c0 !important; }
.base-mark:hover { color: var(--accent) !important; }
.base-mark svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 34; }
.base-legal { overflow: hidden; text-overflow: ellipsis; }
.base-cite { margin-left: auto; }
.topbar { display: flex; align-items: center; gap: 17px; padding: 0 23px; border-bottom: 1px solid var(--line); background: #121216; z-index: 6; min-width: 0; overflow: hidden; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: -.8px; display: flex; align-items: center; gap: 9px; white-space: nowrap; color: var(--text); text-decoration: none; }
.brand:hover .logo { transform: rotate(-5deg) scale(1.08); }
.logo { width: 27px; height: 27px; background: var(--accent); border-radius: 8px; display: grid; place-items: center; color: #262018; font-size: 18px; font-weight: 900; transform: rotate(-5deg); }
.divider { height: 27px; width: 1px; background: var(--line); }
.book-title-wrap { min-width: 0; flex: 1 1 0; }  /* takes the leftover width; long titles truncate instead of widening the page */
.book-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.book-sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 12px; font-weight: 600; transition: background .15s, border-color .15s; }
.btn:hover { background: #2b2b34; border-color: #55545e; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #211b10; }
.btn.primary:hover { background: var(--accent2); }
.btn.small { padding: 3px 8px; }
.icon-btn { width: 35px; height: 35px; padding: 0; display: grid; place-items: center; font-size: 17px; }
.mobile-only { display: none; }

.layout { min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr) 286px; transition: grid-template-columns .22s ease; position: relative; }

/* Sidebars */
.sidebar { background: var(--panel); overflow: auto; padding: 21px 17px; border-right: 1px solid var(--line); min-width: 0; }
.sidebar.right { border-right: 0; border-left: 1px solid var(--line); padding: 21px 18px; }
.panel-close { display: block; margin: -12px -8px 8px auto; width: 30px; height: 30px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 21px; line-height: 1; }
.panel-close:hover { background: #303038; color: var(--accent); }
.panel-tab { position: absolute; z-index: 2; top: 50%; width: 28px; height: 52px; display: none; background: #25252d; border: 1px solid #444; border-radius: 0 8px 8px 0; color: var(--accent); }
.left-tab { left: 0; }
.right-tab { right: 0; border-radius: 8px 0 0 8px; }
.scrim { display: none; }

.section-label { font: 500 10px var(--mono); letter-spacing: 1.5px; color: var(--muted); text-transform: uppercase; margin: 3px 0 13px; }
.dropzone { border: 1px dashed #57545c; border-radius: 13px; padding: 21px 14px; text-align: center; background: #1d1d23; transition: .2s; }
.dropzone.drag, .maker-drop.drag { border-color: var(--accent); background: #29251c; }
.drop-icon { font-size: 26px; color: var(--accent); margin-bottom: 7px; }
.dropzone strong { font-size: 13px; display: block; }
.dropzone p { font-size: 11px; color: var(--muted); line-height: 1.6; margin: 7px 0 14px; }
.dropzone-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.make-wide { width: 100%; margin: 10px 0 23px; }
.library-head { display: flex; justify-content: space-between; align-items: center; }
.library-head .section-label { margin-bottom: 11px; }
.count { font: 11px var(--mono); color: var(--muted); }
.library-empty { text-align: center; color: var(--muted); font-size: 11px; line-height: 1.6; padding: 23px 12px; border: 1px solid var(--line); border-radius: 10px; }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 9px; border-radius: 10px; cursor: pointer; margin: 3px 0; }
.lib-item:hover, .lib-item.active { background: #28272e; }
.lib-thumb { width: 37px; height: 49px; border-radius: 4px; flex-shrink: 0; background-size: cover; background-position: center; }
.lib-text { min-width: 0; flex: 1; }
.lib-name { font-size: 11px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 4px 0; }
.lib-pages { font: 10px var(--mono); color: var(--muted); }
.lib-item.missing .lib-pages { color: #d99a6c; }
.lib-remove { width: 26px; height: 26px; border-radius: 7px; background: transparent; color: var(--muted); font-size: 17px; opacity: 0; flex-shrink: 0; }
.lib-item:hover .lib-remove, .lib-remove:focus-visible { opacity: 1; }
.lib-remove:hover { background: #3a3a44; color: var(--text); }
.fine-print { font-size: 10px; color: #777580; line-height: 1.6; margin: 18px 1px 0; }

.control-group { padding: 0 0 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.control-title { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; margin-bottom: 11px; }
.value { font: 10px var(--mono); color: var(--accent); }
.seg { display: flex; gap: 4px; padding: 3px; background: #111115; border-radius: 8px; }
.seg button { flex: 1; background: transparent; padding: 7px 4px; border-radius: 6px; font-size: 10px; color: var(--muted); }
.seg button.selected { background: #303038; color: var(--text); }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 11px; margin: 10px 0; color: #dedce3; }
.zoom-buttons { display: flex; gap: 8px; align-items: center; }
.select, .text-input { background: #111115; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: 11px; max-width: 140px; }
.range { accent-color: var(--accent); width: 100%; height: 3px; }
.toggle-wrap { display: flex; align-items: center; cursor: pointer; }
.toggle { width: 29px; height: 17px; border-radius: 20px; background: #404047; position: relative; transition: .18s; flex: none; }
.toggle::after { content: ''; width: 11px; height: 11px; background: #ddd; border-radius: 50%; position: absolute; top: 3px; left: 3px; transition: .18s; }
input:checked + .toggle { background: var(--accent); }
input:checked + .toggle::after { left: 15px; background: #342a16; }
input:focus-visible + .toggle { outline: 2px solid var(--accent); outline-offset: 2px; }
.more-controls { border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; margin-top: 12px; }
.more-controls summary { font-size: 11px; font-weight: 700; cursor: pointer; }
.more-controls .control-row { margin-bottom: 0; }

/* Reader */
.main { min-width: 0; min-height: 0; display: grid; grid-template-rows: 1fr 56px; background: var(--reader); position: relative; }
.stage { min-height: 0; position: relative; overflow: hidden; touch-action: pan-x pan-y; background-color: var(--reader); background-image: radial-gradient(#25252a .65px, transparent .65px); background-size: 17px 17px; }
.stage.bg-black { background: #000; }
.stage.bg-checker { background-image: linear-gradient(45deg, #17171a 25%, transparent 25%), linear-gradient(-45deg, #17171a 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #17171a 75%), linear-gradient(-45deg, transparent 75%, #17171a 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
.stage.bg-light { background-color: #e4dfd2; background-image: radial-gradient(#c8c1b3 .65px, transparent .65px); }

.page-wrap { position: absolute; inset: 0; display: flex; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; scrollbar-color: #555 transparent; }
.page-wrap.fit-page { overflow: hidden; }
.page-wrap.pannable { cursor: grab; }
.page-wrap.panning { cursor: grabbing; user-select: none; }
.pages { margin: auto; display: flex; align-items: center; gap: var(--gutter); flex: none; }
.pages:empty { display: none; }
.page-wrap.rtl.double .pages { flex-direction: row-reverse; }
.page-img { display: block; flex: 0 1 auto; min-width: 0; user-select: none; -webkit-user-drag: none; filter: var(--page-filter); box-shadow: 0 12px 50px #000a; }
.page-wrap.no-shadow .page-img { box-shadow: none; }

.fit-page .pages { width: 100%; height: 100%; justify-content: center; padding: 0; }
.fit-page .page-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fit-page.double .page-img { max-width: calc((100% - var(--gutter)) / 2); }
.fit-height .pages { height: 100%; }
.fit-height .page-img { height: 100%; width: auto; max-width: none; }
.fit-width .pages { width: 100%; align-items: flex-start; }
.fit-width .page-img { width: 100%; height: auto; }
.fit-width.double .page-img { width: calc((100% - var(--gutter)) / 2); }
.fit-actual .pages { align-items: flex-start; }
.fit-actual .page-img { max-width: none; max-height: none; height: auto; }

.page-wrap.webtoon { display: block; overflow-x: hidden; overflow-anchor: none; } /* scroll compensation is done in JS for every browser */
.page-wrap.webtoon .pages { flex-direction: column; align-items: center; width: 100%; margin: 0 auto; padding: 0 0 var(--gutter); }
.page-wrap.webtoon .page-img { flex: none; width: 100%; max-width: calc(850px * var(--zoom)); height: auto; aspect-ratio: 2 / 3; box-shadow: none; }

.pages.turn-fwd { animation: turn-fwd .22s ease; }
.pages.turn-back { animation: turn-back .22s ease; }
@keyframes turn-fwd { from { opacity: .35; transform: translateX(22px); } to { opacity: 1; transform: none; } }
@keyframes turn-back { from { opacity: .35; transform: translateX(-22px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .pages.turn-fwd, .pages.turn-back { animation: none; } }

.empty-state { margin: auto; text-align: center; max-width: 410px; padding: 28px; }
.empty-art { width: 160px; height: 205px; margin: 0 auto 25px; position: relative; transform: rotate(-4deg); }
.cover { position: absolute; border-radius: 5px; box-shadow: 0 14px 30px #0008; border: 1px solid #ffffff25; }
.cover.one { width: 112px; height: 155px; background: linear-gradient(145deg, #fe9f4f, #a7344f 55%, #252546); left: 8px; top: 22px; transform: rotate(-13deg); }
.cover.two { width: 115px; height: 166px; background: linear-gradient(155deg, #39b7ab, #314581 54%, #eaa54e); right: 3px; top: 6px; transform: rotate(9deg); display: grid; place-items: center; font-size: 55px; }
.cover.two::after { content: 'PANELLI'; font-size: 11px; letter-spacing: 4px; font-weight: 800; position: absolute; bottom: 13px; }
.empty-state h1 { font-size: 25px; letter-spacing: -.8px; margin: 0 0 8px; }
.empty-state p { font-size: 12px; color: var(--muted); line-height: 1.7; margin: 0 0 19px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.empty-actions .btn { padding: 10px 18px; }
.stage.bg-light .empty-state { color: #1b1a17; }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; pointer-events: none; opacity: 0; transition: opacity .18s; }
.stage:hover .overlay { opacity: 1; }
.stage.empty .overlay { display: none; }
.nav-arrow { pointer-events: auto; width: 40px; height: 54px; background: #111b; border: 1px solid #fff2; border-radius: 8px; font-size: 24px; backdrop-filter: blur(6px); }
.nav-arrow:hover { background: #282832; }
/* Pages never receive presses themselves, so phones can't raise their Save Image menu on a long press;
   the press lands on the page area and the magnifier finds the image by position. */
.page-img { pointer-events: none; -webkit-touch-callout: none; }
.stage { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.loupe { position: absolute; z-index: 8; width: 170px; height: 170px; border-radius: 50%; pointer-events: none; background-color: var(--reader); background-repeat: no-repeat; border: 3px solid var(--accent); box-shadow: 0 14px 40px #000c, inset 0 0 0 1px #0006; }
.stage.magnifying { cursor: zoom-in; user-select: none; -webkit-user-select: none; }
.stage.magnifying .overlay { opacity: 0; }
.loupe.shape-square { border-radius: 14px; }
.loupe.shape-strip { width: min(340px, calc(100% - 16px)); height: 96px; border-radius: 12px; }
@media (min-width: 761px) {
  .loupe { width: 220px; height: 220px; }
  .loupe.shape-strip { width: 480px; height: 120px; }
}
.page-badge { position: absolute; top: 15px; left: 50%; transform: translateX(-50%); font: 10px var(--mono); letter-spacing: .7px; background: #111c; border: 1px solid #ffffff1a; border-radius: 30px; padding: 7px 11px; color: #ddd; pointer-events: none; }
.toast { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 9px 14px; background: #28282e; border: 1px solid #41414a; border-radius: 8px; font-size: 11px; line-height: 1.5; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; }

.bottom { display: flex; align-items: center; gap: 12px; padding: 0 19px; background: #131317; border-top: 1px solid #29292f; }
.bottom .icon-btn { background: transparent; border: 0; color: #b5b3bb; }
.bottom .icon-btn:hover { color: var(--accent); }
.progress { flex: 1; display: flex; align-items: center; gap: 11px; }
.page-num { font: 10px var(--mono); color: var(--muted); min-width: 64px; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; z-index: 20; background: #050507cc; display: grid; place-items: center; padding: 18px; backdrop-filter: blur(8px); }
.modal-card { position: relative; width: min(520px, 100%); max-height: 100%; overflow: auto; background: #1d1d24; border: 1px solid #41414a; border-radius: 20px; padding: 28px; box-shadow: 0 30px 100px #000b; }
.modal-card h2 { font-size: 27px; letter-spacing: -1px; margin: 0 0 7px; }
.modal-card > p { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0 0 21px; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 8px; background: transparent; color: var(--muted); font-size: 21px; }
.modal-close:hover { background: #303038; color: var(--text); }
.help-grid { display: grid; grid-template-columns: 1fr auto; gap: 13px 18px; font-size: 12px; color: #c8c6ce; }
.help-grid b { font: 11px var(--mono); color: var(--accent); text-align: right; }
.help-foot { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 15px; color: var(--muted); font-size: 11px; line-height: 1.7; }

.maker { width: min(820px, 100%); display: flex; flex-direction: column; }
.maker-fields { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font: 500 10px var(--mono); letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.field .text-input, .field .select { max-width: none; width: 100%; font: 13px var(--font); letter-spacing: 0; text-transform: none; color: var(--text); padding: 9px 10px; }
.maker-drop { border: 1px dashed #57545c; border-radius: 13px; background: #16161b; min-height: 180px; max-height: 46vh; overflow: auto; padding: 12px; transition: .2s; }
.maker-empty { text-align: center; padding: 30px 12px; }
.maker-empty strong { display: block; font-size: 13px; }
.maker-empty p { font-size: 11px; color: var(--muted); margin: 7px 0 0; }
.maker-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.maker-grid:empty { display: none; }
.maker-page { position: relative; background: #202027; border: 1px solid var(--line); border-radius: 9px; padding: 6px; cursor: grab; }
.maker-page.dragging { opacity: .4; }
.maker-page.drop-target { border-color: var(--accent); }
.maker-page img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 5px; background: #111; pointer-events: none; }
.maker-num { position: absolute; top: 10px; left: 10px; font: 10px var(--mono); background: #111d; border-radius: 20px; padding: 2px 7px; }
.maker-name { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 6px 2px 4px; }
.maker-item-tools { display: flex; gap: 4px; }
.maker-item-tools button { flex: 1; background: #2a2a32; border-radius: 6px; padding: 4px 0; font-size: 13px; color: #cfcdd6; }
.maker-item-tools button:hover { background: #3a3a44; color: var(--accent); }
.maker-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.maker-tools .count { margin-left: auto; }
.maker-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); padding-top: 16px; }
.maker-actions .btn { padding: 10px 18px; }

/* Desktop panel collapse */
@media (min-width: 761px) {
  .layout.hide-library { grid-template-columns: 0 minmax(0, 1fr) 286px; }
  .layout.hide-settings { grid-template-columns: 270px minmax(0, 1fr) 0; }
  .layout.hide-library.hide-settings { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .layout.hide-library #librarySidebar, .layout.hide-settings #settingsSidebar { visibility: hidden; padding-left: 0; padding-right: 0; border: 0; overflow: hidden; }
  .layout.hide-library .left-tab, .layout.hide-settings .right-tab { display: block; }
}
@media (min-width: 761px) and (max-width: 1000px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr) 245px; }
  .layout.hide-library { grid-template-columns: 0 minmax(0, 1fr) 245px; }
  .layout.hide-settings { grid-template-columns: 220px minmax(0, 1fr) 0; }
  .sidebar, .sidebar.right { padding: 16px 13px; }
  .topbar { padding: 0 15px; gap: 11px; }
  .book-title { max-width: 26vw; }
  .dropzone-actions { grid-template-columns: 1fr; }
}

/* Phone */
@media (max-width: 760px) {
  .app { grid-template-rows: 55px 1fr auto; }
  .base { gap: 10px; padding-left: 11px; padding-right: 11px; }
  .base-legal { display: none; }
  .topbar { padding: 0 11px; gap: 9px; }
  .brand { font-size: 17px; }
  .logo { width: 24px; height: 24px; }
  .divider, .top-actions .optional { display: none; }
  .book-title { max-width: 100%; font-size: 12px; }
  .book-sub { font-size: 10px; }
  .top-actions { gap: 5px; }
  .btn { padding: 7px 9px; font-size: 11px; }
  .mobile-only { display: grid; }
  .layout { grid-template-columns: 1fr; }
  .main { grid-column: 1; grid-row: 1; }
  .sidebar { position: absolute; z-index: 5; top: 8px; bottom: 8px; width: min(310px, 88vw); border: 1px solid var(--line) !important; border-radius: 14px; box-shadow: 0 20px 60px #000b; padding: 18px !important; display: none; }
  .sidebar.left { left: 8px; }
  .sidebar.right { right: 8px; }
  .sidebar.open { display: block; }
  .scrim { position: absolute; inset: 0; z-index: 4; background: #0007; }
  .scrim.open { display: block; }
  .lib-remove { opacity: 1; }
  .overlay { display: none; }
  .bottom { padding: 0 9px; gap: 6px; }
  .bottom .icon-btn { width: 31px; }
  .page-num { min-width: 52px; font-size: 9px; }
  .modal-card { padding: 22px 18px; border-radius: 16px; }
  .maker-fields { grid-template-columns: 1fr 1fr; }
  .maker-fields .wide { grid-column: 1 / -1; }
  .maker-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 9px; }
  .maker-tools .count { width: 100%; margin: 0; }
}
