/* ==========================================================================
   Dashboard (app.html) and login. Uses tokens.css + base.css.
   ========================================================================== */
body.dash, body.login { position: relative; }
body.dash::before, body.login::before { content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .16 0 0 0 0 .16 0 0 0 0 .2 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] body.dash::before, :root[data-theme="dark"] body.login::before { opacity: 0.35; }
body.dash > header, body.dash > main, body.login > main { position: relative; z-index: 1; }
body.dash > header { position: sticky; }

.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.02em; text-decoration: none; }
.top { position: sticky; top: 0; z-index: var(--z-sticky); height: var(--header-h); background: color-mix(in srgb, var(--bg) 84%, transparent); backdrop-filter: blur(14px) saturate(1.4); box-shadow: 0 1px 0 var(--line); }
.top-in { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.top-end { display: flex; align-items: center; gap: var(--space-2); }

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-5); padding: clamp(28px, 5vw, 56px) 0 var(--space-6); }
.head .ui-eyebrow { color: var(--accent-ink); margin-bottom: var(--space-2); }
.head h1 { font-size: var(--text-4xl); }
.tools { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.tools .ui-search { width: 260px; max-width: calc(100vw - 2 * var(--gutter)); }
.tools { flex-wrap: nowrap; }
@media (max-width: 560px) { .tools { flex-wrap: wrap; width: 100%; } .tools .ui-search { width: 100%; flex: 1 1 100%; } }
.search-k { position: absolute; right: 10px; top: 50%; translate: 0 -50%; pointer-events: none; opacity: 0.8; }
.tools .ui-input:focus ~ .search-k { opacity: 0; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: var(--space-6) var(--space-5); padding-bottom: var(--space-9); }
.album { position: relative; display: flex; flex-direction: column; gap: var(--space-3); animation: rise 0.7s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 55ms); }
.album.no-anim { animation: none; }
.album.is-removing { animation: none; transition: opacity 0.28s, transform 0.28s var(--ease-in); opacity: 0; transform: scale(0.92); }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.album-cover { position: relative; display: grid; place-items: center; padding: var(--space-5) var(--space-5) var(--space-4); border-radius: var(--radius-lg); background: radial-gradient(var(--line-strong) 0.7px, transparent 1px) 0 0 / 14px 14px, var(--surface-2); border: 1px solid var(--line); aspect-ratio: 1 / 1.08; perspective: 900px; overflow: hidden; transition: border-color var(--dur-2), box-shadow var(--dur-3) var(--ease-out); }
.album:hover .album-cover { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
.book { position: relative; width: min(100%, calc(var(--ar, 0.707) * 200px), 170px); aspect-ratio: var(--ar, 0.707); transform-style: preserve-3d; transform: rotateY(-14deg) rotateX(2deg); transition: transform 0.7s var(--ease-spring); border-radius: 2px 5px 5px 2px; box-shadow: 8px 14px 22px -8px rgb(var(--shadow-color) / 0.38), 2px 2px 0 var(--surface-sunk); }
.book::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 9%; z-index: 3; border-radius: 2px 0 0 2px; background: linear-gradient(90deg, rgb(0 0 0 / 0.28), rgb(255 255 255 / 0.12) 40%, transparent); pointer-events: none; }
.album:hover .book, .album:focus-within .book { transform: rotateY(-4deg) rotateX(0deg) translateY(-4px) scale(1.04); }
.book-face { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; background: var(--page-paper, #fffdf4); }
.cover-live { position: absolute; inset: 0; overflow: hidden; background: #fffdf4; } .cover-live .r-page { position: absolute; left: 0; top: 0; }
.has-live .cover-ph { display: none; }
.book-face:has(.cover-live) .cover-ph { display: none; }

.cover-ph { --c1: #292a35; --c2: #3a3b49; position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 12% 12% 12% 16%; background: linear-gradient(160deg, var(--c2), var(--c1)); color: #fdfaec; }
.cover-ph.tone-1 { --c1: #1f5a5a; --c2: #2a7a77; } .cover-ph.tone-2 { --c1: #8a2f47; --c2: #b0405a; } .cover-ph.tone-3 { --c1: #3a4a6e; --c2: #4f6593; }
.cover-ph__tag { align-self: flex-start; font: 700 0.9rem/1 var(--font-display); color: #c4566c; background: #fdfaec; border-radius: 2px; padding: 3px 6px; box-shadow: 0 0 0 1.5px #0c0d11; }
.cover-ph__t { font: 600 clamp(15px, 1.3vw + 6px, 20px)/1.05 var(--font-display); letter-spacing: -0.02em; font-variation-settings: "opsz" 72, "SOFT" 40; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.cover-ph__slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; } .cover-ph__slots i { aspect-ratio: 1.1; border: 1.5px solid #fdfaec; opacity: 0.55; border-radius: 1.5px; }
.cover-ph__slots i:first-child { background: #fdfaec; opacity: 0.85; }

.album-body { display: grid; gap: 6px; padding: 0 var(--space-1); }
.album-title { font: 560 var(--text-xl)/1.2 var(--font-display); letter-spacing: -0.015em; font-variation-settings: "opsz" 36; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 36px; }
.album-link { text-decoration: none; }
.album-link::after { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: var(--radius-lg); }
.album-link:focus-visible { outline: none; } .album-link:focus-visible::after { box-shadow: var(--shadow-focus); outline: 2px solid var(--focus); outline-offset: 2px; }
.album-meta { color: var(--muted); font-size: var(--text-sm); }
.album-prog { height: 4px; border-radius: 2px; background: var(--line-strong); overflow: hidden; margin-top: 2px; }
.album-prog i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(var(--p)); background: var(--accent-strong); border-radius: 2px; transition: transform 0.9s var(--ease-out); }
.album-more { position: absolute; z-index: 2; right: 0; bottom: calc(100% - var(--cover-h, 0px)); top: auto; opacity: 0; transition: opacity var(--dur-2); }
.album-more { right: 10px; top: 10px; bottom: auto; }
.album:hover .album-more, .album:focus-within .album-more, .album-more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .album-more { opacity: 1; } }
.album-rename { position: relative; z-index: 3; height: 32px; margin-top: -4px; font: 560 var(--text-lg) var(--font-display); }
.album.is-skel .sk-cover { aspect-ratio: 1 / 1.08; border-radius: var(--radius-lg); height: auto; }
.album.is-skel { animation: none; }

.album-new { display: grid; place-content: center; justify-items: center; gap: var(--space-2); aspect-ratio: auto; min-height: 220px; align-self: start; border: 2px dashed var(--line-strong); border-radius: var(--radius-lg); background: transparent; color: var(--ink); padding: var(--space-6); animation: rise 0.7s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 55ms); transition: border-color var(--dur-2), background var(--dur-2), transform var(--dur-3) var(--ease-spring); }
.album-new .ui-slotnum { font-size: 1.9rem; transition: transform 0.5s var(--ease-spring); }
.album-new b { font: 560 var(--text-lg) var(--font-display); } .album-new small { color: var(--muted); font-size: var(--text-sm); }
.album-new:hover { border-color: var(--accent-strong); background: var(--accent-soft); }
.album-new:hover .ui-slotnum { transform: rotate(-6deg) scale(1.1); }
.album-new:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.empty img { margin-bottom: var(--space-3); } .empty { padding-top: var(--space-8); }
[data-state] .ui-empty h2 { font-family: var(--font-display); }

/* new album dialog */
.nd-choices { border: 0; margin: 0; padding: 0; display: grid; gap: var(--space-2); min-width: 0; }
.nd-choices legend { padding: 0; margin-bottom: 6px; }
.nd-choices .ui-choice { grid-template-columns: 44px 1fr; align-items: center; gap: var(--space-3); }
.nd-choices .ui-choice > span:last-child { display: grid; gap: 2px; } .nd-choices b { font-weight: 600; } .nd-choices small { color: var(--muted); font-size: var(--text-sm); }
.nd-ico svg { width: 44px; height: 44px; }
.nd-ico { display: grid; place-items: center; }
:root[data-theme="dark"] .nd-ico svg [stroke="var(--navy)"] { stroke: var(--cream); }

/* page format step */
.ui-dialog > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.ui-dialog__body { min-height: 0; }
.nd-formats { border: 0; margin: 0; padding: 0; display: grid; gap: var(--space-2); min-width: 0; }
.nd-formats legend { padding: 0; margin-bottom: 6px; }
.fm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.fm-card { position: relative; display: grid; justify-items: center; align-content: start; gap: 2px; padding: var(--space-2) var(--space-1) var(--space-3); text-align: center; background: var(--surface-raised); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); cursor: pointer; transition: border-color var(--dur-2), background var(--dur-2), box-shadow var(--dur-2); }
.fm-card:hover { border-color: var(--ink); }
.fm-card > input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.fm-card:has(input:checked) { border-color: var(--accent-strong); background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface-raised)); box-shadow: 0 0 0 1px var(--accent-strong); }
.fm-card:has(input:focus-visible) { box-shadow: var(--shadow-focus); }
.fm-card b { font-size: var(--text-sm); font-weight: 600; line-height: 1.2; }
.fm-card small { color: var(--muted); font-size: var(--text-xs); line-height: 1.25; font-variant-numeric: tabular-nums; }
.fm-box { display: grid; place-items: center; width: 100%; height: 72px; }
.fm-paper { position: relative; display: block; background: var(--cream); border: 1.5px solid var(--navy); border-radius: 2px 3px 3px 2px; box-shadow: 3px 4px 0 -1px color-mix(in srgb, var(--navy) 22%, transparent); transition: width var(--dur-3) var(--ease-out), height var(--dur-3) var(--ease-out); }
.fm-paper::before { content: ""; position: absolute; left: 12%; top: 0; bottom: 0; width: 1px; background: color-mix(in srgb, var(--navy) 28%, transparent); }
.fm-card:has(input:checked) .fm-paper { border-color: var(--accent-strong); }
:root[data-theme="dark"] .fm-paper { border-color: var(--cream); box-shadow: 3px 4px 0 -1px rgb(0 0 0 / 0.5); }
:root[data-theme="dark"] .fm-card:has(input:checked) .fm-paper { border-color: var(--accent-strong); }
.fm-custom { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: var(--space-2); }
.fm-x { padding-bottom: 10px; color: var(--muted); }
@media (max-width: 560px) { .fm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .fm-box { height: 68px; } }
@media (prefers-reduced-motion: reduce) { .fm-paper { transition: none; } }

/* login */
body.login { display: grid; min-height: 100dvh; }
.login-wrap { display: grid; place-items: center; padding: var(--space-5); }
.login-card { position: relative; width: min(400px, 100%); display: grid; gap: var(--space-4); padding: var(--space-8) var(--space-7) var(--space-7); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-3); }
.login-card::before { content: ""; position: absolute; inset: 8px; border: 1.5px dashed var(--line-strong); border-radius: calc(var(--radius-xl) - 6px); pointer-events: none; }
.login-card h1 { font-size: var(--text-3xl); } .login-card form { display: grid; gap: var(--space-4); margin-top: var(--space-2); }
.login-mark { position: absolute; top: -22px; right: 28px; transform: rotate(5deg); } .login-mark .ui-slotnum { font-size: 1.6rem; }
.login-card.is-shake { animation: shake 0.45s var(--ease-out); }
@keyframes shake { 20% { translate: -8px; } 40% { translate: 7px; } 60% { translate: -4px; } 80% { translate: 2px; } }
.login-tools { position: fixed; top: 16px; right: 16px; display: flex; align-items: center; gap: var(--space-2); }
.login-card .brand { font-size: 1.1rem; }
@media (prefers-reduced-motion: reduce) { .album, .album-new { animation: none; } .book { transition: none; } }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; gap: var(--space-5) var(--space-3); }
  .album-cover { padding: var(--space-3); aspect-ratio: 1 / 1.15; }
  .album-title { font-size: var(--text-lg); }
  .album-meta { font-size: var(--text-xs); }
  .album-new { min-height: 0; aspect-ratio: 1 / 1.15; padding: var(--space-3); }
  .album-new small { display: none; }
}
@media (max-width: 560px) {
  .demo-badge { display: none; }
  .book { width: min(88%, calc(var(--ar, 0.707) * 150px), 124px); }
  .album-title { white-space: normal; padding-right: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}

/* signed-in user + log out (header) */
.who { display: inline-flex; align-items: center; gap: var(--space-1); }
.who-name { font-size: 0.8125rem; color: var(--muted); max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .who-name { display: none; } }
