/* ============================================
   HOME SCREEN
   Top bar (profile, Pro, settings), logo, "continue your game", the four
   modes, shortcuts, and the banner's place at the bottom.
   Every size is in em of one scale set on .home-overlay: 16px on the
   375x812 phone (where each em value equals the px it stands for), and the
   whole screen grows or shrinks together on other screens, borders and
   corners included. Shown and hidden from linotte.js (showHomeScreen /
   hideHomeScreen) with an inline display, so no .hidden cascade issues.
   ============================================ */

/* The home's scale, also used by the options menu's header when it opens
   from the home (see linotte.css), so its back arrow lands exactly where the
   options icon was. */
:root {
  --home-scale: round(down, min(100vw / 23.4375, 100dvh / 50.75, 22px), 1px);
}

@media (orientation: landscape) {
  :root {
    --home-scale: round(down, min(100dvh / 27, 100vw / 52.75, 22px), 1px);
  }
}

.home-overlay {
  position: fixed;
  inset: 0;
  z-index: 60; /* above the game and the options menu (50) */
  /* Opaque before the background art (.opt-bg) has loaded, so the board
     never shows through on a first visit. */
  background-color: whitesmoke;
  /* The phone's 16px, scaled by whichever side runs out first. */
  font-size: var(--home-scale);
  font-family: "Changa One", sans-serif;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .875em;
  padding: calc(.75em + env(safe-area-inset-top, 0px)) calc(1em + env(safe-area-inset-right, 0px))
    calc(.5em + env(safe-area-inset-bottom, 0px)) calc(1em + env(safe-area-inset-left, 0px));
  box-sizing: border-box;
  /* Never clip anything on a very short screen: scroll instead. */
  overflow-y: auto;
}

.home-top,
.home-header,
.home-main,
.home-ad {
  position: relative;
  width: min(100%, 26.875em); /* 430px on the phone */
  flex: none;
}

/* The home's blocks are layers of their own all the time. A sky's effects (a bolt, a cloud) come and go as layers of their
   own, and each time the page's layers change the browser may paint again what lies over them: on a phone the whole home
   (logo, buttons, header) was seen to vanish for one frame every few seconds over a sky with moving layers. */
.home-top,
.home-header,
.home-main,
.home-ad {
  will-change: transform;
}

/* Buttons don't inherit the font by default. */
.home-overlay button {
  font: inherit;
  color: inherit;
  margin: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- top bar ---------- */
.home-top {
  display: flex;
  align-items: center;
  gap: .625em;
}

.home-profile {
  flex: 1;
  min-width: 0;
  max-width: 18em; /* on a wide landscape bar it would run across the screen */
  height: calc(2.75em + 2px); /* as tall as the icons beside it plus a hair: a pill looks smaller than a circle of the same height */
  display: flex;
  align-items: center;
  gap: .5em;
  padding: 0 .75em 0 .25em !important;
  border-radius: 1.375em;
  background: var(--pill-bg, rgba(255, 255, 255, .5)); /* a background's ink may give it a fill (themes/README.md, "The ink") */
  border: var(--btn-border);
  /* The thickness of the options icon's ring (13 of its 180.86 units, in its 2.75em). */
  border-width: calc(2.75em * 13 / 180.86);
  box-sizing: border-box;
  text-align: left;
}

/* PRO and settings stay on the right (two classes: beats the buttons'
   margin reset above). */
.home-top .home-profile {
  margin-right: auto;
}

.home-avatar {
  flex: none;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  box-sizing: border-box;
  /* A generic buddy until the player signs in; the circle crops the
     shoulders like a profile photo. */
  background: url("resources/images/avatar-guest.svg") center / 100% no-repeat, rgb(228, 209, 187);
  background-origin: border-box; /* the buddy reaches under the rim too */
  border: .125em solid rgba(0, 0, 0, .35);
}

.home-pinfo {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.home-pname {
  font-size: 1.0625em;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-psub {
  display: flex;
  align-items: center;
  gap: .4em;
  font-family: system-ui, sans-serif;
  font-size: .6875em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.home-psub > :not(.win-badge) {
  opacity: .75;
}

/* Its text is a little larger (1.0625em), but its box is the top bar's:
   the same height and border as the profile and the options icon, so the
   sizes below are divided back to the bar's em. */
.home-pro {
  flex: none;
  height: calc(2.75em / 1.0625 + 2px); /* as the profile pill: a hair taller than the icons */
  padding: 0 1em !important;
  border-radius: calc(1.375em / 1.0625);
  background: rgb(232, 185, 35);
  border: var(--btn-border);
  border-width: calc(2.75em * 13 / 180.86 / 1.0625); /* the options icon's ring */
  box-sizing: border-box;
  font-size: 1.0625em !important;
  color: #5f4604 !important;
}

/* Without Pro it invites: GET PRO, in gold. With Pro it's a membership
   card: a gold star and PRO on the dark brown of the game's text. */
.home-pro {
  white-space: nowrap;
}

body.has-star .home-pro {
  background: #3d240c;
  color: rgb(242, 200, 60) !important;
}

body.has-star .home-pro::before {
  content: "\2605\00a0"; /* star */
  font-family: system-ui, sans-serif;
}

body.has-star .home-pro-get,
body:not(.has-star) .home-pro-owned {
  display: none;
}

/* The gear is drawn by ::after so that, back from the options menu, the
   menu's arrow (::before) can turn into it: the reverse of the menu's own
   gear-to-arrow change (see #icon-back in linotte.css). */
.home-settings {
  flex: none;
  position: relative;
  width: 2.75em;
  height: 2.75em;
  border: 0;
  background: none;
}

.home-settings::after,
.home-settings.from-back::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("resources/images/g10455.svg") center / contain no-repeat;
}

.home-settings.from-back::before {
  background-image: url("resources/images/t001.svg");
  animation: iconMorphOut var(--morph) var(--ease-out) forwards;
}

.home-settings.from-back::after {
  animation: iconMorphIn var(--morph) var(--ease-out) both;
}

/* ---------- logo ---------- */
/* The logo and its title take all the room between the top bar and the
   modes, centred in it, and the logo grows to fill it: up to 190px (the
   old home's logo) and never wider than the column. The title is a quarter
   of the logo's height, as on the old home (48px under a 190px logo).
   Container units (cqh/cqw) measure that room. */
.home-header {
  flex: 1 1 0;
  min-height: 9em; /* a very short screen scrolls instead of crushing it */
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1em;
}

.home-logo {
  width: min(70cqh, 11.875em, 100cqw);
  height: min(70cqh, 11.875em, 100cqw);
  border-radius: 24%;
  box-shadow: 0 .5em 1.25em rgba(0, 0, 0, .3);
}

.home-title {
  font-size: calc(min(70cqh, 11.875em, 100cqw) * .25);
  line-height: 1.1;
  color: var(--ink-bg);
  text-shadow: var(--ink-bg-shadow);
}

/* ---------- main block ---------- */
.home-main {
  display: flex;
  flex-direction: column;
  gap: .75em;
}

.home-continue {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .625em;
  padding: .625em .625em .625em .875em;
  border-radius: .875em;
  background: rgba(255, 255, 255, .5);
  border: var(--btn-border);
}

.home-continue[hidden] {
  display: none;
}

.home-continue-text b {
  display: block;
  font-weight: 400;
  font-size: 1.125em;
  line-height: 1.1;
}

.home-continue-text span {
  font-family: system-ui, sans-serif;
  font-size: .8125em;
}

.button.home-continue-btn {
  width: 6em;
  min-height: 2.5em;
  margin: 0;
  background-color: rgb(46, 160, 90);
}

.home-continue-btn .text-button {
  font-size: 1.125em;
}

/* The four modes, all the same size, with a little more room under them
   than between the other rows (they are the screen's main choice). */
.home-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75em;
  margin-bottom: 1.5em;
}

.button.home-mode-btn {
  width: 100%;
  min-height: 0;
  height: 4.875em;
  margin: 0;
  flex-direction: column;
  gap: .25em;
}

.home-mode-btn .text-button {
  margin: 0;
  font-size: 1.625em;
  white-space: nowrap;
}

.home-mode-btn .pro-tag {
  font-size: .42em;
  vertical-align: .35em;
}

.home-mode-sub {
  font-family: system-ui, sans-serif;
  font-size: .75em;
  color: rgba(255, 255, 255, .92);
  white-space: nowrap;
}

.home-mode-online {
  background-color: rgb(120, 80, 200);
}

.home-mode-friend {
  background-color: rgb(250, 59, 151);
}

.home-mode-bot {
  background-color: rgb(230, 140, 40);
}

.home-mode-table {
  background-color: rgb(46, 160, 90);
}

/* Shortcuts: translucent white tiles, like the options menu's buttons. */
.home-extras {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .625em;
}

.home-extra {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25em;
  padding: .5em .25em !important;
  border: 0;
  border-radius: .875em;
  background: rgba(255, 255, 255, .5);
  font-size: .9375em !important;
}

.home-extra-icon {
  width: 2.25em;
  height: 2.25em;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
}


/* ---------- banner ---------- */
/* An anchored banner is about 50px tall on a phone; the place is kept even
   before AdMob is in, so the home doesn't jump when it arrives, and a
   gap separates it from the buttons (so it isn't tapped by mistake). */
.home-ad {
  margin-top: .5em; /* a little more room between the buttons and the ad */
  /* An adaptive anchored banner (full width, about 60px tall on a phone):
     it earns more than a fixed 320x50 in the same place. In the home's
     units (its own text is .8125em): 3.75em of the home = 60px at 16px. */
  min-height: calc(3.75em / .8125);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .75em;
  padding: 0 .75em !important;
  border-radius: .5em;
  background: rgba(255, 255, 255, .85);
  border: .0625em solid rgba(0, 0, 0, .2);
  box-sizing: border-box;
  text-align: left;
  font-family: system-ui, sans-serif !important;
  font-size: .8125em !important;
}

.home-ad b {
  font-family: "Changa One", sans-serif;
  font-weight: 400;
  font-size: 1.15em;
  margin-right: .3em;
}

.home-ad-cta {
  padding: .25em .75em;
  border-radius: 1em;
  background: rgb(232, 185, 35);
  color: #5f4604;
  font: 1.1em "Changa One", sans-serif;
}

/* ---------- landscape ---------- */
/* Logo on the left, the main block on the right, top bar above and the
   banner below both. The scale comes from the height. */
@media (orientation: landscape) {
  .home-overlay {
    font-size: var(--home-scale);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 30em);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top top"
      "header main"
      "ad ad";
    justify-content: center;
    align-items: center;
    column-gap: 2em;
    row-gap: .75em;
  }

  .home-top {
    grid-area: top;
    width: 100%;
  }

  /* The whole left column, logo and title centred in it. */
  .home-header {
    grid-area: header;
    width: 100%;
    height: 100%;
    min-height: 0;
    align-self: stretch;
  }

  .home-main {
    grid-area: main;
    width: 100%;
    margin: 0;
    gap: .625em;
  }

  .home-continue {
    padding-block: .375em;
  }

  .button.home-mode-btn {
    height: 3.75em;
  }

  .home-extra {
    flex-direction: row;
    justify-content: center;
    gap: .4em;
    padding: .375em .25em !important;
  }

  .home-extra-icon {
    width: 1.75em;
    height: 1.75em;
  }

  .home-ad {
    grid-area: ad;
    width: min(100%, 45.5em); /* a 728px leaderboard on a wide screen */
    justify-self: center;
  }

  /* Pro: no banner, so no room kept for it: the rest is centred in the screen. */
  body.is-pro .home-overlay {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "header main";
  }

  body.is-pro .home-ad {
    display: none;
  }
}

/* The banner's text is 13px on the phone: its SOON matches the others' 10px. */
.home-ad > .soon-badge {
  font-size: .77em;
}

/* Same for PRO (17px text) and the shortcut tiles (15px text). */
.home-pro > .soon-badge {
  font-size: .588em;
}

.home-extra > .soon-badge {
  font-size: .667em;
}

/* The FRIEND button: a red "NEW" tag, the shape of the gold "+2" on ONLINE, while a friend request waits or a
   friend has just been made (see updateFriendsBadge in linotte.js). */
#home-friend-btn {
  position: relative;
}

.home-badge {
  position: absolute;
  top: -.6em;
  right: -.4em;
  z-index: 1;
  padding: 0 .55em;
  border-radius: .7em;
  border: 1.5px solid rgba(0, 0, 0, .35);
  background: #e0443a;
  color: #fff;
  font: .75em/1.5 "Changa One", sans-serif;
  white-space: nowrap;
  pointer-events: none;
}

.home-badge[hidden] {
  display: none;
}

/* A developer who switched online play on (?online=1, see linotte.js) sees
   ONLINE and FRIEND without their SOON badge. */
.online-enabled #home-online-btn .soon-badge,
.online-enabled #home-friend-btn .soon-badge {
  display: none;
}

/* With accounts switched on (public/shared/accounts.js) the profile button
   signs in for real. */
.accounts-enabled #home-profile .soon-badge {
  display: none;
}

/* A signed-in player's own photo (Google/Apple), cropped like the buddy. */
.home-avatar {
  overflow: hidden;
}

.home-avatar > img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-avatar.has-photo {
  background: rgb(228, 209, 187);
}

.home-avatar.has-photo > img {
  display: block;
}

/* The badge by the name: the account's online wins. Gold with a star for
   Pro players (their opponents see it too), plain for the others (only the
   player sees it). See showHomeBadge in linotte.js. */
.win-badge {
  flex: none;
  font-size: 1.05em;
}

.win-badge[hidden] {
  display: none;
}

/* The name on its own line (a long one gets "…"); the badge starts the line
   under it (.home-psub). */
.home-pname {
  display: flex;
  align-items: center;
  min-width: 0;
}

#home-pname {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The ✕ on "Continue your game": ends the paused game (after asking). Sits
   on the card's top-right corner, half outside it. */
.home-continue {
  position: relative;
}

.home-continue-end {
  position: absolute;
  top: -.55em;
  right: -.55em;
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  border-radius: 50%;
  border: var(--btn-border);
  background: rgb(240, 232, 222) center / 55% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' stroke='%233d240c' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M2 2l6 6M8 2L2 8'/%3E%3C/svg%3E");
  cursor: pointer;
}

/* A bigger area to tap than the drawn circle. */
.home-continue-end::before {
  content: "";
  position: absolute;
  inset: -.5em;
}

/* "Continue your game": PLAY on the left, away from the ✕ on the right. */
.home-continue {
  grid-template-columns: auto minmax(0, 1fr);
}

.home-continue .home-continue-btn {
  order: -1;
}

/* The player's country: its flag before "Signed in". */
/* The country's flag, before the name (the first row); the second row is the level and the points. */
.home-flag {
  flex: none;
  margin-right: .3em;
  font-size: .9em;
}

.home-flag[hidden] {
  display: none;
}

/* The options icon is on the left, as in games: first in the top row. */
.home-top .home-settings {
  order: -1;
}

/* Today's first online game is worth a bonus: ONLINE wears a gold "+2" with a
   little gift box (drawn, like the tags' padlock) until it's won (see
   showHomeBadge in linotte.js). */
body.daily-open #home-online-btn::after {
  content: "+2";
  position: absolute;
  top: -.6em;
  right: -.4em;
  z-index: 1;
  padding: 0 .45em 0 1.7em;
  border-radius: .7em;
  border: 1.5px solid rgba(0, 0, 0, .35);
  background: rgb(232, 185, 35) .32em 45% / 1.2em no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%235f4604'%3E%3Crect x='3' y='9' width='18' height='4.5' rx='1'/%3E%3Crect x='4.5' y='14.5' width='15' height='7' rx='1.2'/%3E%3C/g%3E%3Cpath d='M12 9v12.5' stroke='%23f2c84a' stroke-width='2.2'/%3E%3Cpath d='M12 8.6C10.6 5.4 7.4 4.6 6.6 6.3 5.8 8 9 8.8 12 8.6zM12 8.6c1.4-3.2 4.6-4 5.4-2.3.8 1.7-2.4 2.5-5.4 2.3z' fill='none' stroke='%235f4604' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E");
  color: #5f4604;
  font: .75em/1.5 "Changa One", sans-serif;
  white-space: nowrap;
  pointer-events: none;
}
