
:root {
  color-scheme: light;
  --bg: #f4f1e8;
  --paper: #fffdf7;
  --ink: #1d2832;
  --muted: #697580;
  --line: #ded8ca;
  --accent: #17324d;
  --accent-soft: #e7eef4;
  --danger: #8b2f2f;
  --shadow: 0 12px 32px rgba(40, 48, 54, .10);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Yu Gothic UI", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(255,255,255,.9), transparent 35%),
    var(--bg);
  color: var(--ink);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(23, 50, 77, .25);
  outline-offset: 3px;
}

.topbar {
  max-width: 1120px;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(30px, 6vw, 46px); letter-spacing: -.04em; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px max(48px, env(safe-area-inset-bottom));
}

.hero {
  padding: 18px 0 22px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.hero-copy { margin-bottom: 3px; font-weight: 800; font-size: 18px; }
.hero-sub { margin: 0; color: var(--muted); }

.primary-button, .secondary-button, .read-button, .icon-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.primary-button:active, .secondary-button:active, .read-button:active, .icon-button:active {
  transform: scale(.97);
}

.primary-button {
  flex: 0 0 auto;
  padding: 14px 21px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  font-size: 16px;
  box-shadow: 0 6px 18px rgba(23,50,77,.18);
}

.icon-button {
  width: 46px;
  height: 46px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 21px;
}

.status {
  min-height: 26px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}
.status.error { color: var(--danger); }

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.wiki-card, .skeleton-card {
  min-width: 0;
  border-radius: 24px;
  background: var(--paper);
  border: 1px solid rgba(160,150,130,.24);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.wiki-card { display: flex; flex-direction: column; min-height: 490px; }

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: linear-gradient(135deg, #dfe9ef, #ebe5d9);
}

.thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.thumb.loaded { display: block; }

.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(23,50,77,.32);
  font: 900 54px/1 Georgia, serif;
}

.card-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}
.length-label { color: var(--muted); font-size: 12px; }

.card-title {
  margin-bottom: 10px;
  font-size: 23px;
  line-height: 1.3;
  letter-spacing: -.02em;
}

.extract {
  margin-bottom: 18px;
  color: #46535e;
  font-size: 15px;
  line-height: 1.75;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  overflow: hidden;
}

.card-actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  gap: 8px;
}

.read-button, .secondary-button {
  min-height: 44px;
  padding: 11px 12px;
  display: grid;
  place-items: center;
  text-decoration: none;
  font-weight: 900;
}
.read-button { background: var(--accent); color: white; }
.secondary-button {
  background: var(--accent-soft);
  color: var(--accent);
}
.secondary-button.saved { background: #e9efe4; color: #365428; }

.minor-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
}

.text-button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}
.text-button:hover { text-decoration-color: currentColor; }
.text-button.danger { color: var(--danger); }

.hint {
  margin-top: 24px;
  padding: 16px 18px;
  border: 1px dashed #c7bfaf;
  border-radius: 18px;
  color: var(--muted);
  line-height: 1.6;
}
.hint strong { color: var(--ink); }
.hint p { margin: 3px 0 0; }

.skeleton-card {
  height: 490px;
  background:
    linear-gradient(110deg, #fffdf7 25%, #f0ece3 37%, #fffdf7 50%);
  background-size: 200% 100%;
  animation: shimmer 1.25s infinite linear;
}
@keyframes shimmer { to { background-position-x: -200%; } }

.library-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: min(82vh, 850px);
  border: 0;
  border-radius: 26px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0,0,0,.28);
}
.library-dialog::backdrop { background: rgba(20,30,40,.42); backdrop-filter: blur(3px); }

.dialog-head {
  padding: 20px 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-head h2 { margin: 0; font-size: 28px; }

.tabs {
  display: flex;
  gap: 7px;
  padding: 0 20px 12px;
  overflow-x: auto;
}
.tab {
  white-space: nowrap;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.library-content {
  min-height: 220px;
  max-height: 48vh;
  overflow-y: auto;
  padding: 4px 20px 18px;
}

.library-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.library-item:last-child { border-bottom: 0; }
.library-item h3 { margin: 0 0 5px; font-size: 17px; }
.library-item p { margin: 0 0 8px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.library-item-actions { display: flex; gap: 14px; align-items: center; }
.library-item a { color: var(--accent); font-weight: 900; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

.danger-zone {
  padding: 12px 20px 18px;
  border-top: 1px solid var(--line);
}

@media (max-width: 830px) {
  .cards { grid-template-columns: 1fr; }
  .wiki-card { min-height: 0; }
  .thumb-wrap { aspect-ratio: 2 / 1; }
  .extract { -webkit-line-clamp: 5; }
  .skeleton-card { height: 440px; }
}

@media (max-width: 560px) {
  .topbar { padding-left: 16px; padding-right: 16px; }
  main { padding-left: 16px; padding-right: 16px; }
  .hero { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .wiki-card { border-radius: 20px; }
  .card-title { font-size: 21px; }
  .thumb-wrap { aspect-ratio: 16 / 9; }
}
