:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --paper: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --faint: #d8e0ec;
  --line: #e2e8f0;
  --accent: #163b72;
  --accent-dark: #0b254d;
  --accent-soft: #e8eef8;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 247, 251, 0) 240px),
    var(--bg);
}

body.sheet-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(25px, 7vw, 42px);
  line-height: 1.08;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.add-button,
.count-pill {
  min-height: 36px;
  border-radius: 999px;
  font-size: 13px;
}

.add-button {
  padding: 0 13px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.count-pill {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
}

.search-panel {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -16px;
  padding: 10px 16px 12px;
  background: rgba(245, 247, 251, 0.92);
  border-bottom: 1px solid rgba(226, 232, 240, 0.86);
  backdrop-filter: blur(18px);
}

.search-box {
  display: block;
  position: relative;
}

.search-box input,
.form-stack input,
.form-stack textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.search-box input {
  height: 48px;
  padding: 0 46px 0 16px;
}

.form-stack input {
  height: 44px;
  padding: 0 12px;
}

.form-stack textarea {
  min-height: 92px;
  padding: 10px 12px;
  resize: vertical;
}

.search-box input:focus,
.form-stack input:focus,
.form-stack textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 59, 114, 0.14);
}

.clear-search {
  position: absolute;
  right: 8px;
  top: 50%;
  width: 32px;
  height: 32px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 22px;
  line-height: 1;
}

.category-tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  white-space: nowrap;
}

.category-tab[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.library-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.library-meta strong {
  margin-left: 6px;
  color: var(--ink);
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.poster-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  outline: 0;
}

.poster-card:focus-visible {
  box-shadow: 0 0 0 3px rgba(22, 59, 114, 0.18), 0 10px 28px rgba(15, 23, 42, 0.08);
}

.poster-image-wrap {
  aspect-ratio: 3 / 4;
  padding: 6px;
  background: #edf2f8;
}

.poster-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
  background: #edf2f8;
}

.poster-info {
  min-height: 112px;
  padding: 10px;
}

.poster-info span,
.tagline,
.updated {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.poster-info h2 {
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0;
}

.poster-info time {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  margin-top: 56px;
  padding: 30px 20px;
  border: 1px dashed var(--faint);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 18px;
}

.detail-sheet[aria-hidden="true"],
.admin-sheet[aria-hidden="true"] {
  display: none;
}

.detail-sheet,
.admin-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.46);
}

.sheet-panel,
.admin-panel {
  position: absolute;
  inset: auto 0 0;
  max-height: 92vh;
  overflow: auto;
  border-radius: 18px 18px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.close-button {
  position: sticky;
  top: 12px;
  z-index: 2;
  float: right;
  width: 38px;
  height: 38px;
  margin: 12px 12px 0 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.preview-frame {
  padding: 22px 22px 0;
  clear: both;
}

.preview-frame img {
  width: min(100%, 560px);
  max-height: 68vh;
  margin: 0 auto;
  border-radius: var(--radius);
  object-fit: contain;
  background: #edf2f8;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.16);
}

.sheet-content,
.admin-step {
  padding: 18px 20px max(24px, env(safe-area-inset-bottom));
}

.sheet-content h2,
.admin-step h2 {
  margin: 7px 0 8px;
  font-size: 24px;
  line-height: 1.2;
}

.sheet-content p,
.admin-note {
  color: var(--muted);
  line-height: 1.7;
}

.sheet-content .updated {
  margin-top: 10px;
  color: var(--muted);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.primary-action,
.secondary-action {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-weight: 700;
}

.primary-action {
  background: var(--accent);
  color: #ffffff;
}

.secondary-action {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-dark);
}

.admin-panel {
  padding-top: 10px;
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.form-stack label {
  display: grid;
  gap: 7px;
}

.form-stack label span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 4px;
}

.form-message {
  min-height: 24px;
  padding: 0 20px 22px;
  color: var(--accent);
  font-size: 14px;
}

.form-message[data-error="true"] {
  color: var(--danger);
}

.admin-list-wrap {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.admin-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-list-heading h3 {
  margin: 0;
  font-size: 16px;
}

.admin-list-heading span,
.admin-list-empty {
  color: var(--muted);
  font-size: 13px;
}

.admin-poster-list {
  display: grid;
  gap: 10px;
}

.admin-poster-item {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.admin-poster-item img {
  width: 52px;
  height: 68px;
  border-radius: 5px;
  object-fit: cover;
  background: #edf2f8;
}

.admin-poster-item strong,
.admin-poster-item span {
  display: block;
}

.admin-poster-item strong {
  font-size: 14px;
  line-height: 1.3;
}

.admin-poster-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.delete-poster-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  background: #fee4e2;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.admin-item-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.edit-poster-button,
.delete-poster-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
}

.edit-poster-button {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.delete-poster-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

@media (min-width: 480px) {
  .form-actions {
    grid-template-columns: 1fr 1fr;
  }

  .admin-poster-item {
    grid-template-columns: 52px 1fr auto;
  }

  .admin-item-actions {
    grid-column: auto;
    grid-template-columns: auto auto;
  }
}

@media (max-width: 380px) {
  .topbar {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 28px;
  }

  .search-panel {
    margin-inline: -28px;
    padding-inline: 28px;
  }

  .poster-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
  }

  .poster-card {
    transition: transform 160ms ease, box-shadow 160ms ease;
  }

  .poster-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
  }

  .sheet-panel {
    inset: 5vh max(32px, calc((100vw - 920px) / 2));
    border-radius: 14px;
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 320px;
    max-height: 90vh;
  }

  .admin-panel {
    inset: 8vh max(32px, calc((100vw - 560px) / 2)) auto;
    border-radius: 14px;
    max-height: 84vh;
  }

  .close-button {
    position: absolute;
    right: 0;
  }

  .preview-frame {
    display: flex;
    align-items: center;
    padding: 32px;
  }

  .sheet-content {
    align-self: end;
    padding: 32px 28px;
  }

  .admin-step {
    padding: 34px 32px 20px;
  }

  .form-message {
    padding-inline: 32px;
  }
}
