/* THREE.D MAGAZINE MAKE — iOS tokens + layout */
:root{
  --system-bg:#fff;
  --system-grouped:#f2f2f7;
  --secondary-bg:#f2f2f7;
  --system-fill:#d1d1d6;
  --label:#000;
  --secondary-label:#8e8e93;
  --separator:rgba(198,198,200,.30);
  --tint:#007aff;
  --destructive:#ff3b30;
  --sheet:#fcfcf9;
  --radius-sm:4px;--radius-md:8px;--radius-lg:10px;--radius-xl:12px;--radius-sheet:20px;
  --bar-height:44px;
}
.dark{
  --system-bg:#000;
  --system-grouped:#1c1c1e;
  --secondary-bg:#1c1c1e;
  --system-fill:#555558;
  --label:#fff;
  --secondary-label:#ebebf5cc;
  --separator:rgba(58,58,60,.50);
  --tint:#0a84ff;
  --destructive:#ff453a;
  --sheet:#0b0b0c;
}
*{box-sizing:border-box}
html{font-size:16px}
body{
  margin:0;padding:0;
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text",system-ui,sans-serif;
  background:var(--system-grouped);
  color:var(--label);
  padding-top:env(safe-area-inset-top);
  padding-bottom:env(safe-area-inset-bottom);
  overflow:hidden;
  height:100vh;
  display:flex;
  flex-direction:column;
}
.nav{
  height:var(--bar-height);
  padding:0 env(safe-area-inset-left);
  padding-right:env(safe-area-inset-right);
  background:rgba(255,255,255,.08);
  backdrop-filter:blur(20px);
  border-bottom:1px solid var(--separator);
  display:flex;
  align-items:center;
  gap:8px;
  position:relative;
  z-index:10;
  overflow:hidden;
}
.dark .nav{background:rgba(0,0,0,.10)}
.nav h1{
  font:600 20pt/1 "SF Pro Display",-apple-system,sans-serif;
  margin:0;
  flex:1;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.nav-right{
  display:flex;
  gap:4px;
}
.nav-btn{
  width:44px;height:44px;
  border:0;
  background:transparent;
  color:var(--label);
  font-size:18px;
  cursor:pointer;
  border-radius:var(--radius-md);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.nav-btn.tint{color:var(--tint)}
.nav-btn[aria-pressed="true"]{color:var(--tint)}
.nav-btn:active{background:rgba(0,0,0,.06)}
.sf{
  font-family:"SF Symbols";
  font-size:18px;
  line-height:1;
  overflow:hidden;
}
.stage{
  flex:1;
  position:relative;
  background:var(--system-grouped);
  overflow:hidden;
}
.view{
  position:absolute;
  inset:0;
  display:none;
}
.view.view-active{
  display:flex;
  flex-direction:column;
}
#view-book iframe{
  width:100%;
  height:100%;
  border:0;
}
.bottom-bar{
  height:var(--bar-height);
  padding:0 env(safe-area-inset-left);
  padding-right:env(safe-area-inset-right);
  padding-left:12px;
  background:rgba(255,255,255,.08);
  backdrop-filter:blur(20px);
  border-top:1px solid var(--separator);
  display:flex;
  align-items:center;
  justify-content:space-between;
  overflow:hidden;
}
.dark .bottom-bar{background:rgba(0,0,0,.10)}
.badge{
  font:500 15pt/1 "SF Pro Text",-apple-system,sans-serif;
  color:var(--secondary-label);
  padding:0 12px;
}
.pager{
  display:flex;
  gap:2px;
}
/* reader */
.reader-container{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:auto;
  padding:16px;
}
.reader-single,.reader-spread{
  max-width:100%;
  max-height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}
.reader-spread{
  gap:16px;
}
.reader-page{
  max-width:100%;
  max-height:100%;
  background:var(--sheet);
  border-radius:var(--radius-lg);
  box-shadow:0 4px 24px rgba(0,0,0,.15);
  position:relative;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.reader-page-wrapper{
  max-width:100%;
  max-height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  transform-origin:center center;
}
.reader-page-wrapper img{
  max-width:100%;
  max-height:100%;
  width:auto;
  height:auto;
  object-fit:contain;
  display:block;
}
.reader-page img{
  max-width:100%;
  max-height:100%;
  width:auto;
  height:auto;
  object-fit:contain;
  display:block;
}
.spread-spine{
  width:2px;
  background:var(--separator);
  margin:0 8px;
}
.page-badge{
  position:absolute;
  bottom:12px;
  left:50%;
  transform:translateX(-50%);
  font:500 15pt/1 "SF Pro Text",sans-serif;
  color:var(--secondary-label);
  background:rgba(0,0,0,.3);
  padding:4px 12px;
  border-radius:var(--radius-sm);
}
.reader-placeholder{
  color:var(--secondary-label);
  font-size:14px;
  padding:40px;
  text-align:center;
}
/* grid canvas */
.grid-scroll{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:12px;
  padding:16px;
  overflow-y:auto;
  flex:1;
}
.grid-empty{
  padding:40px;
  text-align:center;
  color:var(--secondary-label);
  font-size:14px;
}
@media(max-width:700px){
  .grid-scroll{grid-template-columns:repeat(2,1fr)}
}
.grid-tile{
  background:var(--system-bg);
  border-radius:var(--radius-md);
  box-shadow:0 2px 8px rgba(0,0,0,.08);
  position:relative;
  cursor:pointer;
  border:2px solid transparent;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  transition:border-color .15s;
}
.grid-tile:active{
  border-color:var(--tint);
}
.grid-tile.dragging{
  transform:scale(1.04);
  box-shadow:0 8px 24px rgba(0,0,0,.3);
}
.grid-tile img{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
  display:block;
}
.tile-num{
  position:absolute;
  bottom:6px;
  right:6px;
  font:500 13pt/1 "SF Pro Text",sans-serif;
  color:var(--label);
  background:rgba(0,0,0,.3);
  padding:2px 8px;
  border-radius:var(--radius-sm);
}
.insertion-line{
  position:absolute;
  left:0;
  right:0;
  height:2px;
  background:var(--tint);
  opacity:.6;
  pointer-events:none;
  z-index:5;
}
/* side panel */
.side-panel{
  position:fixed;
  top:env(safe-area-inset-top);
  bottom:env(safe-area-inset-bottom);
  right:0;
  width:280px;
  max-width:90vw;
  background:rgba(242,242,247,.85);
  backdrop-filter:blur(20px);
  display:flex;
  flex-direction:column;
  z-index:20;
  box-shadow:-4px 0 20px rgba(0,0,0,.1);
  border-top-left-radius:var(--radius-xl);
  border-bottom-left-radius:var(--radius-xl);
  border-left:1px solid var(--separator);
  transform:translateX(100%);
  transition:transform .35s cubic-bezier(.25,.46,.25,.99);
}
.dark .side-panel{background:rgba(28,28,30,.90)}
.side-panel.panel-open{
  transform:translateX(0);
}
.panel-handle{
  width:32px;
  height:4px;
  background:var(--system-fill);
  border-radius:2px;
  margin:8px auto;
}
.panel-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:8px 12px;
  border-bottom:1px solid var(--separator);
}
.panel-header .caption{
  font:500 13pt/1 "SF Pro Text",sans-serif;
  color:var(--secondary-label);
}
.panel-list{
  flex:1;
  overflow-y:auto;
  padding:4px 0;
}
.panel-row{
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  border-bottom:1px solid var(--separator);
  height:52px;
}
.panel-row .thumb{
  width:32px;
  height:44px;
  background:var(--sheet);
  border-radius:var(--radius-sm);
  overflow:hidden;
  display:flex;
  align-items:center;
  justify-content:center;
}
.panel-row .thumb img{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
}
.panel-row .label{
  flex:1;
  font:400 15pt/1 "SF Pro Text",sans-serif;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.panel-row .drag-handle{
  cursor:grab;
  padding:4px;
  color:var(--secondary-label);
  min-width:44px;
  min-height:44px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.panel-row .drag-handle:active{cursor:grabbing}
.panel-row .menu-btn{
  cursor:pointer;
  padding:4px;
  color:var(--secondary-label);
  border:0;
  background:transparent;
  font-size:16px;
  min-width:44px;
  min-height:44px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.panel-footer{
  padding:8px;
  border-top:1px solid var(--separator);
  display:flex;
  flex-direction:column;
  gap:6px;
}
.panel-btn{
  height:44px;
  border:0;
  background:transparent;
  border-radius:var(--radius-md);
  font:500 15pt/1 "SF Pro Text",sans-serif;
  color:var(--label);
  cursor:pointer;
  display:flex;
  align-items:center;
  gap:6px;
  justify-content:center;
}
.panel-btn:active{background:rgba(0,0,0,.06)}
/* sheets — iOS modal sheet */
.sheet{
  position:fixed;
  bottom:0;
  left:0;
  right:0;
  background:rgba(242,242,247,.92);
  backdrop-filter:blur(20px);
  border-top-left-radius:var(--radius-sheet);
  border-top-right-radius:var(--radius-sheet);
  padding-bottom:env(safe-area-inset-bottom);
  z-index:30;
  transform:translateY(100%);
  transition:transform .35s cubic-bezier(.25,.46,.25,.99);
}
.dark .sheet{background:rgba(28,28,30,.92)}
.sheet.sheet-open{
  transform:translateY(0);
}
.sheet.sheet-full{
  height:80vh;
}
.sheet-handle{
  width:32px;
  height:4px;
  background:var(--system-fill);
  border-radius:2px;
  margin:8px auto;
}
.sheet-row{
  display:flex;
  align-items:center;
  gap:12px;
  padding:14px 20px;
  font:400 17pt/1 "SF Pro Text",sans-serif;
  cursor:pointer;
  border-bottom:1px solid var(--separator);
}
.sheet-row:active{background:rgba(0,0,0,.04)}
.sheet-row .sf{
  font-size:20px;
  min-width:24px;
  text-align:center;
}
.sheet-row.sheet-destructive{
  color:var(--destructive);
}
.sheet-sep{
  height:8px;
  background:var(--secondary-bg);
  margin:4px 0;
}
/* editor tabs */
.editor-tabs{
  display:flex;
  border-bottom:1px solid var(--separator);
}
.tab-btn{
  flex:1;
  height:44px;
  border:0;
  background:transparent;
  font:500 14pt/1 "SF Pro Text",sans-serif;
  color:var(--secondary-label);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  border-bottom:2px solid transparent;
}
.tab-btn.active,.tab-btn[aria-pressed="true"]{
  color:var(--label);
  border-color:var(--tint);
}
.editor-body{
  flex:1;
  overflow:auto;
}
.editor-footer{
  height:var(--bar-height);
  padding:0 env(safe-area-inset-right);
  border-top:1px solid var(--separator);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding-left:12px;
}
.editor-footer .nav-btn{font-size:17px}
.editor-footer .tint{color:var(--tint);font-weight:600}
/* ctx menu */
.ctx-menu{
  position:fixed;
  background:var(--system-bg);
  border-radius:var(--radius-xl);
  box-shadow:0 8px 32px rgba(0,0,0,.3);
  min-width:180px;
  z-index:40;
  border:1px solid var(--separator);
  overflow:hidden;
}
.ctx-item{
  padding:12px 16px;
  font:400 16pt/1 "SF Pro Text",sans-serif;
  cursor:pointer;
  display:flex;
  align-items:center;
  gap:10px;
}
.ctx-item:active{background:rgba(0,0,0,.06)}
.ctx-item.ctx-destructive{color:var(--destructive)}
.ctx-separator{
  height:1px;
  background:var(--separator);
  margin:4px 0;
}
/* assemble animation */
.assemble-overlay{
  position:fixed;
  inset:0;
  background:var(--system-bg);
  z-index:50;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.assemble-card{
  position:absolute;
  width:160px;
  height:220px;
  background:var(--sheet);
  border-radius:var(--radius-lg);
  box-shadow:0 8px 32px rgba(0,0,0,.3);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  opacity:0;
  transform:scale(.7);
}
.assemble-card img{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
}
.spine-glow{
  position:fixed;
  top:0;
  bottom:0;
  left:50%;
  width:2px;
  background:var(--tint);
  opacity:0;
  transform:translateX(-50%);
  z-index:49;
}
.ultra-thin{
  background:rgba(255,255,255,.08);
  backdrop-filter:blur(20px);
}
.dark .ultra-thin{background:rgba(0,0,0,.10)}
.tint{color:var(--tint)}
/* mobile bottom sheet */
@media(max-width:700px){
  .side-panel{
    position:fixed;
    top:50%;
    left:0;
    right:0;
    width:100%;
    max-width:100vw;
    height:70vh;
    bottom:auto;
    border-left:0;
    border-top-left-radius:var(--radius-sheet);
    border-top-right-radius:var(--radius-sheet);
    border-bottom:1px solid var(--separator);
    transform:translateY(100%);
  }
  .side-panel.panel-open{
    transform:translateY(0);
  }
  .sheet{height:auto;max-height:80vh}
}
::-webkit-scrollbar{
  width:8px
}
::-webkit-scrollbar-track{
  background:transparent
}
::-webkit-scrollbar-thumb{
  background:var(--system-fill);
  border-radius:var(--radius-sm)
}
::-webkit-scrollbar-thumb:hover{
  background:var(--secondary-label)
}
/* Tap-target safety (≥44px) for editor controls rendered inside
   #editor-body. These selectors carry an ID ancestor so their
   specificity (0,1,1,1) beats the matching rules in editor.css (0,0,1,0)
   even though app.css loads first — keeping the edit confined here. */
#editor-body .color-swatch{
  min-width:44px;
  min-height:44px;
  width:44px;
  height:44px;
}
#editor-body .aspect-btn{
  min-height:44px;
}
#editor-body .filter-chip{
  min-height:44px;
}
