:root {
  --bg: #030b20;
  --surface: #07142f;
  --surface-2: #0a1938;
  --surface-3: #0d2044;
  --line: #18315d;
  --line-soft: rgba(102, 130, 183, .2);
  --text: #f4f7ff;
  --muted: #8493b1;
  --purple: #7157f5;
  --purple-bright: #8c72ff;
  --yellow: #ffbd21;
  --pink: #ff4f82;
  --danger: #ff6a78;
  --radius: 14px;
  --focus: 0 0 0 3px rgba(140, 114, 255, .42);
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    radial-gradient(circle at 20% -10%, rgba(38, 56, 113, .32), transparent 28rem),
    var(--bg);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
:focus-visible { outline: 0; box-shadow: var(--focus); }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link:focus { position: fixed; z-index: 100; top: 12px; left: 12px; padding: 10px 14px; border-radius: 8px; background: var(--purple); color: white; }

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.app-header { min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 28px; border-bottom: 1px solid var(--line-soft); }
.brand { display: flex; align-items: center; gap: 11px; color: white; text-decoration: none; }
.brand__mark { font-size: 32px; filter: drop-shadow(0 0 12px rgba(113,87,245,.35)); }
.brand strong { display: block; font-family: "Segoe Script", "Bradley Hand", cursive; font-size: 19px; line-height: 1; }
.brand small { display: block; margin-top: 5px; color: #a5afc4; font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.sync-status { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 6px 9px; color: #86d7b0; background: rgba(45,171,111,.1); border: 1px solid rgba(45,171,111,.24); border-radius: 999px; white-space: nowrap; }
.sync-status span { font-size: 13px; }
.sync-status small { font-size: 9px; font-weight: 700; }
.sync-status.is-syncing { color: #d8bd71; background: rgba(255,189,33,.08); border-color: rgba(255,189,33,.2); }
.sync-status.is-error, .sync-status.is-local { color: #8e9bb5; background: rgba(126,145,179,.08); border-color: rgba(126,145,179,.2); }
.desktop-nav { display: flex; align-self: stretch; gap: 6px; }
.nav-item { min-width: 78px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 9px 13px; color: var(--muted); background: transparent; border: 0; border-radius: 9px; text-decoration: none; cursor: pointer; font-size: 11px; font-weight: 600; }
.nav-item span { font-size: 20px; line-height: 1; }
.nav-item:hover, .nav-item.is-active { color: #b7abff; background: rgba(113,87,245,.13); }
.nav-item--muted { cursor: default; }

main { padding: 28px 0 96px; }
.profile-card { display: flex; align-items: stretch; overflow: hidden; background: linear-gradient(110deg, #081936, #06122c); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 14px 45px rgba(0,0,0,.24); }
.profile-card__intro { min-width: 340px; display: flex; align-items: center; gap: 16px; padding: 22px 25px; }
.avatar { width: 72px; height: 72px; display: grid; place-items: center; flex: none; overflow: hidden; background: radial-gradient(circle at 60% 30%, #ffb04b, #6e3fd4 70%); border: 3px solid #283d70; border-radius: 50%; font-size: 45px; }
.profile-card h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.profile-card h1 span { font-size: 17px; }
.profile-card p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.stats { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); }
.stat { display: flex; flex-direction: column; justify-content: center; padding: 20px; border-left: 1px solid var(--line-soft); text-align: center; }
.stat small { color: #9ba8c2; font-size: 11px; }
.stat strong { margin-top: 7px; font-size: 27px; line-height: 1; }
.stat strong em { color: var(--muted); font-size: 11px; font-style: normal; font-weight: 500; }
.star { color: var(--yellow); font-style: normal; }
.heart { color: var(--pink); font-style: normal; }

.library { padding-top: 24px; }
.library__toolbar { display: flex; align-items: center; gap: 10px; }
.filters { display: flex; gap: 7px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter { flex: none; min-height: 34px; padding: 6px 13px; color: #9ba9c7; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 11px; font-weight: 650; }
.filter:hover { color: white; border-color: #3b5790; }
.filter.is-active { color: white; background: var(--purple); border-color: var(--purple); box-shadow: 0 7px 22px rgba(113,87,245,.22); }
.filter span { margin-left: 4px; opacity: .75; }
.search { min-width: 185px; display: flex; align-items: center; gap: 6px; margin-left: auto; padding: 0 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.search:focus-within { border-color: var(--purple); box-shadow: var(--focus); }
.search input { width: 100%; height: 34px; padding: 0; color: var(--text); background: transparent; border: 0; outline: 0; font-size: 11px; }
.view-toggle { width: 34px; height: 34px; padding: 0; color: #9ba9c7; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin: 28px 0 18px; }
.section-heading p { margin: 0 0 3px; color: var(--purple-bright); font-size: 10px; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.section-heading h2 { margin: 0; font-size: 22px; }

.button { min-height: 38px; padding: 8px 16px; border: 0; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 12px; transition: transform .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button--primary { color: white; background: linear-gradient(100deg, #7657ef, #523bd3); box-shadow: 0 8px 22px rgba(82,59,211,.28); }
.button--primary:hover { background: linear-gradient(100deg, #8569ff, #6046e1); }
.button--ghost { color: #b8c2d7; background: #102142; border: 1px solid var(--line); }
.button--danger { color: #ff8591; background: transparent; border: 1px solid rgba(255,106,120,.45); }
.button--danger-solid { color: white; background: #c94152; }

.book-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.book-card { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; transition: border-color .16s ease, transform .16s ease; }
.book-card:hover { border-color: #425a94; transform: translateY(-3px); }
.book-card__open { width: 100%; display: block; padding: 0; text-align: left; background: none; border: 0; cursor: pointer; }
.cover { position: relative; aspect-ratio: 3 / 4; display: block; overflow: hidden; background: #0c1d3d; }
.cover--fallback { background: radial-gradient(circle at 72% 18%, hsla(var(--cover-hue, 250), 75%, 58%, .52), transparent 36%), linear-gradient(150deg, hsl(var(--cover-hue, 250), 48%, 30%), #071027 72%); }
.cover--fallback::before { content: attr(data-symbol); position: absolute; top: 28%; left: 50%; transform: translate(-50%, -50%); font-size: 50px; filter: drop-shadow(0 8px 16px rgba(0,0,0,.35)); }
.cover__image { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .35s ease; }
.book-card:hover .cover__image { transform: scale(1.035); }
.cover__shade { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.04) 38%, rgba(1,5,15,.92) 100%); }
.cover__copy { position: absolute; inset: auto 12px 13px; z-index: 1; display: block; text-shadow: 0 2px 6px rgba(0,0,0,.8); }
.cover__title { display: block; font-size: clamp(14px, 1.55vw, 20px); font-weight: 900; line-height: 1.04; text-transform: uppercase; overflow-wrap: anywhere; }
.cover__author { display: block; margin-top: 6px; color: rgba(255,255,255,.78); font-size: 8px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.cover__favorite { position: absolute; z-index: 2; right: 9px; top: 9px; width: 27px; height: 27px; display: none; place-items: center; color: var(--pink); background: rgba(3,11,32,.8); border: 1px solid rgba(255,255,255,.18); border-radius: 50%; }
.cover__favorite.is-visible { display: grid; }
.book-card__meta { min-height: 68px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 4px 8px; padding: 9px 11px 10px; }
.book-card__date { grid-column: 1 / -1; color: #d4a92e; font-size: 9px; font-weight: 750; text-transform: uppercase; }
.book-card__rating { color: var(--yellow); font-size: 15px; letter-spacing: .7px; white-space: nowrap; }
.book-card__rating .empty-rating { color: #667596; font-size: 14px; }
.book-card__mood { max-width: 88px; overflow: hidden; font-size: 16px; white-space: nowrap; text-overflow: clip; }
.book-card__mood small { margin-left: 2px; color: #8e9dbc; font-size: 9px; vertical-align: middle; }
.book-card.is-unread { border-color: #15294d; }
.book-card.is-unread .cover__image { filter: saturate(.55) brightness(.72); }
.book-card.is-unread .cover__shade { background: linear-gradient(to bottom, rgba(1,7,20,.2) 30%, rgba(1,5,15,.96) 100%); }
.book-card.is-unread .book-card__date { color: #7888a8; }
.add-tile { width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 9px; margin-top: 16px; color: #9b86ff; background: transparent; border: 1px dashed #4c39b8; border-radius: 9px; cursor: pointer; font-size: 12px; font-weight: 650; }
.add-tile:hover { color: white; background: rgba(113,87,245,.08); border-color: var(--purple); }
.add-tile span { font-size: 22px; font-weight: 300; }
.empty-state { padding: 60px 24px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-state > span { font-size: 38px; }
.empty-state h3 { margin: 8px 0 4px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); }
.quote-card { position: relative; display: flex; align-items: center; gap: 11px; margin-top: 17px; padding: 13px 46px 13px 18px; color: #a9b5cd; background: #07142c; border: 1px solid #142a51; border-radius: 9px; }
.quote-card > span { color: #60739d; font-size: 26px; }
.quote-card p { margin: 0; font-size: 11px; font-style: italic; }
.quote-card small { margin-left: auto; color: #667596; white-space: nowrap; font-size: 9px; }
.quote-card .icon-button { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); }
.quote-card[hidden] { display: none; }
.icon-button, .back-button, .more-button { border: 0; background: transparent; color: #aab5ca; cursor: pointer; }
.icon-button { width: 28px; height: 28px; border-radius: 6px; font-size: 20px; }

.mobile-nav { display: none; }

.dialog { width: min(520px, 100%); height: 100dvh; max-height: none; margin: 0 0 0 auto; padding: 0; color: var(--text); background: #050e26; border: 0; border-left: 1px solid #283b72; box-shadow: -25px 0 70px rgba(0,0,0,.5); }
.dialog::backdrop, .confirm-dialog::backdrop { background: rgba(0,3,13,.76); backdrop-filter: blur(3px); }
.dialog form { min-height: 100%; }
.dialog__header { height: 68px; display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.dialog__header h2 { margin: 0; text-align: center; font-size: 16px; }
.back-button, .more-button { width: 38px; height: 38px; border-radius: 8px; font-size: 21px; }
.more-button { font-size: 14px; }
.dialog__body { padding: 22px 24px 32px; }
.detail-summary { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 18px; align-items: center; padding: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.detail-summary img { width: 112px; aspect-ratio: 2 / 3; display: block; object-fit: cover; border-radius: 7px; box-shadow: 0 12px 28px rgba(0,0,0,.3); }
.detail-summary h3 { margin: 9px 0 4px; font-size: 19px; line-height: 1.14; }
.detail-summary p { margin: 0; color: #9ba8c2; font-size: 11px; }
.detail-summary__contents { margin-top: 10px !important; color: #7585a6 !important; line-height: 1.45; }
.read-status { display: inline-flex; padding: 4px 8px; color: #f5c94a; background: rgba(255,189,33,.1); border: 1px solid rgba(255,189,33,.25); border-radius: 999px; font-size: 9px; font-weight: 750; text-transform: uppercase; }
.read-status.is-unread { color: #94a1bb; background: rgba(123,140,174,.08); border-color: rgba(123,140,174,.25); }
.reading-fields { display: grid; grid-template-columns: 1fr 1fr; align-items: stretch; gap: 10px; margin-top: 16px; }
.reading-fields .check-card { min-height: 64px; }
.reading-fields .field--date { padding: 9px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.reading-fields .field--date > span { margin-bottom: 4px; }
.reading-fields .field--date input { height: 34px; }
.reading-fields .field--date[hidden] { display: none; }
.check-card--read .check-card__icon { color: var(--yellow); background: rgba(255,189,33,.1); }
.reading-duration { min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 9px 12px; color: #8796b4; background: rgba(9,25,56,.72); border: 1px solid var(--line); border-radius: 8px; }
.reading-duration > span { width: 31px; height: 31px; display: grid; place-items: center; flex: none; color: #9b86ff; background: rgba(113,87,245,.12); border-radius: 7px; font-size: 19px; }
.reading-duration small, .reading-duration strong { display: block; }
.reading-duration small { font-size: 8px; }
.reading-duration strong { margin-top: 2px; color: #e8edfa; font-size: 11px; }
.reading-duration.is-warning strong { color: #ff9ba5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.field { position: relative; display: block; }
.field--wide { grid-column: 1 / -1; }
.field > span, .choice-group legend { display: block; margin-bottom: 6px; color: #c1c9d9; font-size: 10px; font-weight: 700; }
.field b { color: var(--pink); }
.field input, .field textarea { width: 100%; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; outline: 0; }
.field input { height: 41px; padding: 0 11px; }
.field textarea { display: block; padding: 11px 11px 25px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #58698e; }
.field input:focus, .field textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(113,87,245,.2); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field__error { display: block; min-height: 16px; color: var(--danger); font-size: 10px; }
.choice-group { min-width: 0; margin: 17px 0 0; padding: 0; border: 0; }
.stars-input { display: flex; align-items: center; gap: 4px; }
.stars-input button:not(.clear-rating) { width: 34px; height: 34px; padding: 0; color: #765cff; background: transparent; border: 0; cursor: pointer; font-size: 29px; line-height: 1; }
.stars-input button.is-selected { color: var(--yellow); }
.clear-rating { margin-left: 8px; color: #7181a1; background: transparent; border: 0; text-decoration: underline; cursor: pointer; font-size: 10px; }
.mood-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.mood-picker button { width: 39px; height: 39px; padding: 0; background: var(--surface-2); border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-size: 22px; transition: transform .14s ease, background .14s ease; }
.mood-picker button:hover { transform: translateY(-1px); }
.mood-picker button.is-selected { background: rgba(113,87,245,.2); border-color: var(--purple); }
.field--comment { margin-top: 17px; }
.counter { position: absolute; right: 10px; bottom: 7px; color: #667596; font-size: 9px; }
.toggle-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.check-card { position: relative; min-height: 58px; display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.check-card:has(input:checked) { background: rgba(113,87,245,.13); border-color: var(--purple); }
.check-card input { position: absolute; opacity: 0; }
.check-card:has(input:focus-visible) { box-shadow: var(--focus); }
.check-card__icon { width: 31px; height: 31px; display: grid; place-items: center; flex: none; color: var(--pink); background: rgba(255,79,130,.1); border-radius: 7px; }
.check-card strong, .check-card small { display: block; }
.check-card strong { font-size: 10px; }
.check-card small { margin-top: 2px; color: #7181a1; font-size: 8px; }
.dialog__actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.dialog__spacer { flex: 1; }
.confirm-dialog { width: min(390px, calc(100% - 28px)); padding: 0; color: var(--text); background: #081630; border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 25px 75px rgba(0,0,0,.5); text-align: center; }
.confirm-dialog > div { padding: 30px; }
.confirm-dialog__icon { font-size: 36px; }
.confirm-dialog h2 { margin: 7px 0; font-size: 20px; }
.confirm-dialog p { margin: 0; color: var(--muted); font-size: 12px; }
.confirm-dialog .dialog__actions { justify-content: center; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; padding: 10px 16px; color: white; background: #192951; border: 1px solid #334a7b; border-radius: 8px; box-shadow: 0 14px 35px rgba(0,0,0,.35); font-size: 12px; font-weight: 650; transform: translate(-50%, 80px); opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 900px) {
  .app-shell { width: min(100% - 28px, 760px); }
  .desktop-nav { display: none; }
  .profile-card { display: block; }
  .profile-card__intro { min-width: 0; }
  .stats { border-top: 1px solid var(--line-soft); }
  .stat:first-child { border-left: 0; }
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  body { background: var(--bg); font-size: 14px; }
  .app-shell { width: 100%; }
  .app-header { min-height: 64px; padding: 0 16px; }
  .brand__mark { font-size: 26px; }
  .brand strong { font-size: 16px; }
  .brand small { font-size: 7px; }
  .sync-status { margin-left: auto; padding: 5px 7px; }
  .sync-status small { max-width: 88px; overflow: hidden; text-overflow: ellipsis; }
  main { padding: 15px 12px 95px; }
  .profile-card__intro { padding: 16px; }
  .avatar { width: 58px; height: 58px; font-size: 36px; }
  .profile-card h1 { font-size: 17px; }
  .profile-card p { font-size: 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat { min-height: 80px; padding: 13px 8px; }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .stat strong { font-size: 23px; }
  .library { padding-top: 14px; }
  .library__toolbar { align-items: stretch; flex-wrap: wrap; }
  .filters { width: 100%; order: 2; }
  .search { flex: 1; margin: 0; }
  .section-heading { margin: 20px 0 12px; }
  .section-heading h2 { font-size: 19px; }
  .button--desktop, .view-toggle { display: none; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cover__title { font-size: clamp(13px, 4.1vw, 17px); }
  .book-card__meta { min-height: 60px; padding: 8px; }
  .book-card__rating { font-size: 13px; }
  .quote-card { display: block; padding: 14px 40px 14px 15px; }
  .quote-card > span { display: none; }
  .quote-card small { display: block; margin: 6px 0 0; }
  .mobile-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; min-height: 67px; display: grid; grid-template-columns: repeat(4, 1fr); align-items: end; padding: 7px 8px max(7px, env(safe-area-inset-bottom)); background: rgba(4,13,34,.97); border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
  .mobile-nav a, .mobile-nav button, .mobile-nav > span { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px; color: #7483a3; background: transparent; border: 0; text-decoration: none; font-size: 8px; }
  .mobile-nav a span, .mobile-nav button span, .mobile-nav > span b { font-size: 18px; font-weight: 400; }
  .mobile-nav .is-active { color: #907cff; }
  .dialog { width: 100%; border-left: 0; }
  .dialog__header { height: 60px; }
  .dialog__body { padding: 18px 15px 90px; }
  .detail-summary { grid-template-columns: 88px minmax(0,1fr); gap: 13px; padding: 10px; }
  .detail-summary img { width: 88px; }
  .detail-summary h3 { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .toggle-row { grid-template-columns: 1fr; }
  .reading-fields { grid-template-columns: 1fr; }
  .dialog__actions { position: sticky; bottom: 0; padding: 12px 0 max(12px, env(safe-area-inset-bottom)); background: #050e26; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
