/* ---------- Refinements: motion, touch and materials ----------
   Principles from Apple's fluid-interface talks and Emil Kowalski's design engineering:
   feedback on press, hover only for real pointers, strong custom curves, exits faster
   than entrances, translucent materials, and gentler (not absent) reduced motion. */

:root {
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in-out: cubic-bezier(.77, 0, .175, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
}

/* Touch: no grey tap flash, no 300ms wait, no accidental text selection on long-press. */
button, .pill, .btn, .q-option, .q-next, .marker, .c-card, a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, .pill, .btn, .q-next { -webkit-user-select: none; user-select: none; }

/* Press: instant, firm feedback the moment a finger or button goes down. */
.pill, .btn, .q-next, .tidbit-copy, .viewer-controls button, .viewer-note-nav button {
  transition-property: transform, background-color, border-color, color, box-shadow;
  transition-duration: 140ms;
  transition-timing-function: var(--ease-out);
}
.pill:active, .btn:active, .q-next:active, .tidbit-copy:active,
.viewer-controls button:active, .viewer-note-nav button:active { transform: scale(.97); transition-duration: 80ms; }
.q-option:active:not(:disabled) { transform: scale(.985); }
.c-card { display: block; transition: transform 140ms var(--ease-out); }
.c-card:active { transform: scale(.98); }
.marker:active { transform: scale(.92); }

/* Quiz answer letters: colour only, never "all". */
.q-letter { transition: background-color 200ms ease, border-color 200ms ease, color 200ms ease; }

/* Hover: only for devices with a real pointer, so phones don't keep a "stuck" hover after a tap. */
@media (hover: none), (pointer: coarse) {
  .pill:hover { border-color: var(--rule); }
  .q-option:hover:not(:disabled) { border-color: var(--rule); }
  .fx-hover .pill:not([aria-pressed="true"]):hover,
  .fx-hover .btn:not(.btn-primary):hover { background: none; border-color: var(--ink); }
  .fx-hover .btn-primary:hover, .fx-hover .q-next:hover { background: var(--ink); }
  .fx-quiz .q-option:hover:not(:disabled) { transform: none; box-shadow: none; }
  .fx-quiz .q-option:hover:not(:disabled) .q-letter { background: none; border-color: var(--rule); color: inherit; }
  .c-card:hover .c-thumb img { transform: none; }
}
/* Buttons no longer fade on hover; the press does the talking. */
.btn:hover, .q-next:hover { opacity: 1; }

/* Detail markers: settle in smoothly, no overshoot (a tap carries no momentum). */
.marker { transition: opacity 260ms var(--ease-out), transform 260ms var(--ease-out), background-color 160ms ease; }
.show-details .marker:nth-child(2) { transition-delay: 40ms; }
.show-details .marker:nth-child(3) { transition-delay: 80ms; }
.show-details .marker:nth-child(4) { transition-delay: 120ms; }
.show-details .marker:nth-child(5) { transition-delay: 160ms; }
.show-details .marker:nth-child(6) { transition-delay: 200ms; }

/* Header: a lighter, more glass-like material. */
.masthead {
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

/* Toast: rises and returns along the same path; quick out, quicker away. */
.toast { transition: opacity 220ms var(--ease-out), transform 320ms var(--ease-out); }
.toast:not(.is-on) { transition-duration: 160ms, 200ms; }

/* ---------- Collection as a sheet ---------- */
.collection {
  background: color-mix(in srgb, #000 32%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: none;
  overscroll-behavior: contain;
  transition: opacity 300ms var(--ease-out);
}
.collection-inner {
  position: relative;
  max-width: none;
  min-height: calc(100% - 5vh);
  margin-top: 5vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -18px 60px -24px rgba(0,0,0,.45);
  padding-top: 26px;
  transition: transform 420ms var(--ease-drawer);
  will-change: transform;
}
.collection-inner > * { max-width: var(--max); margin-left: auto; margin-right: auto; }
.sheet-grabber {
  position: absolute; top: 0; left: 0; right: 0; height: 26px;
  display: grid; place-items: center;
  cursor: grab; touch-action: none;
}
.sheet-grabber::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: var(--rule); }
.collection.is-entering, .collection.is-leaving { opacity: 0; }
.collection.is-entering .collection-inner, .collection.is-leaving .collection-inner { transform: translateY(100%); }
.collection.is-leaving { transition-duration: 220ms; }
.collection.is-leaving .collection-inner { transition: transform 280ms var(--ease-out); }
.collection.is-dragging .collection-inner { transition: none; }

/* ---------- Viewer: materialise in, leave faster ---------- */
.viewer { animation: none; transition: opacity 260ms var(--ease-out), transform 260ms var(--ease-out); }
.viewer.is-entering { opacity: 0; transform: scale(.985); }
.viewer.is-leaving { opacity: 0; transform: scale(.985); transition-duration: 180ms; }

/* ---------- Typography ---------- */
.essay-body p, .q-explain, .tidbit-list p { text-wrap: pretty; }
body { font-optical-sizing: auto; }

/* ---------- Accessibility settings ---------- */
@media (prefers-reduced-motion: reduce) {
  /* Gentler, not absent: keep short fades, drop movement. */
  .collection, .viewer, .toast { transition: opacity 200ms ease !important; }
  .collection-inner, .viewer, .toast { transform: none !important; }
  .toast { transform: translateX(-50%) !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .masthead { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .collection { background: rgba(0,0,0,.55); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .pill, .btn, .q-option { border-color: var(--ink); }
  .masthead { background: var(--bg); border-bottom-color: var(--ink); }
}
