/* The layers' look: the sheet and dialog, the menu, ask() and toast(). Sizes, corners and motion are the scales'
   tokens (scales/scales.css) and colours the theme's roles; the four sizes of a layer's own are named here and an app
   may set them on its root. An app may style the same classes itself instead of taking this sheet. */
:root {
  --sheet-w: 560px;   /* the dialog's width from 600 px (the standard's 520 to 560) */
  --sheet-gap: 48px;  /* kept clear above a bottom sheet, and round a dialog */
  --menu-w: 200px;    /* an anchored menu's least width */
  --grab-w: 36px;     /* the grabber, 36 by 4 */
}

/* ---- the scrim and the sheet: from the foot under 600 px */
.scrim {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center;
  background: var(--scrim); animation: hu-fade var(--dur-fade) var(--ease);
}
.scrim.boxed { position: absolute; }
.scrim.out { opacity: 0; transition: opacity var(--dur-fade) ease-in; }
.sheet {
  position: relative; display: flex; flex-direction: column; width: 100%; box-sizing: border-box;
  max-height: calc(100% - env(safe-area-inset-top, 0px) - var(--sheet-gap));
  background: var(--panel); color: var(--text); border: var(--line-hair) solid var(--border); border-bottom: 0;
  border-radius: var(--r-sheet) var(--r-sheet) 0 0; outline: none; overscroll-behavior: contain;
  /* the side insets too: a sheet that pads only the foot puts its right-hand controls under a phone's clock */
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  box-shadow: 0 var(--s-6) var(--s-12) var(--shadow-2, transparent);
  animation: hu-up var(--dur-sheet) var(--ease);
  transition: transform var(--dur-fade) var(--ease), opacity var(--dur-fade) ease-in;
}
.sheet.dragging { transition: none; }
.out .sheet { transform: translateY(100%); animation: none; }
.grab { flex: none; display: flex; justify-content: center; padding: var(--s-3) 0; touch-action: none; cursor: grab; }
.grab::before { content: ""; width: var(--grab-w); height: var(--s-1); border-radius: var(--r-pill); background: var(--control-border); }
.sheet-head {
  flex: none; display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-2) var(--s-1) var(--s-5);
  min-height: var(--s-12); box-sizing: border-box; touch-action: none;
}
.sheet-title { flex: 1; margin: 0; font-size: var(--fs-18); font-weight: var(--fw-strong); line-height: var(--lh-heading); }
.sheet-x {
  display: inline-flex; align-items: center; justify-content: center; min-width: var(--hit); min-height: var(--hit);
  padding: var(--s-2); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--muted); cursor: pointer;
}
.sheet-x .ic { width: var(--s-5); height: var(--s-5); }
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--s-1) var(--s-4) var(--s-5); font-size: var(--fs-14); line-height: var(--lh-body);
}

/* ---- from 600 px: the same content as a centred dialog */
@media (min-width: 600px) {
  .scrim { align-items: center; }
  .sheet {
    width: min(var(--sheet-w), calc(100% - var(--sheet-gap))); max-height: calc(100% - var(--sheet-gap));
    padding: 0; border-bottom: var(--line-hair) solid var(--border); border-radius: var(--r-sheet);
    animation-name: hu-pop;
  }
  .out .sheet { transform: scale(.96); opacity: 0; }
  .grab { display: none; }
  .sheet-head { padding-top: var(--s-2); touch-action: auto; }
  .sheet:not(:has(.sheet-head)) .sheet-body { padding-top: var(--s-5); }
}

/* ---- buttons: ask's, and an app's in a sheet */
.b {
  min-height: var(--hit); padding: var(--s-2) var(--s-4); border-radius: var(--r-button); cursor: pointer;
  font: inherit; font-size: var(--fs-14); line-height: var(--lh-body);
  background: var(--panel-2); color: var(--text); border: var(--line-hair) solid var(--control-border);
}
.b.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.b.danger { background: var(--error); color: var(--bg); border-color: transparent; }
.b:focus-visible, .sheet-x:focus-visible, .menu-i:focus-visible {
  outline: var(--line-focus) solid var(--focus); outline-offset: var(--line-focus-offset);
}
.ask .ask-t { margin: 0 0 var(--s-4); font-size: var(--fs-16); }
.acts { display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 599.98px) { .ask .acts .b { flex: 1; } }

/* ---- the menu: anchored from 600 px, a bottom sheet under it */
.menu-layer { position: fixed; inset: 0; z-index: 10; }
.menu-layer.placing { visibility: hidden; }
.menu-scrim { position: absolute; inset: 0; }
.menu {
  position: absolute; min-width: var(--menu-w); max-width: calc(100% - var(--s-4)); max-height: calc(100% - var(--s-4));
  overflow-y: auto; overscroll-behavior: contain; box-sizing: border-box; padding: var(--s-1); outline: none;
  background: var(--panel); color: var(--text); border: var(--line-hair) solid var(--border); border-radius: var(--r-button);
  box-shadow: 0 var(--s-3) var(--s-8) var(--shadow-2, transparent);
  transform-origin: top left; animation: hu-drop var(--dur-fade) var(--ease);
  transition: opacity var(--dur-fade) ease-in;
}
.menu.up { transform-origin: bottom left; }
.out .menu { opacity: 0; animation: none; }
.menu-i {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: var(--hit); padding: var(--s-2) var(--s-3);
  border: 0; border-radius: var(--r-control); background: transparent; color: var(--text); cursor: pointer;
  font: inherit; font-size: var(--fs-14); line-height: var(--lh-body); text-align: start;
}
.menu-i .ic { flex: none; width: var(--s-5); height: var(--s-5); color: var(--muted); }
.menu-i.danger, .menu-i.danger .ic { color: var(--error); }
.menu-i:disabled { opacity: .45; cursor: default; }
.menu-i:focus { background: var(--hover); }
.menu-sep { height: var(--line-hair); margin: var(--s-1) 0; background: var(--border); }
.menu-sheet .sheet-body { padding: 0 var(--s-2) var(--s-3); }
.menu-sheet .menu-i { padding: var(--s-3) var(--s-4); font-size: var(--fs-16); }
@media (hover: hover) {
  .b:hover { filter: brightness(1.08); }
  .sheet-x:hover, .menu-i:not(:disabled):hover { background: var(--hover); color: var(--text); }
}

/* ---- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--s-6) + env(safe-area-inset-bottom, 0px)); z-index: 13;
  transform: translate(-50%, var(--s-5)); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-sheet) var(--ease), transform var(--dur-sheet) var(--ease);
  display: flex; gap: var(--s-2); align-items: center; padding: var(--s-2) var(--s-4); border-radius: var(--r-card);
  max-width: calc(100vw - var(--s-8)); box-sizing: border-box; font-size: var(--fs-14);
  background: var(--panel-2); color: var(--text); border: var(--line-hair) solid var(--border);
}
.toast.in { opacity: 1; transform: translate(-50%, 0); }
.toast .ic { width: var(--s-4); height: var(--s-4); flex: none; }
.toast.bad .ic { color: var(--error); }
.toast:not(.bad) .ic { color: var(--muted); }

@keyframes hu-fade { from { opacity: 0; } }
@keyframes hu-up { from { transform: translateY(100%); } }
@keyframes hu-pop { from { opacity: 0; transform: scale(.96); } }
@keyframes hu-drop { from { opacity: 0; transform: scale(.96); } }

/* slides become fades */
@media (prefers-reduced-motion: reduce) {
  .sheet, .menu { animation-name: hu-fade; }
  .out .sheet { transform: none; opacity: 0; }
  .toast { transform: translate(-50%, 0); transition: opacity var(--dur-fade); }
}
