/* Library, Materials Studio, welcome & misc panels. */

/* ================= Library ================= */
.library {
  grid-column: 1; grid-row: 1; justify-self: end; z-index: var(--z-panel);
  width: var(--sidebar-w); min-height: 0; height: 100%;
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
  padding-left: var(--safe-l);
  transition: transform var(--t-med) var(--ease-out), visibility 0s;
}
.library[inert] { visibility: hidden; transition: transform var(--t-med) var(--ease-out), visibility 0s var(--t-med); }
.library__head { display: flex; align-items: center; gap: 4px; padding: calc(var(--safe-t) + 10px) 10px 6px 18px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand__mark { width: 17px; height: 22px; border-radius: 1.5px; background: linear-gradient(170deg, #F5EEDF, #E2D4BA); box-shadow: inset 4.5px 0 0 -3.3px #AA8955, 0 1px 3px rgba(0,0,0,.4); transform: rotate(-5deg); }
.brand__name { font: 500 25px/1 var(--font-display); letter-spacing: .02em; }
.library__close { display: none; }

.library__search { position: relative; margin: 4px 14px 10px; }
.library__search .i { position: absolute; left: 12px; top: 50%; width: 17px; height: 17px; margin-top: -8.500px; color: var(--fg-faint); pointer-events: none; }
.library__search input {
  width: 100%; height: 42px; padding: 0 12px 0 38px; border-radius: var(--r-pill);
  background: var(--field); border: 1px solid var(--line); color: var(--fg); font-size: 16px;
}
.library__search input::placeholder { color: var(--fg-faint); }
.library__search input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.library__search input::-webkit-search-cancel-button { filter: grayscale(1) opacity(.6); cursor: pointer; }

.shelves { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px; border-bottom: 1px solid var(--line); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; max-width: 100%; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-strong); color: var(--fg-dim); font-size: 13px; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.chip span:first-of-type { overflow: hidden; text-overflow: ellipsis; }
.chip .i { width: 15px; height: 15px; }
.chip small { font: 400 10.500px var(--font-label); color: var(--fg-faint); }
.chip:hover { background: var(--hover); color: var(--fg); }
.chip[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--panel); }
.chip[aria-pressed="true"] small { color: inherit; opacity: .6; }
.chip--icon { padding: 0; width: 32px; justify-content: center; }
.chip--ghost { border-style: dashed; }
@media (pointer: coarse) { .chip { min-height: 38px; } .chip--icon { width: 38px; } }

.library__bar { display: flex; align-items: center; gap: 2px; padding: 10px 8px 4px 18px; }
.library__heading { margin-right: auto; font: 500 12px var(--font-label); letter-spacing: .14em; text-transform: uppercase; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library__list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 14px 18px; display: grid; gap: 10px; align-content: start; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.library__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 18px calc(var(--safe-b) + 10px); border-top: 1px solid var(--line); }
.library__foot p { font-size: 11.500px; line-height: 1.35; color: var(--fg-faint); }
.library__foot .link-btn { flex: none; }
.shelf-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.500px; color: var(--fg-dim); padding: 2px 4px 4px; }

/* Letter cards — each takes on its own paper */
.letter {
  --ink-c: #2B2823;
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start;
  border-radius: 3px; color: var(--ink-c);
  background: linear-gradient(176deg, var(--paper), var(--paper-2));
  box-shadow: 0 0 0 .5px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.22), 0 6px 14px -6px rgba(0,0,0,.4);
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast);
  animation: card-in var(--t-med) var(--ease-out) backwards;
}
.letter[data-paper="midnight"] { --ink-c: #E8E0D0; }
.letter::before { content: ""; position: absolute; inset: 3px -2px -3px 2px; z-index: -1; border-radius: 3px; background: color-mix(in srgb, var(--paper-2) 82%, #000); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.letter:hover { transform: translateY(-1px); }
.letter.is-current { box-shadow: 0 0 0 2px var(--accent), 0 6px 14px -6px rgba(0,0,0,.4); }
.letter__open { display: grid; gap: 3px; min-width: 0; padding: 12px 4px 11px 14px; text-align: left; color: inherit; border-radius: 3px; }
.letter__open:focus-visible { outline-offset: -2px; outline-color: #8A5E1E; }
.letter__title { font: 500 19px/1.2 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.letter__preview { font: 400 12px/1.5 "Courier Prime", ui-monospace, monospace; opacity: .74; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; min-height: 1.5em; }
.letter__preview mark { background: rgba(170,137,85,.45); color: inherit; border-radius: 2px; }
.letter__preview:empty::before { content: attr(data-empty); font-style: italic; opacity: .7; }
.letter__meta { margin-top: 3px; font: 400 10px var(--font-label); letter-spacing: .08em; text-transform: uppercase; opacity: .58; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.letter__tools { display: flex; padding: 4px 4px 0 0; color: var(--ink-c); }
.letter__tools .icon-btn { color: inherit; opacity: .5; width: 36px; height: 38px; }
.letter__tools .icon-btn:hover, .letter__tools .icon-btn:focus-visible { opacity: 1; background: rgba(0,0,0,.07); }
.letter__tools .fav[aria-pressed="true"] { opacity: 1; color: #9A6B1F; }
.letter[data-paper="midnight"] .fav[aria-pressed="true"] { color: #E7BD73; }
.letter__tools .i { width: 18px; height: 18px; }
@media (pointer: coarse) { .letter__tools .icon-btn { width: 42px; height: 44px; } }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } }

/* Card layout: small pages */
.library__list[data-layout="cards"] { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px 12px; }
[data-layout="cards"] .letter { grid-template-columns: 1fr; aspect-ratio: 3 / 3.9; }
[data-layout="cards"] .letter__open { align-content: start; padding: 14px 12px 8px; height: 100%; grid-template-rows: auto 1fr auto; }
[data-layout="cards"] .letter__title { font-size: 17px; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
[data-layout="cards"] .letter__preview { -webkit-line-clamp: 5; line-clamp: 5; font-size: 10.500px; }
[data-layout="cards"] .letter__tools { position: absolute; right: 0; bottom: 0; padding: 0; }
[data-layout="cards"] .letter__meta { padding-right: 62px; white-space: normal; line-height: 1.5; }

/* Empty states */
.empty { display: grid; justify-items: center; gap: 10px; padding: 34px 12px 20px; text-align: center; grid-column: 1 / -1; }
.empty__art { position: relative; width: 62px; height: 78px; margin-bottom: 6px; }
.empty__art i { position: absolute; inset: 0; border-radius: 2px; background: linear-gradient(175deg, #F5EEDF, #E2D4BA); box-shadow: 0 4px 10px rgba(0,0,0,.3); }
.empty__art i:nth-child(1) { transform: rotate(-9deg) translate(-7px, 3px); opacity: .55; }
.empty__art i:nth-child(2) { transform: rotate(5deg) translate(6px, 2px); opacity: .8; }
.empty__art i:nth-child(3)::after { content: ""; position: absolute; left: 12px; right: 12px; top: 20px; height: 1.5px; background: rgba(41,39,35,.3); box-shadow: 0 8px 0 rgba(41,39,35,.22), 0 16px 0 rgba(41,39,35,.14); }
.empty h3 { font: 500 23px/1.15 var(--font-display); }
.empty p { font-size: 13.500px; line-height: 1.5; color: var(--fg-dim); max-width: 30ch; }

.scrim { position: absolute; inset: 0; z-index: calc(var(--z-panel) - 1); background: rgba(10, 8, 6, .5); display: none; animation: fade var(--t-med); }

/* Library as an overlay (tablets & phones) */
@media (max-width: 1023px) {
  .library { position: absolute; inset: 0 auto 0 0; width: min(380px, 100%); transform: translateX(-103%); box-shadow: var(--shadow-panel); }
  [data-library="open"] .library { transform: none; }
  [data-library="open"] .scrim { display: block; }
  .library__close { display: inline-grid; }
}
@media (max-width: 600px) {
  .library { width: 100%; border-right: 0; padding-right: var(--safe-r); }
  [data-library="open"] .scrim { display: none; }
  .library__list[data-layout="cards"] { grid-template-columns: repeat(auto-fill, minmax(142px, 1fr)); }
  .library__list { padding-inline: 16px; }
}

/* ================= Materials Studio ================= */
.studio {
  grid-column: 3; grid-row: 1; justify-self: start; z-index: var(--z-panel);
  width: var(--studio-w); min-height: 0; height: 100%;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  padding-right: var(--safe-r);
  transition: transform var(--t-med) var(--ease-out), visibility 0s;
}
.studio[inert] { visibility: hidden; transition: transform var(--t-med) var(--ease-out), visibility 0s var(--t-med); }
.studio__head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 10px) 10px 4px 20px; }
.studio__title { font: 500 24px/1 var(--font-display); letter-spacing: .01em; }
.studio__title small { display: block; margin-top: 5px; font: 400 10px var(--font-label); letter-spacing: .14em; text-transform: uppercase; color: var(--fg-faint); }
.studio__head, .studio__tabs, .library__head, .library__search, .shelves, .library__bar, .library__foot { flex: none; }
.studio__tabs { display: flex; gap: 0; padding: 8px 9px 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.studio__tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; min-height: 40px; padding: 0 7px; border-bottom: 2px solid transparent; margin-bottom: -1px; font: 500 10px var(--font-label); letter-spacing: .06em; text-transform: uppercase; color: var(--fg-dim); transition: color var(--t-fast), border-color var(--t-fast); }
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-color: var(--accent); }
.tab:focus-visible { outline-offset: -3px; }
.studio__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px calc(var(--safe-b) + 28px); display: grid; gap: 26px; align-content: start; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.studio__body:focus-visible { outline-offset: -3px; }
.group { display: grid; gap: 12px; }
.group__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.group__title { font: 500 19px/1.1 var(--font-display); }
.group__note { font-size: 12.500px; line-height: 1.5; color: var(--fg-dim); }
.group + .group { padding-top: 22px; border-top: 1px solid var(--line); }
.reset-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); }

/* Swatches (preview cards — real buttons) */
.swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.swatches--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.swatches--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.swatches--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.swatch { display: grid; gap: 7px; align-content: start; text-align: left; border-radius: var(--r-md); padding: 5px 5px 8px; border: 1px solid transparent; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
.swatch:hover { background: var(--hover); }
.swatch:active { transform: scale(.985); }
.swatch[aria-pressed="true"] { border-color: var(--accent); background: var(--hover); }
.swatch__name { padding: 0 3px; font-size: 13px; font-weight: 500; line-height: 1.25; }
.swatch__note { padding: 0 3px; margin-top: -4px; font-size: 11.500px; line-height: 1.35; color: var(--fg-dim); }
.swatch[aria-pressed="true"] .swatch__name::after { content: " ✓"; color: var(--accent); }
.swatch__art { position: relative; height: 62px; border-radius: 6px; overflow: hidden; }

/* paper swatch */
.art-paper { background: linear-gradient(176deg, color-mix(in srgb, var(--paper), #fff 22%), var(--paper)); box-shadow: inset 0 0 0 1px rgba(0,0,0,.14), inset 0 0 24px color-mix(in srgb, var(--paper-edge) 50%, transparent); display: grid; align-items: center; padding: 0 12px; font: 400 13px/1.3 "Courier Prime", monospace; color: #2B2823; }
.art-paper[data-paper="midnight"] { color: #E8E0D0; }
.art-paper .paper__sheet { box-shadow: none; }
.art-paper span { position: relative; }
/* ink swatch */
.art-ink { background: linear-gradient(176deg, var(--paper), var(--paper-2)); box-shadow: inset 0 0 0 1px rgba(0,0,0,.14); display: grid; place-items: center; font: 400 17px/1 var(--font-write); color: rgba(var(--ink-rgb), var(--ink-a)); text-shadow: var(--ink-shadow); }
.art-ink .paper__wear { z-index: 0; }
/* font swatch */
.art-font { background: var(--field); box-shadow: inset 0 0 0 1px var(--line); display: grid; align-items: center; padding: 0 12px; font-size: 16px; line-height: 1.2; color: var(--fg); white-space: nowrap; }
/* round swatches (ink color, metal, desk) */
.dot-swatch { justify-items: center; text-align: center; padding: 8px 2px; }
.dot-swatch .swatch__name { font-size: 11.500px; font-weight: 400; color: var(--fg-dim); }
.dot-swatch[aria-pressed="true"] .swatch__name { color: var(--fg); }
.dot-swatch[aria-pressed="true"] .swatch__name::after { content: none; }
.dot { width: 34px; height: 34px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25), inset 0 2px 3px rgba(255,255,255,.25), 0 1px 3px rgba(0,0,0,.3); }
.dot--metal { background: conic-gradient(from 210deg, var(--m-lo), var(--m-hi), var(--m-1), var(--m-lo), var(--m-2), var(--m-hi), var(--m-lo)); }
/* atmosphere scene: a little sheet with its rail, carriage and lamp */
.art-scene { height: 74px; --paper-lit: color-mix(in srgb, var(--paper), rgb(var(--lamp-rgb)) calc(var(--lit-mix) * 100%)); background: linear-gradient(180deg, var(--paper), var(--paper-2)); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.art-scene > b { position: absolute; left: 50%; bottom: 30%; width: 150px; height: 75px; margin-left: -75px; background: var(--paper-lit); opacity: 0;
  -webkit-mask-image: conic-gradient(from -52deg at 50% 100%, transparent 0deg, #000 18deg, #000 86deg, transparent 104deg, transparent 360deg), radial-gradient(circle 75px at 50% 100%, #000 0%, rgba(0,0,0,.6) 50%, transparent 100%);
  mask-image: conic-gradient(from -52deg at 50% 100%, transparent 0deg, #000 18deg, #000 86deg, transparent 104deg, transparent 360deg), radial-gradient(circle 75px at 50% 100%, #000 0%, rgba(0,0,0,.6) 50%, transparent 100%);
  -webkit-mask-composite: source-in; mask-composite: intersect; }
.art-scene[data-lamp="on"] > b { opacity: 1; }
.art-scene > i { position: absolute; left: 0; right: 0; bottom: 30%; height: 2px; margin-bottom: -1px; background: #2c2a27; z-index: 2; }
.art-scene > i::before { content: ""; position: absolute; left: 22%; right: 38%; bottom: 7px; height: 1.5px; background: rgba(41,39,35,.55); box-shadow: 0 -6px 0 rgba(41,39,35,.4), 12px -12px 0 rgba(41,39,35,.28); }
.art-scene[data-paper="midnight"] > i::before { background: rgba(237,228,211,.6); box-shadow: 0 -6px 0 rgba(237,228,211,.45), 12px -12px 0 rgba(237,228,211,.3); }
.art-scene > i::after { content: ""; position: absolute; left: 50%; top: 50%; width: 18px; height: 7px; margin: -3.500px 0 0 -9px; border-radius: 4px; background: linear-gradient(var(--m-hi), var(--m-2)); box-shadow: 0 1px 2px rgba(0,0,0,.45); }
.art-scene[data-night="lamp"]::after { content: ""; position: absolute; inset: 0; z-index: 1; background: radial-gradient(ellipse 62% 96% at 50% 62%, transparent 18%, rgba(8,6,4,.82) 78%); }
.swatch--wide { grid-column: 1 / -1; grid-template-columns: 96px 1fr; align-items: center; gap: 3px 12px; padding: 5px; }
.swatch--wide .swatch__art { height: 58px; grid-row: 1 / span 2; }
.swatch--wide .swatch__name { grid-column: 2; align-self: end; font-size: 14px; }
.swatch--wide .swatch__note { grid-column: 2; align-self: start; margin-top: 0; }

/* Studio as overlay / bottom sheet */
@media (max-width: 1023px) {
  .studio { position: absolute; inset: 0 0 0 auto; width: min(372px, 100%); transform: translateX(103%); box-shadow: var(--shadow-panel); }
  [data-studio="open"] .studio { transform: none; }
}
@media (max-width: 600px) {
  .app { --sheet-h: calc(var(--vvh, 100dvh) * .54); }
  .studio { inset: auto 0 0 0; width: 100%; height: var(--sheet-h); transform: translateY(104%); border-left: 0; border-top: 1px solid var(--line-strong); border-radius: 18px 18px 0 0; padding-right: 0; }
  .studio__head { padding: 12px 8px 0 20px; }
  .studio__head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line-strong); }
  .studio__title { font-size: 21px; }
  .studio__title small { display: none; }
  .studio__tabs { padding-top: 0; }
  .studio__body { padding: 16px 18px calc(var(--safe-b) + 22px); }
  [data-studio="open"] .desk { padding-bottom: var(--sheet-h); }
  [data-studio="open"] .quickbar { display: none; }
  [data-studio="open"] .stage { padding-bottom: 10px; }
}

/* ================= Welcome ================= */
dialog.welcome { width: min(520px, calc(100vw - 28px)); text-align: center; background: radial-gradient(120% 90% at 50% 0%, #3A2C23, #1E1611 75%); color: #EDE4D3; border-color: rgba(237,228,211,.16); }
.welcome .dialog__body { padding: 40px 34px 6px; gap: 0; justify-items: center; }
.welcome__sheet { position: relative; width: 84px; height: 108px; margin-bottom: 26px; border-radius: 2px; background: linear-gradient(175deg, #F7F0E1, #E4D6BC); box-shadow: 0 16px 34px rgba(0,0,0,.5); transform: rotate(-4deg); animation: paper-in .8s var(--ease-out); }
.welcome__sheet::before { content: ""; position: absolute; top: 0; bottom: 0; left: 17px; width: 1.5px; background: #AA8955; opacity: .8; }
.welcome__sheet::after { content: ""; position: absolute; left: 26px; right: 12px; top: 26px; height: 1.5px; background: rgba(41,39,35,.42); box-shadow: 0 10px 0 rgba(41,39,35,.32), 0 20px 0 rgba(41,39,35,.24), 0 30px 0 rgba(41,39,35,.14); }
.welcome h1 { font: 500 46px/1 var(--font-display); letter-spacing: .03em; }
.welcome__tag { margin-top: 10px; font: 500 italic 21px/1.2 var(--font-display); color: #D9BE8A; }
.welcome__points { margin: 26px 0 4px; padding: 0; list-style: none; display: grid; gap: 14px; text-align: left; max-width: 40ch; }
.welcome__points li { display: grid; grid-template-columns: 22px 1fr; gap: 12px; font-size: 14px; line-height: 1.5; color: rgba(237,228,211,.78); }
.welcome__points .i { width: 20px; height: 20px; margin-top: 1px; color: #D9BE8A; }
.welcome__points b { color: #EDE4D3; font-weight: 600; }
.welcome .dialog__actions { justify-content: center; padding: 22px 26px 30px; }
.welcome .btn { border-color: rgba(237,228,211,.25); color: #EDE4D3; }
.welcome .btn--primary { background: #D9BE8A; color: #1E1711; border-color: transparent; min-width: 180px; }

/* ================= Small shared bits ================= */
.kbd-list { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; align-items: center; font-size: 14px; }
kbd { display: inline-block; padding: 3px 7px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--field); font: 400 12px var(--font-label); white-space: nowrap; }
.stat-list { display: grid; gap: 6px; font-size: 13.500px; color: var(--fg-dim); }
.stat-list b { color: var(--fg); font-weight: 600; }
.manage-list { display: grid; gap: 6px; }
.manage-row { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 14px; border: 1px solid var(--line); border-radius: var(--r-md); min-height: 48px; }
.manage-row span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manage-row small { color: var(--fg-faint); font: 400 11px var(--font-label); }
.banner { position: absolute; z-index: var(--z-chrome); left: 50%; top: calc(var(--safe-t) + 60px); transform: translateX(-50%); max-width: calc(100% - 24px); padding: 8px 14px; border-radius: var(--r-pill); background: #5A2A1E; color: #F6DDD3; font-size: 12.500px; border: 1px solid #B4563F; text-align: center; }
