:root {
  color-scheme: light;
  --bg: #f4ead8;
  --surface: #fffaf0;
  --surface-soft: #f8efdE;
  --ink: #28231d;
  --muted: #786f63;
  --line: rgba(56, 45, 34, .14);
  --coral: #d65a5d;
  --coral-deep: #9f393e;
  --sun: #f3bb19;
  --olive: #838b55;
  --olive-deep: #4f5731;
  --shadow: 0 10px 28px rgba(82, 57, 38, .10);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: calc(-12px - env(safe-area-inset-top)) -12px 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 14px;
  background: var(--coral);
  color: #fffaf0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid rgba(40, 35, 29, .86);
  border-radius: 8px;
  background: var(--sun);
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 4px 4px 0 rgba(40, 35, 29, .70);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  color: rgba(255, 250, 240, .82);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
}

h1 {
  margin: 1px 0 0;
  font-size: 25px;
  line-height: 1.04;
  font-weight: 860;
  letter-spacing: 0;
}

.icon-button {
  min-width: 42px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, .92);
  color: var(--coral-deep);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 760;
}

.search-panel,
.status,
.book-card,
.empty,
.recommend-box,
.genre-grid,
.sheet-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-panel {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 3;
  padding: 10px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
}

.search-form input,
.recommend-box textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  outline: none;
}

.search-form input:focus,
.recommend-box textarea:focus {
  border-color: rgba(214, 90, 93, .58);
  box-shadow: 0 0 0 3px rgba(214, 90, 93, .12);
}

.search-form input {
  min-height: 44px;
  padding: 10px 12px;
}

.search-form button,
.recommend-box button,
.recommend-cta,
.format-button,
.fav-button,
.genre-button {
  border: 1px solid rgba(56, 45, 34, .14);
  min-height: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 0 rgba(56, 45, 34, .16), 0 8px 18px rgba(82, 57, 38, .07);
  font-weight: 780;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease, border-color .12s ease;
}

.search-form button:active,
.recommend-box button:active,
.recommend-cta:active,
.quick-tabs button:active,
.book-main:active,
.format-button:active,
.fav-button:active,
.genre-button:active,
.icon-button:active,
.sheet-close:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(56, 45, 34, .14), 0 4px 12px rgba(82, 57, 38, .06);
}

.search-form button,
.recommend-box button {
  background: var(--coral);
  color: white;
  padding: 8px 12px;
}

.recommend-cta {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  margin-top: 9px;
  padding: 11px 12px;
  border-color: rgba(79, 87, 49, .28);
  background: #eef0d4;
  color: var(--olive-deep);
  text-align: left;
}

.recommend-cta span {
  font-size: 15px;
  font-weight: 850;
}

.recommend-cta small {
  margin-top: 1px;
  color: rgba(79, 87, 49, .76);
  font-size: 12px;
  font-weight: 650;
}

.recommend-cta.active {
  border-color: rgba(214, 90, 93, .36);
  background: #f7ded6;
  color: var(--coral-deep);
}

.quick-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding-top: 9px;
}

.quick-tabs button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: 0 2px 0 rgba(56, 45, 34, .12);
  padding: 7px 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease, border-color .12s ease;
}

.quick-tabs button.active {
  border-color: rgba(40, 35, 29, .18);
  background: var(--sun);
  color: var(--ink);
}

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 700;
}

.status.error {
  background: #fde9e6;
  color: var(--coral-deep);
}

.status.note {
  background: #eef0d4;
  color: var(--olive-deep);
}

.status a {
  margin-left: auto;
  border-radius: 7px;
  background: rgba(79, 87, 49, .14);
  color: var(--olive-deep);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 820;
  text-decoration: none;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(120, 111, 99, .25);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.content {
  display: grid;
  gap: 9px;
  padding-top: 12px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 1px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.18;
  font-weight: 850;
}

.section-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.book-card {
  overflow: hidden;
}

.book-main {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  min-height: 78px;
  padding: 11px 12px 9px;
  background: transparent;
  text-align: left;
  transition: background-color .12s ease, transform .12s ease;
}

.book-main:active {
  background: rgba(243, 187, 25, .10);
}

.book-cover,
.sheet-cover {
  display: grid;
  place-items: center;
  border: 1px solid rgba(40, 35, 29, .16);
  background:
    linear-gradient(135deg, rgba(214, 90, 93, .16), rgba(243, 187, 25, .22)),
    #f8efdE;
  color: rgba(40, 35, 29, .55);
  background-position: center;
  background-size: cover;
  font-weight: 900;
}

.book-cover {
  width: 54px;
  height: 72px;
  border-radius: 6px;
  font-size: 24px;
}

.book-cover.has-cover,
.sheet-cover.has-cover {
  color: transparent;
}

.book-copy {
  min-width: 0;
}

.book-title {
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.22;
  font-weight: 820;
}

.book-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.24;
}

.book-genres {
  min-height: 15px;
  margin-top: 7px;
  color: var(--olive-deep);
  font-size: 12px;
  font-weight: 720;
  line-height: 1.25;
}

.book-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 12px 11px 77px;
}

.format-button,
.fav-button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12.5px;
}

.format-button {
  border-color: rgba(79, 87, 49, .24);
  background: #eef0d4;
  color: var(--olive-deep);
}

.format-button:disabled {
  cursor: wait;
  opacity: .58;
}

.fav-button {
  border-color: rgba(214, 90, 93, .22);
  background: #f7ded6;
  color: var(--coral-deep);
}

.download-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: -2px 12px 11px 77px;
  border: 1px solid rgba(79, 87, 49, .20);
  border-radius: 8px;
  background: #eef0d4;
  color: var(--olive-deep);
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 760;
  line-height: 1.28;
}

.download-status[hidden] {
  display: none;
}

.download-status.error {
  border-color: rgba(214, 90, 93, .22);
  background: #fde9e6;
  color: var(--coral-deep);
}

.download-status.loading {
  color: var(--muted);
}

.download-status.success {
  color: var(--olive-deep);
}

.empty,
.recommend-box,
.recommend-summary {
  padding: 15px;
}

.empty {
  color: var(--muted);
}

.genre-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 10px;
}

.genre-button {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 9px;
  color: var(--ink);
  text-align: center;
}

.recommend-box label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 830;
}

.recommend-box textarea {
  min-height: 132px;
  resize: vertical;
  padding: 11px 12px;
}

.recommend-box button {
  width: 100%;
  margin-top: 10px;
}

.recommend-summary {
  border: 1px solid rgba(79, 87, 49, .20);
  border-radius: 8px;
  background: #eef0d4;
  color: var(--olive-deep);
  font-size: 14px;
  font-weight: 720;
}

.skeleton-list {
  display: grid;
  gap: 9px;
}

.skeleton-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 11px 12px;
  overflow: hidden;
}

.skeleton-cover,
.skeleton-lines i {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, #f0e3cf, #fff8ee, #f0e3cf);
  background-size: 240% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-cover {
  width: 54px;
  height: 72px;
}

.skeleton-lines {
  display: grid;
  align-content: start;
  gap: 9px;
  padding-top: 3px;
}

.skeleton-lines i {
  height: 12px;
}

.skeleton-lines i:nth-child(1) { width: 84%; }
.skeleton-lines i:nth-child(2) { width: 58%; }
.skeleton-lines i:nth-child(3) { width: 42%; }

@keyframes shimmer {
  to { background-position: -240% 0; }
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  background: rgba(28, 22, 17, .46);
  overscroll-behavior: contain;
}

.sheet[hidden] {
  display: none;
}

.sheet-panel {
  position: relative;
  width: min(680px, 100%);
  max-height: min(86vh, 760px);
  margin: 0 auto;
  overflow: auto;
  border-radius: 8px 8px 0 0;
  padding: 10px 12px calc(18px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  margin: 0 auto 12px;
  background: rgba(56, 45, 34, .22);
}

.sheet-close {
  position: sticky;
  top: 0;
  z-index: 2;
  float: right;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: -6px 0 4px 10px;
  border: 1px solid rgba(56, 45, 34, .12);
  border-radius: 999px;
  background: rgba(255, 250, 240, .94);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(82, 57, 38, .13);
  font-size: 27px;
  line-height: 1;
  font-weight: 420;
}

.sheet-hero {
  clear: both;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 13px;
  align-items: start;
  padding-top: 2px;
}

.sheet-cover {
  width: 96px;
  min-height: 136px;
  border-radius: 7px;
  font-size: 36px;
}

.sheet-title {
  min-width: 0;
}

.sheet h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.12;
  font-weight: 880;
}

.sheet-actions {
  padding: 14px 0 0;
}

.sheet-panel .download-status {
  margin: 9px 0 0;
}

.sheet .description {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  white-space: pre-wrap;
}

.sheet-loading {
  clear: both;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 13px;
  align-items: start;
}

.sheet-skeleton-cover {
  display: grid;
  place-items: center;
  width: 82px;
  min-height: 118px;
  border: 1px solid rgba(40, 35, 29, .16);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(214, 90, 93, .16), rgba(243, 187, 25, .22)),
    #f8efdE;
  color: rgba(40, 35, 29, .45);
  font-size: 32px;
  font-weight: 900;
}

.sheet-loading-copy {
  min-width: 0;
  padding-top: 2px;
}

.sheet-loading-title {
  color: var(--ink);
  font-size: 19px;
  line-height: 1.14;
  font-weight: 860;
}

.sheet-loading-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.sheet-loading-lines {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.sheet-loading-lines i {
  display: block;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f0e3cf, #fff8ee, #f0e3cf);
  background-size: 240% 100%;
  animation: shimmer 1.2s linear infinite;
}

.sheet-loading-lines i:nth-child(1) { width: 94%; }
.sheet-loading-lines i:nth-child(2) { width: 76%; }
.sheet-loading-lines i:nth-child(3) { width: 54%; }

.sheet-error {
  clear: both;
  display: grid;
  gap: 7px;
  border: 1px solid rgba(214, 90, 93, .20);
  border-radius: 8px;
  background: #fde9e6;
  color: var(--coral-deep);
  padding: 14px;
}

.sheet-error strong {
  color: var(--ink);
}

@media (max-width: 430px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 23px;
  }

  .icon-button {
    width: 38px;
    padding: 0;
    font-size: 0;
  }

  .icon-button::before {
    content: "↻";
    font-size: 18px;
    font-weight: 900;
  }

  .quick-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .genre-grid {
    grid-template-columns: 1fr;
  }

  .sheet-hero {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .sheet-cover {
    width: 82px;
    min-height: 118px;
  }
}
