:root{
  --primary:#1976d2;
  --primary-dark:#0d47a1;
  --bg:#f4f7fb;
  --panel:#ffffff;
  --text:#1f2937;
  --muted:#667085;
  --border:#d8e1ec;
  --soft:#eef5ff;
  --shadow:0 12px 34px rgba(31,41,55,.12);
  --topbar-h:64px;
  --controls-h:74px;
  --actions-h:72px;
  --footer-h:30px;
  --rail-w:78px;
  --sidebar-w:360px;
}
*{box-sizing:border-box}
html{width:100%;min-height:100%;margin:0;overflow-y:auto}body{width:100%;min-height:100%;margin:0;overflow-y:auto}
body{
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Hiragino Kaku Gothic ProN","Noto Sans JP","Yu Gothic",sans-serif;
  color:var(--text);
  background:#f4f7fb;
}
button,label{font:inherit}
button{user-select:none}
button:active{transform:none!important}
button:disabled{opacity:.45;cursor:not-allowed}
.hidden{display:none!important}
.app-shell{min-height:100dvh;height:auto;display:flex;flex-direction:column;min-width:0;background:#f4f7fb}
.topbar{
  flex:0 0 var(--topbar-h);
  height:var(--topbar-h);
  display:flex;align-items:center;gap:16px;
  padding:8px 18px;
  background:rgba(255,255,255,.96);
  border-bottom:1px solid var(--border);
  z-index:5;
}
.brand{display:flex;align-items:center;gap:10px;min-width:160px;font-weight:800;font-size:1.15rem;white-space:nowrap;color:#111827}
.brand-icon{width:27px;height:27px;color:var(--primary)}
.file-zone{display:flex;align-items:center;gap:12px;flex:1;min-width:0}
.open-label{display:inline-flex;align-items:center;gap:8px;border:1px solid var(--border);border-radius:12px;background:#fff;color:#1f2937;padding:9px 14px;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.04);white-space:nowrap}
.open-label:hover{border-color:var(--primary);color:var(--primary)}
.open-label input{display:none}
.file-meta{display:flex;align-items:center;gap:10px;min-width:0;color:#374151}
.file-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:280px;font-weight:650}
.badge{display:inline-flex;align-items:center;border-radius:999px;background:#eef2f7;color:#374151;font-weight:700;padding:6px 10px;font-size:.88rem;white-space:nowrap}
.status-dot{width:18px;height:18px;border-radius:50%;background:#2dbb61;color:#fff;display:inline-flex;align-items:center;justify-content:center;font-size:12px;font-weight:900}
.help-btn{border:0;border-radius:12px;background:transparent;color:#374151;padding:8px 10px;font-weight:750;cursor:pointer;white-space:nowrap}
.help-btn:hover{background:#eef2f7}
.workarea{flex:0 0 calc(100dvh - var(--topbar-h) - var(--actions-h) - var(--footer-h));height:calc(100dvh - var(--topbar-h) - var(--actions-h) - var(--footer-h));min-height:520px;display:grid;grid-template-columns:minmax(0,1fr) var(--sidebar-w);border-bottom:1px solid var(--border)}
.viewer{position:relative;min-width:0;min-height:0;display:flex;flex-direction:column;background:linear-gradient(180deg,#f8fbff 0%,#eef3f8 100%)}
.viewer-main{flex:1 1 auto;min-height:0;display:grid;grid-template-columns:var(--rail-w) minmax(0,1fr) var(--rail-w);background:radial-gradient(circle at 34% 23%,#fff 0%,#f3f7fb 55%,#e9eef5 100%)}
.nav-rail{position:relative;min-width:var(--rail-w);height:100%;display:flex;align-items:center;justify-content:center;background:rgba(236,243,250,.78);border-color:var(--border);z-index:3}
.nav-rail-left{border-right:1px solid var(--border)}
.nav-rail-right{border-left:1px solid var(--border)}
.nav-btn{width:72px;height:72px;border:0;background:transparent;color:#667085;font-size:0;line-height:1;display:flex;align-items:center;justify-content:center;box-shadow:none;cursor:pointer;transition:none;position:relative;padding:0}
.nav-icon{display:block;width:58px;height:58px;object-fit:contain;pointer-events:none;filter:drop-shadow(0 6px 12px rgba(15,23,42,.10))}
.nav-btn:hover:not(:disabled) .nav-icon{opacity:.92}
.nav-btn:disabled .nav-icon{opacity:.45}
.viewer-center{position:relative;min-width:0;min-height:0;overflow:hidden}
.canvas-wrap{position:absolute;inset:0;overflow:auto;display:flex;align-items:flex-start;justify-content:center;padding:24px;overscroll-behavior:contain;scrollbar-gutter:stable both-edges}
#pdfCanvas{background:#fff;box-shadow:0 12px 28px rgba(15,23,42,.22);border-radius:2px;max-width:none;height:auto;flex:0 0 auto}
.empty-state{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:min(560px,calc(100% - 48px));text-align:center;background:rgba(255,255,255,.92);border:1px solid var(--border);border-radius:22px;padding:38px;box-shadow:var(--shadow);z-index:2}
.empty-state h1{margin:0 0 12px;font-size:1.65rem;line-height:1.35}.empty-state p{color:var(--muted);line-height:1.8;margin:8px 0}.empty-actions{margin-top:22px}
.drop-hint{display:none;position:absolute;inset:18px;border:3px dashed var(--primary);border-radius:22px;background:rgba(255,255,255,.86);z-index:10;align-items:center;justify-content:center;font-size:1.25rem;font-weight:800;color:var(--primary)}
body.dragging-file .drop-hint{display:flex}
.loading{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);background:#fff;border:1px solid var(--border);padding:16px 20px;border-radius:16px;box-shadow:var(--shadow);z-index:12;display:none;font-weight:800}.loading.show{display:block}
.viewer-controls{flex:0 0 var(--controls-h);height:var(--controls-h);display:flex;align-items:center;justify-content:center;gap:18px;background:rgba(255,255,255,.76);border-top:1px solid var(--border);padding:10px 12px}
.page-count,.zoom-group{display:inline-flex;align-items:center;justify-content:center;gap:12px;background:#fff;border:1px solid var(--border);border-radius:12px;box-shadow:0 4px 12px rgba(15,23,42,.05);font-weight:800;height:48px}.page-count{min-width:116px}.zoom-group{min-width:202px}.zoom-btn{width:52px;height:46px;border:0;background:#fff;color:#667085;font-size:1.35rem;font-weight:900;cursor:pointer}.zoom-label{min-width:64px;text-align:center}.zoom-btn + .zoom-label,.zoom-label + .zoom-btn{border-left:1px solid #e6edf5}.fit-btn{height:48px;border:1px solid var(--border);border-radius:12px;background:#fff;color:#374151;padding:0 18px;font-weight:800;cursor:pointer}
.sidebar{min-width:0;min-height:0;background:#fff;border-left:1px solid var(--border);display:flex;flex-direction:column;padding:24px 18px 18px;gap:14px}
.sidebar-head{flex:0 0 auto}.sidebar h2{font-size:1rem;margin:0 0 8px}.sidebar p{margin:0;color:var(--muted);line-height:1.65;font-size:.88rem}.thumb-scroll-wrap{min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 20px;gap:8px;flex:1}.thumb-list{min-height:0;overflow:auto;padding:2px 6px 18px 0;scroll-behavior:smooth}.thumb-list::-webkit-scrollbar{width:0;height:0}.thumb-item{display:grid;grid-template-columns:72px 42px minmax(0,1fr);align-items:center;gap:12px;border:2px solid transparent;border-radius:12px;background:#fff;padding:10px;margin:0 0 10px;cursor:grab;box-shadow:0 4px 14px rgba(15,23,42,.06)}.thumb-item.active{border-color:#2f80ed;background:#f0f7ff;box-shadow:0 8px 18px rgba(47,128,237,.18)}.thumb-item.preview-active{border-color:#7c3aed;background:#f5f3ff}.thumb-item.pending:not(.active){border-color:#d9e8ff}.thumb-item.dragging{opacity:.58}.thumb-item.drop-before{border-top:5px solid var(--primary)}.thumb-item.drop-after{border-bottom:5px solid var(--primary)}.thumb-canvas{width:58px;height:76px;object-fit:contain;background:#fff;border:1px solid #e5edf6;border-radius:4px}.thumb-no{font-weight:900;font-size:1.2rem;color:#111827;text-align:center}.thumb-title{font-weight:800;font-size:.9rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.thumb-original{font-size:.78rem;color:var(--muted);margin-top:4px}.thumb-scroll{writing-mode:vertical-rl;direction:rtl;width:16px;height:100%;accent-color:var(--primary)}
.bottom-actions{flex:0 0 var(--actions-h);height:var(--actions-h);display:grid;grid-template-columns:auto minmax(0,1fr) auto auto auto;align-items:center;gap:12px;background:rgba(255,255,255,.96);border-top:1px solid var(--border);padding:10px 14px}.action-status{min-width:0;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.primary-btn,.secondary-btn,.save-btn,.preview-btn{height:50px;border-radius:12px;border:1px solid var(--border);padding:0 18px;font-weight:850;cursor:pointer;white-space:nowrap}.primary-btn{background:var(--primary);border-color:var(--primary);color:#fff}.primary-btn:hover:not(:disabled){background:var(--primary-dark)}.secondary-btn,.save-btn,.preview-btn{background:#fff;color:#374151}.preview-btn.active{border-color:#7c3aed;color:#6d28d9;background:#f5f3ff}.save-btn{min-width:178px}.primary-btn{min-width:156px}.footer{flex:0 0 var(--footer-h);height:var(--footer-h);display:flex;align-items:center;justify-content:center;background:#f8fbff;border-top:1px solid #dde8f3;color:#1565c0;font-size:.82rem}.footer a{color:#1565c0;text-decoration:none;font-weight:800}.footer a:hover{color:#0d47a1}.modal{border:0;border-radius:18px;padding:0;box-shadow:0 22px 60px rgba(0,0,0,.24)}.modal::backdrop{background:rgba(15,23,42,.34)}.modal-box{width:min(560px,calc(100vw - 36px));padding:26px}.modal-close{float:right;border:0;background:#eef2f7;border-radius:10px;padding:7px 12px;cursor:pointer}.modal ol{line-height:1.9}.modal p{color:var(--muted)}
/* ▼ 広告枠：アプリ本体を押し潰さず，広告内をスクロールできる独立領域 */
.ad-panel{
  flex:0 0 auto;
  height:auto;
  min-height:0;
  max-height:none;
  margin:0;
  padding:0;
  border-top:1px solid #d7e6f8;
  border-bottom:1px solid #d7e6f8;
  background:#fff;
  overflow:visible;
  position:relative;
}
.ad-panel[hidden]{
  display:none!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  height:0!important;
  max-height:0!important;
  flex-basis:0!important;
  overflow:hidden!important;
}
.ad-panel-head{
  height:30px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:5px 8px;
  background:#f4f8ff;
  border-bottom:1px solid #d7e6f8;
}
.ad-label{font-size:.72rem;color:#4f6f91;line-height:1}
.ad-wait{font-size:.72rem;color:#667085;margin-left:auto}
.ad-close-btn{
  margin:0!important;
  padding:3px 8px!important;
  min-height:0;
  height:auto;
  line-height:1.2;
  border:0;
  border-radius:999px;
  background:#1565c0;
  color:#fff;
  font-size:.72rem!important;
  font-weight:700;
  cursor:pointer;
  appearance:none;
  -webkit-appearance:none;
  display:none;
  position:relative;
  z-index:3;
}
.ad-close-btn:hover{background:#0d47a1}
.ad-body{
  padding:8px;
  background:#fff;
  overflow:visible;
}
.ad-body iframe{
  max-width:100%!important;
}

@media (max-height:760px){
  .ad-panel{height:auto;min-height:0;max-height:none;flex-basis:auto}
}

@media (max-width:760px){.ad-panel{flex-basis:79px;height:79px;max-height:79px}.ad-body{height:50px;max-height:50px}.ad-body iframe{max-height:50px!important}}
@media (max-width:980px){:root{--sidebar-w:300px;--rail-w:56px}.brand{min-width:auto}.nav-btn{width:46px;height:46px}.bottom-actions{grid-template-columns:auto minmax(0,1fr) auto;grid-auto-flow:row}.save-btn,.preview-btn,.primary-btn{min-width:0}.action-status{grid-column:2/3}.viewer-controls{gap:8px}.fit-btn{padding:0 12px}.sidebar{padding:18px 12px}.thumb-item{grid-template-columns:58px 34px minmax(0,1fr);gap:8px}.thumb-canvas{width:50px;height:66px}}

@media (max-height:760px){
  .ad-panel{
    flex-basis:220px;
    height:220px;
    min-height:220px;
    max-height:220px;
  }
}

@media (max-width:760px){body{overflow:auto}.app-shell{min-height:100dvh;height:auto}.workarea{grid-template-columns:1fr}.viewer{height:calc(100dvh - var(--topbar-h) - var(--actions-h) - var(--footer-h));min-height:520px}.sidebar{height:320px;border-left:0;border-top:1px solid var(--border)}.topbar{gap:8px;padding:8px}.file-name{max-width:120px}.bottom-actions{height:auto;min-height:var(--actions-h);grid-template-columns:1fr 1fr;align-items:stretch}.action-status{grid-column:1/-1;order:-1}.primary-btn,.save-btn,.preview-btn,.secondary-btn{height:44px}.empty-state{padding:24px}.empty-state h1{font-size:1.35rem}.viewer-controls{flex-wrap:wrap;height:auto;min-height:var(--controls-h)}}


@media (max-height:760px){
  .ad-panel{
    flex-basis:220px;
    height:220px;
    min-height:220px;
    max-height:220px;
  }
}

@media (max-width:760px){
  .ad-panel{flex-basis:140px;height:140px;max-height:140px}
  .ad-body{height:110px;overflow:auto}
}
