:root {
  --ink: #233047;
  --ink-soft: #687489;
  --navy: #17253d;
  --orange: #c65e31;
  --orange-dark: #a94a24;
  --green: #37795f;
  --paper: #f3f6f7;
  --card: #ffffff;
  --line: #d4dce3;
  --soft: #e9eef2;
  --gold-soft: #f7e9ca;
  --radius: 12px;
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, label, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.shell { width: min(1480px, calc(100% - 40px)); margin-inline: auto; }
.eyebrow { margin: 0; color: var(--ink-soft); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.topbar { position: sticky; z-index: 20; top: 0; border-bottom: 1px solid #283852; background: rgb(23 37 61 / 97%); color: white; backdrop-filter: blur(12px); }
.topbar-inner { min-height: 78px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.brand-icon { display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid rgb(255 255 255 / 18%); border-radius: 12px; background: rgb(255 255 255 / 8%); color: #e58b58; font-size: .72rem; font-weight: 900; }
.brand-copy span { display: block; margin-bottom: 3px; color: rgb(255 255 255 / 55%); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.brand-copy h1 { overflow: hidden; margin: 0; font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 12px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-size: .87rem; font-weight: 750; text-decoration: none; transition: background 140ms ease, border-color 140ms ease, transform 100ms ease; }
.button:active { transform: translateY(1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .card-open:focus-visible, .card-title:focus-visible, .icon-button:focus-visible, .file-choice:focus-visible { outline: 3px solid rgb(198 94 49 / 30%); outline-offset: 2px; }
.button-primary { background: var(--orange); color: white; }
.button-primary:hover { background: var(--orange-dark); }
.button-outline { border-color: var(--line); background: white; }
.button-outline:hover, .button-ghost:hover { background: var(--soft); }
.button-ghost { background: transparent; }
.button-danger { border-color: #edc6c1; background: #fff5f4; color: #a93d32; }

.main-content { padding-block: 28px 80px; }
.summary { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto minmax(260px, auto); align-items: stretch; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: 0 12px 34px rgb(20 35 55 / 5%); }
.summary-main { padding: 22px 26px; }
.summary h2 { margin: 4px 0 0; font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.7rem, 3vw, 2.25rem); line-height: 1.12; }
.progress-row { display: grid; grid-template-columns: minmax(120px, 280px) auto; align-items: center; gap: 12px; margin-top: 16px; color: var(--ink-soft); font-size: .82rem; }
.progress { height: 8px; overflow: hidden; border-radius: 999px; background: var(--soft); }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--orange); transition: width 200ms ease; }
.stat { min-width: 160px; display: flex; flex-direction: column; justify-content: center; padding: 18px 25px; border-left: 1px solid var(--line); }
.stat strong { font-family: Georgia, 'Times New Roman', serif; font-size: 2rem; color: var(--orange); }
.stat span { margin-top: 2px; color: var(--ink-soft); font-size: .78rem; }
.file-status { min-width: 260px; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-left: 1px solid var(--line); background: #f8fafb; }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #91a0b1; box-shadow: 0 0 0 4px #e6eaee; }
.file-status.connected .status-dot { background: #43a47a; box-shadow: 0 0 0 4px #dcefe7; }
.file-status strong, .file-status small { display: block; }
.file-status strong { font-size: .84rem; }
.file-status small { margin-top: 4px; color: var(--ink-soft); font-size: .72rem; line-height: 1.3; }

.filters { position: sticky; z-index: 15; top: 78px; display: grid; grid-template-columns: minmax(260px, 1.7fr) repeat(4, minmax(140px, auto)); gap: 10px; margin-top: 18px; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: rgb(250 252 253 / 95%); box-shadow: 0 10px 28px rgb(20 35 55 / 6%); backdrop-filter: blur(12px); }
.filters label { min-width: 0; }
input, select, textarea { width: 100%; border: 1px solid #c9d2da; border-radius: 9px; background: white; color: var(--ink); }
input, select { height: 42px; padding: 8px 11px; }
select { cursor: pointer; }
textarea { min-height: 118px; padding: 11px; resize: vertical; line-height: 1.45; }
.search-field { position: relative; }
.search-field input { padding-left: 40px; }
.search-icon { position: absolute; z-index: 1; left: 13px; top: 50%; transform: translateY(-52%); color: var(--ink-soft); font-size: 1.35rem; }

.results-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 34px 2px 16px; }
.results-head h2 { margin: 2px 0 0; font-family: Georgia, 'Times New Roman', serif; font-size: 1.6rem; }
.manual-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.manual-card { overflow: hidden; display: flex; min-width: 0; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; background: white; box-shadow: 0 7px 22px rgb(20 35 55 / 5%); transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease; }
.manual-card:hover { transform: translateY(-3px); border-color: #c99b7c; box-shadow: 0 14px 32px rgb(20 35 55 / 10%); }
.manual-card.owned { border-color: #78ad98; box-shadow: inset 0 3px 0 var(--green), 0 7px 22px rgb(20 35 55 / 5%); }
.card-open { position: relative; width: 100%; padding: 0; border: 0; cursor: pointer; background: var(--soft); }
.cover { position: relative; display: grid; width: 100%; height: 166px; place-items: center; overflow: hidden; background: linear-gradient(145deg, #eef2f4, #d5dde5); }
.cover img { position: relative; z-index: 1; width: auto; height: auto; max-width: 110px; max-height: 144px; object-fit: contain; transition: transform 220ms ease; }
.cover.cover-large { height: auto; aspect-ratio: 4 / 5.1; }
.cover.cover-large img { max-width: 100%; max-height: 100%; }
.card-open:hover img { transform: scale(1.025); }
.cover-fallback { position: absolute; color: #8b99a8; font-family: Georgia, serif; font-size: 1.5rem; font-weight: 800; }
.card-arrow { position: absolute; z-index: 2; right: 9px; bottom: 9px; display: grid; width: 29px; height: 29px; place-items: center; border-radius: 50%; background: rgb(23 37 61 / 85%); color: white; opacity: 0; transition: opacity 150ms ease; }
.card-open:hover .card-arrow, .card-open:focus-visible .card-arrow { opacity: 1; }
.card-body { min-height: 176px; display: flex; flex: 1; flex-direction: column; padding: 13px; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink-soft); font-size: .72rem; }
.badge { max-width: calc(100% - 38px); overflow: hidden; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.card-title { margin: 11px 0 0; padding: 0; border: 0; cursor: pointer; background: transparent; text-align: left; font-family: Georgia, 'Times New Roman', serif; font-size: 1.02rem; font-weight: 700; line-height: 1.22; }
.card-title:hover { color: var(--orange); }
.card-subtitle { display: -webkit-box; overflow: hidden; margin: 6px 0 0; color: var(--ink-soft); font-size: .78rem; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 14px; }
.owned-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink-soft); font-size: .78rem; font-weight: 750; }
.owned-toggle input { width: 17px; height: 17px; accent-color: var(--green); }
.owned .owned-toggle { color: var(--green); }
.note-mark { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 50%; background: var(--gold-soft); font-size: .78rem; }
.load-more { display: flex; justify-content: center; padding-top: 30px; }
.empty { min-height: 340px; display: grid; place-items: center; align-content: center; gap: 8px; border: 1px dashed var(--line); border-radius: 16px; color: var(--ink-soft); text-align: center; }
.empty > span { font-size: 2rem; }
.empty h2 { margin: 0; color: var(--ink); font-family: Georgia, serif; }
.empty p { margin: 0; }

dialog { padding: 0; border: 0; background: transparent; }
dialog::backdrop { background: rgb(14 24 39 / 30%); backdrop-filter: blur(3px); }
.drawer { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; }
.drawer[open] { display: flex; justify-content: flex-end; }
.drawer-panel { position: relative; width: min(580px, 92vw); height: 100%; overflow-y: auto; background: var(--paper); box-shadow: -18px 0 50px rgb(14 24 39 / 20%); animation: enter-right 180ms ease-out; }
@keyframes enter-right { from { transform: translateX(30px); opacity: .5; } }
.icon-button { position: absolute; z-index: 2; right: 14px; top: 14px; display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: 9px; cursor: pointer; background: rgb(255 255 255 / 88%); font-size: 1.35rem; }
.detail-head { display: grid; grid-template-columns: 126px 1fr; align-items: end; gap: 20px; padding: 26px 24px 18px; border-bottom: 1px solid var(--line); background: white; }
.detail-head .cover { border-radius: 8px; box-shadow: 0 8px 22px rgb(18 31 51 / 18%); }
.detail-head h2 { margin: 11px 0 0; font-family: Georgia, serif; font-size: 1.75rem; line-height: 1.08; }
.detail-head p { margin: 8px 0 0; color: var(--ink-soft); font-size: .85rem; }
.detail-body { padding: 22px 24px 36px; }
.details { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: white; }
.details div { display: grid; grid-template-columns: 110px 1fr; gap: 18px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.details div:last-child { border-bottom: 0; }
.details dt { color: var(--ink-soft); font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.details dd { margin: 0; font-size: .9rem; line-height: 1.42; }
.editor { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.editor .owned-toggle { min-height: 38px; color: var(--ink); font-size: .92rem; }
.field-label { display: block; margin: 14px 0 7px; font-size: .82rem; font-weight: 800; }
.save-hint { margin: 8px 0 0; color: var(--ink-soft); font-size: .75rem; }
.source-link { width: 100%; margin-top: 18px; }

.file-dialog { width: min(560px, calc(100% - 28px)); border-radius: 18px; color: var(--ink); }
.file-panel { position: relative; padding: 26px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 24px 80px rgb(14 24 39 / 24%); }
.file-panel h2 { margin: 6px 0 0; font-family: Georgia, serif; font-size: 1.75rem; }
.file-intro { margin: 10px 40px 18px 0; color: var(--ink-soft); line-height: 1.5; }
.file-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-choice { min-height: 112px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: #f9fbfc; text-align: left; }
.file-choice:hover { border-color: #c99b7c; background: #fffaf5; }
.file-choice strong, .file-choice span { display: block; }
.file-choice span { margin-top: 7px; color: var(--ink-soft); font-size: .79rem; line-height: 1.35; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.file-label { position: relative; overflow: hidden; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.fallback-note { margin-top: 12px; padding: 12px; border-radius: 10px; background: #fff4dc; color: #75531b; font-size: .83rem; line-height: 1.4; }
.compatibility { margin: 16px 0 0; color: var(--ink-soft); font-size: .74rem; line-height: 1.4; }
.startup-dialog { width: min(520px, calc(100% - 28px)); border-radius: 20px; color: var(--ink); }
.startup-dialog::backdrop { background: rgb(10 18 31 / 72%); backdrop-filter: blur(7px); }
.startup-panel { padding: 34px; border: 1px solid #d9b38f; border-radius: 20px; background: white; text-align: center; box-shadow: 0 30px 100px rgb(5 12 24 / 42%); }
.startup-symbol { display: grid; width: 58px; height: 58px; margin: 0 auto 18px; place-items: center; border-radius: 16px; background: var(--navy); color: #ef9461; font-size: 1.6rem; }
.startup-panel h2 { margin: 7px 0 0; font-family: Georgia, serif; font-size: 2rem; line-height: 1.1; }
.startup-panel > p:not(.eyebrow) { margin: 14px auto 24px; color: var(--ink-soft); line-height: 1.55; }
.startup-panel .button { width: 100%; }
.startup-primary { min-height: 50px; font-size: 1rem; }
.startup-panel .button-ghost { margin-top: 7px; color: var(--ink-soft); font-size: .8rem; }
.toast { position: fixed; z-index: 50; right: 18px; bottom: 18px; max-width: min(380px, calc(100% - 36px)); padding: 12px 16px; border-radius: 11px; background: var(--navy); color: white; box-shadow: 0 14px 40px rgb(14 24 39 / 25%); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1280px) {
  .summary { grid-template-columns: 1fr auto auto; }
  .file-status { grid-column: 1 / -1; border-top: 1px solid var(--line); border-left: 0; }
  .manual-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .filters { grid-template-columns: minmax(260px, 1.5fr) repeat(2, 1fr); }
  .search-field { grid-column: span 2; }
}
@media (max-width: 960px) {
  .manual-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat { min-width: 140px; padding-inline: 20px; }
}
@media (max-width: 720px) {
  .shell { width: min(100% - 24px, 1480px); }
  .topbar-inner { min-height: 68px; }
  .brand-icon, .brand-copy span { display: none; }
  .brand-copy h1 { font-size: 1.12rem; }
  #file-button-label { display: none; }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary-main { grid-column: span 2; }
  .stat { min-width: 0; border-top: 1px solid var(--line); }
  .stat:nth-child(2) { border-left: 0; }
  .file-status { grid-column: span 2; }
  .filters { position: static; grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: span 2; }
  .manual-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
  .card-body { min-height: 166px; padding: 10px; }
  .cover { height: 154px; }
  .cover img { max-width: 102px; max-height: 132px; }
  .drawer-panel { width: 100%; }
}
@media (max-width: 520px) {
  .manual-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-main, .stat, .file-status { padding: 17px; }
  .filters { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .detail-head { grid-template-columns: 100px 1fr; padding: 22px 18px 16px; }
  .detail-head h2 { font-size: 1.35rem; }
  .detail-body { padding-inline: 18px; }
  .details div { grid-template-columns: 84px 1fr; gap: 10px; }
  .file-actions { grid-template-columns: 1fr; }
  .file-panel { padding: 22px 18px; }
  .startup-panel { padding: 28px 20px 22px; }
  .startup-panel h2 { font-size: 1.65rem; }
  .startup-panel > p:not(.eyebrow) { font-size: .92rem; }
  .card-open .card-arrow { opacity: 1; }
}
@media (max-width: 370px) {
  .shell { width: calc(100% - 16px); }
  .manual-grid { gap: 8px; }
  .card-body { min-height: 174px; padding: 9px; }
  .cover { height: 140px; }
  .cover img { max-width: 92px; max-height: 120px; }
  .card-title { font-size: .94rem; }
  .badge { max-width: calc(100% - 32px); padding-inline: 6px; }
}
@media (pointer: coarse) {
  .card-arrow { opacity: 1; }
}
