/*
 * Pieces shared by the screens: buttons, cards, lists, set rows, forms and dialogs.
 */

.main-button,
.plain-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
}

.main-button {
  min-height: 60px;
  border-color: var(--main);
  background: var(--main);
  color: var(--on-main);
  font-size: 20px;
  font-weight: 500;
}

.main-button .detail,
.plain-button .detail {
  font-size: 15px;
  font-weight: 400;
}

.plain-button .detail {
  color: var(--soft-text);
}

.add-button {
  border-style: dashed;
}

.text-button {
  min-width: var(--tap);
  color: var(--current);
}

.icon-button {
  display: grid;
  flex: none;
  place-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
  color: var(--soft-text);
}

.drag-handle {
  display: grid;
  flex: none;
  gap: 4px;
  place-content: center;
  width: var(--tap);
  min-height: var(--tap);
  margin-left: -12px;
  cursor: grab;
  /* Only dragging these lines moves a row. Dragging anywhere else scrolls. */
  touch-action: none;
}

.drag-handle span {
  width: 20px;
  height: 2px;
  border-radius: 1px;
  background: var(--soft-text);
}

.row.dragging,
.split-card.dragging {
  position: relative;
  z-index: 1;
  background: var(--border);
  box-shadow: 0 6px 16px var(--drag-shadow);
}

.button-row {
  display: flex;
  gap: 8px;
}

.button-row > * {
  flex: 1;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-actions {
  margin-top: 16px;
}

.note-help {
  margin-top: 10px;
}

.plan-repeat {
  margin-bottom: 8px;
}

.section-title {
  margin: 14px 4px 8px;
  color: var(--soft-text);
  font-size: 16px;
  font-weight: 400;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* The whole title is one button. Another button can go on top of it, just left of the arrow. */
.section-row.opening {
  position: relative;
  margin-top: 6px;
}

.section-row.opening .section-title {
  flex: 1;
  margin: 0;
}

.section-row.opening .section-title button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  padding: 0 4px;
}

.section-row.opening .text-button {
  position: absolute;
  top: 2px;
  right: 36px;
  text-align: right;
}

.chevron.turning {
  display: inline-block;
  width: 16px;
  text-align: center;
}

.chevron.turning.open {
  transform: rotate(90deg);
}

.split-arrow {
  display: grid;
  flex: none;
  place-items: center end;
  min-height: var(--tap);
  /* This makes the arrow easier to tap without moving it. */
  margin: 0 -14px 0 -12px;
  padding: 0 14px 0 12px;
  cursor: pointer;
}

.split-add {
  margin-top: 10px;
}

.date-note {
  margin-top: 6px;
}

.date-note + .field {
  margin-top: 14px;
}

.card {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
}

.card.current {
  border: 1px solid var(--current);
}

.card p,
.keep-lines {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.row-button,
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  overflow-wrap: anywhere;
}

.row-button.card {
  min-height: 64px;
}

.row > .size {
  flex: none;
  white-space: nowrap;
}

.slide-row {
  position: relative;
  border-radius: 14px;
  /* The phone still handles scrolling up and down. Sliding sideways is handled in slide.js. */
  touch-action: pan-y;
}

.slide-front {
  position: relative;
  transition: transform 180ms ease;
}

.slide-row.sliding .slide-front {
  transition: none;
}

.slide-delete {
  position: absolute;
  inset: 0 0 0 auto;
  width: 104px;
  background: var(--main);
  color: var(--on-main);
  font-weight: 500;
  text-align: center;
  visibility: hidden;
}

.slide-row.shows-delete {
  overflow: hidden;
  background: var(--main);
}

.slide-row.shows-delete .slide-delete {
  visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
  .slide-front {
    transition: none;
  }
}

/* A past set. It can't be tapped, so it doesn't need a button's height. */
.row.set-line {
  min-height: 30px;
}

.list-check {
  flex: none;
  color: var(--current);
}

.row-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  text-align: left;
}

.row-text .title {
  font-size: 19px;
  font-weight: 500;
}

.row-end {
  flex: none;
  color: var(--soft-text);
}

.chevron {
  flex: none;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.list > * {
  border-bottom: 1px solid var(--line);
}

.card.list {
  padding-top: 0;
  padding-bottom: 0;
}

.card.list > :last-child {
  border-bottom: 0;
}

.done-text {
  color: var(--done);
}

/* This keeps all the words together when a line wraps. */
.last-done {
  white-space: nowrap;
  color: var(--soft-text);
}

.last-done.late {
  color: var(--late);
}

.skipped-text {
  color: var(--current);
}

/* VoiceOver reads this, but it doesn't show. */
.for-voiceover {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.done-card {
  padding: 18px 16px;
  border: 1.5px solid transparent;
  border-radius: 18px;
  background: var(--card);
  text-align: center;
}

.done-card.green {
  border-color: var(--done);
  background: var(--done-card);
}

.done-card h2 {
  margin: 10px 0 4px;
  font-size: 28px;
  font-weight: 700;
}

.done-card p {
  margin: 0 0 4px;
}

.done-card .plain-button {
  margin-top: 10px;
}

.done-card.green .plain-button {
  border-color: var(--done);
}

.done-mark {
  display: inline-grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--done-fill);
  color: var(--on-done);
}

.done-mark path {
  stroke-width: 2.6;
}

@media (prefers-reduced-motion: no-preference) {
  .done-mark.pop {
    animation: pop 450ms ease-out;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0);
  }

  65% {
    opacity: 1;
    transform: scale(1.15);
  }

  to {
    transform: scale(1);
  }
}

.tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px solid var(--strong-border);
  border-radius: 7px;
  color: var(--soft-text);
  font-size: 14px;
  font-weight: 400;
}

.tag.split {
  margin-left: 2px;
  border-color: var(--split);
  color: var(--split);
}

.repeat-mark {
  display: inline-block;
  margin-left: 7px;
  vertical-align: -3px;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.weekdays .choice[aria-pressed='true'] {
  border-color: var(--main);
  background: var(--main);
  color: var(--on-selected);
}

.set-mark {
  white-space: pre;
}

/* Puts text on its own line. */
.own-line {
  display: block;
}

.choices.three {
  grid-template-columns: 1.45fr 1fr 1fr;
}

.choices.three.equal {
  grid-template-columns: repeat(3, 1fr);
}

.exercise-bar {
  display: flex;
  align-items: stretch;
  min-height: 48px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--card);
}

.exercise-bar .toggle {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 6px 12px 6px 14px;
  overflow-wrap: anywhere;
}

.exercise-bar .open-focus {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  border-left: 1px solid var(--border);
  font-size: 26px;
}

.exercise-card {
  overflow: hidden;
  border-radius: 14px;
  background: var(--card);
}

.exercise-card.current {
  border: 1px solid var(--current);
}

.exercise-card .sets {
  padding: 2px 12px 12px;
}

.set-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 50px;
}

.tick {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  min-height: 48px;
  margin-left: -4px;
}

.tick span {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--strong-border);
  border-radius: 50%;
}

.tick.done span {
  border-color: var(--done);
  background: var(--done-fill);
  color: var(--on-done);
}

.tick.next span {
  border-color: var(--current);
}

.numbers {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
}

.numbers.next {
  border-color: var(--current);
  background: var(--inset);
  font-size: 20px;
  font-weight: 500;
}

.numbers.next .minor {
  font-weight: 400;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.chip {
  min-width: var(--tap);
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  text-align: center;
}

.chip[aria-pressed='true'] {
  background: var(--border);
}

.set-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
}

.set-chip {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.set-chip.done {
  color: var(--done);
}

.set-chip[aria-pressed='true'] {
  border: 2px solid var(--current);
}

.segments {
  display: grid;
  flex: none;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  margin: 0 16px 12px;
  padding: 3px;
  border-radius: 12px;
  background: var(--card);
}

.segments button {
  border-radius: 9px;
  color: var(--soft-text);
  text-align: center;
}

.segments button[aria-pressed='true'] {
  background: var(--border);
  color: var(--text);
}

.progress-chart .segments {
  margin: 0 0 8px;
}

.progress-chart .segments button {
  font-size: 15px;
}

.chart-card {
  margin-bottom: 14px;
}

.chart {
  display: block;
  width: 100%;
  /* The finger can still scroll the page from here. */
  touch-action: manipulation;
}

.chart text {
  fill: var(--soft-text);
  font-size: 12px;
}

.chart .label {
  fill: var(--text);
  /* This edge keeps the line from making the label hard to read. */
  stroke: var(--card);
  stroke-width: 4px;
  paint-order: stroke;
}

.chart .best {
  font-weight: 600;
}

.chart .grid {
  stroke: var(--line);
}

.chart .area {
  fill: var(--chart);
  opacity: 0.1;
}

.chart .line {
  fill: none;
  stroke: var(--chart);
  stroke-width: 2px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart .dot {
  fill: var(--chart);
  stroke: var(--card);
  stroke-width: 2px;
}

.chart .ring {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.5px;
}

.chart-info {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.chart-info p:empty {
  display: none;
}

.chart-card .icon-button {
  color: var(--text);
  font-size: 20px;
}

.chart-card .icon-button[aria-disabled='true'] {
  opacity: 0.35;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--card);
}

.stepper .step {
  display: grid;
  flex: none;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--inset);
  font-size: 30px;
}

.stepper .value {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  text-align: center;
}

.stepper .value strong {
  font-size: 40px;
  line-height: 1.1;
}

.sheet .stepper .value strong {
  font-size: 32px;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--switch-off);
}

.switch::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--switch-knob);
  content: '';
}

[aria-checked='true'] .switch {
  background: var(--done-fill);
}

[aria-checked='true'] .switch::before {
  left: 23px;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  margin: 0 2px 6px;
  font-size: 16px;
}

.input {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--strong-border);
  border-radius: 12px;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  overflow-wrap: anywhere;
}

textarea.input {
  display: block;
  min-height: 92px;
  resize: vertical;
}

.input::placeholder {
  color: var(--soft-text);
  opacity: 1;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choice {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.choice[aria-pressed='true'] {
  background: var(--border);
}

.select-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--strong-border);
  border-radius: 50%;
}

[aria-checked='true'] > .select-mark {
  border-color: var(--main);
  background: var(--main);
  color: var(--on-selected);
}

.undo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 0 4px 0 14px;
  border-radius: 14px;
  background: var(--undo);
  color: var(--on-undo);
}

.undo-bar.fading {
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .undo-bar {
    transition: opacity 300ms;
  }
}

.undo-bar span {
  padding: 8px 0;
  overflow-wrap: anywhere;
}

.undo-bar button {
  flex: none;
  padding: 0 14px;
  font-weight: 500;
}

dialog {
  width: calc(100% - 40px);
  max-width: 420px;
  max-height: 85dvh;
  /* The title and X stay at the top while the rest scrolls, so the title has the space above it instead. */
  --dialog-top: 22px;

  padding: 0 22px 22px;
  overflow-y: auto;
  scroll-padding-top: 64px;
  border: 0;
  border-radius: 20px;
  background: var(--inset);
  color: var(--text);
}

dialog:focus {
  outline: none;
}

dialog::backdrop {
  background: var(--behind-dialog);
}

dialog h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--dialog-top) 48px 8px 0;
  background: var(--inset);
}

.close-corner {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  height: 0;
}

.close-corner .close-button {
  margin: calc(var(--dialog-top) - 11px) -11px 0 0;
}

.close-button {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  height: 48px;
}

.close-button span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--raised);
}

.close-button path {
  stroke-width: 2.4;
}

dialog .message {
  color: var(--message);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

dialog .affected {
  margin: 12px 0 0;
  padding-left: 22px;
  list-style: disc;
  overflow-wrap: anywhere;
}

dialog .affected li + li {
  margin-top: 6px;
}

dialog .stack {
  margin-top: 16px;
}

dialog .problem {
  margin-top: 8px;
  color: var(--current);
}

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  --dialog-top: 18px;

  margin: auto auto 0;
  padding: 0 18px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
}

dialog.sheet .stack {
  margin-top: 8px;
}

dialog.menu {
  position: fixed;
  width: 260px;
  margin: 0;
  padding: 0;
  border-radius: 16px;
  background: var(--raised);
  box-shadow: var(--menu-shadow);
}

dialog.menu::backdrop {
  background: none;
}

dialog.menu button {
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--menu-line);
}

dialog.menu button:last-child {
  border-bottom: 0;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
}

.calendar button {
  min-height: 46px;
  border-radius: 50%;
  text-align: center;
}

.calendar button[aria-pressed='true'] {
  background: var(--main);
  color: var(--on-selected);
}

.calendar button:disabled {
  color: var(--unavailable);
}

.month-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 4px;
}

.month-bar > .icon-button {
  justify-self: start;
}

.month-title {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
}

.month-end {
  display: flex;
  justify-content: flex-end;
}

.month-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 4px;
}

.month-letters {
  padding: 2px 0 4px;
  color: var(--soft-text);
  font-size: 14px;
  text-align: center;
}

.month-days button {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 50px;
}

.day-number {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 50%;
}

.today .day-number {
  border-color: var(--current);
}

[aria-pressed='true'] .day-number {
  border-color: var(--main);
  background: var(--main);
  color: var(--on-selected);
}

.marks,
.marks-key .mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 13px;
}

.mark.planned span,
.mark.missed span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
}

.mark.missed span {
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--soft-text);
  background: none;
}

.mark.skipped span {
  display: block;
  width: 9px;
  height: 2px;
  background: var(--soft-text);
}

.mark.done {
  color: var(--done);
}

.mark svg {
  display: block;
  stroke-width: 3;
}

.more-marks {
  color: var(--soft-text);
  font-size: 12px;
  line-height: 13px;
}

.marks-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 4px 0;
  color: var(--soft-text);
  font-size: 14px;
}

.marks-key > span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.calendar-note {
  margin: 8px 4px 0;
}

.app-icon {
  width: 112px;
  height: 112px;
  margin: 12px auto;
  border-radius: 25px;
}

.notice-text {
  font: 14px/1.4 ui-monospace, monospace;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.guide-section summary {
  display: flex;
  align-items: center;
  min-height: 52px;
  font-size: 18px;
}

.guide-section[open] {
  padding-bottom: 14px;
}

.guide-section p {
  margin: 0 0 10px;
}

.photo-small,
.photo-tile {
  border-radius: 10px;
  background: var(--border);
  /* Small previews are cropped to fit. The saved photo isn't. */
  object-fit: cover;
}

.photo-small {
  flex: none;
  width: 48px;
  height: 48px;
}

.photo-tile {
  display: block;
  width: 100%;
  height: 100%;
}

.photo-missing {
  display: grid;
  place-items: center;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.photo-choice {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 10px;
}

.photo-choice .select-mark {
  position: absolute;
  top: 6px;
  right: 6px;
}

.photo-choice:not([aria-checked='true']) .select-mark {
  background: var(--background);
}

.photo-group {
  margin-top: 14px;
}

dialog.photo-viewer {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  border-radius: 0;
  background: #000;
}

/* Photos are always on black, so this needs the dark colors. */
:root[data-theme='light'] dialog.photo-viewer {
  --text: #ececef;
  --soft-text: #a2a6ae;
  --raised: #3a3c42;
  --border: #43464d;

  color: var(--text);
}

.viewer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.viewer-photo {
  display: grid;
  flex: 1;
  min-height: 0;
  place-items: center;
}

/* The whole photo always shows, and never larger than its real size. */
.photo-whole {
  width: auto;
  max-width: 100%;
  height: auto;
  min-height: 0;
  max-height: 100%;
  object-fit: contain;
}

.viewer button:disabled {
  color: var(--soft-text);
}
