.app-shell { display: grid; grid-template-columns: clamp(190px, 16vw, 235px) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; align-self: start; height: 100dvh; display: flex; flex-direction: column;
  padding: 2.1rem .95rem 1.4rem; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .7rem; margin: 0 .5rem 2.8rem; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; background: var(--accent); border-radius: 13px; }
.brand-mark img { width: 31px; height: 31px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.25rem; font-weight: 750; letter-spacing: -.06em; line-height: 1.2; }
.brand small { font-size: .77rem; color: var(--muted); }
.sidebar-nav { display: flex; flex: 1; flex-direction: column; gap: .28rem; }
.sidebar-nav a { display: flex; align-items: center; gap: .8rem; min-height: 45px; padding: .62rem .85rem; text-decoration: none; color: #50584f; border-radius: .62rem; font-weight: 550; font-size: .94rem; }
.sidebar-nav a:hover { background: var(--soft); }
.sidebar-nav a[aria-current] { background: var(--active); color: #263b16; font-weight: 700; }
.sidebar-nav .glyph { width: 19px; height: 19px; }
.nav-settings { margin-top: auto; }
.page-area { width: 100%; max-width: 1650px; margin: 0 auto; min-width: 0; padding: clamp(1.3rem, 2.5vw, 2.8rem) clamp(1.3rem, 3.2vw, 3.5rem) 4rem; }
.library-hero {
  isolation: isolate; overflow: hidden; position: relative; display: flex; flex-direction: column; justify-content: center;
  min-height: clamp(180px, 17vw, 245px); padding: clamp(1.5rem, 3.3vw, 3rem); border-radius: 1.1rem;
  background: #10130f; color: #fafbf7;
}
.library-hero::before {
  content: ""; position: absolute; z-index: -1; inset: 0 0 0 23%;
  background: url("library-controller.webp") right 51% / cover no-repeat;
  mask-image: linear-gradient(90deg, transparent, #000 29%);
}
.hero-label { display: inline-flex; align-items: center; gap: .5rem; font-size: .79rem; font-weight: 600; color: #d3edb5; letter-spacing: .085em; text-transform: uppercase; }
.hero-label .glyph { width: 18px; height: 18px; }
.library-hero h1 { margin: .55rem 0 1.05rem; }
.hero-stats { min-height: 1.4rem; display: flex; align-items: center; gap: .9rem; font-size: .9rem; color: #e4e9dd; }
.hero-stats span { display: inline-flex; align-items: center; gap: .42rem; }
.hero-stats span + span { padding-left: .9rem; border-left: 1px solid #67715e; }
.page-heading { padding: .3rem 0 1.6rem; border-bottom: 1px solid var(--line); }
.page-heading h1 { font-size: clamp(2.1rem, 4vw, 3.2rem); margin: .8rem 0 .4rem; }
.heading-icon, .drop-icon { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: .8rem; color: var(--green); background: var(--active); }
.heading-icon .glyph, .drop-icon .glyph { width: 21px; height: 21px; }
.game-browser, .settings-layout { margin-top: 1.6rem; }
.browser-heading, .browser-heading > div, .card-size-picker, .toolbar, .search, .filter-panel summary, .check { display: flex; align-items: center; }
.browser-heading { justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.browser-heading > div:first-child { flex-wrap: wrap; gap: .65rem; }
.browser-heading h2 { font-size: clamp(1.35rem, 2vw, 1.7rem); }
.count { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.card-size-picker { padding: 3px; gap: 2px; background: #e9ece5; border-radius: .55rem; }
.size-option { width: 34px; height: 29px; border-radius: .38rem; color: var(--muted); }
.size-option .glyph { width: 16px; height: 16px; }
.size-option[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px #151a151a; }
.toolbar { gap: .6rem; margin-bottom: .9rem; }
.search { flex: 1; gap: .65rem; padding: 0 .9rem; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: .65rem; color: var(--muted); }
.search:focus-within { outline: 2px solid #87a966; outline-offset: 1px; }
.search input { appearance: none; width: 100%; min-width: 0; padding: .69rem 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: .9375rem; line-height: 1.4; }
.search input::placeholder { color: #73796e; }
.filter-panel { position: relative; flex: none; }
.filter-panel summary { min-height: 44px; padding: .55rem .85rem; background: var(--surface); border: 1px solid var(--line); list-style: none; }
.filter-panel summary::-webkit-details-marker { display: none; }
.filter-panel[open] summary, .filter-panel summary:has(.filter-count:not([hidden])) { background: var(--active); border-color: #bdd396; }
.filter-count { display: grid; place-items: center; min-width: 1.3rem; height: 1.3rem; padding: 0 .2rem; border-radius: .35rem; color: #fff; background: #375524; font-size: .76rem; }
.filter-menu { z-index: 5; position: absolute; top: calc(100% + .45rem); right: 0; width: min(265px, calc(100vw - 32px)); padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: .85rem; box-shadow: 0 8px 32px #1920121c; }
.check { gap: .6rem; min-height: 33px; font-size: .92rem; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.flag-filters, .flag-actions, .actions, .modal-actions, .danger-zone { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.check + .flag-filters:not(:empty) { border-top: 1px solid var(--line); margin-top: .65rem; padding-top: .8rem; }
.flag-filter { padding: .52rem .65rem; border-color: var(--line); }
.alphabet { display: grid; grid-template-columns: repeat(26, minmax(0, 1fr)); gap: 2px; padding: .28rem; margin: 0 0 1.15rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--surface); }
.letter { min-height: 30px; padding: 0; font-size: .875rem; font-weight: 600; border: 0; border-radius: .4rem; background: transparent; color: var(--muted); }
.letter:hover { background: var(--soft); }
.letter[aria-pressed="true"] { color: #253119; background: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 185px), 1fr)); gap: clamp(.8rem, 1.35vw, 1.4rem); }
.grid--medium { grid-template-columns: repeat(auto-fill, minmax(min(100%, 155px), 1fr)); gap: .8rem; }
.empty { text-align: center; padding: 3.7rem 1rem; background: var(--surface); border: 1px dashed #c9cfc1; border-radius: .9rem; color: var(--muted); }
.empty .glyph { width: 32px; height: 32px; margin-bottom: .6rem; color: #637655; }
.pagination { display: flex; justify-content: center; align-items: center; gap: .85rem; margin-top: 1.5rem; font-size: .875rem; }
.settings-layout { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1rem; }
.settings-section { min-width: 0; padding: clamp(1.15rem, 2vw, 2rem); border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); }
.settings-section h2 { display: flex; align-items: center; gap: .65rem; }
.settings-section h2 .glyph { width: 21px; height: 21px; color: var(--green); }
.settings-flags { grid-column: 1 / -1; }
.flag-create-form, .flag-setting { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.flag-create-form { margin: 1.25rem 0; }
.flag-create-form input, .flag-setting input { flex: 1 1 150px; min-width: 0; }
.flag-setting { padding: .7rem 0; border-top: 1px solid var(--line); }
.flag-setting > span:not(.flag-button) { min-width: 4rem; font-size: .875rem; color: var(--muted); }
.danger-icon { color: var(--danger); }
.drop-zone { position: relative; display: grid; justify-items: center; align-content: center; gap: .2rem; margin-top: 1.15rem; padding: 1.5rem 1rem; text-align: center; border: 1px dashed #aeb8a5; border-radius: .8rem; background: #f8faf6; cursor: pointer; }
.drop-zone:hover, .drop-zone:focus-within, .drop-zone.is-dragging { background: var(--active); border-color: var(--green); }
.drop-zone > span:not(.drop-icon), .drop-zone small { color: var(--muted); font-size: .875rem; }
.drop-icon { margin-bottom: .5rem; }
.drop-zone small { overflow-wrap: anywhere; }
.progress-wrap { margin: 1.25rem 0; }
.progress { height: 8px; overflow: hidden; border-radius: 99px; background: var(--soft); margin-top: .8rem; }
.progress span { display: block; width: 0; height: 100%; background: #94bc5c; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 1.1rem; gap: .65rem; }
.modal-actions { justify-content: flex-end; margin-top: 1rem; gap: .6rem; }
dialog { color: var(--ink); border: 1px solid var(--line); border-radius: 1.2rem; box-shadow: 0 24px 90px #13190e42; max-height: calc(100dvh - 2rem); padding: clamp(1.2rem, 2.4vw, 2rem); }
dialog::backdrop { background: #111a12a6; backdrop-filter: blur(4px); }
.details-dialog { width: min(760px, calc(100% - 2rem)); }
.upload-dialog { width: min(480px, calc(100% - 2rem)); }
.close { z-index: 1; position: absolute; top: .7rem; right: .7rem; border-color: var(--line); background: var(--surface); border-radius: 50%; }
.upload-dialog h2 { margin-right: 2.4rem; }
.details-layout { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.1fr); align-items: start; gap: 1.6rem; }
.details-data { container-type: inline-size; }
.details-heading { display: flex; align-items: start; gap: .5rem; margin: .45rem 1.25rem 0 0; }
.details-title { font-size: 1.5rem; overflow-wrap: anywhere; }
.favorite-modal { flex: none; }
.details-lines { margin: 1rem 0; }
.details-lines > div { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.details-lines dt { margin-bottom: .2rem; color: var(--muted); font-size: .8rem; font-weight: 600; }
.details-lines dd { margin: 0; overflow-wrap: anywhere; font-size: .94rem; }
.checksum-line dd { display: flex; align-items: center; justify-content: space-between; gap: .45rem; }
.checksum-line dd span {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, monospace; font-size: .85rem;
}
.checksum-line .icon { flex: none; }
.modal-flags { justify-content: start; }
.flag-button--modal { min-height: 40px; padding: .55rem .7rem; border-color: var(--line); }
@container (max-width: 22.5rem) {
  .modal-flags { gap: .375rem; }
  .modal-flags #changeCover { padding-inline: .65rem; white-space: nowrap; }
  .modal-flags .collection-flag-label { display: none; }
  .modal-flags .flag-button:has(.collection-flag-label) { width: 44px; height: 44px; padding: 0; }
}
.toasts { position: fixed; z-index: 10; bottom: 1.4rem; right: 1.4rem; display: grid; gap: .5rem; width: min(360px, calc(100% - 2rem)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-radius: .7rem; background: var(--ink); color: #fff; padding: .72rem .85rem; font-size: .9rem; box-shadow: 0 4px 18px #18201428; }
.toast--error { background: #8b3129; }
.toast button { display: grid; place-items: center; padding: .3rem; border: 0; background: transparent; color: inherit; }
@media (max-width: 1080px) { .alphabet { grid-template-columns: repeat(13, 1fr); } }
@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: .8rem 1.1rem; background: var(--bg); border: 0; }
  .brand { align-self: start; margin: 0; }
  .brand-mark { width: 35px; height: 35px; border-radius: .65rem; }
  .brand-mark img { width: 26px; height: 26px; }
  .brand strong { font-size: 1.05rem; }
  .brand small { font-size: .75rem; }
  .sidebar-nav { z-index: 8; position: fixed; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .15rem; padding: .4rem .3rem max(.4rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
  .sidebar-nav a { flex-direction: column; justify-content: center; gap: .2rem; min-height: 48px; padding: .27rem .05rem; font-size: .75rem; letter-spacing: -.035em; }
  .nav-settings { margin-top: 0; }
  .page-area { padding: .3rem 1.1rem calc(6rem + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(4.8rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 600px) {
  .library-hero { min-height: 155px; padding: 1.15rem; }
  .library-hero::before { inset-inline-start: 12%; opacity: .65; mask-image: linear-gradient(90deg, transparent, #000 72%); }
  .library-hero h1 { margin: .45rem 0 .75rem; font-size: clamp(2rem, 7.8vw, 2.7rem); }
  .hero-label { font-size: .75rem; }
  .hero-stats { font-size: .8rem; gap: .55rem; }
  .hero-stats span + span { padding-left: .55rem; }
  .game-browser, .settings-layout { margin-top: 1.15rem; }
  .grid, .grid--medium { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .settings-layout, .details-layout { grid-template-columns: minmax(0, 1fr); }
  .details-layout { gap: 1rem; }
  .alphabet { gap: 0; }
  .letter { min-height: 32px; }
  .filter-panel summary { padding-inline: .65rem; }
  .browser-heading > div:first-child { gap: .45rem; }
  .flag-setting > span:not(.flag-button) { min-width: auto; }
}
@media (max-width: 360px) {
  .page-area { padding-inline: .72rem; }
  .sidebar-nav a { font-size: .7rem; }
  .grid:not(.grid--medium) { grid-template-columns: 1fr; }
}
