/* ==========================================================================
   Material 3 Expressive — Component library
   Every interactive surface has: a state layer, a spring transition, and a
   shape that morphs on press. That trio is what makes M3E read as "M3E".
   ========================================================================== */

/* --------------------------------------------------------------------------
   State layer — the tinted overlay M3 puts over a component on hover/press
   -------------------------------------------------------------------------- */
.state-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-short-4) var(--ease-standard);
}
.m3-interactive:hover > .state-layer      { opacity: var(--state-hover); }
.m3-interactive:focus-visible > .state-layer { opacity: var(--state-focus); }
.m3-interactive:active > .state-layer     { opacity: var(--state-pressed); }

/* Ripples live in their own masked layer. `overflow: hidden` alone is unreliable
   for clipping a transformed child to a rounded corner — WebKit in particular
   drops the radius once the child gets its own compositing layer, letting the
   circle bleed into the corners. An explicit mask forces the rounded clip. */
.ripple-host {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: -webkit-radial-gradient(#fff, #000);
  mask-image: radial-gradient(#fff, #000);
}

/* Ripple — spawned by js/main.js on pointerdown */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.14;
  transform: scale(0);
  pointer-events: none;
  animation: ripple-out var(--dur-long-2) var(--ease-emphasized-decelerate) forwards;
}
@keyframes ripple-out {
  to { transform: scale(1); opacity: 0; }
}

/* Focus ring */
.m3-interactive:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Buttons
   Shape morph: full-round at rest → squarer on press, with a spring.
   -------------------------------------------------------------------------- */
/* --pill is half the component's height. It looks identical to --shape-full
   (999px) at rest, but keeps the animated distance tiny — a bouncy spring
   overshooting from 999px would undershoot past 0 and flash square corners. */
.m3-button {
  --pill: 20px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 24px;
  border: none;
  border-radius: var(--pill);
  font-family: var(--font-plain);
  font-size: var(--type-label-lg);
  font-weight: 600;
  letter-spacing: 0.1px;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition:
    border-radius var(--dur-medium-2) var(--spring-bouncy),
    box-shadow     var(--dur-medium-1) var(--ease-standard),
    background     var(--dur-medium-1) var(--ease-standard),
    transform      var(--dur-medium-2) var(--spring-default);
}
.m3-button:active { border-radius: var(--shape-md); transform: scale(0.96); }

.m3-button.size-s  { --pill: 16px; min-height: 32px; padding: 0 16px; }
.m3-button.size-l  { --pill: 28px; min-height: 56px; padding: 0 32px; font-size: var(--type-title-md); }
.m3-button.size-xl { --pill: 36px; min-height: 72px; padding: 0 44px; font-size: var(--type-headline-sm); gap: 12px; }
.m3-button.size-xl:active { border-radius: var(--shape-lg-increased); }

.m3-button--filled     { background: var(--primary);            color: var(--on-primary); }
.m3-button--filled:hover{ box-shadow: var(--elev-1); }
.m3-button--tonal      { background: var(--secondary-container);  color: var(--on-secondary-container); }
.m3-button--tonal:hover{ box-shadow: var(--elev-1); }
.m3-button--elevated   { background: var(--surface-container-low);color: var(--primary); box-shadow: var(--elev-1); }
.m3-button--elevated:hover { box-shadow: var(--elev-2); }
.m3-button--outlined   { background: transparent;                 color: var(--primary); box-shadow: inset 0 0 0 1px var(--outline); }
.m3-button--text       { background: transparent;                 color: var(--primary); padding: 0 12px; }

/* Connected button group — the segments squeeze toward the pressed one */
.m3-button-group {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--shape-full);
  background: var(--surface-container);
}
.m3-button-group > .m3-button { border-radius: var(--shape-sm); }
.m3-button-group > .m3-button:first-child {
  border-start-start-radius: var(--pill);
  border-end-start-radius: var(--pill);
}
.m3-button-group > .m3-button:last-child {
  border-start-end-radius: var(--pill);
  border-end-end-radius: var(--pill);
}
.m3-button-group > .m3-button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--pill);
}

/* Icon button */
.m3-icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 24px;               /* = half height; see --pill note above */
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition:
    border-radius var(--dur-medium-2) var(--spring-bouncy),
    background    var(--dur-medium-1) var(--ease-standard),
    color         var(--dur-medium-1) var(--ease-standard),
    transform     var(--dur-medium-2) var(--spring-default);
}
.m3-icon-button:active { border-radius: var(--shape-md); transform: scale(0.9); }
.m3-icon-button--tonal    { background: var(--secondary-container); color: var(--on-secondary-container); }
.m3-icon-button--filled   { background: var(--primary); color: var(--on-primary); }
.m3-icon-button--outlined { box-shadow: inset 0 0 0 1px var(--outline); }

/* --------------------------------------------------------------------------
   FAB + FAB menu
   -------------------------------------------------------------------------- */
.m3-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 56px;
  height: 56px;
  padding: 0 16px;
  border: none;
  border-radius: var(--shape-lg);
  background: var(--primary-container);
  color: var(--on-primary-container);
  box-shadow: var(--elev-3);
  font-family: var(--font-plain);
  font-size: var(--type-title-md);
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition:
    border-radius var(--dur-medium-2) var(--spring-bouncy),
    box-shadow    var(--dur-medium-2) var(--ease-standard),
    transform     var(--dur-medium-2) var(--spring-default);
}
.m3-fab:hover  { box-shadow: var(--elev-4); transform: translateY(-2px); }
.m3-fab:active { border-radius: 28px; transform: scale(0.94); }

.fab-dock {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}
.fab-menu {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.fab-menu__item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 18px;
  border: none;
  border-radius: 24px;
  background: var(--surface-container-high);
  color: var(--on-surface);
  box-shadow: var(--elev-2);
  font-family: var(--font-plain);
  font-size: var(--type-label-lg);
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-decoration: none;
  /* Collapsed state */
  opacity: 0;
  transform: translateY(16px) scale(0.6);
  pointer-events: none;
  transition:
    opacity   var(--dur-short-4) var(--ease-standard),
    transform var(--dur-long-1)  var(--spring-bouncy),
    border-radius var(--dur-medium-2) var(--spring-bouncy);
}
.fab-dock[data-open="true"] .fab-menu__item {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
/* Stagger, bottom-up */
.fab-dock[data-open="true"] .fab-menu__item:nth-child(1) { transition-delay: 120ms; }
.fab-dock[data-open="true"] .fab-menu__item:nth-child(2) { transition-delay:  80ms; }
.fab-dock[data-open="true"] .fab-menu__item:nth-child(3) { transition-delay:  40ms; }
.fab-menu__item:active { border-radius: var(--shape-md); }

.fab-dock[data-open="true"] .fab-dock__trigger { border-radius: 28px; }
.fab-dock[data-open="true"] .fab-dock__trigger .m3-icon { transform: rotate(135deg); }
.fab-dock__trigger .m3-icon {
  transition: transform var(--dur-long-1) var(--spring-bouncy);
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.m3-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--shape-xl);
  padding: 24px;
  overflow: hidden;
  transition:
    border-radius var(--dur-long-1)   var(--spring-bouncy),
    box-shadow    var(--dur-medium-2) var(--ease-standard),
    transform     var(--dur-long-1)   var(--spring-default),
    background    var(--dur-medium-2) var(--ease-standard);
}
.m3-card--filled   { background: var(--surface-container-high); color: var(--on-surface); }
.m3-card--elevated { background: var(--surface-container-low);  color: var(--on-surface); box-shadow: var(--elev-1); }
.m3-card--outlined { background: var(--surface); color: var(--on-surface); box-shadow: inset 0 0 0 1px var(--outline-variant); }

.m3-card.m3-interactive { cursor: pointer; }

/* M3 puts the state layer *between* the container and its content. Ours is
   absolutely positioned, so its static siblings paint earlier and end up
   underneath the overlay — every hover washed the card's own content with 8%
   of on-surface. Promoting the content to positioned restores the order. */
.m3-card > *:not(.state-layer):not(.ripple-host),
.role-card > *:not(.state-layer):not(.ripple-host) {
  position: relative;
}

/* Hover softens the card: corners open up symmetrically, it lifts, and the
   surface brightens one step. Nested radii stay concentric with the media
   inside, so the two shapes move together instead of fighting. */
.m3-card.m3-interactive:hover {
  transform: translateY(-8px);
  box-shadow: var(--elev-3);
  border-radius: var(--shape-xxl);
}
.m3-card--filled.m3-interactive:hover   { background: var(--surface-container-highest); }
.m3-card--elevated.m3-interactive:hover { background: var(--surface-container); }
.m3-card--outlined.m3-interactive:hover { background: var(--surface-container-low); }

.m3-card.m3-interactive:active {
  transform: translateY(-2px) scale(0.985);
  border-radius: var(--shape-xl-increased);
}

/* --------------------------------------------------------------------------
   Chips
   -------------------------------------------------------------------------- */
.m3-chip-set { display: flex; flex-wrap: wrap; gap: 8px; }
.m3-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: var(--shape-sm);
  background: transparent;
  color: var(--on-surface-variant);
  box-shadow: inset 0 0 0 1px var(--outline-variant);
  font-family: var(--font-plain);
  font-size: var(--type-label-lg);
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition:
    border-radius var(--dur-medium-2) var(--spring-bouncy),
    background    var(--dur-medium-1) var(--ease-standard),
    color         var(--dur-medium-1) var(--ease-standard),
    box-shadow    var(--dur-medium-1) var(--ease-standard),
    transform     var(--dur-medium-2) var(--spring-default);
}
.m3-chip:active { border-radius: 20px; transform: scale(0.94); }
.m3-chip[aria-pressed="true"] {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  box-shadow: none;
  border-radius: 20px;
}
.m3-chip[aria-pressed="true"] .m3-chip__check { width: 18px; opacity: 1; margin-inline-end: 0; }
.m3-chip__check {
  width: 0;
  opacity: 0;
  overflow: hidden;
  font-size: 18px;
  transition: width var(--dur-medium-2) var(--spring-default), opacity var(--dur-short-3) linear;
}
/* Static, non-interactive tag chip — M3's outlined assist chip.
   The fill is transparent on purpose. Any surface-token fill either collided
   with the card (--highest matched the hover state exactly) or went near-black
   in dark mode (--lowest is #0f0805). Transparent adapts to whatever surface
   the chip lands on, and the outline carries the shape at 3.6:1–4.9:1. */
.m3-tag {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--shape-sm);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--outline);
  color: var(--on-surface);
  font-size: var(--type-label-md);
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* --------------------------------------------------------------------------
   Wavy progress indicator — the signature M3 Expressive meter
   -------------------------------------------------------------------------- */
.m3-wavy {
  display: block;
  width: 100%;
  height: 16px;
  overflow: visible;
}
.m3-wavy__track {
  fill: none;
  stroke: var(--secondary-container);
  stroke-width: 4;
  stroke-linecap: round;
}
[data-theme="dark"] .m3-wavy__track { stroke: var(--surface-container-highest); }
.m3-wavy__indicator {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 0 200;
  transition: stroke-dasharray var(--dur-xlong-2) var(--ease-emphasized);
}
.m3-wavy__stop {
  fill: var(--primary);
  opacity: 0;
  transition: opacity var(--dur-medium-2) var(--ease-standard) 600ms;
}
.m3-wavy.is-filled .m3-wavy__stop { opacity: 1; }

/* --------------------------------------------------------------------------
   Loading indicator — morphing shape, M3E style
   -------------------------------------------------------------------------- */
.m3-loader {
  width: 48px;
  height: 48px;
  background: var(--primary);
  animation:
    loader-morph 2.4s var(--ease-emphasized) infinite,
    loader-spin  2.4s linear infinite;
}
@keyframes loader-morph {
  0%,100% { border-radius: 42% 58% 39% 61% / 55% 42% 58% 45%; }
  25%     { border-radius: 62% 38% 62% 38% / 38% 62% 38% 62%; }
  50%     { border-radius: 30% 70% 45% 55% / 60% 35% 65% 40%; }
  75%     { border-radius: 55% 45% 30% 70% / 45% 60% 40% 55%; }
}
@keyframes loader-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Text fields — outlined, with the floating notched label
   -------------------------------------------------------------------------- */
.m3-field { position: relative; display: block; }
.m3-field__input,
.m3-field__textarea {
  width: 100%;
  padding: 26px 16px 10px;
  border: none;
  border-radius: var(--shape-xs) var(--shape-xs) var(--shape-none) var(--shape-none);
  background: var(--surface-container-highest);
  color: var(--on-surface);
  font-family: var(--font-plain);
  font-size: var(--type-body-lg);
  box-shadow: inset 0 -1px 0 var(--on-surface-variant);
  transition:
    box-shadow    var(--dur-short-4) var(--ease-standard),
    border-radius var(--dur-medium-2) var(--spring-default),
    background    var(--dur-short-4) var(--ease-standard);
}
.m3-field__textarea { min-height: 132px; resize: vertical; }
.m3-field__input:focus,
.m3-field__textarea:focus {
  outline: none;
  box-shadow: inset 0 -3px 0 var(--primary);
  border-radius: var(--shape-md) var(--shape-md) var(--shape-none) var(--shape-none);
}
.m3-field__label {
  position: absolute;
  top: 18px;
  inset-inline-start: 16px;
  color: var(--on-surface-variant);
  font-size: var(--type-body-lg);
  pointer-events: none;
  transform-origin: left center;
  transition: transform var(--dur-medium-1) var(--ease-emphasized),
              color     var(--dur-medium-1) var(--ease-standard);
}
.m3-field__input:focus + .m3-field__label,
.m3-field__input:not(:placeholder-shown) + .m3-field__label,
.m3-field__textarea:focus + .m3-field__label,
.m3-field__textarea:not(:placeholder-shown) + .m3-field__label {
  transform: translateY(-13px) scale(0.75);
  color: var(--primary);
}
.m3-field__textarea + .m3-field__label { top: 20px; }

/* --------------------------------------------------------------------------
   List items
   -------------------------------------------------------------------------- */
.m3-list { display: flex; flex-direction: column; gap: 4px; list-style: none; }
.m3-list-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  border-radius: var(--shape-lg);
  background: var(--surface-container-low);
  overflow: hidden;
  transition: border-radius var(--dur-long-1) var(--spring-bouncy),
              background var(--dur-medium-2) var(--ease-standard);
}
.m3-list-item__leading {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: var(--shape-md);
  background: var(--tertiary-container);
  color: var(--on-tertiary-container);
  transition: border-radius var(--dur-long-1) var(--spring-bouncy);
}
.m3-list-item:hover .m3-list-item__leading { border-radius: 22px; }

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.m3-top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 72px;
  padding: 0 clamp(16px, 4vw, 40px);
  background: transparent;
  transition: background var(--dur-medium-2) var(--ease-standard),
              box-shadow var(--dur-medium-2) var(--ease-standard),
              height     var(--dur-medium-2) var(--ease-emphasized);
}
.m3-top-bar[data-scrolled="true"] {
  height: 64px;
  background: var(--surface-container);
  box-shadow: var(--elev-2);
}
.m3-top-bar__nav { display: flex; gap: 4px; margin-inline-start: auto; }

/* Brand wordmark — cookie-shaped monogram tile + two-weight name */
.brand {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px 6px 6px;
  border-radius: 26px;
  color: var(--on-surface);
  text-decoration: none;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: border-radius var(--dur-medium-2) var(--spring-bouncy);
}
.brand:active { border-radius: var(--shape-md); }

.brand__mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  background: linear-gradient(140deg, var(--primary), var(--tertiary));
  clip-path: url(#brand-clip);
  transition: transform var(--dur-long-1) var(--spring-bouncy);
}
.brand:hover .brand__mark { transform: rotate(-20deg) scale(1.08); }
.brand:active .brand__mark { transform: rotate(-20deg) scale(0.94); }

.brand__monogram {
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--on-primary);
}
[data-theme="dark"] .brand__monogram { color: var(--p-10); }

.brand__name {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  font-size: var(--type-title-lg);
  line-height: 1;
  white-space: nowrap;
}
.brand__given {
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--on-surface-variant);
}
.brand__family {
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variation-settings: "wdth" 100, "GRAD" 0, "ROND" 45;
  background: linear-gradient(100deg, var(--primary), var(--tertiary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.m3-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  color: var(--on-surface-variant);
  font-size: var(--type-label-lg);
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  transition: color var(--dur-medium-1) var(--ease-standard),
              background var(--dur-medium-1) var(--ease-standard),
              border-radius var(--dur-medium-2) var(--spring-bouncy);
}
.m3-nav-link:active { border-radius: var(--shape-sm); }
.m3-nav-link[aria-current="true"] {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* Bottom navigation bar (compact viewports) */
.m3-nav-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 55;
  display: none;
  justify-content: space-around;
  padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-container);
  box-shadow: var(--elev-2);
}
.m3-nav-bar__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  /* A flex item's default min-width is `auto`, i.e. it refuses to shrink below
     its content. Five 64px pills plus the bar's padding need 336px, so without
     this the bar overflowed any viewport narrower than that. */
  min-width: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--on-surface-variant);
  font-family: var(--font-plain);
  font-size: var(--type-label-md);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.m3-nav-bar__pill {
  display: grid;
  place-items: center;
  width: min(64px, 100%);   /* 64px normally, but yields on a very narrow screen */
  height: 32px;
  border-radius: var(--shape-full);
  background: transparent;
  transition: background var(--dur-medium-2) var(--ease-standard),
              width      var(--dur-long-1)   var(--spring-bouncy);
}
.m3-nav-bar__item[aria-current="true"] { color: var(--on-secondary-container); }
.m3-nav-bar__item[aria-current="true"] .m3-nav-bar__pill { background: var(--secondary-container); }

/* --------------------------------------------------------------------------
   Snackbar
   -------------------------------------------------------------------------- */
.m3-snackbar {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 48px;
  padding: 12px 16px 12px 20px;
  border-radius: var(--shape-sm);
  background: var(--inverse-surface);
  color: var(--inverse-on-surface);
  box-shadow: var(--elev-3);
  font-size: var(--type-body-md);
  transform: translate(-50%, 200%);
  transition: transform var(--dur-long-2) var(--spring-bouncy);
}
.m3-snackbar[data-open="true"] { transform: translate(-50%, 0); }
.m3-snackbar__action {
  border: none;
  background: transparent;
  color: var(--inverse-primary);
  font-family: var(--font-plain);
  font-size: var(--type-label-lg);
  font-weight: 700;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Icons
   -------------------------------------------------------------------------- */
.m3-icon {
  font-family: "Material Symbols Rounded", sans-serif;
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}
.m3-icon.filled { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }

/* Until the symbol font resolves, an icon would render its ligature name as
   plain text ("dark_mode") or as tofu boxes. Reserve the box, hide the glyph. */
html:not(.fonts-ready) .m3-icon {
  visibility: hidden;
  min-width: 1em;
}

/* Meter hosts are empty until main.js builds their SVG — hold the space so
   nothing jumps, and never show a bare box. */
[data-wavy] {
  min-height: 16px;
  contain: layout;
}
