:root {
  --bg: #f7f8f2;
  --paper: #ffffff;
  --ink: #1d1d1f;
  --muted: #5b5e64;
  --line: #dfe3d6;
  --accent: #0d9488;
  --accent-2: #155e75;
  --danger: #b91c1c;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, #e9f5e8 0%, transparent 30%),
    radial-gradient(circle at 90% 15%, #e1f0ff 0%, transparent 25%),
    var(--bg);
}

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(247, 248, 242, 0.74);
  backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #d5ddd0;
  border-top-color: var(--accent-2);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.age-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.age-card {
  width: min(560px, 92vw);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.page {
  width: min(1100px, 92vw);
  margin: 2rem auto 3rem;
}

.reader-page {
  width: min(1700px, 98vw);
}

.hero {
  margin-bottom: 1.25rem;
}

.top-nav {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.link-btn {
  display: inline-block;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  background: var(--accent-2);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.link-btn:hover {
  opacity: 0.93;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-2);
  font-size: 0.78rem;
}

h1 {
  margin: 0.2rem 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
}

.auth-panel {
  max-width: 560px;
  margin: 5rem auto 0;
}

.auth-form {
  margin-top: 0.8rem;
}

.auth-note {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.7rem;
}

.error-text {
  color: var(--danger);
  font-weight: 700;
  margin: 0.7rem 0 0;
}

h2 {
  margin: 0 0 0.8rem;
  font-size: 1.1rem;
}

.form-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.form-row-tight {
  margin-top: 0.6rem;
}

input,
select,
button {
  font: inherit;
  border-radius: 10px;
}

input,
select {
  border: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
  background: #fff;
}

input[type="text"] {
  min-width: 220px;
  flex: 1;
}

button {
  border: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.65rem 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:hover {
  opacity: 0.93;
}

button:active {
  transform: translateY(1px);
}

button.danger,
.delete-comic {
  background: var(--danger);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

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

.filters label {
  color: var(--muted);
  font-size: 0.95rem;
}

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

.comic-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.comic-link-card {
  display: block;
  color: var(--ink);
  text-decoration: none;
}

.comic-tile-media {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eef2ea;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.comic-tile-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.comic-tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0.6rem 0.65rem;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
}

.comic-tile-fallback {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #ecf2ea, #dde8ef);
  color: var(--accent-2);
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 700;
  padding: 0.9rem;
}

.gallery-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fcfcfa;
}

.gallery-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.card-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.card-link {
  padding: 0.45rem 0.7rem;
  font-size: 0.88rem;
}

.comic-title {
  margin: 0;
  font-size: 1rem;
}

.comic-meta {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.title-page-editor {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  margin-bottom: 0.7rem;
}

.title-page-preview-wrap {
  margin-bottom: 0.5rem;
}

.title-page-preview {
  width: 110px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.title-page-empty {
  margin: 0;
}

.title-page-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.45rem;
}

.image-wrap {
  position: relative;
}

.image-wrap img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.image-wrap button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-weight: 700;
}

.empty {
  color: var(--muted);
  margin: 0;
  font-size: 0.95rem;
}

.hidden {
  display: none;
}

.reader {
  min-height: 60vh;
}

.reader-stage {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.7rem;
  align-items: center;
}

.reader-stage img {
  width: 100%;
  height: auto;
  object-fit: initial;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f2f5ef;
}

.reader-stage-single {
  grid-template-columns: 1fr;
}

.reader-counter {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 640px) {
  .form-row > * {
    width: 100%;
  }

  input[type="text"] {
    min-width: 0;
  }

  .filters {
    width: 100%;
  }

  .filters select {
    width: 100%;
  }

  .reader-stage {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) {
  .comic-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .comic-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
