/* Biblio design system: CSS variables for theme, everything else built on them. */

:root {
  --bg: #f6f5f2;
  --bg-elevated: #ffffff;
  --bg-sunken: #efeee9;
  --border: #e3e1da;
  --text: #211f1c;
  --text-muted: #6b6862;
  --text-faint: #9c988f;
  --accent: #7a4f2b;
  --accent-strong: #5c3a1e;
  --accent-soft: #f1e4d5;
  --success: #3f7a4f;
  --success-soft: #e3f0e6;
  --danger: #b5473a;
  --danger-soft: #fbe8e5;
  --warn: #b8862f;
  --warn-soft: #faf0dd;
  --info: #3a6f8f;
  --info-soft: #e4eff5;
  --shadow: 0 1px 2px rgba(30, 25, 15, 0.06), 0 8px 24px -12px rgba(30, 25, 15, 0.18);
  --shadow-lg: 0 4px 12px rgba(30, 25, 15, 0.08), 0 24px 48px -16px rgba(30, 25, 15, 0.28);
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

:root[data-theme="dark"] {
  --bg: #1a1815;
  --bg-elevated: #242220;
  --bg-sunken: #14130f;
  --border: #35322c;
  --text: #ede9e1;
  --text-muted: #a8a29a;
  --text-faint: #726d63;
  --accent: #d29b63;
  --accent-strong: #e6b483;
  --accent-soft: #3a2c1c;
  --success: #7bbd8a;
  --success-soft: #1e2f21;
  --danger: #e08579;
  --danger-soft: #3a2220;
  --warn: #e0b768;
  --warn-soft: #382c17;
  --info: #7fb3d1;
  --info-soft: #1c2e38;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.3), 0 24px 48px -16px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1815; --bg-elevated: #242220; --bg-sunken: #14130f; --border: #35322c;
    --text: #ede9e1; --text-muted: #a8a29a; --text-faint: #726d63;
    --accent: #d29b63; --accent-strong: #e6b483; --accent-soft: #3a2c1c;
    --success: #7bbd8a; --success-soft: #1e2f21;
    --danger: #e08579; --danger-soft: #3a2220;
    --warn: #e0b768; --warn-soft: #382c17;
    --info: #7fb3d1; --info-soft: #1c2e38;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.3), 0 24px 48px -16px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 600; margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }

/* ---- layout ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: none; background: var(--bg-elevated); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 700; padding: 4px 10px 18px; }
.sidebar-brand span { color: var(--accent-strong); }
.nav-group { margin-bottom: 18px; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 0 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .92rem; font-weight: 500;
}
.nav-link:hover { background: var(--bg-sunken); text-decoration: none; color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon { width: 18px; text-align: center; opacity: .85; }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--bg-elevated);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.2rem; }
.content { padding: 24px; max-width: 1180px; }
.content-narrow { max-width: 640px; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .content { padding: 16px; }
}

/* ---- primitives ---- */
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 700px) { .grid-cols-2, .grid-cols-3 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 1.15rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-family: inherit; font-size: .92rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row > .field { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; background: var(--bg-sunken); color: var(--text-muted);
}
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); font-size: .8rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 10px; }

.flash { padding: 10px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .88rem; font-weight: 500; }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-success { background: var(--success-soft); color: var(--success); }

/* ---- book cover ---- */
.cover {
  width: 100%; aspect-ratio: 2 / 3; border-radius: var(--radius-sm); object-fit: cover;
  background: linear-gradient(135deg, var(--accent-soft), var(--bg-sunken));
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.cover-placeholder { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 700; color: var(--accent-strong); text-align: center; padding: 10px; }
.cover-sm { width: 44px; aspect-ratio: 2/3; border-radius: 5px; flex: none; }

/* ---- shelf grid ---- */
.book-tile { cursor: pointer; }
.book-tile img, .book-tile .cover { margin-bottom: 8px; }
.book-tile .title { font-weight: 600; font-size: .88rem; line-height: 1.3; }
.book-tile .author { color: var(--text-muted); font-size: .8rem; }

/* ---- stats ---- */
.stat-tile { padding: 16px 18px; }
.stat-value { font-family: var(--font-serif); font-size: 1.8rem; font-weight: 700; }
.stat-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.progress-track { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }

/* ---- swipeable recommendation deck ---- */
.deck-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 10px 0 40px; }
.deck {
  position: relative; width: min(360px, 90vw); height: min(560px, 72vh);
}
.deck-card {
  position: absolute; inset: 0; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  overflow: hidden; touch-action: none; user-select: none; will-change: transform;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .35s ease;
}
.deck-card.dragging { transition: none; cursor: grabbing; }
.deck-card .cover-area { flex: 1; position: relative; background: linear-gradient(160deg, var(--accent-soft), var(--bg-sunken)); }
.deck-card .cover-area img { width: 100%; height: 100%; object-fit: cover; }
.deck-card .cover-fallback {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-size: 2.4rem; font-weight: 700; color: var(--accent-strong); text-align: center; padding: 24px;
}
.deck-card .info { padding: 16px 18px 18px; background: var(--bg-elevated); }
.deck-card .info h3 { margin-bottom: 2px; }
.deck-card .meta { color: var(--text-muted); font-size: .85rem; margin-bottom: 8px; }
.deck-card .reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.stamp {
  position: absolute; top: 26px; padding: 8px 16px; border: 4px solid; border-radius: 10px;
  font-family: var(--font-serif); font-weight: 800; font-size: 1.4rem; letter-spacing: .04em;
  text-transform: uppercase; opacity: 0; transform: rotate(-18deg);
}
.stamp-right { right: 20px; border-color: var(--success); color: var(--success); transform: rotate(14deg); }
.stamp-left { left: 20px; border-color: var(--danger); color: var(--danger); transform: rotate(-14deg); }
.stamp-up { left: 50%; transform: translateX(-50%) rotate(-4deg); border-color: var(--info); color: var(--info); }
.stamp-down { left: 50%; transform: translateX(-50%) rotate(4deg); border-color: var(--warn); color: var(--warn); }

.deck-actions { display: flex; gap: 14px; align-items: center; }
.deck-actions .btn-icon { width: 54px; height: 54px; font-size: 1.35rem; box-shadow: var(--shadow); }
.deck-actions .btn-icon.wishlist { color: var(--info); }
.deck-actions .btn-icon.not-interested { color: var(--danger); }
.deck-actions .btn-icon.already-own { color: var(--warn); }
.deck-actions .btn-icon.purchased { color: var(--success); }
.deck-empty { text-align: center; color: var(--text-muted); padding: 60px 20px; }

/* ---- utility ---- */
.hidden { display: none !important; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; padding: 4px; }
.icon-btn:hover { color: var(--text); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
tr:last-child td { border-bottom: none; }
