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

:root {
  --accent: #c9a84c;
  --accent-light: #e0c97a;
  --accent-dark: #8b3a1e;
  --bg: #1a1a1a;
  --surface: #2a2318;
  --border: #3d3020;
  --text: #f5ecd7;
  --text-muted: #a09070;
  --danger: #c0392b;
  --radius: 10px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Auth Page ===== */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: url('/static/images/login-bg-dragon.png') center center / cover no-repeat;
  position: relative;
}

body.auth-page::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.72);
  z-index: 0;
}

body.auth-page > * { position: relative; z-index: 1; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.logo { text-align: center; margin-bottom: 2rem; }
.logo h1 { font-size: 2rem; color: var(--accent); font-weight: 700; }
.logo p { color: var(--text-muted); font-size: 0.95rem; }

.auth-card label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.auth-card input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.auth-card input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-card button[type="submit"] {
  width: 100%;
  padding: 0.8rem;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-card button[type="submit"]:hover { background: var(--accent-light); }

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

/* ===== Header ===== */
.site-header {
  background: url('/static/images/header-banner.png') center 30% / cover no-repeat;
  color: var(--text);
  padding: 0 1.5rem;
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
  position: relative;
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 5, 0.78);
}

.header-inner {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
}

.brand h1 { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.brand span { font-size: 0.85rem; color: var(--text-muted); }

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

.btn-secondary {
  padding: 0.4rem 1rem;
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 6px;
  color: #fff;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.15); text-decoration: none; }

/* ===== Library ===== */
.library {
  max-width: 1100px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.library h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.empty-state {
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 3rem 0;
  text-align: center;
}

.category-section { margin-bottom: 2.5rem; }

.category-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
}

.ebook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}

.ebook-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}

.ebook-card:hover {
  box-shadow: 0 6px 24px rgba(201,168,76,0.15);
  transform: translateY(-2px);
}

.ebook-cover {
  width: 100%;
  height: 180px;
  object-fit: cover;
}

.placeholder-cover {
  width: 100%;
  height: 180px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
}

.ebook-info {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.ebook-category {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.ebook-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.ebook-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  flex: 1;
  margin-bottom: 1rem;
}

.btn-download {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: var(--accent);
  color: #1a1a1a;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s;
}
.btn-download:hover { background: var(--accent-light); text-decoration: none; }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Admin ===== */
.admin-main {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 2rem;
}

.admin-section h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1rem;
}

.hint { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem; }

.admin-table-wrap { overflow-x: auto; margin-bottom: 1.25rem; }

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

.admin-table th, .admin-table td {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.admin-table th { background: var(--bg); font-weight: 600; }
.td-desc { max-width: 200px; }
.td-link a { color: var(--accent); }
.td-empty { color: var(--text-muted); font-style: italic; }

.add-form {
  margin-top: 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.add-form summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.95rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label { font-size: 0.875rem; font-weight: 600; }

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea {
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group small { color: var(--text-muted); font-size: 0.8rem; }

.btn-primary {
  padding: 0.65rem 1.5rem;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-light); }

.btn-danger-sm {
  padding: 0.3rem 0.75rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 5px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-danger-sm:hover { background: var(--danger); color: #fff; }

.password-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.password-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.password-list code {
  background: var(--bg);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

.inline-form {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input[type="text"] {
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 220px;
  background: var(--bg);
  color: var(--text);
}

.inline-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.flash-messages { margin-bottom: 1.5rem; }

.flash {
  background: #2a2318;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  /* Header */
  .header-inner { flex-direction: column; gap: 0.5rem; align-items: flex-start; padding: 0.75rem 0; }
  .brand h1 { font-size: 1.25rem; }
  nav { width: 100%; justify-content: flex-end; }

  /* Auth */
  .auth-card { padding: 2rem 1.25rem; margin: 1rem; width: calc(100% - 2rem); }

  /* Library */
  .library { margin: 1.5rem auto; }
  .library h2 { font-size: 1.25rem; }
  .ebook-grid { grid-template-columns: 1fr; }

  /* Ebook card — horizontal on small screens */
  .ebook-card { flex-direction: row; }
  .ebook-cover, .placeholder-cover { width: 90px; min-width: 90px; height: auto; min-height: 110px; font-size: 2.5rem; }
  .ebook-info { padding: 0.85rem; }
  .ebook-title { font-size: 0.95rem; }

  /* Admin */
  .admin-section { padding: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input[type="text"] { min-width: unset; width: 100%; }
  .admin-table { font-size: 0.8rem; }
  .admin-table th, .admin-table td { padding: 0.4rem 0.5rem; }
}
