/* ==============================================
   Reads as Deeds — Steampunk Reading Tracker
   ============================================== */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep: #3a2f1e;
  --bg-main: #443826;
  --bg-card: #ebdbc6;
  --bg-card-hover: #f7e4c2;
  --bg-surface: #f5e3c3;
  --bg-header: #1a1510;
  --bg-modal: rgba(20, 15, 8, 0.88);

  --gold: #ddb876;
  --gold-bright: #f0cc7a;
  --gold-dark: #a68a61;
  --bronze: #ba8950;
  --copper: #c88040;
  --ink: #443c2e;
  --ink-light: #6a5644;
  --ink-faint: #9a8a78;
  --cream: #f5e3c3;
  --parchment: #fffff6;
  --red: #c44;
  --green: #5a8a3a;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 2px 6px rgba(58, 47, 30, 0.15);
  --shadow-md: 0 6px 24px rgba(58, 47, 30, 0.2);
  --shadow-lg: 0 16px 48px rgba(58, 47, 30, 0.3);
  --shadow-inset: 0 2px 5px rgba(186, 137, 80, 0.15) inset;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg-main);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Animated gears background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    url('https://s3.us-west-2.amazonaws.com/www.socialdeskclub.com/gears.png') repeat,
    radial-gradient(circle at 30% 30%, #b99869 0%, #665544dd 80%);
  opacity: 0.14;
  animation: gearmove 24s linear infinite;
}

@keyframes gearmove {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 320px 220px, 0 0; }
}

/* --- Typography --- */
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; }
a { color: var(--gold); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--gold-bright); }

/* --- Buttons --- */
.btn-primary {
  background: linear-gradient(135deg, var(--gold) 0%, var(--bronze) 100%);
  color: var(--bg-header);
  border: none;
  padding: 0.6em 1.4em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(186, 137, 80, 0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-full { width: 100%; padding: 0.75em; font-size: 1rem; margin-top: 1em; }

.btn-accent {
  background: var(--gold);
  color: var(--bg-header);
  border: none;
  padding: 0.5em 1.2em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.btn-accent:hover { background: var(--gold-bright); transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--gold-dark);
  padding: 0.45em 1em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-ghost:hover { background: rgba(221, 184, 118, 0.15); color: var(--gold-bright); }

.btn-ghost-dark {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--gold-dark);
  padding: 0.45em 1em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-ghost-dark:hover { background: rgba(186, 137, 80, 0.12); }

.btn-sm {
  padding: 0.3em 0.7em;
  font-size: 0.78rem;
}

.btn-edit {
  background: transparent;
  color: var(--gold-dark);
  border: 1px solid var(--gold-dark);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-edit:hover { background: rgba(186, 137, 80, 0.15); color: var(--gold); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-danger:hover { background: rgba(204, 68, 68, 0.1); }

/* --- Header --- */
header {
  background: var(--bg-header);
  color: var(--gold);
  padding: 1.2em 1.5em 1em;
  box-shadow: 0 4px 16px rgba(26, 21, 16, 0.6);
  border-bottom: 3px double var(--gold-dark);
  position: relative;
  z-index: 10;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1300px;
  margin: 0 auto;
}

.header-left h1 {
  font-size: clamp(1.3rem, 3vw, 2rem);
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold), var(--bronze));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.2em;
}

#user-nav-loggedin {
  display: flex;
  align-items: center;
  gap: 2em;
}

.user-badge {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gold);
  opacity: 0.85;
}

.header-controls {
  max-width: 1300px;
  margin: 0.8em auto 0;
}

.header-controls input {
  width: 100%;
  max-width: 500px;
  padding: 0.6em 1em;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--gold-dark);
  background: rgba(245, 227, 195, 0.12);
  color: var(--cream);
  font-family: var(--font-body);
  transition: border-color 0.2s, background 0.2s;
}
.header-controls input::placeholder { color: rgba(221, 184, 118, 0.4); }
.header-controls input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(245, 227, 195, 0.18);
}

/* --- Main --- */
main {
  flex: 1;
  padding: 1.5em 1em;
  max-width: 1300px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5em;
  flex-wrap: wrap;
  gap: 0.8em;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.6em;
}
#user-browser label {
  font-size: 0.82rem;
  color: var(--cream);
  opacity: 0.7;
  margin-right: 0.3em;
}
#user-select {
  background: rgba(245, 227, 195, 0.12);
  color: var(--cream);
  border: 1px solid var(--gold-dark);
  padding: 0.4em 0.8em;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
}
#user-select option {
  background: var(--bg-header);
  color: var(--cream);
}

/* --- Progress --- */
.progress-container {
  max-width: 650px;
  margin: 0 auto 2em;
  background: var(--parchment);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.progress-bar {
  height: 22px;
  background: linear-gradient(90deg, #ddf876 0%, #ef9869 100%);
  border-radius: var(--radius-lg);
  width: 0;
  transition: width 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.progress-text {
  padding: 0.35em 1em;
  color: var(--ink-light);
  font-weight: 600;
  font-size: 0.9rem;
}

/* --- Year Divider --- */
.book-year {
  margin: 2.5em 0 1em;
  font-family: var(--font-display);
  font-size: 1.4em;
  font-weight: 700;
  color: var(--gold-bright);
  border-bottom: 2px dashed var(--gold-dark);
  padding-bottom: 0.3em;
  display: flex;
  align-items: center;
  gap: 0.8em;
}
.year-goal-edit {
  font-family: var(--font-body);
  font-size: 0.55em;
  color: var(--gold);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.year-goal-edit:hover { opacity: 1; }

/* --- Book Grid --- */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1.5em;
  margin-bottom: 2em;
}

/* --- Book Card --- */
.book-item {
  background: var(--bg-card);
  border: 2px solid var(--bronze);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), var(--shadow-inset);
  padding: 1.4em;
  display: flex;
  gap: 1em;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s, border-color 0.2s;
  position: relative;
  z-index: 2;
}
.book-item:hover {
  transform: scale(1.02) rotate(-0.5deg);
  box-shadow: var(--shadow-lg), var(--shadow-inset);
  border-color: var(--gold);
  background: var(--bg-card-hover);
}

.book-cover {
  width: 90px;
  height: 135px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--gold-dark);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  transition: box-shadow 0.2s, filter 0.2s;
  background: linear-gradient(135deg, rgba(186,137,80,0.15), rgba(221,184,118,0.1));
}
.book-item:hover .book-cover {
  box-shadow: 0 8px 24px rgba(186, 137, 80, 0.3);
  filter: sepia(0.2) drop-shadow(0 0 3px rgba(202, 140, 44, 0.3));
}

.book-info { flex: 1; min-width: 0; }

.book-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.4em;
  line-height: 1.3;
  word-break: break-word;
}

.book-meta {
  font-size: 0.82rem;
  color: var(--ink-light);
  line-height: 1.6;
  margin-bottom: 0.5em;
}
.book-meta strong { color: var(--ink); font-weight: 600; }

.book-score {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  background: linear-gradient(135deg, rgba(221, 184, 118, 0.2), rgba(186, 137, 80, 0.15));
  padding: 0.15em 0.5em;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--copper);
}

.book-tldr {
  font-size: 0.78rem;
  color: var(--ink-faint);
  line-height: 1.5;
  margin-top: 0.4em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-format {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-faint);
  background: rgba(186, 137, 80, 0.1);
  padding: 0.15em 0.5em;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.book-links {
  margin-top: 0.6em;
  display: flex;
  gap: 0.8em;
  align-items: center;
}
.book-links a {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--copper);
  transition: color 0.2s;
}
.book-links a:hover { color: var(--gold-bright); }

.book-actions {
  position: absolute;
  top: 0.6em;
  right: 0.6em;
  display: flex;
  gap: 0.3em;
  opacity: 0;
  transition: opacity 0.2s;
}
.book-item:hover .book-actions { opacity: 1; }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--bg-card);
  border: 2px solid var(--bronze);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2em;
  width: 100%;
  max-width: 420px;
  position: relative;
  animation: slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-card-wide { max-width: 560px; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-card h2 {
  font-family: var(--font-display);
  color: var(--ink);
  font-size: 1.4rem;
  margin-bottom: 1em;
}

.modal-card label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-light);
  margin-bottom: 0.3em;
  margin-top: 0.8em;
}

.modal-card input[type="text"],
.modal-card input[type="password"],
.modal-card input[type="number"],
.modal-card select {
  width: 100%;
  padding: 0.6em 0.8em;
  border: 2px solid var(--gold-dark);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.modal-card input:focus {
  outline: none;
  border-color: var(--gold);
}

.modal-close {
  position: absolute;
  top: 0.8em;
  right: 0.8em;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-faint);
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--ink); }

.auth-toggle {
  margin-top: 1.2em;
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-align: center;
}
.auth-toggle a { color: var(--copper); font-weight: 600; }

.error-text {
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 0.5em;
}

/* --- Tabs --- */
.search-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.2em;
  border-bottom: 2px solid var(--gold-dark);
}
.tab-btn {
  background: none;
  border: none;
  padding: 0.5em 1.2em;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn.active {
  color: var(--copper);
  border-bottom-color: var(--gold);
}

.input-row {
  display: flex;
  gap: 0.6em;
  align-items: flex-end;
}
.input-row input { flex: 1; }

.field-group { flex: 1; }
.field-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-light);
  margin-bottom: 0.2em;
  display: block;
}

/* --- Search Results --- */
.search-results {
  margin-top: 1em;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}
.search-result-item {
  display: flex;
  gap: 0.8em;
  padding: 0.6em;
  border: 1px solid var(--gold-dark);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  align-items: center;
}
.search-result-item:hover {
  background: rgba(221, 184, 118, 0.12);
  border-color: var(--gold);
}
.search-result-item img {
  width: 40px;
  height: 60px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--gold-dark);
  flex-shrink: 0;
}
.search-result-info h4 {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.15em;
}
.search-result-info p {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* --- Preview --- */
.preview-card {
  display: flex;
  gap: 1em;
  padding: 1em;
  background: rgba(221, 184, 118, 0.08);
  border: 1px solid var(--gold-dark);
  border-radius: var(--radius-md);
  margin-top: 1em;
}
.preview-cover {
  width: 80px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gold-dark);
  flex-shrink: 0;
}
.preview-info h3 {
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 0.3em;
}
.preview-info p {
  font-size: 0.82rem;
  color: var(--ink-light);
}
.preview-meta { color: var(--ink-faint) !important; font-size: 0.78rem !important; }
.preview-tldr {
  font-size: 0.75rem !important;
  color: var(--ink-faint) !important;
  margin-top: 0.3em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.confirm-fields { margin-top: 1em; }

.search-status {
  margin-top: 1em;
  padding: 0.8em;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-align: center;
}
.search-status.loading { color: var(--ink-faint); }
.search-status.error { color: var(--red); background: rgba(204, 68, 68, 0.08); }
.search-status.success { color: var(--green); }

/* --- Footer --- */
footer {
  background: rgba(26, 21, 16, 0.85);
  color: var(--cream);
  text-align: center;
  padding: 1.2em;
  border-top: 3px double var(--gold-dark);
  position: relative;
  z-index: 1;
  font-size: 0.82rem;
}
footer p { opacity: 0.6; margin-bottom: 0.4em; }
.footer-attr {
  font-size: 0.72rem;
  color: var(--gold-dark);
  opacity: 0.5;
}
.footer-attr:hover { opacity: 0.8; }

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 4em 2em;
  color: var(--cream);
  opacity: 0.6;
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 0.5em;
}
.empty-state p { font-size: 0.9rem; }

/* --- Loading --- */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--gold-dark);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 2em;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-header);
  color: var(--gold);
  padding: 0.7em 1.5em;
  border-radius: var(--radius-md);
  border: 1px solid var(--gold-dark);
  font-size: 0.85rem;
  z-index: 200;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; gap: 0.6em; }
  .books-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { justify-content: center; }
  .modal-card { padding: 1.5em; }
  .preview-card { flex-direction: column; align-items: center; text-align: center; }
  main { padding: 1em 0.8em; }
}

@media (max-width: 480px) {
  .book-item { flex-direction: column; align-items: center; text-align: center; }
  .book-cover { margin-bottom: 0.5em; }
  .book-links { justify-content: center; }
  .input-row { flex-direction: column; }
}
