/* Shared action controls for both reading themes. Theme tokens also survive
   the stylesheet replacement used by the in-page theme switch. */
:root {
  --action-height: 44px;
  --action-radius: 8px;
  --action-primary: #285b46;
  --action-primary-hover: #204b39;
  --action-saved: #204b39;
  --action-saved-hover: #183c2d;
  --action-ink: #315840;
  --action-border: #aebfac;
  --action-surface: #fffef9;
  --action-hover: #edf3e9;
  --action-focus: #9b603d;
  --action-disabled-surface: #e7ebe3;
  --action-disabled-ink: #657060;
  --action-disabled-border: #d2d9cc;
}

body.study-theme {
  --action-primary: #895734;
  --action-primary-hover: #754727;
  --action-saved: #704421;
  --action-saved-hover: #5e371b;
  --action-ink: #795333;
  --action-border: #c3ab88;
  --action-surface: #fffaf0;
  --action-hover: #f4e8d3;
  --action-focus: #895734;
  --action-disabled-surface: #ede5d7;
  --action-disabled-ink: #7c6b57;
  --action-disabled-border: #dbceb9;
}

body button {
  min-height: var(--action-height);
  line-height: 1.4;
  touch-action: manipulation;
}

body button:is(.primary, .secondary, .tab, .read, .profile-trigger),
body .submit-row .primary,
body #notebook-dialog button:is(.primary, .secondary) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-height);
  padding: 10px 14px;
  border: 1px solid var(--action-border);
  border-radius: var(--action-radius);
  background: var(--action-surface);
  color: var(--action-ink);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: none;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

body button.primary,
body .submit-row .primary,
body #notebook-dialog button.primary,
body #find-more {
  min-height: var(--action-height);
  padding: 10px 18px;
  background: var(--action-primary);
  border-color: var(--action-primary);
  color: #fff;
  font-weight: 600;
}

body #find-more { min-width: 112px; }
body .tab[aria-pressed="true"] {
  background: var(--action-primary);
  border-color: var(--action-primary);
  color: #fff;
}

/* Examples and housekeeping remain quiet, with the same touch target. */
body .sample-action .secondary {
  min-height: var(--action-height);
  padding: 8px 0;
  border-color: transparent;
  background: transparent;
  font-size: 14px;
}
body .text-action { min-height: var(--action-height); }
body #lesson-pagination button,
body .feedback-chip { min-height: var(--action-height); }
body #notebook-dialog .profile-close {
  width: var(--action-height);
  height: var(--action-height);
  min-height: var(--action-height);
  flex-shrink: 0;
}

/* Follow and save use the same 44px box, including the bookmark icon. */
body .card .card-buttons {
  min-width: 0;
  max-width: 100%;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
body .card .card-buttons :is(.read, .follow-reading) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--action-height);
  min-height: var(--action-height);
  max-width: 100%;
  padding: 0 10px;
  border: 1px solid var(--action-border);
  border-radius: var(--action-radius);
  background: var(--action-surface);
  color: var(--action-ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: none;
  transform: none;
}
/* Legacy theme rules mark these two properties important. Keep the override
   confined to the saved state instead of elevating the entire button system. */
body .card .card-buttons .read[aria-pressed="true"] {
  background: var(--action-saved) !important;
  color: #fff !important;
  border-color: var(--action-saved);
}
body .card .card-buttons .read svg { width: 16px; height: 17px; }

body button:focus-visible {
  outline: 3px solid var(--action-focus);
  outline-offset: 3px;
}
body .submit-row { flex-wrap: wrap; }
body .reading-actions { gap: 12px; align-items: center; }
body .reading-actions p { min-width: 0; overflow-wrap: anywhere; }

@media (hover: hover) and (pointer: fine) {
  body button:is(.secondary, .tab, .profile-trigger):not(:disabled):hover,
  body .card .card-buttons :is(.read, .follow-reading):not(:disabled):hover {
    background: var(--action-hover);
    border-color: var(--action-ink);
    box-shadow: none;
    transform: none;
  }
  body button.primary:not(:disabled):hover,
  body #notebook-dialog button.primary:not(:disabled):hover,
  body #find-more:not(:disabled):hover,
  body .tab[aria-pressed="true"]:not(:disabled):hover {
    background: var(--action-primary-hover);
    border-color: var(--action-primary-hover);
    color: #fff;
  }
  body .card .card-buttons .read[aria-pressed="true"]:not(:disabled):hover {
    background: var(--action-saved-hover) !important;
    border-color: var(--action-saved-hover);
  }
}

body button:is(.primary, .secondary, .tab, .read):disabled,
body .submit-row .primary:disabled,
body #notebook-dialog button:is(.primary, .secondary):disabled,
body .card .card-buttons button:disabled,
body #find-more:disabled {
  background: var(--action-disabled-surface);
  color: var(--action-disabled-ink);
  border-color: var(--action-disabled-border);
  opacity: 1;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

@media (max-width: 560px) {
  body .card .card-buttons { width: 100%; justify-content: flex-start; }
  body .reading-actions p { flex-basis: 100%; }
  body .submit-row .helper { flex: 1 1 100%; }
  body .submit-row .primary { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  body button:is(.primary, .secondary, .tab, .read, .profile-trigger) { transition: none; }
}
