/* App additions shared by index.html and reader.html (loaded after shelf.css / reader.css). */
[hidden] { display: none !important; }

/* ---------- iPhone notch / home bar (installed app draws under the status bar) ---------- */
.topbar {
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}
.panel { top: calc(66px + env(safe-area-inset-top)); }
.toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
.to-top { bottom: calc(20px + env(safe-area-inset-bottom)); right: max(20px, env(safe-area-inset-right)); }
.app-reader .layout { padding-bottom: env(safe-area-inset-bottom); }
@media (max-width: 1000px) {
  .app-reader .toc { padding-top: calc(24px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
@media (max-width: 600px) {
  .topbar {
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .panel { top: calc(58px + env(safe-area-inset-top)); }
}
/* bigger tap targets on touch screens */
@media (pointer: coarse) {
  .topbar .btn { min-width: 42px; height: 42px; }
}

/* ---------- shelf ---------- */
.app-shelf .add-btn { gap: 6px; padding: 0 12px; }
.app-shelf .add-btn span { font-size: 14px; }
@media (max-width: 600px) { .app-shelf .add-btn span { display: none; } }

.bk { position: relative; display: flex; flex-direction: column; }
.bk .more {
  position: absolute; top: 8px; left: 8px; z-index: 3; width: 34px; min-width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; transition: opacity .2s;
}
.bk:hover .more, .bk .more:focus-visible, .bk .more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .bk .more { opacity: 1; } }
.bk .more svg { width: 16px; height: 16px; }

.add-slot { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; color: var(--text-dim); font: inherit; text-align: center; }
.add-slot .slot {
  aspect-ratio: 2/3; border-radius: 4px 10px 10px 4px; border: 2px dashed var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; transition: border-color .2s, color .2s;
}
.add-slot:hover .slot, .add-slot:focus-visible .slot { border-color: var(--accent); color: var(--text); }
.add-slot svg { width: 34px; height: 34px; }
.add-slot b { font: 600 15px var(--font-ui); }
.add-slot small { font-size: 12px; }

.empty {
  appearance: none; width: 100%; margin-top: 8px; padding: clamp(36px, 8vw, 72px) 20px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 20px; background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 10px; font: inherit; text-align: center;
  transition: border-color .2s;
}
.empty:hover, .empty:focus-visible { border-color: var(--accent); outline: none; }
.empty svg { width: 52px; height: 52px; color: var(--accent); }
.empty b { font: 600 20px var(--font-read); }
.empty span { color: var(--text-dim); font-size: 14px; }
.ios .empty .desk, .ios .hint-desk { display: none; }

.install {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 20px; padding: 14px 14px 14px 18px;
  border: 1px solid var(--accent); border-radius: 14px; background: var(--surface); font-size: 14px; line-height: 1.5;
}
.install p { margin: 0; flex: 1; }
.install .btn { flex: none; height: 32px; min-width: 32px; }
.share-ic svg { width: 16px; height: 16px; vertical-align: -3px; color: var(--accent); }

.menu {
  position: fixed; z-index: 90; min-width: 220px; padding: 6px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  text-align: left; color: var(--text); font: 500 14px var(--font-ui);
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu .danger { color: #ef4444; }

.drop {
  position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}
.drop div {
  padding: 40px 48px; border: 3px dashed var(--accent); border-radius: 24px; background: var(--surface);
  font: 600 18px var(--font-ui); color: var(--text);
}

.msg {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font: 500 14px/1.45 var(--font-ui); color: var(--text); transition: opacity .25s, transform .25s;
}
.msg.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.msg.err { border-color: #ef4444; }

/* ---------- dialogs ---------- */
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { height: 32px; font-size: 13px; padding: 0 10px; }
body.modal-open { overflow: hidden; }

.modal {
  position: fixed; inset: 0; z-index: 85; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,.55);
}
.sheet {
  width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 18px; background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text);
  font-family: var(--font-ui);
}
.sheet.small { width: min(420px, 100%); }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font: 600 18px var(--font-ui); }
.sheet-body { flex: 1; overflow-y: auto; padding: 18px 20px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-body > p { margin: 0; line-height: 1.55; }
.sheet-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.rv-note { flex: 1; font-size: 13px; color: #ef4444; }

.rv-meta { display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: start; }
.rv-cover .cover { width: 120px; }
.rv-fields { display: grid; gap: 10px; }
.rv-fields label { display: grid; gap: 4px; font: 600 11px var(--font-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); }
.sheet input:not([type]), .sheet input[type="text"] {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 500 16px var(--font-ui); letter-spacing: 0; text-transform: none;
}
.sheet input:focus { outline: none; border-color: var(--accent); }
.rv-row2 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 2px var(--bg-2); }
.swatches button[aria-checked="true"] { border-color: var(--text); }
.rv-info { margin: 14px 0 0 !important; font-size: 13px; color: var(--text-dim); }
.rv-toc-head { margin-top: 20px; }
.rv-toc-head h3 { margin: 0 0 4px; font: 600 12px var(--font-ui); letter-spacing: .18em; text-transform: uppercase; color: var(--text-dim); }
.rv-toc-head p { margin: 0 0 10px; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.rv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rv-item {
  display: grid; grid-template-columns: 28px 120px 1fr 36px; gap: 6px 8px; align-items: center;
  padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
}
.rv-item input:not([type]) { height: 36px; font-size: 16px; }
.rv-chk { display: grid; place-items: center; }
.rv-chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.rv-sub { grid-column: 2 / -1; font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-merge { width: 36px; padding: 0; }
.rv-item.off { opacity: .45; }
.rv-item.merged { margin-top: -6px; border-top-left-radius: 0; border-top-right-radius: 0; border-style: dashed; opacity: .7; }
.rv-item.merged .rv-num, .rv-item.merged .rv-name { text-decoration: line-through; }
@media (max-width: 600px) {
  .modal { padding: 0; align-items: stretch; }
  .sheet { border-radius: 0; border: 0; max-height: none; }
  .sheet-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .sheet-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sheet.small { margin: auto 16px; border-radius: 18px; border: 1px solid var(--line); }
  .modal:has(.sheet.small) { align-items: center; padding: 16px; }
  .rv-meta { grid-template-columns: 88px 1fr; gap: 14px; }
  .rv-cover .cover { width: 88px; }
  .rv-item { grid-template-columns: 26px 1fr 36px; }
  .rv-item .rv-num { grid-column: 2; }
  .rv-item .rv-name { grid-column: 2 / 4; grid-row: 2; }
  .rv-item .rv-merge { grid-column: 3; grid-row: 1; }
  .rv-item .rv-chk { grid-row: 1 / 3; }
  .rv-sub { grid-column: 2 / -1; }
}
/* no keyboard on phones */
@media (hover: none) and (pointer: coarse) { .panel .keys { display: none; } }
