:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --border: #e7e3dc;
  --text: #2a2620;
  --muted: #76716a;
  --accent: #c44536;
  --accent-light: #e7837a;
  --success: #4a7c59;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-user {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
  max-width: 440px;
  margin: 3rem auto;
}

.card.centered { text-align: center; }
.card h2 { margin-top: 0; }

/* Forms */
form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

input[type="email"],
input[type="password"],
input[type="search"],
select {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  transition: opacity 0.15s, background 0.15s;
}

button:disabled {
  opacity: 0.5;
  cursor: wait;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
  background: #a83a2d;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 0.25rem 0.5rem;
}

.link-btn:hover {
  color: var(--text);
}

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--accent); margin: 0.5rem 0 0; font-size: 0.9rem; min-height: 1.2em; }
.hidden { display: none !important; }

.admin-toggle {
  margin-top: 2rem;
  text-align: left;
  font-size: 0.85rem;
}
.admin-toggle summary {
  cursor: pointer;
  color: var(--muted);
  text-align: center;
}
.admin-form { margin-top: 0.75rem; }

/* PIN cells */
.pin-inputs {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.5rem 0;
}

.pin-cell {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  caret-color: var(--accent);
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}

.pin-cell:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 69, 54, 0.15);
}

.pin-cell:not(:placeholder-shown),
.pin-cell.filled {
  background: #fbf8f4;
  border-color: #d6cfc3;
}

@media (max-width: 460px) {
  .pin-inputs { gap: 0.35rem; }
  .pin-cell { width: 40px; height: 50px; font-size: 1.3rem; }
}

/* Toolbar */
.catalog-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.stats {
  font-size: 0.95rem;
  color: var(--muted);
}
.stats strong { color: var(--text); }

.filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filters input[type="search"] {
  min-width: 220px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #f0ece6;
  cursor: zoom-in;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tile-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-img.no-image {
  font-size: 0.85rem;
  color: var(--muted);
  cursor: default;
  text-align: center;
  padding: 1rem;
}

.tile-body {
  padding: 0.9rem 1rem 0.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tile-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

.tile-author {
  font-size: 0.85rem;
  color: var(--muted);
}

.tile-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: auto;
  padding-top: 0.5rem;
}

.tile-meta span { display: block; }

.tile-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--border);
}

.like-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
  transition: all 0.15s;
}

.like-btn .heart::before {
  content: "♡";
  font-size: 1.15rem;
  line-height: 1;
}

.like-btn.liked {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.like-btn.liked .heart::before {
  content: "♥";
}

.like-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.like-btn.liked:hover:not(:disabled) {
  color: white;
}

/* Admin */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-header h2 { margin: 0; }
.admin-actions { display: flex; gap: 0.5rem; }

.admin-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  min-width: 140px;
}
.stat-box .stat-num { font-size: 1.5rem; font-weight: 600; }
.stat-box .stat-label { font-size: 0.8rem; color: var(--muted); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: #faf8f4;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #faf8f4; }

.rank-1 td:first-child { color: #b8860b; font-weight: 700; }
.rank-2 td:first-child { color: #708090; font-weight: 700; }
.rank-3 td:first-child { color: #a0522d; font-weight: 700; }

td .thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 2rem;
}

.lightbox img {
  max-width: 95%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 6px;
}

.lightbox-caption {
  color: white;
  margin-top: 1rem;
  text-align: center;
  max-width: 800px;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  background: transparent;
  border: none;
  color: white;
  font-size: 2.5rem;
  cursor: pointer;
  line-height: 1;
}

@media (max-width: 700px) {
  .topbar { padding: 0.75rem 1rem; }
  .brand h1 { font-size: 1.05rem; }
  main { padding: 1rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
  .catalog-toolbar { flex-direction: column; align-items: stretch; }
  .filters { width: 100%; }
  .filters input[type="search"] { min-width: 0; flex: 1; }
  .tile-body { padding: 0.6rem 0.75rem 0.25rem; }
  .tile-title { font-size: 0.85rem; }
  .tile-author, .tile-meta { font-size: 0.75rem; }
}
