:root {
  /* Стиль IntelliJ IDEA New UI (як у проєкті РЕЧОВА) */
  --primary: #3574f0;
  --primary-hover: #3069d9;
  --primary-soft: #e8f0fe;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-sub: #fafbfc;
  --border: #ebecf0;
  --border-dark: #c9ccd6;
  --text: #1e1f22;
  --text-muted: #6c707e;
  --danger-text: #db5860;
  --danger-bg: #fff1f2;
  --danger-border: #fecaca;
  --success-text: #2e8540;
  --success-bg: #f2fcf5;
  --success-border: #bbf7d0;
  --warning-text: #b87807;
  --warning-bg: #fffbe6;
  --warning-border: #ffe58f;
  --private-text: #6b21a8;
  --private-bg: #f3e8ff;
  --private-border: #e9d5ff;
  --row-hover: #f0f3f8;
  --active-row: #e4eaf8;
  --logo-book: #10234d;
  --logo-pulse: #3574f0;
  --radius: 6px;
  --radius-sm: 4px;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* IntelliJ IDEA New UI Dark */
:root[data-theme="dark"] {
  --primary: #3574f0;
  --primary-hover: #4682fa;
  --primary-soft: rgba(53, 116, 240, 0.22);
  --bg: #1e1f22;
  --surface: #2b2d30;
  --surface-sub: #26282e;
  --border: #393b40;
  --border-dark: #4e5157;
  --text: #dfe1e5;
  --text-muted: #868a91;
  --danger-text: #f75464;
  --danger-bg: rgba(247, 84, 100, 0.14);
  --danger-border: rgba(247, 84, 100, 0.35);
  --success-text: #57965c;
  --success-bg: rgba(87, 150, 92, 0.16);
  --success-border: rgba(87, 150, 92, 0.35);
  --warning-text: #e0a73c;
  --warning-bg: rgba(224, 167, 60, 0.14);
  --warning-border: rgba(224, 167, 60, 0.35);
  --private-text: #c084fc;
  --private-bg: rgba(192, 132, 252, 0.15);
  --private-border: rgba(192, 132, 252, 0.35);
  --row-hover: #32353b;
  --active-row: #2e436e;
  --logo-book: #e6e9f0;
  --logo-pulse: #6ea8fe;
  color-scheme: dark;
}

:root[data-theme="dark"] .badge {
  background: #35383e;
  border-color: #4e5157;
  color: #ced0d6;
}
:root[data-theme="dark"] .badge-private { background: var(--private-bg); border-color: var(--private-border); color: var(--private-text); }
:root[data-theme="dark"] .badge-public { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
:root[data-theme="dark"] .badge-draft { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
:root[data-theme="dark"] .badge-series { background: var(--primary-soft); border-color: rgba(53, 116, 240, 0.5); color: #8ab4f8; }
:root[data-theme="dark"] .dropzone:hover { background: rgba(53, 116, 240, 0.12); }
:root[data-theme="dark"] .player-bar { box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45); }
:root[data-theme="dark"] .img-editor-stage { background: #1e1f22; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  padding-bottom: 100px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.icon-svg {
  width: 15px;
  height: 15px;
  stroke-width: 1.6;
  stroke: currentColor;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
  display: inline-block;
  flex-shrink: 0;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  color: var(--logo-book);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}

.brand:hover {
  opacity: 0.88;
}

.brand-logo-svg {
  width: 44px;
  height: 27px;
  display: block;
  flex-shrink: 0;
}

.brand-logo-svg .logo-book {
  stroke: var(--logo-book);
}

.brand-logo-svg .logo-pulse {
  stroke: var(--logo-pulse);
}

.brand-logo-svg .logo-dot {
  fill: var(--logo-pulse);
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  font-size: 18px;
  line-height: 1;
  letter-spacing: -0.025em;
  color: var(--logo-book);
}

.brand-wordmark-bold {
  font-weight: 800;
}

.brand-wordmark-light {
  font-weight: 400;
  opacity: 0.9;
}

.brand-sub-badge {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

:root[data-theme="dark"] .brand-sub-badge {
  color: #8ab4f8;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--primary);
  display: grid;
  place-items: center;
  color: #ffffff;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons & Inputs (IntelliJ New UI) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-dark);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.1s ease, border-color 0.1s ease;
}

.btn:hover { background: var(--row-hover); border-color: #adb1bd; }
.btn:active { background: var(--active-row); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #ffffff; border-color: var(--primary); font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.btn-danger:hover { background: #ffe4e6; border-color: #fca5a5; }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 4px; }

.input, .select, .textarea {
  width: 100%;
  height: 30px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-dark);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.textarea { height: auto; min-height: 76px; padding: 7px 9px; }

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(53, 116, 240, 0.15);
}

.pill-group {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.pill:hover { color: var(--text); background: var(--row-hover); }
.pill.active { background: var(--primary); color: #ffffff; font-weight: 600; }

/* Filters & Chips */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0 12px;
  align-items: center;
}

.filters-bar .search-wrap { flex: 1 1 240px; }

.cat-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.chip {
  height: 26px;
  padding: 0 10px;
  border-radius: 13px;
  border: 1px solid var(--border-dark);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.chip:hover { background: var(--row-hover); color: var(--text); }
.chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* Cards & Grid */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(53, 116, 240, 0.1);
}

.book-cover {
  aspect-ratio: 1 / 1;
  background: var(--row-hover);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  color: var(--text-muted);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover-placeholder {
  display: grid;
  place-items: center;
  color: var(--primary);
  opacity: 0.65;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  background: #f0f3f8;
  border: 1px solid #d2d5de;
  color: #383a42;
  white-space: nowrap;
}

.badge-private { background: var(--private-bg); border-color: var(--private-border); color: var(--private-text); }
.badge-public { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.badge-draft { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.badge-series { background: var(--primary-soft); border-color: #b7d2fc; color: var(--primary); }

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 6px 0;
}
.check-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  cursor: pointer;
}

.book-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.book-title { font-weight: 600; font-size: 13.5px; margin: 0; color: var(--text); }
.book-meta { color: var(--text-muted); font-size: 12px; }

/* Book Detail */
.book-detail-header {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 20px;
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

@media (max-width: 720px) {
  .book-detail-header { grid-template-columns: 1fr; }
}

.chapters-list {
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s ease;
}

.chapter-row:last-child { border-bottom: none; }
.chapter-row:hover { background: var(--row-hover); }
.chapter-row.playing {
  background: var(--active-row);
  color: var(--primary);
}

/* Sticky Audio Player */
.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--surface);
  border-top: 1px solid var(--border-dark);
  padding: 10px 18px;
  box-shadow: 0 -4px 16px rgba(30, 31, 34, 0.08);
}

.player-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.2fr 2fr 1fr;
  gap: 14px;
  align-items: center;
}

@media (max-width: 820px) {
  .player-inner { grid-template-columns: 1fr; gap: 8px; }
}

.player-info { min-width: 0; }
.player-book { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-chapter { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }

.player-controls {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.player-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.player-seek {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.player-seek input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.player-extras {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.player-close-btn {
  min-width: 28px;
  padding: 4px 8px;
  color: var(--text-muted);
  border-color: var(--border);
  background: transparent;
}

.player-close-btn:hover {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.chapter-progress-badge {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--primary-soft);
  color: var(--primary);
}

/* Panels, Dropzone, Tables & Modals */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.dropzone {
  background: var(--surface);
  border: 2px dashed #b8c2d1;
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(30, 31, 34, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 32px rgba(30, 31, 34, 0.18);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table th {
  background: var(--surface-sub);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
}

.table tbody tr:hover { background: var(--row-hover); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.muted { color: var(--text-muted); }
.empty-state {
  text-align: center;
  padding: 40px 18px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Chapter & Player Cover Art */
.continue-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.continue-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.continue-card:hover {
  border-color: var(--primary);
  background: var(--row-hover);
}

.continue-cover {
  width: 54px;
  height: 54px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--row-hover);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.continue-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.continue-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.continue-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.continue-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.continue-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.continue-play-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 12px;
  flex-shrink: 0;
}

.continue-dismiss-btn {
  min-width: 28px;
  padding: 0 7px;
  color: var(--text-muted);
  border-color: var(--border);
  background: transparent;
}

.continue-dismiss-btn:hover {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.chapter-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chapter-thumb {
  width: 60px;
  height: 60px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  cursor: zoom-in;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.chapter-thumb:hover {
  transform: scale(1.04);
  border-color: var(--primary);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.player-meta { min-width: 0; flex: 1; }

.player-cover {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  cursor: zoom-in;
}

.artwork-lightbox {
  cursor: zoom-out;
}

.artwork-lightbox-inner {
  max-width: min(92vw, 460px);
  text-align: center;
}

.artwork-lightbox-inner img {
  width: 100%;
  max-height: 76vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

.artwork-lightbox-caption {
  margin-top: 10px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
}

/* Image Editor Modal */
.img-editor-card {
  max-width: 420px;
  max-height: 92vh;
  overflow-y: auto;
}

.img-editor-stage {
  position: relative;
  width: min(300px, 76vw);
  height: min(300px, 76vw);
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-dark);
  background: #ebecf0;
  touch-action: none;
  cursor: grab;
}

.img-editor-stage:active { cursor: grabbing; }

.img-editor-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.img-editor-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.35) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.35) 1px, transparent 1px);
  background-size: 33.333% 33.333%;
  box-shadow: inset 0 0 0 1px rgba(53, 116, 240, 0.45);
}

.img-editor-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.img-editor-sliders {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.img-editor-sliders input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

/* Audio Waveform Visualizer & Timed Engraving Sketch Stage */
.btn-active-icon {
  background: var(--primary-soft) !important;
  border-color: var(--primary) !important;
  color: var(--primary) !important;
}

.player-wave {
  display: block;
  width: 100%;
  max-width: 1120px;
  height: 32px;
  margin: 0 auto 8px;
}

.sketch-stage {
  max-width: 1120px;
  margin: 0 auto 10px;
  display: flex;
  justify-content: center;
}

.sketch-paper {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: #faf6ed;
  border: 1px solid #dfd7c5;
  border-radius: 8px;
  padding: 12px 12px 10px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(30, 31, 34, 0.12);
}

:root[data-theme="dark"] .sketch-paper {
  background: #23252a;
  border-color: #3d4047;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.sketch-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 4px;
}

.sketch-frame {
  width: 100%;
  max-width: 260px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 5px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.sketch-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.sketch-user-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 4px;
  cursor: zoom-in;
}

.sketch-caption {
  margin-top: 8px;
  font-size: 12.5px;
  font-style: italic;
  color: #4b463d;
}

:root[data-theme="dark"] .sketch-caption {
  color: #c3c7d1;
}

.sketch-dots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.sketch-dot {
  border: 1px solid var(--border-dark);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
}

.sketch-dot.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Smartphone Adaptation (iOS Safari + Android Chrome) */
button, .btn, .chip, .pill, .book-card, .chapter-row {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.player-bar {
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}

body.player-open {
  padding-bottom: 130px;
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
    padding-bottom: 40px;
  }

  body.player-open {
    padding-bottom: calc(185px + env(safe-area-inset-bottom, 0px));
  }

  .container {
    padding: 0 12px;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  .input, .select, .textarea {
    font-size: 16px;
    height: 38px;
  }

  .btn {
    min-height: 36px;
    padding: 0 12px;
    font-size: 13.5px;
  }

  .btn-sm {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12.5px;
  }

  .pill {
    padding: 6px 11px;
    font-size: 13px;
  }

  .cat-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .cat-chips::-webkit-scrollbar { display: none; }
  .chip {
    flex-shrink: 0;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
  }

  .book-detail-header {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px;
  }

  .book-detail-header .book-cover {
    max-width: 220px;
    margin: 0 auto;
    width: 100%;
  }

  .chapter-row {
    padding: 11px 12px;
    min-height: 48px;
  }

  /* Compact touch-friendly sticky player on mobile */
  .player-bar {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .player-inner {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .player-buttons {
    gap: 8px;
  }

  .player-buttons .btn {
    min-height: 38px;
    min-width: 42px;
  }

  .player-extras {
    justify-content: space-between;
  }

  .player-extras .select {
    height: 34px;
    font-size: 13px !important;
  }

  .player-close-btn {
    min-height: 34px;
    min-width: 36px;
  }
}

@media (max-width: 560px) {
  .books-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .book-body {
    padding: 9px;
    gap: 4px;
  }

  .book-title {
    font-size: 13px;
    line-height: 1.3;
  }

  .book-meta {
    font-size: 11.5px;
  }

  .badge {
    font-size: 10px;
    padding: 1px 5px;
  }
}

/* Chapter Drawing Studio Overlay (Laptop & Smartphone) */
body.draw-open {
  overflow: hidden;
}

.draw-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.draw-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  gap: 8px;
}

.draw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.draw-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.draw-title-meta {
  min-width: 0;
}

.draw-title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draw-status {
  font-size: 11px;
}

.draw-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.draw-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.draw-paper-wrap {
  width: min(100%, 100vh - 220px, 680px);
  max-height: 100%;
  aspect-ratio: 1 / 1;
  background: #faf6ed;
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

.draw-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.draw-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draw-colors {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
}

.draw-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.draw-swatch.active {
  transform: scale(1.15);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.draw-swatch-custom {
  position: relative;
  display: grid;
  place-items: center;
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.draw-swatch-custom input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.draw-controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  .draw-shell {
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .draw-paper-wrap {
    width: min(100%, 100vh - 235px);
  }

  .draw-swatch {
    width: 26px;
    height: 26px;
  }
}
