:root {
  --bg-page: #ffffff;
  --peach: #e3b38d;
  --peach-dark: #c97b38;
  --terracotta: #a9655a;
  --terracotta-deep: #8b4c42;
  --dusty-rose: #d59b95;
  --wood-top: #e29b59;
  --wood-front: #c77b38;
  --wood-bracket: #7d451c;
  --ink: #2b211d;
  --muted-bubble: #d6dce2;
  --font-rounded: "Quicksand", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-condensed: "Oswald", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #faf6f2;
  color: var(--ink);
  font-family: var(--font-rounded);
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.is-hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 28px rgba(139, 76, 66, 0.08);
}

/* Global Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
  background: var(--bg-page);
  position: sticky;
  top: 0;
  z-index: 20;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--peach);
  padding: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

.app-title {
  margin: 0;
  font-size: 2rem;
  font-weight: 500;
  color: var(--peach);
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
}

/* Main Viewport */
.app-main {
  flex: 1;
  padding: 8px 16px 96px;
  overflow-x: hidden;
}

.screen-view {
  display: none;
}

.screen-view.is-active {
  display: block;
}

/* 3D Perspective Wooden Plank */
.plank-unit {
  position: relative;
  width: 100%;
}

.plank-top {
  height: 16px;
  margin: 0 20px;
  background: linear-gradient(180deg, #e59f5e 0%, #dc924f 100%);
  transform: perspective(260px) rotateX(38deg);
  transform-origin: bottom;
}

.plank-front {
  height: 11px;
  background: linear-gradient(180deg, #cf8340 0%, #bd7130 100%);
  border-radius: 1px;
  box-shadow: 0 2px 4px rgba(125, 69, 28, 0.16);
}

.plank-brackets {
  display: flex;
  justify-content: space-between;
  padding: 0 46px;
}

.plank-bracket {
  width: 14px;
  height: 9px;
  background: var(--wood-bracket);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 24% 100%);
}

/* 1. Library Screen */
.library-shelves {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 12px;
}

.library-shelf-card {
  position: relative;
  padding-top: 72px;
  padding-bottom: 18px;
  cursor: pointer;
  transition: transform 0.16s ease;
}

.library-shelf-card:active {
  transform: scale(0.985);
}

.shelf-props-layer {
  position: absolute;
  left: 26px;
  right: 24px;
  bottom: 34px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  z-index: 2;
}

.shelf-plaque {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 4;
  background: #ffffff;
  border: 2px solid #3a2d27;
  border-radius: 18px;
  padding: 2px;
  box-shadow: 0 2px 0 rgba(58, 45, 39, 0.15);
}

.shelf-plaque-inner {
  border: 1.5px solid #3a2d27;
  border-radius: 14px;
  padding: 5px 22px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.plaque-star {
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
}

.plaque-star-tr {
  top: -6px;
  right: -5px;
}

.plaque-star-bl {
  bottom: -5px;
  left: -5px;
}

.library-add-wrap {
  display: flex;
  justify-content: center;
  margin-top: 26px;
}

.circle-plus-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--peach-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(201, 123, 56, 0.32);
  transition: transform 0.15s ease;
}

.circle-plus-btn:active {
  transform: scale(0.92);
}

/* 2. Shelf Detail Screen */
.shelf-hero {
  margin-top: 6px;
  margin-bottom: 14px;
}

.shelf-hero-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 18px 0 36px;
  margin-bottom: -14px;
  position: relative;
  z-index: 3;
}

.shelf-condensed-title {
  margin: 0 0 12px;
  font-family: var(--font-condensed);
  font-size: 2.3rem;
  font-weight: 700;
  color: var(--terracotta);
  line-height: 1;
  letter-spacing: 0.01em;
}

.shelf-hero-mascot {
  width: 122px;
  flex-shrink: 0;
}

.shelf-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.terracotta-input {
  width: 100%;
  height: 36px;
  padding: 0 30px 0 10px;
  border: 1.8px solid var(--terracotta);
  background: #ffffff;
  color: var(--ink);
  font-family: var(--font-rounded);
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
}

.terracotta-input::placeholder {
  color: var(--terracotta);
  opacity: 0.78;
}

.input-clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--terracotta);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.terracotta-select {
  height: 36px;
  padding: 0 8px;
  border: 1.8px solid var(--terracotta);
  background: #ffffff;
  color: var(--terracotta);
  font-family: var(--font-rounded);
  font-size: 0.85rem;
  font-weight: 700;
  outline: none;
}

.outline-pill-btn {
  height: 36px;
  padding: 0 14px;
  border: 1.8px solid var(--terracotta);
  border-radius: 18px;
  background: #ffffff;
  color: var(--terracotta);
  font-family: var(--font-rounded);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.outline-pill-btn.is-active {
  background: var(--terracotta);
  color: #ffffff;
}

.shelf-rows-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.shelf-book-row {
  display: flex;
  flex-direction: column;
}

.shelf-books-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 22px;
  margin-bottom: -4px;
  position: relative;
  z-index: 2;
  align-items: end;
}

.book-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.book-cover-img {
  width: 68px;
  height: 92px;
  object-fit: cover;
  border-radius: 3px 6px 6px 3px;
  border: 1.5px solid #2b211d;
  box-shadow: -3px 2px 0 #d9d2cb;
  background: #f5efe8;
}

.book-tile-caption {
  margin-top: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  max-width: 82px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-delete-badge {
  position: absolute;
  top: -7px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: #c93b2b;
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}

.empty-shelf-note {
  text-align: center;
  padding: 28px 16px;
  color: var(--terracotta);
  font-weight: 600;
}

/* 3. CapyScanner Screen */
.scan-heading {
  margin: 4px 0 14px;
  text-align: center;
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--peach-dark);
}

.scanner-stage {
  position: relative;
  margin: 0 14px 16px;
}

.scanner-box {
  height: 132px;
  border: 4px solid var(--peach);
  background: #ffffff;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.barcode-bars {
  width: 84%;
  height: 82px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
}

.barcode-bar {
  background: var(--peach);
  height: 100%;
}

.scanner-video-wrap {
  position: absolute;
  inset: 0;
  background: #1a1412;
}

.scanner-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-laser {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: #ff5252;
  box-shadow: 0 0 8px #ff5252;
}

.peeking-capy-slot {
  position: absolute;
  right: -24px;
  bottom: 2px;
  width: 44px;
  pointer-events: none;
  z-index: 4;
}

.peach-block-btn {
  display: block;
  width: calc(100% - 28px);
  margin: 0 auto 14px;
  height: 46px;
  border: none;
  background: var(--peach);
  color: var(--peach-dark);
  font-family: var(--font-rounded);
  font-size: 1.35rem;
  font-weight: 600;
  cursor: pointer;
}

.outline-block-btn {
  display: block;
  width: calc(100% - 28px);
  margin: 0 auto 14px;
  height: 42px;
  border: 1.8px solid var(--terracotta);
  background: #ffffff;
  color: var(--terracotta);
  font-family: var(--font-rounded);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.isbn-lookup-box {
  width: calc(100% - 28px);
  margin: 0 auto 14px;
  padding: 10px;
  border: 1.8px solid var(--terracotta);
  background: #fffaf6;
}

.isbn-lookup-row {
  display: flex;
  gap: 8px;
}

.sample-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.sample-pill {
  border: 1px solid var(--peach-dark);
  background: #ffffff;
  color: var(--peach-dark);
  border-radius: 12px;
  padding: 3px 9px;
  font-family: var(--font-rounded);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.manual-entry-wrapper {
  width: calc(100% - 28px);
  margin: 0 auto;
}

.manual-entry-banner {
  background: var(--peach);
  color: #1e1815;
  text-align: center;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.manual-entry-card {
  border: 1.8px solid var(--terracotta);
  border-top: none;
  padding: 16px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.manual-photo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.cover-upload-btn {
  display: inline-flex;
  cursor: pointer;
}

.manual-preview {
  position: relative;
  width: 52px;
  height: 68px;
}

.manual-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1.5px solid var(--terracotta);
  border-radius: 4px;
}

.tiny-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--terracotta);
  color: #ffffff;
  font-size: 0.85rem;
  cursor: pointer;
}

.manual-submit-row {
  display: flex;
  justify-content: center;
}

.pill-outline-submit {
  padding: 8px 22px;
  border: 1.8px solid var(--terracotta);
  border-radius: 18px;
  background: #ffffff;
  color: var(--terracotta);
  font-family: var(--font-rounded);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

/* 4. Post-Scan / Post-Entry Result Screen */
.result-book-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin: 18px 8px 34px;
}

.result-cover-slot img {
  width: 104px;
  height: 144px;
  object-fit: cover;
  border: 1.5px solid #2b211d;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.result-meta {
  flex: 1;
  padding-top: 12px;
}

.result-title {
  margin: 0 0 10px;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}

.result-detail {
  margin: 0 0 8px;
  font-size: 0.96rem;
  font-weight: 500;
  color: var(--ink);
}

.result-status {
  margin: 14px 0 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
}

.result-flow {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 0 12px;
}

.capy-cash-slot {
  margin-bottom: -32px;
  z-index: 3;
}

.cool-find-stage {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 14px;
  margin-bottom: -34px;
  z-index: 3;
}

.speech-bubble {
  position: relative;
  background: var(--muted-bubble);
  color: var(--ink);
  padding: 24px 26px;
  border-radius: 50% 48% 52% 46%;
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: -12px;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: -10px;
  bottom: 12px;
  border-width: 10px 14px 4px 0;
  border-style: solid;
  border-color: transparent var(--muted-bubble) transparent transparent;
}

.peach-large-btn {
  width: 100%;
  height: 58px;
  border: none;
  background: var(--peach);
  color: #ffffff;
  font-family: var(--font-rounded);
  font-size: 1.55rem;
  font-weight: 600;
  cursor: pointer;
}

.existing-shelf-picker {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1.8px solid var(--terracotta);
  background: #fffaf6;
}

.fab-camera-btn {
  position: fixed;
  right: max(18px, calc(50vw - 222px));
  bottom: 24px;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: #9f6a4d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(159, 106, 77, 0.35);
  z-index: 25;
}

/* Flush Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 76px;
  display: flex;
  border-top: 1.5px solid var(--dusty-rose);
  background: #ffffff;
  z-index: 20;
}

.bottom-nav-tab {
  flex: 1;
  border: none;
  border-right: 1.5px solid var(--dusty-rose);
  background: #ffffff;
  color: var(--terracotta);
  font-family: var(--font-rounded);
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
}

.bottom-nav-tab:last-child {
  border-right: none;
}

.bottom-nav-tab.is-active {
  background: var(--dusty-rose);
  color: var(--terracotta-deep);
}

/* Side Drawers & Modals */
.backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 33, 29, 0.42);
  z-index: 40;
}

.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: #ffffff;
  border: 2px solid var(--terracotta);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title {
  margin: 0;
  color: var(--terracotta);
  font-size: 1.2rem;
}

.modal-message {
  margin: 0;
  font-size: 0.92rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.side-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 84%;
  max-width: 340px;
  background: #ffffff;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform 0.24s ease;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
}

.side-drawer-left {
  left: 0;
  transform: translateX(-105%);
}

.side-drawer-right {
  right: 0;
  transform: translateX(105%);
}

.side-drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1.5px solid #f0e3d8;
}

.drawer-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--terracotta);
}

.drawer-close-btn {
  border: none;
  background: none;
  font-size: 1.7rem;
  color: var(--terracotta);
  cursor: pointer;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--terracotta);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.quick-shelf-list,
.manage-shelves-list,
.master-search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-shelf-item,
.manage-shelf-item,
.master-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border: 1.5px solid #e7d5c6;
  border-radius: 10px;
  background: #fffcf9;
  font-size: 0.92rem;
  font-weight: 600;
}

.quick-shelf-item {
  cursor: pointer;
}

.count-badge {
  background: var(--peach);
  color: #ffffff;
  border-radius: 12px;
  padding: 2px 9px;
  font-size: 0.8rem;
}

.peach-compact-btn {
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: var(--peach);
  color: #ffffff;
  font-family: var(--font-rounded);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.danger-outline-btn {
  height: 36px;
  border: 1.8px solid #c93b2b;
  border-radius: 10px;
  background: #ffffff;
  color: #c93b2b;
  font-family: var(--font-rounded);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.file-label-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.inline-row {
  display: flex;
  gap: 8px;
}

.inline-row .terracotta-select {
  flex: 1;
}

.pref-field,
.pref-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.pref-field {
  flex-direction: column;
  align-items: stretch;
}

.version-note {
  margin: 4px 0 0;
  text-align: center;
  font-size: 0.78rem;
  color: #8f7b71;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(16px);
  background: var(--terracotta-deep);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 70;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}