:root {
  --green: #2d6a4f;
  --green-dark: #1b4332;
  --green-light: #d8f3dc;
  --bg: #f5f5f5;
  --card: #fff;
  --text: #333;
  --muted: #777;
  --warn: #b35c00;
  --danger: #c0392b;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; } /* author display rules must not override hidden */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

a { color: var(--green); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--card); padding: 0.6rem 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}
.brand { font-weight: 700; font-size: 1.25rem; text-decoration: none; color: var(--green-dark); margin-right: auto; }
.icon-link { font-size: 1.4rem; text-decoration: none; color: var(--text); }
.sync-badge { border: none; background: var(--green-light); color: var(--green-dark); border-radius: 999px; padding: 0.2rem 0.7rem; font-size: 0.85rem; }
.sync-badge[data-state="pending"], .sync-badge[data-state="error"] { background: #ffe8cc; color: var(--warn); }

.banner { background: var(--green-dark); color: #fff; padding: 0.6rem 1rem; display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; }

main { padding: 0.75rem 1rem; max-width: 720px; margin: 0 auto; }

.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--card); border-top: 1px solid #ddd;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0.4rem 0; font-size: 0.75rem; text-decoration: none; color: var(--text); }
.nav-icon { font-size: 1.4rem; line-height: 1.2; }
.nav-btn.primary { background: var(--green); color: #fff; font-weight: 600; }

.btn {
  display: inline-block; background: var(--card); color: var(--green-dark);
  border: 1px solid var(--green); border-radius: var(--radius);
  padding: 0.5rem 0.9rem; font-size: 1rem; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.big { width: 100%; padding: 0.8rem; font-size: 1.1rem; }
.btn.small { padding: 0.15rem 0.5rem; font-size: 0.85rem; }
.btn.icon { padding: 0.5rem 0.7rem; }

input, select, textarea {
  width: 100%; font: inherit; padding: 0.55rem 0.7rem;
  border: 1px solid #ccc; border-radius: var(--radius); background: #fff;
}
input[type="checkbox"] { width: auto; }
input[type="file"] { border: none; padding: 0.3rem 0; }

.card { background: var(--card); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); }
.form { display: flex; flex-direction: column; gap: 0.6rem; }
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 0.6rem; }
.field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; color: var(--muted); }
.field > input, .field > textarea, .field > select { color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.muted { color: var(--muted); }
h2 { font-size: 1.2rem; margin-bottom: 0.5rem; }
h3 { font-size: 1rem; margin: 0.5rem 0; }

.searchbar { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.search { font-size: 1.05rem; }
.chips { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.4rem; margin-bottom: 0.4rem; }
.chip { flex: none; width: auto; border: 1px solid #ccc; background: #fff; border-radius: 999px; padding: 0.25rem 0.75rem; font-size: 0.85rem; white-space: nowrap; }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }

.hit > div { border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.6rem; font-weight: 600; }
.hit .ok { background: var(--green-light); color: var(--green-dark); }
.hit .ko { background: #ffe8cc; color: var(--warn); }

.results { display: flex; flex-direction: column; gap: 0.4rem; }
.series-card {
  display: flex; align-items: center; gap: 0.6rem; background: var(--card); border-radius: var(--radius);
  padding: 0.7rem 0.8rem; text-decoration: none; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.series-name { font-weight: 600; margin-right: auto; }
.series-count { color: var(--muted); font-size: 0.9rem; }
.badge { border-radius: 999px; padding: 0 0.5rem; font-size: 0.85rem; }
.badge.ok { background: var(--green-light); color: var(--green-dark); }
.badge.warn { background: #ffe8cc; color: var(--warn); }

.book-row { display: flex; align-items: center; gap: 0.7rem; background: var(--card); border-radius: var(--radius); padding: 0.4rem 0.6rem; cursor: pointer; }
.book-text { min-width: 0; }
.book-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.book-meta { color: var(--muted); font-size: 0.85rem; }

.cover { flex: none; border-radius: 3px; object-fit: cover; background: #eee; }
.cover.small { width: 40px; height: 58px; }
.cover.large { width: 120px; height: 175px; }
.cover.placeholder {
  display: flex; flex-direction: column; justify-content: space-between; overflow: hidden;
  background: hsl(var(--hue) 45% 42%); color: #fff; padding: 3px; font-size: 0.55rem; line-height: 1.1;
}
.cover.large.placeholder { font-size: 0.9rem; padding: 8px; }
.ph-label { font-weight: 700; font-size: 0.8rem; align-self: flex-end; }

.more { margin: 0.5rem auto; display: block; }
.version { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 1rem; }

.assign-bar { position: sticky; bottom: 80px; display: flex; justify-content: space-between; align-items: center; background: var(--green-dark); color: #fff; padding: 0.6rem 0.8rem; border-radius: var(--radius); margin-top: 0.5rem; }

dialog.sheet { margin: auto; width: min(92vw, 520px); border: none; border-radius: var(--radius); padding: 1rem; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog .row { display: grid; grid-template-columns: 1fr 5rem; gap: 0.5rem; align-items: center; margin: 0.3rem 0; }

.overlay { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; display: flex; flex-direction: column; gap: 0.75rem; padding: 1rem; align-items: center; justify-content: center; }
.camera { width: 100%; max-height: 45vh; object-fit: cover; border-radius: var(--radius); background: #000; }
.camera-error { background: #ffe8cc; color: var(--warn); padding: 0.75rem; border-radius: var(--radius); }

.burst { display: flex; flex-direction: column; gap: 0.6rem; }
.burst > .field { flex-direction: row; align-items: center; gap: 0.4rem; font-size: 1.1rem; }
.manual-isbn { display: flex; gap: 0.5rem; }
.scan-log { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }
.scan { display: flex; align-items: center; gap: 0.5rem; background: var(--card); border-radius: var(--radius); padding: 0.45rem 0.6rem; }
.scan > a { margin-right: auto; text-decoration: none; color: var(--text); }
.scan.duplicate { background: #eef; }
.scan.notfound { background: #ffe8cc; }
.scan.cancelled { opacity: 0.5; text-decoration: line-through; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 0.5rem; margin: 0.75rem 0; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.8rem; text-decoration: none; color: var(--text); border-radius: 4px; padding: 3px; background: var(--card); border: 1px solid transparent; }
.slot.missing { border: 2px dashed #bbb; min-height: 80px; justify-content: center; font: inherit; color: var(--muted); cursor: pointer; }
.slot.wish { border: 2px solid #e0b000; min-height: 80px; justify-content: center; }
.slot .lent { font-size: 0.7rem; color: var(--warn); }
.wish-line { display: block; background: var(--card); border-radius: var(--radius); padding: 0.6rem 0.8rem; margin-bottom: 0.4rem; text-decoration: none; color: var(--text); }

.book-head { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 0.75rem; }
.cover-choices { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.cover-choices img { width: 70px; height: 100px; object-fit: cover; border-radius: 3px; cursor: pointer; border: 2px solid transparent; }
.cover-choices img:hover { border-color: var(--green); }

.onboarding { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 2rem; }
.fatal { color: var(--danger); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 30;
  background: #222; color: #fff; padding: 0.55rem 1rem; border-radius: 999px; max-width: 90vw; text-align: center;
}
.toast.error { background: var(--danger); }
