:root {
  --bg: #121212;
  --row-h: 170px;
  --tier-w: 1150px;
  --line: #4a3b2a;
  --window-bg: #e8dbc3;
  --sidebar-bg: #dccaa5;
  --border-color: #4a3b2a;
  --gold-accent: #b89548;
  --ink: #2b2018;
  --ink-muted: #665243;
  --tab-bg: #3d2f24;
  --tab-text: #a89582;
  --tab-hover: #4f3d2f;
  --font-title: "Cinzel", serif;
  --font-body: "Lato", sans-serif;
}
body {
  background-color: var(--bg);
  background-image: radial-gradient(circle at center, #1f1f1f 0%, #050505 100%);
  color: var(--ink);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  margin: 0;
}

#capture-area {
  padding: 15px;
  background: var(--window-bg);
  width: fit-content;
  border: 3px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 0 0 2px #2a2118, 0 20px 60px rgba(0,0,0,0.6);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.7" numOctaves="3" stitchTiles="stitch"/></filter><rect width="200" height="200" filter="url(%23n)" opacity="0.04"/></svg>');
}
h2 {
  letter-spacing: 1px;
  font-family: var(--font-title);
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

/* Desktop Layout */
.tier-row { display: flex; width: var(--tier-w); min-height: var(--row-h); margin-bottom: 3px; border: 1px solid var(--border-color); border-radius: 4px; overflow: hidden; }
.tier-header {
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  color: #000;
  text-align: center;
  flex-shrink: 0;
  user-select: none;
}
.label { font-size: 32px; font-weight: 900; line-height: 1; font-family: var(--font-title); }
.description { font-size: 11px; font-weight: 800; text-transform: uppercase; opacity: 0.85; font-family: var(--font-title); letter-spacing: 0.5px; }
.items {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: rgba(42, 33, 24, 0.15);
  min-height: var(--row-h);
  align-content: flex-start;
}

/* Tier Colors */
.s { background: #ff7f7f; } .a { background: #ffbf7f; } .b { background: #ffff7f; }
.c { background: #bfff7f; } .d { background: #7ffff0; } .e { background: #83a2ff; } .f { background: #7f7f7f; }

.book {
  width: 140px;
  height: 140px;
  object-fit: cover;
  cursor: grab;
  border-radius: 3px;
  user-select: none;
  -webkit-user-drag: element;
  touch-action: manipulation;
}
.book.selected {
  outline: 3px solid var(--gold-accent);
  outline-offset: 2px;
}

/* Controls */
.btn-container {
  margin-top: 10px;
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--tab-bg);
  background-image: linear-gradient(to bottom, rgba(255,255,255,0.05), rgba(0,0,0,0.2));
  padding: 15px;
  border-radius: 8px;
  width: 95%;
  max-width: var(--tier-w);
  box-sizing: border-box;
  border: 1px solid #2a2118;
}
button, #search-bar {
  padding: 12px;
  font-weight: 800;
  cursor: pointer;
  background: var(--tab-hover);
  color: var(--tab-text);
  border: 1px solid #2a2118;
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font-title);
  transition: all 0.2s;
}
button:hover { background: #5a4536; color: #dccaa5; }
button:active { transform: translateY(1px); }
#search-bar {
  cursor: text;
  background: rgba(0,0,0,0.3);
  flex-grow: 1;
  min-width: 200px;
  outline: none;
  font-family: var(--font-body);
  color: #dccaa5;
}

#library-section { width: 95%; max-width: var(--tier-w); margin-top: 20px; }
#library-section h3 {
  font-family: var(--font-title);
  color: var(--gold-accent);
  letter-spacing: 0.5px;
}
#library-section h3 span { color: var(--tab-text); }
#library { background: rgba(42, 33, 24, 0.15); padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; border: 1px solid var(--line); min-height: 200px; border-radius: 4px; }

/* Workspace with sidebar */
.tier-workspace {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  position: relative;
  padding-bottom: 40px;
}

#capture-area {
  padding: 15px;
  background: var(--window-bg);
  width: var(--tier-w);
  box-sizing: border-box;
  border: 3px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 0 0 2px #2a2118, 0 20px 60px rgba(0,0,0,0.6);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.7" numOctaves="3" stitchTiles="stitch"/></filter><rect width="200" height="200" filter="url(%23n)" opacity="0.04"/></svg>');
}

.sidebar-right {
  position: fixed;
  right: 0;
  top: 120px; /* Below nav and controls */
  width: 240px;
  background: var(--tab-bg);
  border: 1px solid #2a2118;
  border-left: 3px solid var(--gold-accent);
  border-radius: 8px 0 0 8px;
  padding: 15px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,0.5);
  z-index: 100;
}

.sidebar-header-title {
  font-family: var(--font-title);
  color: var(--gold-accent);
  font-size: 14px;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(184, 149, 72, 0.3);
  padding-bottom: 8px;
  margin-bottom: 5px;
  font-weight: 700;
  text-align: right;
}

.saved-lists-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.save-item {
  display: flex;
  flex-direction: column;
  background: var(--tab-hover);
  border: 1px solid #2a2118;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  width: 100%;
  text-align: right;
}

.save-item:hover {
  background: #5a4536;
  border-color: var(--gold-accent);
}

.save-item-name {
  color: #dccaa5;
  font-weight: 700;
  font-family: var(--font-title);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.save-item-meta {
  color: var(--tab-text);
  font-size: 10px;
  text-transform: uppercase;
}

.save-item-actions {
  display: flex;
  gap: 5px;
  margin-top: 8px;
  justify-content: flex-end;
}

.mini-btn {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--tab-text);
  padding: 2px 6px;
  font-size: 9px;
  border-radius: 3px;
  cursor: pointer;
}

.mini-btn:hover {
  background: #2a2118;
  color: #fff;
}

.mini-btn.delete {
  color: #ffb3b3;
}

.mini-btn.delete:hover {
  background: #6b2020;
}

.no-saves {
  color: var(--tab-text);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  margin-top: 10px;
}

/* MOBILE RESPONSIVE TWEAKS */
@media (max-width: 1400px) {
  .tier-workspace {
    flex-direction: column;
    align-items: center;
  }
  .sidebar-right {
    width: 95vw;
    max-width: var(--tier-w);
    max-height: 300px;
  }
}
@media (max-width: 1150px) {
  .tier-row { width: 95vw; flex-direction: column; min-height: auto; }
  .tier-header { width: auto; height: 50px; flex-direction: row; gap: 10px; }
  .label { font-size: 20px; }
  .items { min-height: 100px; }
  .book { width: 90px; height: 90px; }
  #capture-area { padding: 5px; width: 100%; box-sizing: border-box; }
  body { padding: 5px; }
}

/* Floating ghost preview for click-to-pickup */
#picked-ghost {
  position: fixed;
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  pointer-events: none;
  z-index: 99999;
  opacity: 0.92;
  transform: translate(-50%, -50%);
  box-shadow: 0 12px 30px rgba(0,0,0,0.55), 0 0 15px rgba(184, 149, 72, 0.3);
  display: none;
}

/* Search popover results (near search bar) */
.search-wrap { position: relative; flex-grow: 1; min-width: 200px; }
#search-bar { width: 100%; box-sizing: border-box; }
#search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--tab-bg);
  border: 1px solid #2a2118;
  border-radius: 10px;
  padding: 10px;
  display: none;
  z-index: 9999;
  max-height: 320px;
  overflow: auto;
  box-shadow: 0 18px 40px rgba(0,0,0,0.55);
}
#search-results .sr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  user-select: none;
}
#search-results .sr-title {
  font-size: 12px;
  color: var(--gold-accent);
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-family: var(--font-title);
}
#search-results .sr-hint { font-size: 12px; color: var(--tab-text); }
#search-results .sr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
}
.sr-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  border-radius: 10px;
  padding: 6px;
  border: 1px solid transparent;
}
.sr-item:hover { border-color: var(--gold-accent); background: rgba(184, 149, 72, 0.1); }
.sr-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  object-fit: cover;
  background: #2a2118;
}
.sr-name {
  font-size: 11px;
  color: var(--tab-text);
  line-height: 1.15;
  max-height: 2.3em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== NAV BAR ===== */
.nav-bar { display:flex; justify-content:space-between; align-items:center; padding:12px 40px; background:var(--tab-bg); border-bottom:3px solid #2a2118; background-image:linear-gradient(to bottom,rgba(255,255,255,.05),rgba(0,0,0,.2)); flex-wrap:wrap; gap:6px; width:100%; box-sizing:border-box; }
.nav-bar a { color:var(--tab-text); text-decoration:none; font-family:var(--font-title); font-size:.95rem; padding:6px 16px; border-radius:4px; transition:all .2s; }
.nav-bar a:hover { background:var(--tab-hover); color:#dccaa5; }
.nav-bar a.active { color:var(--gold-accent); font-weight:700; }
.nav-bar a.nav-title { color:var(--gold-accent); font-size:1.1rem; font-weight:700; letter-spacing:1px; padding:0; background:none; }
.nav-bar a.nav-title:hover { background:none; color:#dccaa5; }
@media(max-width:768px){ .nav-bar{ padding:10px 15px; } .nav-bar a{ font-size:.8rem; padding:4px 10px; } .nav-bar a.nav-title{ font-size:.9rem; } }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-card {
  width: min(460px, 92vw);
  background: var(--tab-bg);
  border: 2px solid #2a2118;
  border-left: 4px solid var(--gold-accent);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.modal-title {
  font-family: var(--font-title);
  font-size: 18px;
  color: var(--gold-accent);
  margin-bottom: 10px;
}

.modal-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--tab-text);
  margin: 10px 0 6px;
  font-family: var(--font-title);
}

.modal-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(0,0,0,0.3);
  color: #dccaa5;
  border: 1px solid #2a2118;
  border-radius: 6px;
  padding: 10px;
  font-family: var(--font-body);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

