:root {
  --bg: #0d1219;
  --bg-alt: #141a24;
  --card-bg: #1b2431;
  --fg: #e9e6df;
  --muted: #9aa5b1;
  --accent: #c9a24b;
  --accent-soft: rgba(201, 162, 75, 0.15);
  --border: rgba(255, 255, 255, 0.09);
  --danger: #d16a6a;
  --ok: #6ac48a;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
header.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13, 18, 25, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
}
.site-header .brand {
  font-family: var(--serif);
  font-size: 1.3rem;
  letter-spacing: 0.5px;
  color: var(--fg);
}
.site-header .brand strong { color: var(--accent); }
.site-header nav a {
  color: var(--muted);
  margin-left: 22px;
  font-size: 0.95rem;
}
.site-header nav a:hover { color: var(--accent); text-decoration: none; }

.cart-btn {
  margin-left: 22px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 7px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.9rem;
  vertical-align: middle;
}
.cart-btn:hover { border-color: var(--accent); }
.cart-count {
  display: inline-block;
  background: var(--accent);
  color: #14181f;
  font-size: 0.72rem;
  font-weight: bold;
  padding: 1px 7px;
  border-radius: 20px;
  margin-left: 4px;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.qty-stepper button {
  background: var(--card-bg);
  border: none;
  color: var(--fg);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 1rem;
}
.qty-stepper button:hover { background: var(--accent-soft); color: var(--accent); }
.qty-stepper span {
  min-width: 26px;
  text-align: center;
  font-size: 0.85rem;
}

.cart-line {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-line img { width: 46px; height: 68px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.cart-line .info { flex: 1; min-width: 0; }
.cart-line .info .title { font-size: 0.92rem; }
.cart-line .info .price { color: var(--muted); font-size: 0.8rem; }
.cart-line .remove-line { color: var(--danger); cursor: pointer; font-size: 0.78rem; background: none; border: none; padding: 0; }

/* Hero */
.hero {
  padding: 76px 0 56px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: radial-gradient(ellipse at top, var(--bg-alt), var(--bg) 70%);
}
.hero .tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.6rem;
  max-width: 620px;
  margin: 0 auto 14px;
  color: var(--fg);
}
.hero .subtitle {
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 0.8rem;
}

/* Sections */
section { padding: 64px 0; }
section.alt { background: var(--bg-alt); }
section h2 {
  font-family: var(--serif);
  font-size: 1.8rem;
  margin: 0 0 8px;
  color: var(--fg);
}
section .section-intro {
  color: var(--muted);
  max-width: 640px;
  margin: 0 0 32px;
}

/* Book grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 28px;
}
.book-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.book-card .cover {
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: #05070a;
}
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card .body {
  padding: 16px 18px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.book-card h3 {
  font-family: var(--serif);
  margin: 0 0 4px;
  font-size: 1.15rem;
}
.book-card .series {
  color: var(--accent);
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.book-card p.desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 12px;
  flex: 1;
}
.book-card .formats {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.book-card .price {
  font-size: 1.1rem;
  color: var(--fg);
  margin-bottom: 12px;
}

.btn {
  display: inline-block;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  padding: 10px 18px;
  border-radius: 5px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: var(--sans);
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: var(--accent); color: #14181f; text-decoration: none; }
.btn.primary { background: var(--accent); color: #14181f; }
.btn.primary:hover { background: #e0b95e; }
.btn.small { padding: 6px 12px; font-size: 0.8rem; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Cart button state */
.add-to-cart-btn.in-cart {
  background: transparent;
  border-color: var(--ok);
  color: var(--ok);
}
.add-to-cart-btn.in-cart:hover { background: var(--ok); color: #0d1219; }
.add-to-cart-btn.just-added { animation: cart-pulse 0.5s ease; }
@keyframes cart-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Forms */
input, textarea, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 9px 11px;
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 0.9rem;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
input[readonly], textarea[readonly] {
  opacity: 0.55;
  background: rgba(255, 255, 255, 0.03);
  cursor: not-allowed;
}
input[readonly]:focus, textarea[readonly]:focus {
  border-color: var(--border);
}
label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 12px 0 5px;
}
form .field { margin-bottom: 6px; }

/* About */
.about-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 36px;
  align-items: start;
}
.about-grid img.photo {
  border-radius: 8px;
  border: 1px solid var(--border);
}
.social-row { margin-top: 16px; display: flex; gap: 16px; }

/* Newsletter */
.newsletter-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
}
.newsletter-box form {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 18px auto 0;
  flex-wrap: wrap;
}
.newsletter-box form input { flex: 1; min-width: 140px; }

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  color: var(--muted);
  font-size: 0.85rem;
}
footer .footer-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
footer a.admin-link { color: var(--muted); font-size: 0.75rem; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  position: relative;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  max-width: 460px;
  width: 100%;
  /* margin:auto (not align-items:center on the parent) centers vertically
     while still degrading gracefully to top-visible-and-scrollable when the
     content is taller than the viewport -- align-items:center on a scrolling
     flex parent clips the top of tall content instead of centering it. */
  margin: auto 0;
}
.modal h3 { font-family: var(--serif); margin-top: 0; padding-right: 34px; }
.modal .close-x {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.modal .close-x:hover { background: rgba(255, 255, 255, 0.16); border-color: var(--accent); color: var(--accent); }
.modal .close-x svg { display: block; }

/* the image viewer centers its image via flexbox rather than text-align
   (a floated/absolute close-x otherwise competes with text-align centering
   for whatever inline content follows it on the same line). */
.image-viewer-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.msg { font-size: 0.85rem; margin-top: 10px; }
.msg.ok { color: var(--ok); }
.msg.error { color: var(--danger); }

.order-banner {
  text-align: center;
  padding: 14px 20px;
  font-size: 0.9rem;
}
.order-banner.ok { background: rgba(106,196,138,0.15); color: var(--ok); }
.order-banner.error { background: rgba(209,106,106,0.15); color: var(--danger); }

.badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Admin */
body.admin-body { background: var(--bg); }
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.admin-header h1 { font-family: var(--serif); font-size: 1.4rem; margin: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 28px; flex-wrap: wrap; }
.tabs button {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--sans);
}
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.admin-table th, table.admin-table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}
table.admin-table th { color: var(--muted); font-weight: 600; }

.login-box {
  max-width: 340px;
  margin: 120px auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}
.login-box h1 { font-family: var(--serif); font-size: 1.3rem; text-align: center; }

.settings-divider {
  border-top: 1px solid var(--border);
  margin: 28px 0 20px;
}

.book-edit-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.book-edit-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.book-edit-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
}
.book-edit-preview:hover { background: rgba(255,255,255,0.03); }
.book-edit-preview .preview-cover {
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 3px;
  background: #05070a;
  flex-shrink: 0;
}
.book-edit-preview .preview-info { flex: 1; min-width: 0; }
.book-edit-preview .preview-title { font-family: var(--serif); font-size: 1rem; }
.book-edit-preview .expand-chevron {
  color: var(--muted);
  transition: transform 0.15s;
  font-size: 0.9rem;
}
.book-edit-card.expanded .expand-chevron { transform: rotate(180deg); }
.book-edit-card .book-edit-body {
  display: none;
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.book-edit-card.expanded .book-edit-body { display: block; }
.book-edit-card .grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.nl-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.nl-toolbar button, .nl-toolbar select {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.85rem;
}
.nl-toolbar button:hover { border-color: var(--accent); }
.nl-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--muted);
}
.swatch-group { display: flex; gap: 5px; }
.swatch-group .swatch {
  box-sizing: border-box;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  vertical-align: middle;
}
.swatch-group .swatch:hover { border-color: var(--accent); }
.custom-color-swatch {
  display: inline-flex;
  flex: 0 0 auto;
  align-self: center;
  box-sizing: border-box;
  width: 22px;
  height: 22px;
  line-height: 0;
  font-size: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  margin: 0;
  position: relative;
  overflow: hidden;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.custom-color-swatch:hover { border-color: var(--accent); }
.custom-color-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}
.nl-editor {
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 16px;
  margin-top: 10px;
  background: #0d1219;
  color: #e9e6df;
  font-family: var(--sans);
  line-height: 1.6;
}
.nl-editor:focus { outline: none; border-color: var(--accent); }
.nl-editor img { max-width: 100%; }
.nl-source {
  width: 100%;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  resize: vertical;
  white-space: pre;
}

.nl-history {
  border-top: 1px solid var(--border);
  margin-top: 28px;
  padding-top: 20px;
}
.nl-history summary {
  cursor: pointer;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 1.05rem;
}
.nl-history-row:hover { background: rgba(255, 255, 255, 0.03); cursor: pointer; }

.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.image-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
}
.image-card:hover { border-color: var(--accent); }
.image-card .image-thumb-wrap {
  position: relative;
  margin-bottom: 8px;
}
.image-card .image-thumb {
  display: block;
  width: 100%;
  height: 100px;
  object-fit: contain;
  background: #05070a;
  border-radius: 4px;
}
.view-image-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 18, 25, 0.75);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.8rem;
  cursor: pointer;
}
.view-image-icon:hover { border-color: var(--accent); color: var(--accent); }

.image-card.add-image-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 148px;
  border-style: dashed;
}
.image-card.add-image-card:hover { background: rgba(255, 255, 255, 0.03); }
.add-image-card .add-image-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 8px;
}
.add-image-card .image-filename { margin-bottom: 0; color: var(--fg); }
.image-card .image-filename {
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-all;
  margin-bottom: 8px;
}
.image-card .image-filename .rename-input {
  width: 100%;
  padding: 4px 6px;
  font-size: 0.72rem;
  margin-bottom: 4px;
}
.image-card .rename-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.image-card .rename-actions button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
}
.image-card .rename-actions .rename-confirm:hover { border-color: var(--ok); color: var(--ok); }
.image-card .rename-actions .rename-cancel:hover { border-color: var(--danger); color: var(--danger); }
.image-card .image-controls {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.image-card.open .image-controls { display: flex; }
.image-card .image-controls button { flex: 1; min-width: 60px; }
.status-pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}
.status-pill.pending_payment { background: rgba(201,162,75,0.2); color: var(--accent); }
.status-pill.paid { background: rgba(106,196,138,0.2); color: var(--ok); }
.status-pill.shipped { background: rgba(106,150,196,0.2); color: #6a9ec4; }
.status-pill.cancelled { background: rgba(209,106,106,0.2); color: var(--danger); }

@media (max-width: 640px) {
  .about-grid { grid-template-columns: 1fr; }
  .newsletter-box form { flex-direction: column; }
}
