:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  color: #172033;
  background: #ffffff;
  font-synthesis: none;
  --ink: #172033;
  --muted: #667085;
  --paper: #ffffff;
  --canvas: #f6f8fb;
  --line: #dfe3eb;
  --line-strong: #c9d0dc;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #edf4ff;
  --green: #267a55;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(23, 32, 51, 0.08);
  --shadow-small: 0 8px 24px rgba(23, 32, 51, 0.06);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: linear-gradient(180deg, #ffffff 0, var(--canvas) 38rem, var(--canvas) 100%);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.28); outline-offset: 3px; }

.shell {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 72px;
}
.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 30px;
}
.brand-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  font-size: clamp(34px, 5vw, 52px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.045em;
}
h2 {
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -.02em;
}
h3 { margin-bottom: 10px; font-size: 16px; }

.button, button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  color: var(--ink);
  background: var(--paper);
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .15s ease;
}
.primary { border-color: var(--accent); color: white; background: var(--accent); }
.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.ghost:hover { border-color: var(--line-strong); background: var(--canvas); }
.danger { color: var(--danger); }

.topbar-actions { position: relative; }
.menu-trigger {
  display: grid;
  width: 46px;
  min-height: 46px;
  place-content: center;
  gap: 5px;
  padding: 0;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow-small);
}
.menu-trigger span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 99px;
  background: var(--ink);
  transition: transform .15s ease, opacity .15s ease;
}
.menu-trigger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-trigger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-trigger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.app-menu {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.app-menu button { width: 100%; border: 0; text-align: left; background: transparent; }
.app-menu button:hover { background: #fff1f0; }

.auth-card, .loading-card, .empty, .detail-panel {
  max-width: 660px;
  margin: 10vh auto 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(24px, 5vw, 48px);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.auth-card { border-top: 4px solid var(--accent); }
.auth-card h1 { margin-bottom: 20px; }
.auth-card form, .stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink);
  background: white;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea { min-height: 130px; resize: vertical; line-height: 1.7; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 560px);
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow-small);
}
.inline-form { display: flex; gap: 8px; }
.inline-form input { min-width: 0; }
.inline-form button { flex: 0 0 auto; }
.status-line { min-height: 24px; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.status-line.error { color: var(--danger); }

.floating-save {
  position: fixed;
  z-index: 30;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: inline-flex;
  min-height: 54px;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 13px 20px 13px 16px;
  color: white;
  background: var(--accent);
  box-shadow: 0 16px 36px rgba(37, 99, 235, .3);
  font-weight: 800;
}
.floating-save span { font-size: 23px; font-weight: 400; line-height: 1; }
.floating-save:hover { background: var(--accent-dark); transform: translateY(-2px); }

.quick-save-dialog {
  position: fixed;
  inset: auto max(22px, env(safe-area-inset-right)) max(88px, calc(env(safe-area-inset-bottom) + 76px)) auto;
  width: min(440px, calc(100% - 32px));
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 28px 72px rgba(23, 32, 51, .22);
}
.quick-save-dialog::backdrop { background: rgba(23, 32, 51, .18); backdrop-filter: blur(2px); }
.quick-save-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.quick-save-head h2 { margin-bottom: 0; font-size: 22px; }
.quick-save-copy { margin: 14px 0 20px; color: var(--muted); line-height: 1.65; }
.dialog-close { width: 38px; min-height: 38px; padding: 0; border: 0; border-radius: 50%; background: var(--canvas); font-size: 23px; line-height: 1; }
.quick-save-form { display: grid; gap: 12px; }
.quick-save-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.book-card {
  display: flex;
  overflow: hidden;
  min-height: 330px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow-small);
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.book-card:hover { transform: translateY(-3px); border-color: #b9c8e7; box-shadow: var(--shadow); }
.book-card:active { transform: translateY(-1px); }
.card-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 8.5;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(145deg, #eaf1ff, #f7f9fc);
}
.card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.book-card:hover .card-media img { transform: scale(1.025); }
.card-media-placeholder { display: grid; height: 100%; place-items: center; color: #8ca5d8; }
.card-media-placeholder span { font-size: 32px; font-weight: 800; letter-spacing: -.05em; }
.card-body { display: flex; min-height: 0; flex: 1; flex-direction: column; padding: 18px; }
.site { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.source-kind {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid #c9d9fb;
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .09em;
}
.source-kind.youtube { border-color: #f5c2c0; color: #b42318; background: #fff1f0; }
.source-kind.pdf { border-color: #d7c8f8; color: #6941c6; background: #f5f0ff; }
.source-kind.x { border-color: #cfd4dc; color: #111827; background: #f8fafc; }
.source-kind.audio { border-color: #a7e0cf; color: #08745f; background: #ecfdf8; }
.source-kind.image { border-color: #b7d3f8; color: #175cd3; background: #eff8ff; }
.source-kind.video { border-color: #c4b5fd; color: #5b21b6; background: #f5f3ff; }
.source-kind.email { border-color: #a9d7ef; color: #075985; background: #f0f9ff; }
.brand-kicker .source-kind { margin-right: 8px; vertical-align: middle; }
.detail-audio { width: 100%; margin: 20px 0 4px; }
.detail-video { display: block; width: 100%; max-height: min(70vh, 720px); margin: 20px 0 4px; border-radius: 14px; background: #101828; }
.book-card h2 { margin-bottom: 11px; font-size: 19px; line-height: 1.45; }
.summary { display: -webkit-box; overflow: hidden; margin-bottom: 16px; color: #475467; line-height: 1.65; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 16px; }
.card-open-hint { color: var(--accent); font-size: 12px; font-weight: 800; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag, .status-badge { border-radius: 99px; padding: 4px 8px; background: #eef1f5; color: #526072; font-size: 11px; }
.status-badge.ready { background: #e8f5ee; color: var(--green); }
.status-badge.failed { background: #feeceb; color: var(--danger); }
.status-badge.processing, .status-badge.queued { background: #fff4dd; color: #8a6116; }

.detail-view .toolbar, .detail-view > .status-line { display: none; }
.detail-nav {
  position: sticky;
  z-index: 15;
  top: max(12px, env(safe-area-inset-top));
  width: max-content;
  margin: 0 0 14px;
}
.back-button {
  min-height: 44px;
  border-color: var(--line-strong);
  border-radius: 12px;
  padding-inline: 14px 17px;
  font-weight: 750;
  box-shadow: var(--shadow-small);
}
.back-button:hover { border-color: #9eb2da; color: var(--accent-dark); background: var(--paper); }
.back-arrow { margin-right: 7px; font-size: 18px; }
.detail-panel { max-width: 860px; margin-top: 0; padding: clamp(22px, 5vw, 48px); }
.detail-head { display: flex; justify-content: space-between; gap: 16px; }
.detail-head h2 { margin-bottom: 12px; font-size: clamp(25px, 4vw, 38px); line-height: 1.35; }
.detail-meta { color: var(--muted); font-size: 13px; }
.detail-hero {
  overflow: hidden;
  margin: 26px 0 30px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
}
.detail-hero img { display: block; width: 100%; max-height: 540px; object-fit: contain; }
.detail-hero figcaption, .image-gallery figcaption { padding: 9px 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.summary-full { color: #344054; font-size: 16px; line-height: 1.85; }
.key-points { margin-bottom: 28px; padding-left: 1.3rem; color: #344054; line-height: 1.8; }
.image-section { margin: 30px 0; }
.image-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.image-gallery figure { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.image-gallery img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.source-link { display: inline-flex; align-items: center; text-decoration: none; color: var(--accent-dark); }
.source-link:hover { border-color: #9eb2da; background: var(--accent-soft); }
.error-box { border-radius: 10px; padding: 12px; color: var(--danger); background: #feeceb; }
.hidden, [hidden] { display: none !important; }

.summary-overview {
  margin: 30px 0 42px;
  border: 1px solid #c9d9fb;
  border-radius: 16px;
  padding: clamp(20px, 4vw, 30px);
  background: linear-gradient(145deg, #f4f8ff, #ffffff);
}
.summary-label { margin-bottom: 8px; color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.summary-overview h3 { margin-bottom: 12px; font-size: 21px; }
.summary-overview > p:not(.summary-label) { margin-bottom: 18px; color: #344054; font-size: 16px; line-height: 1.85; }
.summary-overview ul { display: grid; gap: 9px; margin: 0; padding-left: 1.3rem; color: #263753; line-height: 1.65; }
.summary-sections { display: grid; gap: 42px; }
.summary-section { padding-bottom: 40px; border-bottom: 1px solid var(--line); }
.summary-section:last-child { border-bottom: 0; }
.summary-section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.summary-section-head > span { color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.summary-section-head h3 { margin: 0; font-size: clamp(20px, 3vw, 27px); line-height: 1.4; }
.timestamp-link {
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 999px;
  padding: 5px 9px;
  color: #b42318;
  background: #fff1f0;
  font-size: 11px;
  font-weight: 850;
  text-decoration: none;
}
.timestamp-link:hover { background: #fee4e2; }
.section-copy p { color: #344054; font-size: 16px; line-height: 1.9; }
.section-highlights {
  display: grid;
  gap: 10px;
  margin: 22px 0;
  padding: 16px 18px 16px 40px;
  border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0;
  color: #1d3153;
  background: var(--accent-soft);
  line-height: 1.7;
}
.section-images { display: grid; gap: 18px; margin: 24px 0; }
.section-image { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.section-image img, .detail-hero img { display: block; width: 100%; height: auto; max-height: none; object-fit: contain; }
.section-image figcaption { padding: 10px 13px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.section-annotations { margin-top: 22px; border-radius: 12px; padding: 16px; background: #f8fafc; }
.annotation-title { margin-bottom: 9px; color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.section-annotations dl { display: grid; gap: 10px; margin: 0; }
.section-annotations dl > div { display: grid; grid-template-columns: minmax(90px, 150px) 1fr; gap: 10px; }
.section-annotations dt { font-weight: 800; }
.section-annotations dd { margin: 0; color: #475467; line-height: 1.6; }

.saved-highlights {
  margin: 44px 0 32px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 32px 0;
}
.saved-highlights-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.saved-highlights-head h3 { margin: 0; font-size: 23px; }
.saved-highlights-head > span { border-radius: 99px; padding: 5px 9px; color: var(--accent-dark); background: var(--accent-soft); font-size: 11px; font-weight: 900; }
.highlight-list { display: grid; gap: 12px; }
.highlight-item { border: 1px solid var(--line); border-radius: 13px; padding: 17px; background: #fbfcfe; }
.highlight-item blockquote { margin: 0; border-left: 3px solid var(--accent); padding-left: 14px; color: #263753; font-size: 15px; line-height: 1.8; }
.highlight-note { margin: 14px 0 0; border-radius: 9px; padding: 11px 12px; color: #475467; background: #fff; font-size: 13px; line-height: 1.65; }
.highlight-note span { display: block; margin-bottom: 3px; color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .08em; }
.highlight-item footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 11px; color: var(--muted); font-size: 11px; }
.highlight-delete { min-height: 32px; border: 0; padding: 4px 8px; color: var(--danger); background: transparent; font-size: 11px; }
.highlight-empty { margin: 0; border-radius: 11px; padding: 16px; color: var(--muted); background: #f8fafc; font-size: 13px; line-height: 1.7; }
.highlightable-content { user-select: text; -webkit-user-select: text; }
.selection-highlight-bar {
  position: fixed;
  z-index: 45;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  width: min(680px, calc(100% - 150px));
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transform: translateX(-50%);
  border: 1px solid #b9c8e7;
  border-radius: 16px;
  padding: 11px 12px 11px 16px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 20px 56px rgba(23, 32, 51, .22);
}
.selection-highlight-bar p { min-width: 0; margin: 0; color: #475467; font-size: 12px; line-height: 1.45; }
.selection-highlight-bar p span { display: block; margin-bottom: 2px; color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.selection-highlight-bar q { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-highlight-bar button { flex: 0 0 auto; }
.highlight-dialog {
  width: min(520px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 28px 72px rgba(23, 32, 51, .24);
}
.highlight-dialog::backdrop { background: rgba(23, 32, 51, .2); backdrop-filter: blur(2px); }
.highlight-dialog blockquote { max-height: 180px; overflow: auto; margin: 18px 0; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; padding: 12px 14px; color: #263753; background: var(--accent-soft); line-height: 1.7; }
.highlight-dialog textarea { min-height: 105px; }
.status-line.success { color: var(--green); }

@media (max-width: 850px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .shell { width: min(100% - 22px, 1160px); }
  .topbar { align-items: center; margin-bottom: 24px; }
  h1 { font-size: 34px; }
  .book-grid { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form button { width: 100%; }
  .card-media { aspect-ratio: 16 / 8; }
  .detail-panel { border-radius: 16px; }
  .image-gallery { grid-template-columns: 1fr; }
  .detail-actions { flex-direction: column; }
  .detail-actions > * { justify-content: center; width: 100%; }
  .floating-save { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); min-height: 50px; padding: 11px 17px 11px 13px; }
  .quick-save-dialog {
    inset: auto 0 0 0;
    width: 100%;
    max-width: none;
    border-width: 1px 0 0;
    border-radius: 22px 22px 0 0;
    padding: 22px 18px max(22px, env(safe-area-inset-bottom));
  }
  .section-annotations dl > div { grid-template-columns: 1fr; gap: 3px; }
  .summary-section-head { align-items: flex-start; flex-wrap: wrap; }
  .timestamp-link { margin-left: 34px; }
  .selection-highlight-bar { bottom: max(78px, calc(env(safe-area-inset-bottom) + 68px)); width: calc(100% - 28px); }
  .selection-highlight-bar p { max-width: calc(100% - 118px); }
  .highlight-dialog { inset: auto 0 0 0; width: 100%; max-width: none; margin: 0; border-width: 1px 0 0; border-radius: 22px 22px 0 0; padding: 22px 18px max(22px, env(safe-area-inset-bottom)); }
}
