:root {
  --bg: #f7f3eb;
  --panel: #ffffff;
  --text: #222;
  --muted: #666;
  --border: #ddd;
  --primary: #1f7aec;
  --success: #22c55e;
  --success-dark: #16a34a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  width: 100%;
}

body {
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  perspective: 1200px;
  perspective-origin: left center;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.brand-area {
  justify-self: start;
}

.header-actions {
  justify-self: center;
  display: flex;
  gap: 12px;
}

.header-actions button {
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel {
  max-width: 1400px;
  margin: 20px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  opacity: 1;
  box-shadow: var(--shadow);
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: 20px;
  align-items: start;
}

.search-column,
.sidebar-column {
  min-width: 0;
}

#search-input,
#book-title,
#author-name,
#isbn,
#book-url {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px;
  margin: 8px 0;
  border: 1px solid #ccc;
  border-radius: 6px;
}

#book-edit-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#book-edit-area input,
#book-edit-area textarea,
#book-edit-area button {
  width: 100%;
  box-sizing: border-box;
}

#results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
}

.book-card {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.book-card img {
  width: 100%;
  max-width: 320px;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 12px;
  background: #fff;
}

.card-body {
  flex: 1;
  min-width: 200px;
  padding: 12px;
}

.card-body h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.card-body p {
  margin: 4px 0;
  color: #555;
  font-size: 0.95rem;
}

.book-preview {
  border: 2px solid #2ecc71;
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
  background: #f7f3eb;
}

.book-preview img {
  width: 100%;
  max-width: 180px;
  display: block;
  margin-bottom: 10px;
  border-radius: 6px;
}

.tier-0 {
  border-left: 5px solid #2ecc71;
}

.tier-100 {
  border-left: 5px solid #f1c40f;
}

.tier-1000 {
  border-left: 5px solid #e67e22;
}

.verified-badge {
  display: inline-block;
  background: #2ecc71;
  color: white;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-weight: bold;
}

.book-cover {
  width: 120px;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 10px;
}

.front-cover {
  display: block;
}

.back-cover {
  display: block;
  width: 100px;
  margin-left: 10px;
}

.add-book-btn {
  background-color: var(--success);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  margin-top: 10px;
}

.add-book-btn:hover {
  background-color: var(--success-dark);
}

#authors-button {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2001;
  display: inline-block;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  text-decoration: none;
}

.page-wrapper {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.page-wrapper.hidden {
  opacity: 0;
  pointer-events: none;
}

.page-wrapper:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}

.authors-page {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.7s ease, opacity 0.7s ease;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12), 10px 0 35px rgba(0, 0, 0, 0.18);
}

.page-wrapper.hidden .authors-page {
  transform: rotateY(18deg) translateX(-8%);
  opacity: 0;
}

.page-wrapper:not(.hidden) .authors-page {
  transform: rotateY(0deg) translateX(0);
  opacity: 1;
}

.page-front,
.page-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: #fff;
  overflow-y: auto;
  padding: 24px;
  box-sizing: border-box;
}

.page-back {
  transform: rotateY(180deg);
  background: #f6f6f6;
}

#authors-results {
  margin-top: 16px;
}

.hidden {
  display: none;
}

#cover-dropzone {
  border: 2px dashed #bbb;
  border-radius: 8px;
  padding: 14px;
  margin-top: 8px;
  background: #fafafa;
  color: #666;
}

#book-editor-overlay {
  display: none;
}

#book-editor-overlay:not(.hidden) {
  display: flex;
}


#book-editor-modal {
  background: #f7f3eb;
  width: min(700px, 100%);
  max-height: none;
  overflow: auto;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  margin-top: 0;
}

#book-editor-modal h2 {
  margin-top: 0;
  margin-bottom: 16px;
}

#book-editor-modal label {
  display: block;
  margin-bottom: 10px;
  font-weight: 600;
}

#book-editor-modal input,
#book-editor-modal textarea {
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font: inherit;
}

#book-editor-modal textarea {
  resize: vertical;
  min-height: 110px;
}

#book-editor-modal button {
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

#editor-upload-btn {
  background: #1f7aec;
  color: #fff;
}

#editor-save-btn {
  background: #22c55e;
  color: #fff;
}

#editor-cancel-btn {
  background: #e5e7eb;
  color: #111827;
}

#editor-cover-preview {
  max-width: 180px;
  border-radius: 8px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

#book-editor-modal > div:last-child {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

@media (max-width: 640px) {
  #book-editor-modal {
    padding: 16px;
    width: 100%;
  }

  #book-editor-modal button {
    width: 100%;
  }

  #book-editor-modal > div:last-child {
    display: grid;
  }
}

@media (max-width: 768px) {
  .main-layout {
    display: flex;
    flex-direction: column;
  }

  .sidebar-column {
    order: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .search-column {
    order: 2;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .panel {
    width: 100%;
    max-width: 100%;
  }

  #results {
    grid-template-columns: 1fr;
  }
}

  .main-layout {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    gap: 16px;
  }

  .search-column {
    flex: 1 1 0;
    min-width: 0;
  }

  .sidebar-column {
    flex: 0 0 320px;
    min-width: 320px;
  }

  .panel {
    max-width: none;
    width: auto;
  }

  #results {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 16px;
  }
}

@media (max-width: 520px) {
  #results {
    grid-template-columns: 1fr;
  }

  .search-column,
  .sidebar-column {
    min-width: 86vw;
  }
}

.post-meta {
  font-size: 0.85rem;
  opacity: 0.75;
  margin-bottom: 6px;
}

.selected-discussion {
  background: transparent;
  border: none;
  box-shadow: none;
}

.selected-discussion-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: flex-start;
}

#back-to-posts-btn {
  align-self: flex-start;
}

.comment-card {
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: #151515;
}

.comment-root {
  margin-left: 0;
}

.comment-reply {
  margin-left: 28px;
  border-left: 2px solid #444;
  padding-left: 12px;
}

.hidden {
  display: none;
}

.post-meta {  
  font-size: 0.85rem;
  opacity: 0.8;
  margin-bottom: 6px;
  color: #f0f0f0;x;
}

#selected-discussion {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.selected-discussion {
  margin-top: 20px;
}

.selected-thread {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.06);
  color: #f5f5f5;
}

.reply-context {
   margin: 12px 0;
  opacity: 0.85;
  font-size: 0.95rem;
  color: #f0f0f0;
}

.comment-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: #f2f2f2;
}

.comment-root {
  margin-left: 0;
}

.comment-reply {
  margin-left: 28px;
  border-left: 2px solid #444;
  padding-left: 12px;
}

.hidden {
  display: none;
}
.thread-actions {
  margin: 12px 0 16px;
}

.thread-actions button {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.main-page,
#main-page,
#discussion-section {
  padding-left: 24px;
  padding-right: 24px;
}

.discussion-panel {
  padding-left: 32px;
  padding-right: 24px;
}

#discussions-list,
#selected-discussion {
  margin-left: 12px;
}

#auth-box {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px;
  text-align: center;
}

#authors-results {
  display: block;
}

#book-edit-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

#book-edit-area input,
#book-edit-area textarea,
#book-edit-area button {
  display: block;
  width: 100%;
}

#book-edit-area textarea {
  min-height: 120px;
  resize: vertical;
}
