/* The cards that come up from the bottom: every pop-up box in the game (see shared/sheet.js). Global, unscoped.
   What's in each box is styled where the box is made (theme.css for the shared ones, the screens' own stylesheets for
   theirs); this is the card itself - its dimmed page, its shape and pill, and what scrolls in it. */

/* The dialog covers the screen with nothing of its own to see, so the dimmed layer and the card can each be moved
   (sheet.js). It mustn't be something that scrolls (overflow: visible, not hidden): while the card slides in from below
   the screen, iOS scrolled the dialog to show what had the focus in it, which sent the card up to the middle of the
   screen until the slide was over. What sticks out below the screen as the card comes and goes is off the screen anyway,
   and something fixed to the screen never makes the page longer. */
.sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  overflow: visible;
  /* It has the focus while it's open (see sheet.js), but it's the box as a whole: no outline round the screen */
  outline: none;
}
.sheet::backdrop { background: none; }

/* On its way down, nothing in it takes a tap */
.sheet.is-closing { pointer-events: none; }

/* The dimmed page around the card. A finger dragged on it doesn't scroll the page underneath. */
.sheet-scrim {
  position: absolute;
  inset: 0;
  touch-action: none;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
/* Over another card that stays up (reminders over a Daily Jam result): only a little more dim, so the page isn't dimmed
   and blurred twice over */
.sheet.is-stacked > .sheet-scrim {
  background: var(--scrim-light);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* The card: along the bottom edge, rounded at its top corners, as tall as what's in it up to nearly the whole screen -
   and on a computer or an iPad, about as wide as a phone, in the middle. Its own touches: it's dragged to put it away
   (a list in it scrolls itself - .sheet-body). Clear of a phone's notch, held sideways. */
.sheet-card {
  position: absolute;
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: 0;
  max-width: 480px;
  max-height: calc(100vh - 24px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: 22px 22px 0 0;
  /* Solid, not the see-through white of the cards on the page: a tall card with little in it showed the page through */
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.3);
  touch-action: none;
  outline: none;
  /* How far what's in it is from its sides (.sheet-head, .sheet-body), and what scrolls in it from the head's bottom -
     for what reaches out to them (the account's tabs and pages, theme.css) */
  --sheet-side: 20px;
  --sheet-top: 14px;
}
/* A block of its own because a line with env() in it always replaces the line before, even where dvh is unknown. In the
   iPhone app the page runs under the status bar, so the card stops short of it. */
@supports (max-height: 100dvh) {
  .sheet-card { max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px)); }
}

/* Pulled up past its place, the card carries on below its bottom edge: never a gap under it */
.sheet-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 80px;
  background: inherit;
  pointer-events: none;
}

/* Being dragged with a mouse: no words picked out on the way */
.sheet-card.is-dragging { -webkit-user-select: none; user-select: none; }

/* The leaderboard, and the account while signed in: as tall as they'll ever be from the start, so the × and the tabs
   stay where they are as rows and stats come in, and from tab to tab */
.sheet.sheet-tall > .sheet-card { height: 88vh; }
@supports (height: 100dvh) {
  .sheet.sheet-tall > .sheet-card { height: min(88dvh, calc(100dvh - 24px - env(safe-area-inset-top, 0px))); }
}

/* The pill, and the title and × beside each other under it. It stays put over what scrolls (and over it: a hairline
   once that's scrolled - sheet.js). */
.sheet-head {
  position: relative;
  z-index: 1;
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  padding: 6px var(--sheet-side) 0;
  -webkit-user-select: none;
  user-select: none;
}
.sheet-head > :not(.sheet-grabber) { margin-top: 2px; }
/* Anything else in the head (the leaderboard's tabs) takes a row to itself, under the title */
.sheet-head > .sheet-row-full { grid-column: 1 / -1; margin-top: 14px; }
.sheet-card.is-scrolled > .sheet-head { box-shadow: 0 1px 0 var(--field-line); }

.sheet-grabber {
  grid-column: 1 / -1;
  justify-self: center;
  display: block;
  width: 36px;
  height: 5px;
  margin: 0 0 6px;
  border-radius: 3px;
  background: var(--grabber);
}

/* What's in it, one thing under another. Too tall for the screen, it scrolls - without taking the page along when it
   gets to an end. At the bottom, clear of the phone's home bar. */
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 16px;
  padding: var(--sheet-top) var(--sheet-side) max(20px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  outline: none;
}

/* A phone held sideways: wider, so what's in it takes fewer lines, and closer to the top and bottom edges */
@media (orientation: landscape) and (max-height: 500px) {
  .sheet-card { max-width: 640px; max-height: calc(100vh - 8px); --sheet-side: 16px; --sheet-top: 10px; }
  .sheet.sheet-tall > .sheet-card { height: calc(100vh - 8px); }
  @supports (max-height: 100dvh) {
    .sheet-card { max-height: calc(100dvh - 8px - env(safe-area-inset-top, 0px)); }
    .sheet.sheet-tall > .sheet-card { height: calc(100dvh - 8px - env(safe-area-inset-top, 0px)); }
  }
  .sheet-head { padding: 5px var(--sheet-side) 0; }
  .sheet-grabber { margin-bottom: 4px; }
  .sheet-body { gap: 12px; padding: var(--sheet-top) var(--sheet-side) max(14px, calc(env(safe-area-inset-bottom, 0px) + 6px)); }
}


/* ---------- Home's Expand (home/script.js): a list of rows ---------- */

/* One under the other, a line between each and the next one showing */
.sheet-body.sheet-rows {
  gap: 0;
  padding: 0 16px max(10px, env(safe-area-inset-bottom, 0px));
}
.sheet-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.sheet-row:not([hidden]) ~ .sheet-row { border-top: 1px solid var(--field-line); border-radius: 0; }
/* Pressed, a row is tinted, as an iPhone's list rows are - and it doesn't shrink as other buttons do (theme.css): a
   full-width row shrunk pulled its line in from the edges while the next row's stayed */
button.sheet-row:is(:active, .is-pressed) { background: var(--field); scale: none; }
@media (hover: hover) {
  button.sheet-row:hover { background: var(--field); }
}

/* Help and Privacy, side by side, quieter */
.sheet-links {
  min-height: 44px;
  justify-content: center;
  gap: 4px;
  color: var(--ink-muted);
  font-size: 15px;
  cursor: default;
}
.sheet-links a {
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink-muted);
  text-decoration: underline;
  text-decoration-color: var(--field-line);
  text-underline-offset: 3px;
}
.sheet-links a:active { background: var(--field); color: var(--ink); }
@media (hover: hover) {
  .sheet-links a:hover { background: var(--field); color: var(--ink); }
}
