/* Ensure [hidden] always wins over component display rules */
[hidden] {
  display: none !important;
}


/* ── Font size setting ───────────────────────────────────────────────────── */
html.font-md {
  --fs-12: 15px;
  --fs-13: 16px;
  --fs-14: 18px;
  --fs-15: 19px;
  --fs-16: 20px;
  --fs-18: 23px;
  --fs-22: 28px;
  --fs-28: 35px;
}

html.font-lg {
  --fs-12: 18px;
  --fs-13: 20px;
  --fs-14: 21px;
  --fs-15: 23px;
  --fs-16: 24px;
  --fs-18: 27px;
  --fs-22: 33px;
  --fs-28: 42px;
}

/* ── Settings cog ────────────────────────────────────────────────────────── */
.btn-settings {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-subtle);
  flex-shrink: 0;
}

.btn-settings:active { opacity: 0.6; }

.is-native .footer-text { display: none; }

.font-size-picker {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  margin: var(--space-4) 0 var(--space-2);
}

.font-size-picker__btn {
  flex: 1;
  padding: var(--space-3);
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
}

.font-size-picker__btn.is-selected {
  border-color: var(--primary, #43352f);
  background: var(--surface-raised, #f0ece4);
}

.font-size-picker__label {
  font-size: var(--fs-12);
  color: var(--text-subtle);
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
}

.spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pwa-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: var(--bg);
  transition: opacity 0.25s ease;
}

@media (display-mode: standalone) {
  .pwa-splash {
    display: flex;
  }
}

.pwa-splash.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.pwa-splash-logo {
  width: 35vw;
  max-width: 180px;
  aspect-ratio: 1;
  background: url('/assets/icon-512.png') center / contain no-repeat;
}

.pwa-splash-title {
  font-size: var(--fs-28);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

/* ── Search bar ──────────────────────────────────────────────────────────── */

#btn-search[aria-expanded='true'] {
  color: var(--primary);
}

.app-search-bar {
  padding: var(--space-2) var(--space-4);
  background: var(--bg);
  display: flex;
  justify-content: center;
}

.app-search-bar .app-input {
  margin-bottom: 0;
  max-width: calc(480px - 2 * var(--space-4));
  width: 100%;
}

/* ── Book index ──────────────────────────────────────────────────────────── */

.reorder-banner {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--fs-14);
  color: var(--text-subtle);
}

.reorder-banner[hidden] {
  display: none;
}

.book-grid .book-card {
  transition: transform 0.12s ease;
}

.book-grid .book-card.is-dragging {
  transition: none;
  opacity: 0.5;
  z-index: 5;
  position: relative;
}

.drag-handle {
  touch-action: none;
  cursor: grab;
  flex-shrink: 0;
}

.drag-handle:active {
  cursor: grabbing;
}

.page-card__badge {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-subtle);
  line-height: 1;
}

.book-grid__empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: var(--fs-14);
  color: var(--text-subtle);
  padding: var(--space-6) 0;
}

/* ── Page editor ─────────────────────────────────────────────────────────── */

.page-editor-header {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  background: #fff;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}

.page-editor-header__top {
  height: 52px;
}

.editor-search-overlay {
  position: absolute;
  top: var(--space-3);
  right: var(--space-4);
  width: fit-content;
  z-index: 20;
}

.editor-search-overlay .app-input {
  margin-bottom: 0;
  background: var(--bg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.search-results-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  max-height: 240px;
  overflow-y: auto;
  min-width: 220px;
}

.search-results-list li {
  padding: 6px 12px;
  cursor: pointer;
  font-size: var(--fs-13);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results-list li:hover,
.search-results-list li.is-active {
  background: var(--bg-subtle);
}

.search-results-list__empty {
  color: var(--text-subtle);
  cursor: default;
}

/* Hide Excalidraw's hamburger and help button — we replaced these */
.main-menu-trigger,
.help-icon {
  display: none !important;
}

/* ── Global search dialog ────────────────────────────────────────────────── */

.global-search-dialog {
  width: min(92vw, 520px);
}

.global-search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
}

.global-search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.1s;
}

.global-search-result:hover,
.global-search-result:focus-visible {
  background: var(--bg-subtle);
  outline: none;
}

.global-search-result__text {
  font-size: var(--fs-14);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.global-search-result__page {
  font-size: var(--fs-11);
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.global-search-empty {
  font-size: var(--fs-14);
  color: var(--text-subtle);
  text-align: center;
  margin: var(--space-4) 0 var(--space-2);
}

/* ── Book list ────────────────────────────────────────────────────────────── */

.app-header {
  height: calc(74px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}

.fab {
  position: fixed;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  right: var(--space-5);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary, #43352f);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 20;
}

.fab:active {
  opacity: 0.85;
}

.app-header-logo {
  width: 64px;
  height: 64px;
}


.app-header-title {
  font-size: var(--fs-18);
  font-weight: 700;
  color: var(--text);
}

.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 44px;
  height: calc(44px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-subtle);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  z-index: 10;
}

main.f-fill {
  padding-bottom: calc(44px + env(safe-area-inset-bottom));
}


.book-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-4);
  box-sizing: border-box;
}

.book-card {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid #c8c8c4;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-3);
  transition: box-shadow 0.15s;
  min-height: 80px;
}

.book-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-color: #b8b8b4;
}

.book-card:active {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.book-card__thumb {
  flex-shrink: 0;
  width: 64px;
  aspect-ratio: 1;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-card__thumb .ic {
  width: 32px;
  height: 32px;
}

.book-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-1);
  min-width: 0;
  padding-right: var(--space-6);
}

.book-card__title {
  font-size: var(--fs-15, var(--fs-14));
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card__date {
  font-size: var(--fs-12);
  color: var(--text-subtle);
}

.book-card__menu {
  position: absolute;
  bottom: var(--space-1);
  right: var(--space-1);
}

/* ── Dropdowns ───────────────────────────────────────────────────────────── */

.app-dropdown {
  position: fixed;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.14),
    0 2px 6px rgba(0, 0, 0, 0.08);
  min-width: 200px;
  display: flex;
  flex-direction: column;
}

.app-dropdown[hidden] {
  display: none;
}

.app-dropdown .menu-item {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-14);
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  width: 100%;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-dropdown .menu-item:hover,
.app-dropdown .menu-item:active {
  background: var(--surface-sunken);
}

.app-dropdown .menu-item.danger {
  color: var(--danger, #c0392b);
}

.app-dropdown .menu-sep {
  height: 1px;
  background: var(--line);
  margin: var(--space-1) 0;
}

/* ── Dialog ──────────────────────────────────────────────────────────────── */

.app-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: min(92vw, 400px);
  background: var(--bg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.app-dialog__title {
  font-size: var(--fs-18);
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--space-4);
}

.app-dialog__label {
  display: block;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text-subtle);
  margin-bottom: var(--space-2);
}

.app-input {
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-15);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  outline: none;
  margin-bottom: var(--space-4);
  font-family: inherit;
}

.app-input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.app-input--compact {
  margin-bottom: var(--space-2);
}

.app-dialog__body {
  font-size: var(--fs-14);
  color: var(--text-subtle);
  line-height: 1.5;
  margin: 0 0 var(--space-5);
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  height: 155px;
  overflow-y: auto;
}

.icon-picker__empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: var(--fs-13);
  color: var(--text-subtle);
  padding: var(--space-4) 0;
}

.icon-picker__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background: var(--surface);
  cursor: pointer;
  color: inherit;
  transition:
    background 0.1s,
    border-color 0.1s,
    opacity 0.1s;
  padding: 0;
}

.icon-picker__btn:hover {
  background: var(--surface-sunken);
  opacity: 0.8;
}

.icon-picker__btn.is-selected {
  border-color: currentColor;
  background: var(--surface-sunken);
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.color-picker__btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline-offset: 2px;
}

.color-picker__btn.is-selected {
  border-color: var(--text);
}

.btn.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn.btn-primary:hover {
  opacity: 0.85;
}

.btn.btn-primary:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Landing gate ────────────────────────────────────────────────────────────── */

.landing-main {
  padding: var(--space-6) var(--space-4);
}

.landing-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 340px;
  width: 100%;
  gap: var(--space-3);
}

.landing-gate__logo {
  width: 72px;
  max-width: 72px;
  margin-bottom: var(--space-2);
}

.landing-gate__title {
  font-size: var(--fs-22);
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.landing-gate__message {
  font-size: var(--fs-14);
  color: var(--text-subtle);
  line-height: 1.5;
  margin: 0;
}

.landing-gate__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-2);
}

.landing-gate__actions .btn {
  width: 100%;
}

.landing-gate__btn-continue {
  outline: 1px solid var(--line);
  outline-offset: -1px;
}

.landing-gate__hint {
  font-size: var(--fs-12);
  color: var(--text-subtle);
  line-height: 1.5;
  margin: 0;
}

/* ── Splash ────────────────────────────────────────────────────────────────── */

.pwa-splash-footer {
  position: absolute;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  font-size: var(--fs-13);
  color: var(--text-subtle);
}

.HintViewer {
  display: none !important;
}
