/*
  The bento fills the viewport. Primary canvas is iPad Pro 11"
  landscape (1194×834). Portrait of that iPad (834×1194) uses a
  second arrangement. 1024×768 and 1366×1024 share the landscape
  grid and must not scroll or clip the page.
*/

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap-bento);
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  padding:
    calc(var(--inset-y) + var(--safe-top))
    calc(var(--inset-x) + var(--safe-right))
    calc(var(--inset-y) + var(--safe-bottom))
    calc(var(--inset-x) + var(--safe-left));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex: none;
  min-height: 60px;
  padding: 0 var(--space-2);
}

.clock {
  display: block;
  font-size: var(--text-clock);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-clock);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.header__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 0;
}

.header__greeting {
  color: var(--secondary-label);
  font-size: var(--text-greeting);
  font-weight: var(--weight-semibold);
}

.header__date {
  font-size: var(--text-date);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-title);
  line-height: var(--leading-tight);
}

.widgets {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(0, 0.94fr) minmax(0, 1.08fr);
  grid-template-rows: minmax(0, 1.18fr) minmax(0, 0.78fr) minmax(148px, 0.82fr);
  grid-template-areas:
    "calendar weather kids"
    "calendar tesla kids"
    "shopping shopping shopping";
  gap: var(--gap-bento);
}

.widget--calendar { grid-area: calendar; }
.widget--weather { grid-area: weather; }
.widget--tesla { grid-area: tesla; }
.widget--shopping { grid-area: shopping; }
.widget--kids { grid-area: kids; }

/*
  Landscape iPad, including the installed app (1194×834) and a Safari
  tab (~1194×760). 100svh/100dvh follow the visible viewport, so the
  bento fits instead of scrolling by the toolbar.
*/
@media (orientation: landscape) and (min-width: 901px) and (min-height: 700px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }
}

/*
  Shorter landscape windows keep the same bento at the iPad's widget height
  and let the page scroll, instead of crushing the cards.
*/
@media (orientation: landscape) and (min-width: 901px) and (max-height: 699px) {
  html,
  body {
    position: static;
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .widgets {
    flex: none;
    height: 672px;
  }
}

/* Portrait iPad and phones: one column, page scroll, same cards. */
@media (orientation: portrait), (max-width: 900px) {
  html,
  body {
    position: static;
    height: auto;
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .header {
    align-items: flex-end;
    padding-top: var(--space-2);
  }

  .widgets {
    display: flex;
    flex-direction: column;
    flex: none;
    gap: var(--space-3);
  }

  .widget--calendar,
  .widget--kids {
    min-height: 440px;
  }

  .widget--weather,
  .widget--shopping {
    min-height: 300px;
  }

  .widget--tesla {
    min-height: 260px;
  }
}

/*
  iPad Pro 11" portrait (834×1194) and other large portrait tablets.
  A 2-column bento fills the height, so the page does not scroll.
  Kids sit side by side inside their card (see widgets.css).
*/
@media (orientation: portrait) and (min-width: 700px) and (min-height: 1000px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
  }

  .header {
    align-items: center;
    padding-top: 0;
  }

  .widgets {
    display: grid;
    flex: 1;
    min-height: 0;
    height: auto;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.9fr);
    grid-template-rows: minmax(0, 1.12fr) minmax(0, 0.82fr) minmax(0, 0.7fr) minmax(0, 1fr);
    grid-template-areas:
      "calendar weather"
      "calendar tesla"
      "shopping shopping"
      "kids kids";
    gap: var(--gap-bento);
  }

  .widget--calendar,
  .widget--weather,
  .widget--tesla,
  .widget--shopping,
  .widget--kids {
    min-height: 0;
  }
}
