/* board-extras.css — additional styles for Timelense-board.html
   Supplements prototypes/proto-common.css with detail panel, edit forms,
   loading states, and board-specific additions. */

/* ── Scroll sync: force instant programmatic scrolling ────────────────────────
   proto-common.css sets `scroll-behavior: smooth` on .study-column-track. In the
   real board, multiple tracks are scroll-synced to each other. A smooth animated
   scroll fires many scroll events over its ~300ms duration; the sync listener
   copies each intermediate position to the other tracks, which restarts more
   smooth animations — an endless feedback loop (continuous drift, then juddering,
   then a frozen UI). Overriding to `auto` makes alignColumns() and sync writes
   land instantly. Native mouse-wheel/trackpad scrolling is unaffected. */
.study-column-track {
  scroll-behavior: auto;
}

/* ── Event detail panel ──────────────────────────────────────────────────── */
.event-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 60px; /* above dock */
  width: 360px;
  /* Near-opaque so the panel — and the edit form inside it — stays easy to read
     over content. var(--bg-sidebar) alone is only ~0.7 alpha in the dark themes. */
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  /* Colour-coded on the left edge to match the topic's minimap colour;
     the colour itself is set inline per-event in openDetailPanel(). */
  border-left: 4px solid var(--border);
  backdrop-filter: blur(18px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  box-sizing: border-box;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.event-detail-panel.hidden {
  display: none;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.detail-date {
  font-size: 16px; /* 12px × ~1.3 */
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.03em;
}
.detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.detail-close:hover { color: var(--text); }

.detail-topic {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.detail-topic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.detail-title {
  font-size: 22px; /* 17px × ~1.3 */
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px;
  line-height: 1.3;
}

.detail-desc {
  font-size: 17px; /* 13px × ~1.3 */
  color: var(--text-muted);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
  margin-bottom: 14px;
}
.detail-desc a { color: var(--accent); }

.detail-media-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.detail-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius, 8px);
  border: 1px solid var(--border);
}
.detail-video-link {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}
.detail-video-link:hover { border-color: var(--accent); }

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.detail-btn-edit, .detail-btn-delete {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.detail-btn-edit:hover { border-color: var(--accent); color: var(--accent); }
.detail-btn-delete:hover { border-color: #ef4444; color: #ef4444; }

.detail-readonly-note {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Edit event form (inside detail panel) ───────────────────────────────── */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.edit-date-row {
  display: flex;
  gap: 6px;
}
.edit-date-row input {
  flex: 1;
  padding: 7px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.edit-date-row input:focus { outline: none; border-color: var(--accent); }

.edit-form textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 120px;
}
.edit-form textarea:focus { outline: none; border-color: var(--accent); }

.edit-form-actions {
  display: flex;
  gap: 8px;
}
.edit-form-actions button {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.edit-form-actions button.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: 600;
}
.edit-form-actions button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.edit-form-actions button:not(.primary):hover { border-color: var(--accent); }
.edit-status {
  font-size: 11px;
  color: var(--text-muted);
  min-height: 14px;
}

/* ── Palette folder crumb ────────────────────────────────────────────────── */
.palette-folder-crumb {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 16px 0;
  font-size: 11px;
  color: var(--text-muted);
}
.palette-folder-crumb.hidden { display: none; }
.palette-crumb-back {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
}
.palette-crumb-back:hover { color: var(--text); border-color: var(--accent); }
.palette-crumb-path { color: var(--text-muted); }

/* Folder row in palette results */
.palette-item.folder-item .pi-icon::after { content: ''; }

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.board-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  height: 50vh;
  color: var(--text-muted);
  font-size: 14px;
}
.board-loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Event card additions ────────────────────────────────────────────────── */
.event-card-media-count {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Public badge in column header */
.col-public-badge {
  font-size: 12px;
  margin-left: 4px;
  opacity: 0.7;
}

/* ── Dock add-event form ─────────────────────────────────────────────────── */
.dock-inline-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
}
.dock-inline-form input,
.dock-inline-form textarea,
.dock-inline-form select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.dock-inline-form input:focus,
.dock-inline-form textarea:focus,
.dock-inline-form select:focus { outline: none; border-color: var(--accent); }
.dock-inline-form-row { display: flex; gap: 5px; }
.dock-inline-form-row input { flex: 1; }
.dock-form-actions { display: flex; gap: 6px; }
.dock-form-actions button { flex: 1; }
.dock-form-actions button.primary {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600;
}

/* ── Account dock panel ──────────────────────────────────────────────────── */
.account-user-info {
  padding: 12px 0 8px;
  font-size: 13px;
  color: var(--text);
}
.account-user-email {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
}
.auth-tab {
  flex: 1;
  padding: 7px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.auth-tab:first-child { border-radius: var(--radius, 8px) 0 0 var(--radius, 8px); }
.auth-tab:last-child  { border-radius: 0 var(--radius, 8px) var(--radius, 8px) 0; }
.auth-tab.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }

.auth-field {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  margin-bottom: 7px;
}
.auth-field:focus { outline: none; border-color: var(--accent); }
.auth-error { color: #ef4444; font-size: 11px; margin-bottom: 6px; min-height: 14px; }
.auth-status { color: var(--text-muted); font-size: 11px; min-height: 14px; }

/* ── Studies dock panel ──────────────────────────────────────────────────── */
.studies-select {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  margin-bottom: 8px;
}
.studies-select:focus { outline: none; border-color: var(--accent); }
/* Native <option> popups render on an opaque OS surface, so the theme's
   translucent --bg-elevated would leave near-white text on a near-white base
   (illegible). Force a solid background + contrasting text. */
.studies-select option { background: var(--bg); color: var(--text); }
.studies-btn-row { display: flex; gap: 5px; margin-bottom: 5px; }
.studies-btn-row button { flex: 1; }

/* ── AI dock panel ───────────────────────────────────────────────────────── */
.ai-result-preview {
  margin-top: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 10px;
  font-size: 11px;
  color: var(--text-muted);
  max-height: 140px;
  overflow-y: auto;
}
.ai-result-title { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.ai-status { font-size: 11px; color: #ef4444; margin-top: 6px; min-height: 14px; }

/* ── Big centered "Generating…" overlay ──────────────────────────────────── */
.ai-generating-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}
.ai-generating-card {
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 96%, var(--text) 4%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  padding: 32px 40px;
  text-align: center;
  min-width: 260px;
  max-width: 360px;
}
.ai-generating-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-generating-msg { font-size: 17px; font-weight: 700; color: var(--text); }
.ai-generating-sub { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ── Generic centered modal dialog ───────────────────────────────────────── */
.board-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
}
.board-modal-card {
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 96%, var(--text) 4%);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  padding: 20px 22px;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}
.board-modal-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.modal-hint { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; line-height: 1.4; }
.modal-radio-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
.modal-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
}
.modal-radio:hover { background: var(--accent-soft); }
.modal-radio input { accent-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.modal-btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}
.modal-btn-secondary:hover { color: var(--text); }

/* ── Shrink main area when detail panel is open ──────────────────────────── */
.main.detail-open {
  padding-right: 360px;
}

/* ── Column overflow menu ────────────────────────────────────────────────── */
.col-overflow-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  padding: 0 3px;
  line-height: 1;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.15s;
}
.study-column-header:hover .col-overflow-btn,
.col-overflow-btn:focus { opacity: 1; }
.col-overflow-btn:hover { color: var(--text); }

#col-overflow-menu,
#event-card-menu {
  position: fixed;
  z-index: 1200;
  /* Must be fully opaque — var(--bg-elevated) is near-transparent in the dark
     themes (rgba(...,0.06)), which let the card text bleed through. */
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 94%, var(--text) 6%);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  padding: 5px 0;
  width: 190px;
  font-size: 12px;
}
#event-card-menu { width: 200px; }

/* ── Per-event ⋯ menu button ─────────────────────────────────────────────── */
.event-card-menu-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 4;
}
.event-card:hover .event-card-menu-btn,
.event-card-menu-btn:focus { opacity: 1; }
.event-card-menu-btn:hover { color: var(--text); background: var(--accent-soft); }
.com-item {
  padding: 8px 14px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.com-item:hover:not(.disabled) { background: var(--accent-soft); }
.com-item.disabled { color: var(--text-muted); cursor: default; }
.com-item.danger  { color: #ef4444; }
.com-item.danger:hover { background: rgba(239,68,68,0.12); }
.com-sep { border: none; border-top: 1px solid var(--border); margin: 3px 0; }

/* ── Column resize handle ────────────────────────────────────────────────── */
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}
.col-resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  left: 3px;
  width: 2px;
  height: 100%;
  background: transparent;
  transition: background 0.15s;
}
.col-resize-handle:hover::after,
.study-column.resizing .col-resize-handle::after {
  background: var(--accent);
}
.study-column { position: relative; }

/* ── Hover preview card ──────────────────────────────────────────────────── */
.event-hover-preview {
  display: none;
  position: fixed;
  z-index: 1100;
  width: 220px;
  padding: 10px 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: none;
}
.ehp-date  { font-size: 10px; color: var(--accent); font-weight: 600; margin-bottom: 3px; }
.ehp-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.ehp-desc  { font-size: 11px; color: var(--text-muted); line-height: 1.5; }

/* ── Event card thumbnail strip ─────────────────────────────────────────── */
.event-card-thumbs {
  display: flex;
  gap: 5px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.card-thumb {
  width: 52px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s, transform 0.15s;
  flex-shrink: 0;
}
.card-thumb:hover { opacity: 1; transform: scale(1.05); }
.card-thumb-video {
  width: 52px;
  height: 40px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
}
.card-thumb-video:hover { color: var(--accent); border-color: var(--accent); }
.card-thumb-more {
  width: 52px;
  height: 40px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.card-thumb-more:hover { color: var(--accent); border-color: var(--accent); }

/* ── Detail panel media grid ─────────────────────────────────────────────── */
.detail-media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.detail-media-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-elevated);
  cursor: pointer;
  aspect-ratio: 4/3;
  border: 1px solid var(--border);
}
.detail-media-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.detail-media-item:hover .detail-media-del { opacity: 1; }
.detail-media-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.65);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.detail-media-del:hover { background: #ef4444; }
.detail-media-video-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(0,0,0,0.3);
  color: #fff;
}
.detail-media-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 5px;
  font-size: 9px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-add-media {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.detail-add-btn {
  flex: 1;
  min-width: 80px;
  padding: 6px 8px;
  font-size: 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, color 0.15s;
}
.detail-add-btn:hover { border-color: var(--accent); color: var(--accent); }
.detail-link-form {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.detail-link-form.open { display: flex; }
.detail-link-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.detail-link-input:focus { outline: none; border-color: var(--accent); }
.detail-link-row { display: flex; gap: 6px; }
.detail-link-row button { flex: 1; padding: 6px; font-size: 11px; }
.detail-link-row button.primary {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.detail-link-row button:not(.primary) {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
}

/* ── Gallery modal ───────────────────────────────────────────────────────── */
.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.gallery-modal.hidden { display: none; }
.gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(6px);
}
.gallery-close {
  position: absolute;
  top: 18px;
  right: 22px;
  z-index: 10;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.gallery-close:hover { background: rgba(255,255,255,0.2); }
.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.gallery-nav:hover { background: rgba(255,255,255,0.25); }
.gallery-nav:disabled { opacity: 0.3; cursor: default; }
.gallery-prev { left: 20px; }
.gallery-next { right: 20px; }
.gallery-stage {
  position: relative;
  z-index: 5;
  max-width: calc(100vw - 140px);
  max-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-stage img {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  object-fit: contain;
  border-radius: 6px;
  display: block;
}
.gallery-stage iframe {
  width: min(800px, calc(100vw - 140px));
  height: min(450px, calc(100vh - 200px));
  border: none;
  border-radius: 6px;
}
.gallery-stage video {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  border-radius: 6px;
}
.gallery-stage .gallery-link-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #fff;
  text-align: center;
}
.gallery-link-view a {
  color: var(--accent);
  word-break: break-all;
  text-decoration: none;
}
.gallery-link-view a:hover { text-decoration: underline; }
.gallery-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 14px 80px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  align-items: center;
  gap: 12px;
}
.gallery-counter {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
}
.gallery-caption {
  flex: 1;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-actions { display: flex; gap: 8px; }
.gallery-del-btn {
  padding: 5px 12px;
  background: rgba(239,68,68,0.2);
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: 6px;
  color: #fca5a5;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.gallery-del-btn:hover { background: rgba(239,68,68,0.4); }

/* ── Play-through control bar (feature 6) ───────────────────────────────────── */
.play-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface, #1b1f2a);
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  color: var(--text, #fff);
  font-size: 13px;
}
.play-bar-btn {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.play-bar-btn:hover { filter: brightness(1.1); }
.play-bar-progress { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.play-bar-rec { color: #ef4444; font-weight: 700; letter-spacing: 0.5px; animation: pt-blink 1s steps(2,start) infinite; }
@keyframes pt-blink { 50% { opacity: 0.3; } }
.play-bar-speed-label { font-size: 11px; color: var(--text-muted, rgba(255,255,255,0.6)); }
.play-bar-speed { width: 90px; accent-color: var(--accent); }

/* Countdown dots, centered at the top, draining before each jump. */
.play-countdown {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface, rgba(20,24,33,0.85));
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  box-shadow: 0 6px 22px rgba(0,0,0,0.35);
}
.play-countdown-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--border, rgba(255,255,255,0.25));
  transition: background 0.2s ease, transform 0.2s ease;
}
.play-countdown-dot.on { background: var(--accent); transform: scale(1.15); }
.play-countdown-dot.paused.on { background: var(--text-muted, #888); }

/* During a play-through, hide the left sidebar so it isn't shown/recorded. */
body.playthrough-active .sidebar { display: none; }

/* During a play-through the detail panel IS the thing the audience reads, so
   give it more room and more legible body text. The enlarged type comes from
   the base .detail-* rules (already sized up); here we widen the panel (the
   user's attention is on it) and raise the body-text contrast — the muted grey
   used elsewhere is too faint to read at a glance, and on Light Minimal it's
   almost invisible on the light bg. */
body.playthrough-active .event-detail-panel {
  width: 520px;
}
body.playthrough-active .event-detail-panel .detail-desc {
  line-height: 1.6;
  color: var(--text);
}
/* Light Minimal's muted grey (#8a8d96) on its light bg (#f7f7f8) has almost no
   contrast — force the full-strength ink for both heading and body while playing. */
[data-theme="light"] body.playthrough-active .event-detail-panel .detail-desc,
[data-theme="light"] body.playthrough-active .event-detail-panel .detail-title {
  color: #1a1b1e;
}

/* ── Print / PDF ─────────────────────────────────────────────────────────── */
/* The JS buildPrintContent() generates a self-contained #print-content node
   that is appended to <body> just before window.print() and removed after.
   Everything else is hidden so the existing board DOM never fights the printer. */
/* The output mirrors the on-screen "Light Minimal" theme: white cards with a
   soft grey border + colored accent edge, pill-shaped year badges, Segoe UI
   type, and a discreet Timelense watermark repeated on every page.
   print-color-adjust:exact keeps the accent colors faithful; the design also
   degrades gracefully (colored text + borders) if a printer drops backgrounds. */
@media print {
  html, body { background: #ffffff !important; }

  /* Hide all screen content; show only the generated print layer */
  body > *:not(#print-content) { display: none !important; }
  #print-content {
    display: block !important;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    color: #1a1b1e;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  #print-content * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ---- Document header ---- */
  .pc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16pt;
    margin-bottom: 16pt;
    padding-bottom: 10pt;
    border-bottom: 1.5pt solid #e7e7ea;
  }
  .pc-header-main { min-width: 0; }
  .pc-main-title {
    margin: 0;
    font-size: 22pt;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.15;
    color: #1a1b1e;
  }
  .pc-subtitle {
    margin: 5pt 0 0;
    font-size: 10.5pt;
    line-height: 1.45;
    color: #8a8d96;
    max-width: 72ch;
  }
  .pc-header-brand {
    flex: none;
    font-size: 11pt;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #5b5bd6;
    white-space: nowrap;
  }

  /* ---- Column-header color dot ---- */
  .pc-col-dot {
    width: 9pt;
    height: 9pt;
    border-radius: 50%;
    background: var(--pc-accent, #5b5bd6);
    flex: none;
  }

  /* ---- Event card ---- */
  .pc-card {
    break-inside: avoid;
    page-break-inside: avoid;
    background: #ffffff;
    border: 0.75pt solid #e7e7ea;
    border-left: 2.5pt solid var(--pc-accent, #5b5bd6);
    border-radius: 6pt;
    padding: 9pt 11pt;
    margin-bottom: 9pt;
  }
  .pc-year {
    display: inline-block;
    margin-bottom: 6pt;
    padding: 2pt 8pt;
    font-size: 8.5pt;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--pc-accent, #5b5bd6);
    background: color-mix(in srgb, var(--pc-accent, #5b5bd6) 12%, white);
    border-radius: 999px;
  }
  .pc-title {
    margin: 0 0 4pt;
    font-size: 11.5pt;
    font-weight: 600;
    line-height: 1.3;
    color: #1a1b1e;
  }
  .pc-desc {
    margin: 0;
    font-size: 9.5pt;
    line-height: 1.5;
    color: #5c5f66;
  }

  /* ---- Timeline table ---- */
  .pc-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 8pt 0;   /* horizontal gutter only; rows touch so the axis rail is continuous */
    table-layout: fixed;
  }

  /* Left timeline axis — a continuous rail with a node + year label per slot,
     echoing the on-screen minimap. */
  .pc-axis-th { border-bottom: 2pt solid #e7e7ea; }
  .pc-axis {
    position: relative;
    vertical-align: top;
    padding: 9pt 9pt 0 0;
    text-align: right;
    border-right: 1.5pt solid #d8d8de;   /* the rail */
  }
  .pc-axis-year {
    font-size: 9pt;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #8a8d96;
    white-space: nowrap;
  }
  .pc-axis-node {
    position: absolute;
    right: -3.25pt;          /* centered on the 1.5pt rail */
    top: 12pt;
    width: 5.5pt;
    height: 5.5pt;
    border-radius: 50%;
    background: #5b5bd6;
    border: 1pt solid #ffffff;
  }
  .pc-th {
    vertical-align: bottom;
    padding: 0 0 8pt;
    text-align: left;
    font-size: 10.5pt;
    font-weight: 700;
    color: #1a1b1e;
    border-bottom: 2pt solid var(--pc-accent, #5b5bd6);
  }
  .pc-th .pc-col-dot {
    display: inline-block;
    vertical-align: middle;
    margin-right: 5pt;
  }
  .pc-td {
    vertical-align: top;
    padding: 8pt 0 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .pc-td .pc-card { margin-bottom: 0; }
  tr { break-inside: avoid; page-break-inside: avoid; }

  /* ---- Discreet brand watermark (repeats on every page) ---- */
  .pc-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 4mm;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 8pt;
    color: #b6b8bf;
  }
  .pc-foot-brand {
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #a9a4e0;
  }

  .pc-empty-note { font-size: 11pt; color: #8a8d96; }
}

/* ── Dock view section label ─────────────────────────────────────────────── */
.dock-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 0 4px;
}
.dock-toggle-row { margin-bottom: 6px; }
.dock-toggle-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE — Option A (drawer + bottom action bar + function sheet)
   Activated by JS via `body.viewport-mobile` (auto on narrow screens, or via the
   viewport toggle). All desktop rules stay intact; these only apply in that mode.
   The mobile chrome (#m-* nodes) is injected once by public/js/mobile.js and
   reuses the existing sidebar, dock, detail panel, play-bar and countdown.
   ═══════════════════════════════════════════════════════════════════════════ */

/* The injected chrome is hidden by default; the mobile mode reveals it. */
#m-actionbar, #m-fn-sheet, #m-scrim, #m-hamburger { display: none; }

/* The viewport toggle lives in the topbar and is available in BOTH modes so a
   desktop user can preview/enter mobile, and vice-versa. */
#m-viewport-toggle { display: flex; }

body.viewport-mobile #m-hamburger { display: flex; }

/* ---------- Off-canvas nav drawer (reuses #sidebar) ---------- */
body.viewport-mobile .sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(82vw, 320px);
  z-index: 1000;
  transform: translateX(-104%);
  transition: transform 0.25s ease;
  padding: 18px 16px;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
}
body.viewport-mobile.drawer-open .sidebar { transform: none; }
/* Neutralise the desktop collapse behaviour while in mobile (the ☰ in the
   drawer header just closes the drawer instead). */
body.viewport-mobile .sidebar.collapsed { width: min(82vw, 320px); padding: 18px 16px; }
body.viewport-mobile .sidebar.collapsed .hide-on-collapse { display: revert; }

/* ---------- Topbar: hamburger + condensed spacing ---------- */
body.viewport-mobile .topbar { padding: 12px 14px; }
#m-hamburger {
  align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; font-size: 17px; cursor: pointer;
  margin-right: 4px;
}

/* ---------- Shared dimming scrim (drawer + sheets) ---------- */
body.viewport-mobile #m-scrim {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
}
body.viewport-mobile.drawer-open #m-scrim,
body.viewport-mobile.fn-open #m-scrim,
body.viewport-mobile.dock-sheet-open #m-scrim { display: block; opacity: 1; pointer-events: auto; }

/* ---------- Bottom action bar ---------- */
body.viewport-mobile #m-actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 700;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 34%);
}
.m-ab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px; border-radius: 13px; cursor: pointer;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-weight: 600; font-family: inherit;
}
.m-ab.accent { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.m-ab:active { transform: scale(0.97); }

/* ---------- Functions grid sheet ---------- */
body.viewport-mobile #m-fn-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  max-height: 80%;
  background: var(--bg-sidebar); border-top: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(102%); transition: transform 0.25s ease;
  display: flex; flex-direction: column;
  backdrop-filter: blur(16px); box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.4);
}
body.viewport-mobile.fn-open #m-fn-sheet { transform: none; }
.m-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--border); margin: 4px auto 12px; flex-shrink: 0; }
.m-sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.m-sheet-head .h { flex: 1; font-weight: 700; font-family: var(--font-heading); font-size: 16px; }
.m-sheet-head .m-close { width: 34px; height: 34px; border-radius: 9px; background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text); font-size: 17px; cursor: pointer; }
.m-fn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; overflow-y: auto; }
.m-fn {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 15px 6px; border-radius: 14px; cursor: pointer; text-align: center;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
}
.m-fn:active { transform: scale(0.96); }
.m-fn .ic { font-size: 23px; line-height: 1; }
.m-fn .lb { font-size: 11px; color: var(--text-muted); }

/* ---------- Reuse the dock-panel content as a bottom sheet ---------- */
/* The desktop .dock has `transform: translateX(-50%)`, which would make it the
   containing block for the fixed panel below; clear it so the sheet anchors to
   the viewport. */
body.viewport-mobile .dock { position: static; transform: none; }
body.viewport-mobile .dock-bar,
body.viewport-mobile #dock-restore,
body.viewport-mobile #dock-minimize { display: none !important; }
body.viewport-mobile #dock-panel {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 1000;
  max-height: 78%; overflow-y: auto; width: auto; margin: 0;
  border-radius: 22px 22px 0 0; border: 1px solid var(--border); border-bottom: none;
  padding: 22px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg-sidebar); backdrop-filter: blur(16px);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.4);
}
body.viewport-mobile #dock-panel.hidden { display: none; }
/* drag-grip affordance at the top of the dock sheet */
body.viewport-mobile #dock-panel::before {
  content: ""; position: sticky; top: 0; display: block;
  width: 38px; height: 4px; border-radius: 99px; background: var(--border);
  margin: -8px auto 12px;
}

/* ---------- Full-screen event detail (also the play-through enlarged box) ---------- */
body.viewport-mobile .event-detail-panel {
  inset: 0; width: auto; bottom: 0; z-index: 1100;
  border-left: none; border-radius: 0;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
}
body.viewport-mobile.playthrough-active .event-detail-panel { width: auto; }

/* ---------- Board: single-column-friendly, swipe horizontally to compare ---------- */
body.viewport-mobile .content { padding: 16px 14px 92px; overflow-x: auto; }
body.viewport-mobile .study-column { flex: 0 0 80vw; min-width: 0; max-width: none; }
body.viewport-mobile .board-minimap { flex-basis: 34px; }

/* ---------- "Rotate for full compare" hint (3+ topic columns, portrait) ---------- */
#m-rotate-hint { display: none; }
body.viewport-mobile #m-rotate-hint {
  position: fixed; left: 50%; bottom: calc(82px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 690;
  display: none; align-items: center; gap: 10px;
  max-width: calc(100vw - 28px);
  padding: 8px 9px 8px 15px;
  background: var(--bg-sidebar); border: 1px solid var(--accent); border-radius: 999px;
  color: var(--text); font-size: 12.5px; line-height: 1.3;
  backdrop-filter: blur(12px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
}
body.viewport-mobile #m-rotate-hint.show { display: flex; }
body.viewport-mobile.playthrough-active #m-rotate-hint,
body.viewport-mobile.drawer-open #m-rotate-hint,
body.viewport-mobile.fn-open #m-rotate-hint,
body.viewport-mobile.dock-sheet-open #m-rotate-hint { display: none !important; }
.rh-x {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 14px; cursor: pointer; line-height: 1;
}

/* ---------- Play chrome sits above the full-screen detail; hide app chrome ---------- */
body.viewport-mobile .play-bar { bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1300; }
body.viewport-mobile .play-countdown { z-index: 1300; }
body.viewport-mobile.playthrough-active #m-actionbar,
body.viewport-mobile.playthrough-active #m-hamburger { display: none; }

/* ── Drag-and-drop: move/copy event cards between topic columns ───────────────
   Cards are draggable when signed in (set via the `draggable` attribute in
   board.js). A column the user owns highlights as a valid drop target while a
   card is dragged over it; columns owned by other authors never get the class,
   so they give no drop affordance. */
.event-card[draggable="true"] { cursor: grab; }
.event-card.dragging {
  opacity: 0.45;
  cursor: grabbing;
}
.study-column.drop-target {
  outline: 2px dashed var(--dot-color, var(--accent));
  outline-offset: -2px;
  background: color-mix(in srgb, var(--dot-color, var(--accent)) 10%, transparent);
}

/* Clear-viewport button: an icon-btn that also shows a text label. */
#clear-board-btn {
  width: auto;
  padding: 0 12px;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

/* ── Sidebar folder tree ──────────────────────────────────────────────────── */
.nav-item.nav-folder,
.nav-item.nav-topic { gap: 6px; }
.nav-item .nav-caret {
  flex-shrink: 0;
  width: 12px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}
.nav-item .nav-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item .nav-count {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  padding-left: 4px;
}
.nav-item.nav-folder { font-weight: 600; color: var(--text); }

/* ── Drag a sidebar topic onto the board to add it to the comparison ──────────
   The dragged nav item dims; a vertical indicator marks the insertion slot. */
.nav-item[draggable="true"] { cursor: grab; }
.nav-item.dragging { opacity: 0.45; }
.topic-drop-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  pointer-events: none;
  z-index: 7;
  display: none;
}

/* ── Unsaved-study reminder: red dot on the "Studies" sidebar section + dock btn
   while the open study has layout edits that haven't been saved. */
.sidebar-section-title.has-unsaved::after,
.dock-btn[data-group="studies"].has-unsaved::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: #ef4444;
  vertical-align: middle;
}
