/* The theme menu in every header (crates/tally-web/src/theme.rs): a disclosure whose button
   shows the current choice, opening onto System, Light and Dark. Without the script it is
   a form; with it (js/theme.js) it is a keyboard menu and the page changes in place, in a
   short crossfade. Its class names are its own (theme-…), so neither app.css nor a page's
   stylesheet reaches into it. Motion: the icon turns into the new one, the list unfolds,
   the check draws in; none of it for prefers-reduced-motion. */

.theme-menu {
  position: relative;
  flex: none;
}

.theme-menu > summary {
  list-style: none;
}

.theme-menu > summary::-webkit-details-marker {
  display: none;
}

.theme-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 8px 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  transition: border-color .2s ease, color .2s ease;
}

.theme-button:hover,
.theme-menu[open] .theme-button {
  border-color: var(--faint);
  color: var(--ink);
}

/* The three icons in one cell: the current one shows, the others wait turned away. */
.theme-icons {
  display: grid;
  width: 18px;
  height: 18px;
}

.theme-icon {
  grid-area: 1 / 1;
  opacity: 0;
  transform: rotate(-90deg) scale(.5);
}

.theme-menu[data-current="system"] .theme-icon[data-icon="system"],
.theme-menu[data-current="light"] .theme-icon[data-icon="light"],
.theme-menu[data-current="dark"] .theme-icon[data-icon="dark"] {
  opacity: 1;
  transform: none;
}

.theme-icon svg,
.theme-item-icon svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* System: the screen half filled, light and dark side by side. */
.theme-fill {
  fill: currentColor;
  stroke: none;
  opacity: .9;
}

.theme-chevron {
  width: 10px;
  height: 7px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-menu[open] .theme-chevron {
  transform: rotate(180deg);
}

.theme-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: grid;
  min-width: 180px;
  margin: 0;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-menu);
  transform-origin: top right;
}

.theme-list-title {
  margin: 0;
  padding: 5px 10px 7px;
  color: var(--faint);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.3;
}

.theme-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}

.theme-item:hover,
.theme-item:focus-visible {
  background: var(--surface-2);
  color: var(--ink);
  outline-offset: -2px;
}

.theme-item-icon {
  flex: none;
  color: var(--muted);
}

.theme-item[aria-pressed="true"] {
  color: var(--ink);
  font-weight: 600;
}

.theme-item[aria-pressed="true"] .theme-item-icon {
  color: var(--brand);
}

.theme-item-name {
  flex: 1;
}

.theme-check {
  flex: none;
  width: 10px;
  height: 6px;
  margin: -3px 2px 0 8px;
  border-left: 2px solid var(--brand);
  border-bottom: 2px solid var(--brand);
  opacity: 0;
  transform: rotate(-45deg);
}

.theme-item[aria-pressed="true"] .theme-check {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .theme-icon {
    transition: opacity .3s ease, transform .55s var(--ease-out);
  }

  .theme-chevron {
    transition: transform .25s var(--ease-out);
  }

  .theme-menu[open] .theme-list {
    animation: theme-unfold .24s var(--ease-out) both;
  }

  .theme-item[aria-pressed="true"] .theme-check {
    animation: theme-check .32s var(--ease-out) both;
  }

  /* The page crossfades from one theme to the other (the script asks for a view
     transition only when motion is welcome). */
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: .34s;
    animation-timing-function: var(--ease-in-out);
  }
}

@keyframes theme-unfold {
  from {
    opacity: 0;
    transform: translate3d(0, -4px, 0) scale(.97);
  }
}

@keyframes theme-check {
  from {
    opacity: 0;
    transform: rotate(-45deg) scale(.3);
  }
}
