:root {
  color-scheme: light;
  --bg: #f4efe7;
  --panel: rgba(255, 251, 247, 0.84);
  --panel-strong: rgba(255, 247, 239, 0.96);
  --line: rgba(74, 51, 40, 0.14);
  --text: #2f221d;
  --muted: #71564b;
  --accent: #8e2f2a;
  --accent-soft: #edd3ca;
  --danger: #7f1d1d;
  --shadow: 0 24px 60px rgba(87, 57, 36, 0.14);
  --radius-lg: 28px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(214, 165, 121, 0.28), transparent 32%),
    radial-gradient(circle at bottom right, rgba(128, 50, 45, 0.18), transparent 36%),
    linear-gradient(145deg, #f9f4eb, #efe4d6);
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.page-shell,
.login-shell {
  min-height: 100vh;
  padding: 28px;
}

.page-shell {
  width: min(100%, 1480px);
  margin: 0 auto;
}

.login-shell {
  display: grid;
  place-items: center;
}

.login-card,
.panel,
.edit-dialog {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.54);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(100%, 480px);
  padding: 32px;
  border-radius: var(--radius-lg);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
}

h2 {
  font-size: 1.7rem;
}

.login-copy,
.hero-copy,
.status,
.security-note p,
.card-date,
.card-url,
.source {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.92rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
}

.note-textarea {
  min-height: 132px;
  resize: vertical;
}

.html-textarea {
  width: 100%;
  min-height: 180px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  font: inherit;
  resize: vertical;
}

.primary-button,
.ghost-button {
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background-color 140ms ease;
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, #9a3a34, #6d221e);
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(68, 43, 33, 0.12);
}

.danger-button {
  color: var(--danger);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.hero-controls {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-status {
  text-align: right;
}

.content-shell {
  min-width: 0;
}

.panel {
  border-radius: var(--radius-lg);
  padding: 24px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.catalog-head {
  align-items: center;
}

.filter-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.compact-field,
.search-field {
  min-width: 0;
}

.stats {
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 24px 18px;
  align-items: start;
}

.empty-state {
  overflow: hidden;
}

.card {
  display: grid;
  gap: 10px;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: visible;
}

.thumb-wrap {
  aspect-ratio: 0.7 / 1;
  border-radius: 18px 18px 10px 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(238, 219, 206, 0.88)),
    linear-gradient(135deg, rgba(142, 47, 42, 0.14), rgba(243, 225, 213, 0.9));
  box-shadow:
    0 18px 30px rgba(78, 46, 28, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  overflow: hidden;
  position: relative;
}

.thumb,
.thumb-placeholder {
  width: 100%;
  height: 100%;
}

.thumb {
  display: block;
  object-fit: cover;
  object-position: center top;
  background: rgba(255, 255, 255, 0.7);
}

.thumb-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.16em;
}

.card-body {
  display: grid;
  gap: 6px;
  padding: 0 4px;
}

.card h3 {
  font-size: 0.98rem;
  line-height: 1.45;
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-weight: 700;
  letter-spacing: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-note {
  position: relative;
  display: inline-flex;
  width: fit-content;
}

.note-chip {
  border: 1px solid rgba(142, 47, 42, 0.18);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--accent);
  background: rgba(142, 47, 42, 0.08);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  cursor: help;
}

.note-chip:focus-visible {
  outline: 2px solid rgba(142, 47, 42, 0.42);
  outline-offset: 2px;
}

.note-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  z-index: 4;
  width: min(520px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 250, 245, 0.98);
  border: 1px solid rgba(74, 51, 40, 0.12);
  box-shadow: 0 18px 34px rgba(44, 26, 20, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.card-note:hover .note-popover,
.card-note:focus-within .note-popover {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.note-popover-label {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.note-popover-body {
  margin: 0;
  max-height: min(60vh, 420px);
  overflow: auto;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.65;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.card-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.shelf-book {
  position: relative;
  padding-bottom: 12px;
}

.shelf-book::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(98, 63, 46, 0.26), rgba(98, 63, 46, 0.04));
  filter: blur(1px);
}

.cover-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.card:hover .card-actions,
.card:focus-within .card-actions {
  opacity: 1;
  transform: translateY(0);
}

.shelf-button {
  padding: 8px 10px;
  font-size: 0.78rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 16px rgba(44, 26, 20, 0.12);
}

.empty-state {
  padding: 32px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(74, 51, 40, 0.08);
}

.status {
  min-height: 1.3em;
  margin: 4px 0 0;
}

.edit-dialog {
  width: min(100% - 24px, 520px);
  border: 0;
  border-radius: 26px;
  padding: 0;
}

.edit-dialog::backdrop {
  background: rgba(44, 26, 20, 0.42);
  backdrop-filter: blur(4px);
}

.dialog-form {
  padding: 24px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

@media (max-width: 720px) {
  .page-shell,
  .login-shell {
    padding: 16px;
  }

  .hero {
    flex-direction: column;
  }

  .hero-controls {
    width: 100%;
    justify-items: stretch;
  }

  .hero-actions {
    justify-content: flex-start;
  }

  .hero-status {
    text-align: left;
  }

  .filter-row {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .card-actions {
    opacity: 1;
    transform: translateY(0);
  }
}
