*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, a, select, input { touch-action: manipulation; }
:root {
  --page: #F5F5F7;
  --white: #FFFFFF;
  --ink: #1D1D1F;
  --ink2: #6E6E73;
  --ink3: #AEAEB2;
  --accent: #0071E3;
  --sep: rgba(0,0,0,0.08);
  --card-shadow: 0 2px 12px rgba(0,0,0,0.06), 0 0 0 0.5px rgba(0,0,0,0.04);
  --card-shadow-hover: 0 14px 44px rgba(0,0,0,0.13), 0 0 0 0.5px rgba(0,0,0,0.06);
  --r: 18px;
  --pill: 980px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
}
html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--page); color: var(--ink); min-height: 100vh; -webkit-font-smoothing: antialiased; }

/* NAV */
nav {
  position: sticky; top: 0; z-index: 200; height: 52px;
  background: rgba(245,245,247,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid rgba(0,0,0,0.1);
  display: flex; align-items: center; justify-content: center; padding: 0 22px;
}
.nav-inner { width: 100%; max-width: 1100px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.nav-brand { font-size: 17px; font-weight: 600; letter-spacing: -0.022em; white-space: nowrap; }
.search-wrap {
  flex: 1; max-width: 300px; position: relative;
  opacity: 0; transform: translateY(-4px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.search-wrap.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; stroke: var(--ink3); fill: none; pointer-events: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#search { width: 100%; height: 30px; padding: 0 12px 0 30px; border: none; border-radius: var(--pill); background: rgba(0,0,0,0.06); font-family: var(--font); font-size: 14px; color: var(--ink); outline: none; transition: background .2s, box-shadow .2s; }
#search:focus { background: rgba(0,0,0,0.09); box-shadow: 0 0 0 3px rgba(0,113,227,0.3); }
#search::placeholder { color: var(--ink3); }
.nav-actions { display: flex; align-items: center; gap: 10px; }
.btn-nav { height: 30px; padding: 0 14px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.14); background: var(--white); font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; transition: background .15s; white-space: nowrap; }
.btn-nav:hover { background: var(--page); }
.btn-nav.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-nav.primary:hover { opacity: .88; }

/* ── HAMBURGER BUTTON ────────────────────────────────────────────────────── */
.btn-hamburger {
  display: none;
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: transparent; color: var(--ink); cursor: pointer;
  align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s;
}
.btn-hamburger:hover { background: rgba(0,0,0,0.06); }
.btn-hamburger svg { width: 20px; height: 20px; stroke: var(--ink); fill: none; stroke-width: 2; stroke-linecap: round; }

/* ── MOBILE DROPDOWN MENU ────────────────────────────────────────────────── */
.mobile-menu {
  display: none;
  position: fixed; top: 52px; left: 0; right: 0; z-index: 190;
  background: rgba(245,245,247,0.97);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid rgba(0,0,0,0.1);
  padding: 14px 18px 18px;
  flex-direction: column; gap: 12px;
}
.mobile-menu.open { display: flex; animation: menuSlide .2s ease; }
@keyframes menuSlide { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }
.mobile-menu-btns { display: flex; gap: 10px; }
.mobile-menu-btns .btn-nav { flex: 1; height: 44px; justify-content: center; font-size: 15px; border-radius: var(--pill); }

/* ── MOBILE STICKY SEARCH BAR ────────────────────────────────────────────── */
.mobile-search-bar {
  display: none;
  position: sticky; top: 52px; z-index: 180;
  background: rgba(245,245,247,0.95);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  padding: 9px 16px 10px;
  border-bottom: 0.5px solid rgba(0,0,0,0.08);
}
.mobile-search-inner { position: relative; }
.mobile-search-inner svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--ink3); fill: none; pointer-events: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#mobileSearch { width: 100%; height: 36px; padding: 0 14px 0 34px; border: none; border-radius: var(--pill); background: rgba(0,0,0,0.07); font-family: var(--font); font-size: 15px; color: var(--ink); outline: none; transition: background .2s, box-shadow .2s; }
#mobileSearch:focus { background: rgba(0,0,0,0.1); box-shadow: 0 0 0 3px rgba(0,113,227,0.3); }
#mobileSearch::placeholder { color: var(--ink3); }

/* ── MOBILE BREAKPOINT ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .search-wrap  { display: none !important; }
  .nav-actions  { display: none !important; }
  .btn-hamburger { display: flex; }
  .mobile-search-bar { display: block; }
  .hero { padding: 36px 18px 20px; }
  .hero h1 { font-size: clamp(32px, 9vw, 48px); margin-bottom: 10px; }
  .hero-sub { font-size: 15px; }
  .hero-search-wrap { display: none; }
  .filter-bar { padding: 0 14px 22px; gap: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .recent-strip { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .main { padding: 0 14px 60px; }
  .m-arrow { display: none !important; }
  #viewerBg { padding: 0; align-items: flex-end; gap: 0; }
  #viewerModal { border-radius: 20px 20px 0 0; max-height: 96vh; }
  .modal-viewer { height: 300px; }
  .paper { height: 272px; width: calc(272px * 8.5 / 11); }
  .paper.landscape { height: calc(260px * 8.5 / 11); width: 260px; }
}

/* HERO */
.hero { max-width: 1100px; margin: 0 auto; padding: 72px 22px 52px; text-align: center; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; opacity: 0; animation: fadeUp .55s .05s ease forwards; }
.hero h1 {
  font-size: clamp(42px,6vw,68px);
  font-weight: 700;
  letter-spacing: -0.042em;
  line-height: 1.04;
  margin-bottom: 14px;
  opacity: 0;
  animation: fadeUp .55s .13s ease forwards;
}
.hero h1 .gradient-text {
  display: inline-block;
  padding-bottom: 6px;
  background: linear-gradient(90deg, #3B82F6, #8B5CF6, #EC4899, #EF4444, #F97316, #8B5CF6, #3B82F6);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 8s linear infinite;
}
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
.hero-sub { font-size: 19px; font-weight: 300; color: var(--ink2); letter-spacing: -0.014em; opacity: 0; animation: fadeUp .55s .22s ease forwards; }
.hero-search-wrap { position: relative; max-width: 520px; margin: 28px auto 0; opacity: 0; animation: fadeUp .55s .32s ease forwards; }
.hero-search-wrap svg { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--ink3); fill: none; pointer-events: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#heroSearch { width: 100%; height: 54px; padding: 0 22px 0 50px; border: none; border-radius: var(--pill); background: var(--white); font-family: var(--font); font-size: 16px; color: var(--ink); outline: none; box-shadow: 0 2px 16px rgba(0,0,0,0.09), 0 0 0 0.5px rgba(0,0,0,0.06); transition: box-shadow .2s; }
#heroSearch:focus { box-shadow: 0 2px 24px rgba(0,0,0,0.13), 0 0 0 3px rgba(0,113,227,0.3); }
#heroSearch::placeholder { color: var(--ink3); }
@keyframes fadeUp { from { opacity:0; transform:translateY(18px); } to { opacity:1; transform:translateY(0); } }

/* FILTER ROW */
.filter-bar { max-width: 1100px; margin: 0 auto; padding: 0 22px 30px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 15px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.14); background: var(--white); font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; transition: all .18s cubic-bezier(.25,.46,.45,.94); user-select: none; }
.chip:hover { border-color: rgba(0,0,0,0.26); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #F5F5F7; }

/* SUB-FILTER ROW */
.sub-filter-bar {
  max-width: 1100px; margin: -18px auto 0; padding: 0 22px 22px;
  display: none; gap: 6px; flex-wrap: wrap; align-items: center;
}
.sub-filter-bar.visible { display: flex; }
.sub-chip {
  height: 26px; padding: 0 11px; border-radius: var(--pill);
  border: 0.5px solid rgba(0,0,0,0.12); background: var(--page);
  font-family: var(--font); font-size: 12px; font-weight: 500; color: var(--ink2);
  cursor: pointer; display: inline-flex; align-items: center;
  transition: all .15s; user-select: none;
}
.sub-chip:hover { border-color: rgba(0,0,0,0.24); color: var(--ink); }
.sub-chip.active { background: var(--accent); border-color: var(--accent); color: white; }

/* MAIN */
.main { max-width: 1100px; margin: 0 auto; padding: 0 22px 80px; }
.sec-hd { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.sec-title { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.sec-count { font-size: 13px; color: var(--ink2); }

/* SKELETON */
.skeleton {
  background: linear-gradient(90deg, #e8e8ed 25%, #f2f2f5 50%, #e8e8ed 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r);
}
/* Skeleton cards mirror real card structure — no layout jump */
.skel { opacity: 1 !important; animation: none !important; pointer-events: none; }
.skel .rc-thumb,
.skel .card-thumb { background: none; padding: 0; }
.skel-line { height: 12px; border-radius: 6px; display: block; }

/* Smooth fade-in when real content replaces skeletons */
#grid, #recentStrip { animation: none; }
.grid { animation: gridFadeIn .35s ease both; }
@keyframes gridFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { to { background-position: -200% 0; } }
/* ── Skeleton chips in filter bar ─────────────────────────────────────── */
.skel-chip {
  height: 32px;
  border-radius: var(--pill);
  pointer-events: none;
  border: none;
}

/* Prevent filter bar from collapsing before chips arrive */
.filter-bar { min-height: 66px; align-items: flex-start; }

/* Chips fade + rise in, skeleton chips stay in shimmer loop */
.chip:not(.skeleton) {
  animation: chipIn .22s ease both;
}
.chip:not(.skeleton):nth-child(2)  { animation-delay: .04s; }
.chip:not(.skeleton):nth-child(3)  { animation-delay: .08s; }
.chip:not(.skeleton):nth-child(4)  { animation-delay: .12s; }
.chip:not(.skeleton):nth-child(5)  { animation-delay: .16s; }
.chip:not(.skeleton):nth-child(6)  { animation-delay: .20s; }
.chip:not(.skeleton):nth-child(7)  { animation-delay: .24s; }
.chip:not(.skeleton):nth-child(8)  { animation-delay: .28s; }
@keyframes chipIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Category section headers fade up instead of snapping in */
.cat-section {
  animation: fadeUp .3s ease both;
}
.cat-section:nth-child(2) { animation-delay: .05s; }
.cat-section:nth-child(3) { animation-delay: .10s; }
.cat-section:nth-child(4) { animation-delay: .15s; }

/* Sub-filter bar slides in smoothly instead of jumping */
.sub-filter-bar {
  display: flex !important;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-bottom: 0;
  pointer-events: none;
  transition: max-height .28s ease, opacity .22s ease, padding-bottom .28s ease;
}
.sub-filter-bar.visible {
  max-height: 80px;
  opacity: 1;
  padding-bottom: 22px;
  pointer-events: auto;
}
/* RECENT */
.recent-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-bottom: 48px; }
.rc { background: var(--white); border-radius: var(--r); box-shadow: var(--card-shadow); overflow: hidden; cursor: pointer; transition: box-shadow .28s cubic-bezier(.25,.46,.45,.94), transform .28s cubic-bezier(.25,.46,.45,.94); }
.rc:hover { box-shadow: var(--card-shadow-hover); transform: scale(1.03) translateY(-2px); }
.rc-thumb { width: 100%; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #FFFFFF; }
.rc-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 14px; transition: transform .3s ease; }
.rc:hover .rc-thumb img { transform: scale(1.05); }
.rc-body { padding: 10px 12px 12px; border-top: 0.5px solid var(--sep); }
.rc-name { font-size: 12px; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-cat { font-size: 11px; color: var(--ink3); }

/* GRID */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { background: var(--white); border-radius: var(--r); box-shadow: var(--card-shadow); overflow: hidden; cursor: pointer; transition: box-shadow .28s cubic-bezier(.25,.46,.45,.94), transform .28s cubic-bezier(.25,.46,.45,.94); opacity: 0; animation: cardIn .38s ease forwards; }
.card:hover { box-shadow: var(--card-shadow-hover); transform: scale(1.022) translateY(-2px); }
@keyframes cardIn { from { opacity:0; transform:scale(0.95); } to { opacity:1; transform:scale(1); } }
.card-thumb { width: 100%; aspect-ratio: 4/3; background: #FFFFFF; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.card-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 16px; transition: transform .3s ease; }
.card:hover .card-thumb img { transform: scale(1.04); }
.card-body { padding: 12px 14px 14px; border-top: 0.5px solid var(--sep); }
.card-name { font-size: 14px; font-weight: 600; letter-spacing: -0.014em; margin-bottom: 4px; line-height: 1.3; }
.card-orig-label { display: inline-block; font-size: 11px; font-weight: 500; color: var(--ink2); background: var(--page); border: 0.5px solid rgba(0,0,0,0.12); border-radius: var(--pill); padding: 2px 8px; margin-top: 3px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 10px; font-weight: 500; padding: 2px 7px; border-radius: var(--pill); background: var(--page); color: var(--ink2); border: 0.5px solid rgba(0,0,0,0.08); }
.empty { text-align: center; padding: 80px 20px; color: var(--ink2); }
.empty p:first-child { font-size: 44px; margin-bottom: 12px; }
.empty p:last-child { font-size: 15px; }
.cat-section { margin-bottom: 44px; }
.cat-section-hd { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 0.5px solid var(--sep); }
.cat-section-title {
  font-size: 42px; font-weight: 700; letter-spacing: -0.026em;
  display: inline-block;
  background: linear-gradient(90deg, #3B82F6, #8B5CF6, #EC4899, #EF4444, #F97316, #3B82F6);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 6s linear infinite;
}
.cat-section-count { font-size: 13px; color: var(--ink2); margin-left: auto; }

/* ── SHARED MODAL BASE ───────────────────────────────────────────────────── */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.42); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 500; align-items: center; justify-content: center; padding: 20px; gap: 16px; }
.modal-bg.open { display: flex; }
.modal { background: var(--white); border-radius: 24px; width: 100%; overflow: hidden; overflow-y: auto; max-height: calc(100vh - 40px); box-shadow: 0 32px 80px rgba(0,0,0,0.26); position: relative; animation: mpop .3s cubic-bezier(.34,1.56,.64,1) forwards; }
@keyframes mpop { from { opacity:0; transform:translateY(40px); } to { opacity:1; transform:translateY(0); } }
.m-close { position: absolute; top: 13px; right: 13px; width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(0,0,0,0.07); color: var(--ink); font-size: 11px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .15s; z-index: 10; }
.m-close:hover { background: rgba(0,0,0,0.13); }

/* ── SHEET VIEWER MODAL ──────────────────────────────────────────────────── */
#viewerBg .modal { max-width: 720px; }
.m-arrow { flex-shrink: 0; width: 48px; height: 48px; border-radius: 50%; border: none; background: rgba(255,255,255,0.92); color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 12px rgba(0,0,0,0.15); transition: background .15s, transform .15s; user-select: none; }
.m-arrow:hover { background: #fff; transform: scale(1.08); }
.m-arrow:active { transform: scale(0.95); }
.m-arrow:disabled { opacity: 0.25; cursor: default; transform: none; }
.modal-viewer { position: relative; width: 100%; height: 500px; background: #E8E8ED; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.paper { position: relative; height: 460px; width: calc(460px * 8.5 / 11); background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.10); flex-shrink: 0; transition: width .3s ease, height .3s ease; overflow: hidden; }
.paper.landscape { height: calc(440px * 8.5 / 11); width: 440px; }
.orient-toggle { display: flex; gap: 6px; }
.btn-orient { height: 44px; width: 44px; border-radius: 10px; border: 1.5px solid var(--sep); background: var(--white); color: var(--ink2); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .18s; flex-shrink: 0; }
.btn-orient:hover { border-color: rgba(0,0,0,0.26); color: var(--ink); }
.btn-orient.active { background: var(--ink); border-color: var(--ink); color: white; }
.btn-orient svg { flex-shrink: 0; }
#paperFrame { width: 100%; height: 100%; border: none; display: block; }
.retag-overlay { display: none; position: absolute; inset: 0; background: rgba(232,232,237,0.88); align-items: center; justify-content: center; flex-direction: column; gap: 10px; z-index: 10; }
.retag-overlay.visible { display: flex; }
.retag-spinner { width: 32px; height: 32px; border: 3px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.retag-overlay-label { font-size: 13px; font-weight: 600; color: var(--ink2); }
@keyframes spin { to { transform: rotate(360deg); } }
.modal-body { padding: 18px 22px 24px; }
.modal-cat { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; margin-bottom: 5px; color: var(--ink) !important; }
.modal-title { font-size: 24px; font-weight: 700; letter-spacing: -0.028em; color: var(--ink); margin-bottom: 4px; }
.modal-counter { font-size: 12px; color: var(--ink3); margin-bottom: 10px; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; min-height: 22px; }
.modal-tag { font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: var(--pill); background: var(--page); color: var(--ink2); border: 0.5px solid rgba(0,0,0,0.1); cursor: pointer; transition: all .15s; }
.modal-tag:hover { background: #FDECEA; color: #C0291F; border-color: #C0291F; }
.modal-tag:hover::after { content: ' ✕'; }
.tag-editor { margin-bottom: 0px; }
.tag-input-row { display: flex; gap: 8px; margin-bottom: 6px; }
#tagInput { flex: 1; height: 34px; padding: 0 12px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.18); font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; background: var(--white); transition: border-color .15s, box-shadow .15s; }
#tagInput:focus { box-shadow: 0 0 0 3px rgba(0,113,227,0.25); border-color: var(--accent); }
#tagInput::placeholder { color: var(--ink3); }
#tagAddBtn { height: 34px; padding: 0 16px; border-radius: var(--pill); border: none; background: var(--accent); color: white; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .15s; white-space: nowrap; }
#tagAddBtn:hover { opacity: .88; }
#tagSaveStatus { font-size: 12px; font-weight: 500; min-height: 18px; display: block; }
.ref-row { display: none; align-items: center; gap: 6px; margin-bottom: 14px; flex-wrap: nowrap; }
.ref-row.visible { display: flex; }
.btn-ref { height: 44px; padding: 0 20px; border-radius: var(--pill); border: 1.5px solid var(--sep); background: var(--page); color: var(--ink); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: all .18s; flex-shrink: 0; }
.btn-ref.on { background: #34C759; color: #fff; border-color: #34C759; }
.btn-ref:hover { border-color: rgba(0,0,0,0.22); }
.corner-btns { display: flex; gap: 6px; flex: 1; }
.corner-btn { flex: 1; height: 44px; border-radius: 10px; border: 1.5px solid var(--sep); background: var(--white); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .18s; color: var(--ink); }
.corner-btn:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.corner-btn.selected { border-color: var(--accent); background: var(--accent); color: white; }
.corner-btn:disabled { opacity: 0.28; cursor: default; color: var(--ink3); border-color: var(--sep); background: var(--white); }
.corner-btn.selected:disabled { background: var(--page); border-color: var(--sep); color: var(--ink3); }
.ref-scale-row { display: none; align-items: center; gap: 6px; flex: 1; }
.ref-scale-row.visible { display: flex; }
.ref-scale-val { font-size: 12px; font-weight: 600; color: var(--ink2); min-width: 32px; text-align: center; }
.btn-scale { width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid var(--sep); background: var(--white); font-size: 20px; font-weight: 400; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink); transition: all .18s; flex-shrink: 0; line-height: 1; }
.btn-scale:hover { border-color: var(--accent); color: var(--accent); }
.btn-scale:active { background: var(--page); }
.action-row { display: flex; gap: 10px; }
.btn-print { flex: 1; height: 52px; background: var(--accent); color: #fff; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 17px; font-weight: 600; cursor: pointer; letter-spacing: -0.01em; transition: opacity .18s, transform .15s; display: flex; align-items: center; justify-content: center; }
.btn-print:hover { opacity: .88; }
.btn-print:active { transform: scale(0.98); }
.btn-retag { flex: 1; height: 52px; background: var(--page); color: var(--ink); border: 0.5px solid rgba(0,0,0,0.14); border-radius: var(--pill); font-family: var(--font); font-size: 17px; font-weight: 600; cursor: pointer; letter-spacing: -0.01em; transition: all .18s; display: flex; align-items: center; justify-content: center; }
.btn-retag:hover:not(:disabled) { border-color: rgba(0,0,0,0.3); background: #EBEBED; }
.btn-retag:active:not(:disabled) { transform: scale(0.98); }
.btn-retag:disabled { opacity: 0.45; cursor: default; }
.btn-delete { width: 100%; height: 44px; background: transparent; color: #C0291F; border: 0.5px solid rgba(192,41,31,0.3); border-radius: var(--pill); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; letter-spacing: -0.01em; transition: all .18s; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 4px;margin-bottom: 14px; }
.btn-delete:hover:not(:disabled) { background: #FFF0EE; border-color: #C0291F; }
.btn-delete:active:not(:disabled) { transform: scale(0.98); }
.btn-delete:disabled { opacity: 0.4; cursor: default; }

/* ── INFO / EDIT TOGGLE ──────────────────────────────────────────────────── */
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
.modal-header-text { flex: 1; min-width: 0; }
.btn-info { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,0.13); background: var(--page); color: var(--ink2); font-size: 13px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .18s; margin-top: 2px; font-family: var(--font); }
.btn-info:hover { border-color: var(--accent); color: var(--accent); background: rgba(0,113,227,0.06); }
.btn-info.active { background: var(--accent); border-color: var(--accent); color: white; }
.edit-panel { overflow: hidden; max-height: 0; opacity: 0; transition: max-height .32s cubic-bezier(.4,0,.2,1), opacity .22s ease; }
.edit-panel.open { max-height: 400px; opacity: 1; }

/* ── CATEGORY EDITOR ─────────────────────────────────────────────────────── */
.cat-editor { margin-bottom: 14px; }
.cat-editor-row { display: flex; gap: 8px; align-items: center; }
#catSelect { flex: 1; height: 34px; padding: 0 28px 0 12px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.18); font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; background: var(--white); appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236E6E73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
#catSelect:focus { box-shadow: 0 0 0 3px rgba(0,113,227,0.25); border-color: var(--accent); }
.cat-new-row { display: none; gap: 8px; margin-top: 8px; }
.cat-new-row.visible { display: flex; }
#catNewInput { flex: 1; height: 34px; padding: 0 12px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.18); font-family: var(--font); font-size: 13px; color: var(--ink); outline: none; background: var(--white); transition: border-color .15s, box-shadow .15s; }
#catNewInput:focus { box-shadow: 0 0 0 3px rgba(0,113,227,0.25); border-color: var(--accent); }
#catNewInput::placeholder { color: var(--ink3); }
#catSaveBtn { height: 34px; padding: 0 16px; border-radius: var(--pill); border: none; background: var(--accent); color: white; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .15s; white-space: nowrap; }
#catSaveBtn:hover { opacity: .88; }
#catSaveStatus { font-size: 12px; font-weight: 500; min-height: 18px; display: block; margin-top: 4px; }

/* ── UPLOAD MODAL ────────────────────────────────────────────────────────── */
#uploadBg .modal { max-width: 520px; }
.upload-inner { padding: 32px 28px 28px; }
.upload-inner h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.028em; margin-bottom: 4px; }
.upload-inner .upload-sub { font-size: 14px; color: var(--ink2); margin-bottom: 24px; }
.drop-zone { border: 2px dashed #D1D1D6; border-radius: 14px; padding: 40px 20px; text-align: center; cursor: pointer; transition: border-color .2s, background .2s; }
.drop-zone.over { border-color: var(--accent); background: #F0F6FF; }
.drop-icon { font-size: 36px; margin-bottom: 10px; }
.drop-zone h3 { font-size: 15px; font-weight: 600; margin-bottom: 5px; }
.drop-zone p  { font-size: 13px; color: var(--ink2); }
.btn-browse { display: inline-block; margin-top: 14px; padding: 7px 18px; background: var(--accent); color: white; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity .18s; }
.btn-browse:hover { opacity: .85; }
.upload-file-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.upload-file-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--page); border-radius: 10px; font-size: 13px; }
.upload-file-thumb { width: 36px; height: 36px; object-fit: contain; border-radius: 6px; background: #E5E5EA; }
.upload-file-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-remove { background: none; border: none; color: var(--ink3); font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1; }
.upload-file-remove:hover { color: #FF3B30; }
.btn-upload { width: 100%; margin-top: 16px; height: 48px; background: var(--ink); color: white; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity .18s; display: none; }
.btn-upload:hover { opacity: .85; }
.btn-upload.visible { display: block; }
.btn-upload:disabled { opacity: .5; cursor: default; }
.upload-status { margin-top: 12px; text-align: center; font-size: 14px; font-weight: 500; min-height: 20px; }
.upload-status.success { color: #34C759; }
.upload-status.error   { color: #FF3B30; }
.upload-divider { margin-top: 24px; padding-top: 24px; border-top: 0.5px solid #E5E5EA; }
.upload-divider-label { font-size: 13px; color: var(--ink2); margin-bottom: 10px; }
.btn-tag-all { width: 100%; height: 44px; background: var(--page); color: var(--ink); border: 0.5px solid rgba(0,0,0,0.14); border-radius: var(--pill); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .18s; }
.btn-tag-all:hover { opacity: .75; }
.btn-tag-all:disabled { opacity: .4; cursor: default; }
.tag-all-status { margin-top: 10px; text-align: center; font-size: 13px; font-weight: 500; min-height: 18px; }

/* ── DELETE PIN MODAL ────────────────────────────────────────────────────── */
#deletePinBg .modal { max-width: 360px; }
.pin-inner { padding: 32px 28px 28px; text-align: center; }
.pin-inner h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.024em; margin-bottom: 6px; }
.pin-inner p { font-size: 14px; color: var(--ink2); margin-bottom: 22px; }
#deletePinInput {
  width: 100%; height: 52px; text-align: center; letter-spacing: 0.22em;
  font-size: 22px; font-weight: 700; font-family: var(--font);
  border: 1.5px solid rgba(0,0,0,0.18); border-radius: 14px;
  outline: none; background: var(--page); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  margin-bottom: 10px;
}
#deletePinInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,113,227,0.25); }
#deletePinInput.shake {
  animation: pinShake .35s ease;
  border-color: #C0291F;
  box-shadow: 0 0 0 3px rgba(192,41,31,0.2);
}
@keyframes pinShake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
#deletePinError { font-size: 13px; color: #C0291F; font-weight: 500; min-height: 18px; margin-bottom: 16px; display: block; }
.pin-actions { display: flex; gap: 10px; }
.btn-pin-cancel { flex: 1; height: 44px; background: var(--page); color: var(--ink); border: 0.5px solid rgba(0,0,0,0.14); border-radius: var(--pill); font-family: var(--font); font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity .15s; }
.btn-pin-cancel:hover { opacity: .75; }
.btn-pin-confirm { flex: 1; height: 44px; background: #C0291F; color: white; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity .15s; }
.btn-pin-confirm:hover { opacity: .88; }

@media print {
  body > * { display: none !important; }
  #viewerBg { display: flex !important; position: fixed !important; inset: 0 !important;
    background: white !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    padding: 0 !important; gap: 0 !important; align-items: flex-start !important; justify-content: flex-start !important; z-index: 9999 !important; }
  .m-arrow, .m-close, .modal-body { display: none !important; }
  #viewerModal { border-radius: 0 !important; box-shadow: none !important; max-width: 100vw !important;
    width: 100vw !important; max-height: none !important; overflow: visible !important; animation: none !important; }
  .modal-viewer { width: 100vw !important; height: 100vh !important; background: white !important; }
  .paper { width: 100vw !important; height: 100vh !important; box-shadow: none !important; transition: none !important; overflow: visible !important; }
  #paperFrame { width: 100vw !important; height: 100vh !important; border: none !important; }
  .retag-overlay { display: none !important; }
  .orient-toggle { display: none !important; }
}

/* ── GENERATE MODAL ──────────────────────────────────────────────────────── */
#generateBg .modal { max-width: 560px; }
.gen-inner { padding: 32px 28px 28px; }
.gen-inner h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.028em; margin-bottom: 4px; }
.gen-sub { font-size: 14px; color: var(--ink2); margin-bottom: 24px; }
.gen-drop { border: 2px dashed #D1D1D6; border-radius: 14px; padding: 40px 20px; text-align: center; cursor: pointer; transition: border-color .2s, background .2s; margin-bottom: 20px; }
.gen-drop.over { border-color: var(--accent); background: #F0F6FF; }
.gen-drop.has-image { padding: 0; border-style: solid; border-color: #D1D1D6; overflow: hidden; }
.gen-drop-icon { font-size: 32px; margin-bottom: 8px; }
.gen-drop h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.gen-drop p { font-size: 13px; color: var(--ink2); }
.gen-preview-img { width: 100%; max-height: 280px; object-fit: contain; display: block; padding: 16px; background: #FAFAFA; }
.gen-preview-footer { padding: 10px 14px; border-top: 0.5px solid var(--sep); display: flex; align-items: center; justify-content: space-between; }
.gen-preview-name { font-size: 13px; font-weight: 500; }
.btn-gen-change { font-size: 13px; color: var(--accent); background: none; border: none; cursor: pointer; font-weight: 500; }
.btn-gen-change:hover { text-decoration: underline; }
.gen-error { display: none; background: #FFF2F2; border: 1px solid #FFD0D0; border-radius: 10px; padding: 12px 16px; color: #C0291F; font-size: 14px; margin-bottom: 16px; }
.gen-error.visible { display: block; }
.btn-generate { width: 100%; height: 48px; background: var(--ink); color: white; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 15px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .18s; }
.btn-generate:hover { opacity: .85; }
.btn-generate:disabled { opacity: .4; cursor: default; }
.gen-spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; display: none; }
.btn-generate.loading .gen-spinner { display: block; }
.gen-result { display: none; }
.gen-result.visible { display: block; }
.gen-result-img-wrap { background: #FAFAFA; border-radius: 10px; overflow: hidden; margin-bottom: 16px; display: flex; align-items: center; justify-content: center; min-height: 220px; }
.gen-result-img-wrap img { max-width: 100%; max-height: 320px; object-fit: contain; display: block; padding: 16px; }
.gen-result-meta { margin-bottom: 16px; }
.gen-result-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.gen-result-cat { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); margin-bottom: 8px; }
.gen-result-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.gen-result-tag { font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: var(--pill); background: var(--page); color: var(--ink2); border: 0.5px solid rgba(0,0,0,0.1); }
.gen-result-actions { display: flex; gap: 8px; }
.btn-gen-print { flex: 1; height: 44px; background: var(--accent); color: white; border: none; border-radius: var(--pill); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .18s; }
.btn-gen-print:hover { opacity: .88; }
.btn-gen-another { flex: 1; height: 44px; background: var(--page); color: var(--ink); border: 0.5px solid rgba(0,0,0,0.14); border-radius: var(--pill); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .18s; }
.btn-gen-another:hover { opacity: .75; }
.gen-loading-overlay { display: none; position: absolute; inset: 0; background: rgba(255,255,255,0.88); backdrop-filter: blur(4px); border-radius: 24px; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 5; }
.gen-loading-overlay.visible { display: flex; }
.gen-loading-spinner { width: 28px; height: 28px; border: 3px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.gen-loading-text { font-size: 14px; font-weight: 500; color: var(--ink2); }
.gen-code-wrap { margin-top: 12px; display: none; }
.gen-code-wrap.visible { display: block; }
.gen-code-label { font-size: 13px; color: var(--ink2); margin-bottom: 8px; }
.gen-code-row { display: flex; gap: 8px; }
#genCodeInput { flex: 1; height: 44px; padding: 0 14px; border-radius: var(--pill); border: 0.5px solid rgba(0,0,0,0.18); font-family: var(--font); font-size: 15px; color: var(--ink); outline: none; background: var(--white); letter-spacing: 0.08em; text-transform: uppercase; }
#genCodeInput:focus { box-shadow: 0 0 0 3px rgba(0,113,227,0.25); border-color: var(--accent); }
#genCodeSubmit { height: 44px; padding: 0 20px; border-radius: var(--pill); border: none; background: var(--accent); color: white; font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .18s; white-space: nowrap; }
#genCodeSubmit:hover { opacity: .88; }

/* ── BOOK MODE ───────────────────────────────────────────────────────────── */
.book-select-badge {
  display: none; position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 700;
  align-items: center; justify-content: center;
}
body.book-mode .card { cursor: pointer; }
body.book-mode .card-thumb::after {
  content: ''; position: absolute; inset: 0;
  border: 3px solid transparent;
  border-radius: calc(var(--r) - 2px);
  pointer-events: none; transition: border-color .15s, background .15s;
}
body.book-mode .card.book-sel .card-thumb::after {
  border-color: transparent; background: rgba(0,113,227,0.08);
}
body.book-mode .card.book-sel {
  box-shadow: 0 0 0 3px var(--accent), var(--card-shadow-hover);
  transform: scale(1.022) translateY(-2px);
}
body.book-mode .card.book-sel .book-select-badge { display: flex; }

.book-float-bar {
  display: none; position: fixed; bottom: 24px;
  left: 50%; transform: translateX(-50%); z-index: 300;
  background: var(--ink); color: white; border-radius: var(--pill);
  height: 56px; padding: 0 8px 0 20px;
  align-items: center; gap: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28); white-space: nowrap;
}
.book-float-bar.visible { display: flex; animation: fadeUp .2s ease; }
.book-float-count { font-size: 15px; font-weight: 600; }
.book-float-cancel {
  height: 40px; padding: 0 16px; border-radius: var(--pill);
  border: 1px solid rgba(255,255,255,0.2); background: transparent;
  color: white; font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer;
}
.book-float-done {
  height: 40px; padding: 0 20px; border-radius: var(--pill);
  border: none; background: var(--accent); color: white;
  font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
.book-float-done:disabled { opacity: .4; cursor: default; }

/* ── BOOK BUILDER MODAL ──────────────────────────────────────────────────── */
#bookBuilderBg .modal { max-width: 660px; }
.bk-inner { padding: 20px 22px 26px; }
.bk-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.bk-title { font-size: 20px; font-weight: 700; letter-spacing: -0.024em; }
.bk-counter { display: none; }
.bk-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 14px; scroll-behavior: smooth; }
.bk-strip::-webkit-scrollbar { height: 4px; }
.bk-strip::-webkit-scrollbar-thumb { background: var(--ink3); border-radius: 2px; }
.bk-thumb {
  flex-shrink: 0; width: 52px; cursor: pointer;
  border-radius: 8px; overflow: hidden;
  border: 2.5px solid transparent; transition: border-color .15s; position: relative;
}
.bk-thumb img { width: 100%; aspect-ratio: 8.5/11; object-fit: contain; background: white; display: block; }
.bk-thumb.active { border-color: var(--accent); }
.bk-thumb-x {
  position: absolute; top: 2px; right: 2px; width: 15px; height: 15px;
  background: rgba(0,0,0,0.55); color: white; border-radius: 50%;
  font-size: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.bk-thumb-num {
  position: absolute; bottom: 2px; left: 0; right: 0;
  text-align: center; font-size: 9px; font-weight: 700; color: var(--ink2);
}
.bk-preview {
  background: #E8E8ED; border-radius: 12px; overflow: hidden;
  height: 340px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px; position: relative;
}
.bk-paper { background: white; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.16); }
.bk-paper.portrait  { height: 300px; width: calc(300px * 8.5 / 11); }
.bk-paper.landscape { height: calc(280px * 8.5 / 11); width: 280px; }
.bk-frame { width: 100%; height: 100%; border: none; display: block; }
.bk-settings { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.bk-ref-row { display: none; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.bk-ref-row.visible { display: flex; }
.bk-corner-btns { display: flex; gap: 5px; }
.bk-corner-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1.5px solid var(--sep);
  background: var(--white); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s; color: var(--ink);
}
.bk-corner-btn:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.bk-corner-btn.selected { border-color: var(--accent); background: var(--accent); color: white; }
.bk-corner-btn:disabled { opacity: .28; cursor: default; }
.bk-scale-row { display: none; align-items: center; gap: 5px; }
.bk-scale-row.visible { display: flex; }
.bk-scale-val { font-size: 12px; font-weight: 600; color: var(--ink2); min-width: 30px; text-align: center; }
.bk-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; }
.bk-nav-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px solid var(--sep); background: var(--white);
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .15s; color: var(--ink);
}
.bk-nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.bk-nav-btn:disabled { opacity: .25; cursor: default; }
.bk-nav-label { font-size: 14px; font-weight: 600; color: var(--ink2); min-width: 90px; text-align: center; }
.btn-gen-pdf {
  width: 100%; height: 52px; background: var(--accent); color: white;
  border: none; border-radius: var(--pill); font-family: var(--font);
  font-size: 17px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .18s;
}
.btn-gen-pdf:hover { opacity: .88; }
.btn-gen-pdf:disabled { opacity: .4; cursor: default; }
.bk-spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%;
  animation: spin .7s linear infinite; display: none;
}
.btn-gen-pdf.loading .bk-spinner { display: block; }
@media (max-width: 640px) {
  .bk-preview { height: 240px; }
  .bk-paper.portrait  { height: 210px; width: calc(210px * 8.5 / 11); }
  .bk-paper.landscape { height: calc(196px * 8.5 / 11); width: 196px; }
}