/* epsibox shell: wallpaper, lock screen, home screen and the window every app
   opens into. Phones get a phone layout; anything larger gets a tablet layout
   that fills the window. Apps bring their own stylesheet. */

@font-face {
  font-family: "DM Sans";
  src: url("/fonts/DMSans-Variable.woff") format("woff");
  font-weight: 100 1000;
  font-display: swap;
}
@font-face {
  font-family: "Lora";
  src: url("/fonts/Lora-Variable.woff") format("woff");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  /* Indigo dye, rice paper, and brass for the bell. */
  --ink: #1b2440;
  --dye: #131a30;
  --wash: #e6eaf2;
  --paper: #f6f7fa;
  --slate: #66708a;
  --brass: #a87b2c;
  --brass-light: #d8b46a;

  --sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Lora", ui-serif, Georgia, "Times New Roman", serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --home-bar: calc(22px + var(--safe-bottom));
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* --screen-height is set only where the page comes up short of the real screen
   (an iPhone opened from the home screen: see fitScreen in main.js). */
html,
body {
  height: var(--screen-height, 100%);
  margin: 0;
}

body {
  font-family: var(--sans);
  font-optical-sizing: auto;
  font-size: 16px;
  line-height: 1.45;
  color: #fff;
  background: var(--dye);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--brass-light);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---------- the screen ---------- */

#device {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--screen-height, 100%);
  overflow: hidden;
  isolation: isolate;
  background: var(--dye);
}

/* Opened from a home screen there are no browser bars, so the full height of
   the window is ours. Asking for it outright covers the strip an iPhone can
   otherwise leave along the bottom. */
@media (display-mode: standalone) {
  html,
  body,
  #device {
    min-height: 100vh;
  }
}

#wallpaper {
  position: absolute;
  inset: 0;
  background: var(--wallpaper, linear-gradient(#162048, #0b1026)) center bottom / cover no-repeat;
}

/* A soft scrim so white labels stay readable over any picture. */
#wallpaper::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(12, 16, 34, 0.34), rgba(12, 16, 34, 0) 42%, rgba(12, 16, 34, 0) 70%, rgba(12, 16, 34, 0.3));
}

#screen,
#app-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

#app-layer {
  pointer-events: none;
}

/* ---------- lock screen ---------- */

.lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 12vh) 28px calc(var(--safe-bottom) + 30px);
  text-align: center;
  text-shadow: 0 1px 18px rgba(8, 12, 30, 0.35);
}

.lock-date {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.lock-clock {
  margin: 2px 0 0;
  font-size: clamp(84px, 27vw, 104px);
  font-weight: 250;
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: lining-nums;
}

.lock-bottom {
  margin-top: auto;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-shadow: none;
}

.lock-message {
  margin: 0 0 4px;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.4;
  background: rgba(12, 16, 34, 0.62);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.lock-button {
  display: block;
  width: 100%;
  padding: 15px 20px;
  border: 0;
  border-radius: 999px;
  font-size: 16.5px;
  font-weight: 560;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 28px rgba(8, 12, 30, 0.28);
}

.lock-button:active {
  background: #fff;
  transform: scale(0.985);
}

.lock-dev {
  padding: 14px 16px 16px;
  border-radius: 20px;
  text-align: left;
  background: rgba(12, 16, 34, 0.55);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.lock-dev p {
  margin: 0 0 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
}

.lock-dev button {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  font-size: 14.5px;
  text-align: left;
  background: transparent;
}

.lock-dev button:active {
  background: rgba(255, 255, 255, 0.12);
}

.lock-name {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.72);
}

.lock-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  box-shadow: 0 2px 8px rgba(8, 12, 30, 0.3);
}

/* ---------- home screen ---------- */

.home {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 0 calc(var(--safe-bottom) + 14px);
}

.status {
  display: none;
  justify-content: space-between;
  padding: 2px 30px 0;
  font-size: 14.5px;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(8, 12, 30, 0.4);
}


.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  row-gap: 22px;
  align-content: start;
  padding: 26px 16px 0;
  flex: 1;
}

.app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
}

.app-icon .tile {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(8, 12, 30, 0.28);
  transition: transform 0.18s var(--ease-out), filter 0.18s;
}

.app-icon .tile svg {
  width: 100%;
  height: 100%;
  display: block;
}

.app-icon:active .tile {
  transform: scale(0.92);
  filter: brightness(0.82);
}

.app-icon .label {
  max-width: 84px;
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 4px rgba(8, 12, 30, 0.55);
}

.dock {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 0 14px;
  padding: 14px 18px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  backdrop-filter: blur(22px) saturate(1.4);
}

.dock .label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* ---------- app window ---------- */

.app-window {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  border-radius: inherit;
  color: var(--ink);
  background: var(--wash);
}

.app-root {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-loading {
  margin: auto;
  font-size: 15px;
  color: var(--slate);
}

/* The way home, at the bottom of every app. Tap it (or press Escape). With a
   mouse it is a pill; on a phone or tablet it is a small button (further down). */
.home-bar {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 50;
  width: 190px;
  height: var(--home-bar);
  padding: 0 0 calc(var(--safe-bottom) + 7px);
  border: 0;
  color: var(--home-bar-color, inherit);
  background: none;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.home-bar-pill {
  display: block;
  width: 128px;
  height: 5px;
  border-radius: 3px;
  background: currentColor;
  opacity: 0.38;
  transition: opacity 0.15s, transform 0.15s;
}

.home-bar:hover .home-bar-pill {
  opacity: 0.7;
}

.home-bar:active .home-bar-pill {
  opacity: 0.9;
  transform: scaleX(0.92);
}

.home-bar-mark {
  display: none;
}

/* ---------- toast ---------- */

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--home-bar) + 76px);
  z-index: 100;
  max-width: calc(100% - 48px);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14.5px;
  color: #fff;
  background: rgba(19, 26, 48, 0.94);
  box-shadow: 0 8px 24px rgba(8, 12, 30, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s var(--ease-out);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- tablets, laptops and desktops ---------- */

@media (min-width: 700px) and (min-height: 520px) {
  :root {
    --home-bar: calc(24px + var(--safe-bottom));
  }

  .lock {
    padding-top: calc(var(--safe-top) + 11vh);
    padding-bottom: calc(var(--safe-bottom) + 44px);
  }

  .lock-date {
    font-size: 24px;
  }

  .lock-clock {
    font-size: clamp(124px, 15vw, 180px);
    font-weight: 220;
  }

  .lock-bottom {
    max-width: 340px;
  }

  .home {
    padding-top: calc(var(--safe-top) + 10px);
    padding-bottom: calc(var(--safe-bottom) + 20px);
  }

  .status {
    display: flex;
  }

  /* Icons keep a fixed size and spacing; a wider window simply fits more per row. */
  .icon-grid {
    grid-template-columns: repeat(auto-fill, 128px);
    justify-content: center;
    row-gap: 38px;
    width: 100%;
    max-width: 1090px;
    margin: 0 auto;
    padding: 54px 32px 0;
  }

  .app-icon {
    gap: 8px;
  }

  .app-icon .tile {
    width: 78px;
    height: 78px;
    border-radius: 19px;
  }

  .app-icon .label {
    max-width: 118px;
    font-size: 13.5px;
  }

  /* The dock shrinks to fit its icons and floats in the middle. */
  .dock {
    align-self: center;
    gap: 24px;
    margin: 0;
    padding: 14px 18px;
    border-radius: 34px;
  }

  .home-bar {
    width: 300px;
  }

  .home-bar-pill {
    width: 216px;
  }

  #toast {
    bottom: calc(var(--home-bar) + 26px);
  }
}

/* Phones and tablets draw a bar of their own along the bottom edge, and swiping
   that one up leaves epsibox altogether. A pill of ours just above it invites
   exactly that, so here the way home is a small button with the epsibox mark:
   plainly something to tap, and clear of the system's bar. */
@media (hover: none) and (pointer: coarse) {
  :root {
    --home-bar: max(32px, calc(18px + var(--safe-bottom)));
  }

  .home-bar {
    width: 132px;
    padding-bottom: max(5px, calc(var(--safe-bottom) - 12px));
  }

  .home-bar-pill {
    display: none;
  }

  .home-bar-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 22px;
    border-radius: 11px;
    /* Frosted, so whatever scrolls underneath does not show through as clutter. */
    background: color-mix(in srgb, currentColor 13%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    backdrop-filter: blur(14px) saturate(1.4);
    transition: transform 0.15s var(--ease-out), background-color 0.15s;
  }

  .home-bar-mark svg {
    display: block;
    width: 20px;
    height: 17px;
    opacity: 0.66;
  }

  .home-bar:active .home-bar-mark {
    transform: scale(0.9);
    background: color-mix(in srgb, currentColor 22%, transparent);
  }
}

/* ---------- moving between screens inside an app ---------- */

/* slide() in main.js sets data-slide for the length of one change. Going
   forward, the new screen arrives from the right over the old one; going back,
   the old one leaves to the right and uncovers what was underneath. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

html[data-slide]::view-transition-old(root),
html[data-slide]::view-transition-new(root) {
  animation-duration: 0.34s;
  animation-timing-function: cubic-bezier(0.25, 0.85, 0.25, 1);
  animation-fill-mode: both;
}

html[data-slide="forward"]::view-transition-old(root) {
  animation-name: slide-under-out;
}

html[data-slide="forward"]::view-transition-new(root) {
  animation-name: slide-over-in;
}

html[data-slide="back"]::view-transition-old(root) {
  z-index: 1;
  animation-name: slide-over-out;
}

html[data-slide="back"]::view-transition-new(root) {
  animation-name: slide-under-in;
}

@keyframes slide-over-in {
  from {
    transform: translateX(100%);
  }
}

@keyframes slide-over-out {
  to {
    transform: translateX(100%);
  }
}

@keyframes slide-under-out {
  to {
    transform: translateX(-26%);
    filter: brightness(0.86);
  }
}

@keyframes slide-under-in {
  from {
    transform: translateX(-26%);
    filter: brightness(0.86);
  }
}

/* Installed to a home screen, the device shows its own clock. */
@media (display-mode: standalone) {
  .status {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
