/*
 * ============================================================================
 *  GOOGLE ADSENSE - STYLES
 * ============================================================================
 *
 *  The ads live in a frame around the app:
 *
 *      +------------------------------------------+
 *      |            top (a band)                 |
 *      +------------------------------------------+
 *      |                 the app                  |  rail
 *      |                                          | (right)
 *      +------------------------------------------+
 *      |            below (a band)                |
 *      +------------------------------------------+
 *
 *  On a phone the only ad is the anchor: a bar at the bottom that goes
 *  from edge to edge. On a computer the anchor is not used at all; the
 *  band at the top, the band at the bottom and the rail on the right are
 *  shown instead.
 *
 *  The frame is measured at run time and written to three custom
 *  properties on <html>: --tsite-top, --tsite-right and --tsite-bottom.
 *  The app's own box is inset by those amounts, so no ad ever covers the
 *  canvas, the sheet, a toolbar or a Save / Export button.
 *
 * ============================================================================
 */

/* --------------------------------------------------------------- shared */

:root {
  --tsite-top: 0px;
  --tsite-right: 0px;
  --tsite-bottom: 0px;

  --tsite-ad-page-bg: #0b0b11;
  --tsite-ad-bg: #1e1e2a;
  --tsite-ad-line: #4a4a5e;
  --tsite-ad-ink: #e8e8f0;
  --tsite-ad-muted: #a8a8bb;
}

.tsite-ad {
  display: block;
  position: relative;
  box-sizing: border-box;
  max-width: 100%;
}

.tsite-ad-label {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  font: 500 10px/1.2 system-ui, -apple-system, 'Segoe UI', sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tsite-ad-muted, #8b8b98);
  pointer-events: none;
  z-index: 1;
}

.tsite-ad--demo {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  border: 1px dashed var(--tsite-ad-line, #4a4a5e);
  border-radius: 8px;
  background: var(--tsite-ad-bg, #1e1e2a);
  color: var(--tsite-ad-muted, #a8a8bb);
  font: 600 13px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
  text-align: center;
  padding: 14px 10px;
}

.tsite-ad--demo .tsite-ad-filler {
  opacity: 0.85;
}

.tsite-ad--live {
  overflow: hidden;
}

/* --------------------------------------------------- the frame itself */

/*
 * The ads take a strip out of the window: a band at the top, a column on
 * the right, a band at the bottom. The app's own box is given what is
 * left, so the canvas, the sheet and the toolbars are drawn inside the
 * space that is left. Nothing is ever covered.
 *
 * The insets come from three custom properties that ads-loader.js
 * measures and writes onto <html>.
 */

/* The page itself gives up the column on the right, so a layout that
   follows the flow is made narrower. */
.tsite-ads-frame body,
.tsite-ads-landing body {
  padding-right: var(--tsite-right, 0px) !important;
}

/* The app's own root, when it sits in the flow. */
.tsite-ads-frame body > #app {
  height: calc(100vh - var(--tsite-top, 0px) - var(--tsite-bottom, 0px)) !important;
  max-height: calc(100vh - var(--tsite-top, 0px) - var(--tsite-bottom, 0px)) !important;
  min-height: 0 !important;
  margin-top: var(--tsite-top, 0px) !important;
}

/* An app whose root is a fixed box is inset from the edges instead. */
.tsite-ads-frame body > #app.tsite-ads-fixed {
  top: var(--tsite-top, 0px) !important;
  right: var(--tsite-right, 0px) !important;
  bottom: var(--tsite-bottom, 0px) !important;
  left: 0 !important;
  width: auto !important;
  height: auto !important;
}

/*
 * Any other fixed box that fills the window is inset the same way.
 */
.tsite-ads-fixed {
  top: var(--tsite-top, 0px) !important;
  right: var(--tsite-right, 0px) !important;
  bottom: var(--tsite-bottom, 0px) !important;
  left: 0 !important;
  width: auto !important;
  height: auto !important;
  max-width: none !important;
  max-height: none !important;
}

/*
 * A fixed box that fills the window in the other direction: it stands
 * against the left-hand edge of the window and its width is its own.
 *
 * The width is left exactly as the app drew it, so a sidebar that fills
 * the height of the window (the whiteboard has one) does not grow to the
 * width of the whole window and push its own logo apart. The right-hand
 * edge only gets a limit, so the box can never run into the ad rail.
 */
.tsite-ads-fixed-tall {
  top: var(--tsite-top, 0px) !important;
  bottom: var(--tsite-bottom, 0px) !important;
  max-width: calc(100% - var(--tsite-right, 0px)) !important;
  max-height: none !important;
}

/*
 * A fixed box that fills the width of the window: a bar at the top, for
 * example. It gives up the height the bands take.
 */
.tsite-ads-fixed-wide {
  top: var(--tsite-top, 0px) !important;
  right: var(--tsite-right, 0px) !important;
  left: 0 !important;
  max-width: none !important;
  max-height: none !important;
}

/* A canvas that is fixed to the window (3d has one) is given the size of
   the frame, so the scene is drawn in the space that is left. */
.tsite-ads-frame body > canvas {
  top: var(--tsite-top, 0px) !important;
  right: var(--tsite-right, 0px) !important;
  bottom: var(--tsite-bottom, 0px) !important;
  left: 0 !important;
  width: calc(100% - var(--tsite-right, 0px)) !important;
  height: calc(100% - var(--tsite-top, 0px) - var(--tsite-bottom, 0px)) !important;
}

/* A box inside the app that fills the height: it gives up the space the
   ads take. */
.tsite-ads-inner {
  height: calc(100vh - var(--tsite-top, 0px) - var(--tsite-bottom, 0px)) !important;
  max-height: none !important;
  min-height: 0 !important;
}

/* A box that is wider than the space the ads leave: it is given the room
   that is left. The width the rail takes is already gone from the body,
   so this must not be taken off a second time. */
.tsite-ads-narrow {
  max-width: 100% !important;
  margin-right: 0 !important;
}

/* ---------------------------------------------------------- top banner */

/*
 * A band across the top of the window. The app's own header stays in
 * reach: the frame gives up the height the band takes, so the app is
 * drawn in the space that is left.
 */
.tsite-ad-slot--top {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  left: 0;
  right: var(--tsite-right, 0px);
  top: 0;
  width: auto;
  padding: 6px 12px;
  background: var(--tsite-ad-page-bg, #0b0b11);
  border-bottom: 1px solid var(--tsite-ad-line, #26262f);
  box-sizing: border-box;
  z-index: 5;
}

.tsite-ad-slot--top .tsite-ad {
  width: 100%;
  max-width: 970px;
  min-height: 58px !important;
}

/*
 * The landing page has its own navigation at the top, and no band above
 * it, so the page is not given any room at the top.
 */
.tsite-ads-landing body {
  padding-top: 0 !important;
}

/* ------------------------------------------------------------ the rail */

/*
 * A fixed column on the right of the window.
 *
 * It runs the whole height of the window: the column is the ad, from the
 * top of the screen to the bottom, with no white part above it and none
 * below it.
 */
.tsite-ad-rail {
  display: none;
}

@media (min-width: 1024px) {
  .tsite-ad-rail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    height: 100vh;
    padding: 12px;
    box-sizing: border-box;
    overflow-y: auto;
    background: var(--tsite-ad-page-bg, #0b0b11);
    border-left: 1px solid var(--tsite-ad-line, #26262f);
    z-index: 5;
  }

  /*
   * The ads in the column grow into the space there is, so the column is
   * filled from the top of the screen to the bottom. A tall, narrow ad is
   * what a rail of this shape is for.
   */
  .tsite-ad-slot--rail {
    display: flex;
    flex: 1 1 0;
    min-height: 250px;
  }

  .tsite-ad-slot--rail .tsite-ad {
    width: 100%;
    height: 100%;
    min-height: 250px;
  }
}

/* The rail already runs the whole height of the window on every page. */
.tsite-ads-landing .tsite-ad-rail {
  top: 0;
  height: 100vh;
  padding-top: 12px;
}

/* ------------------------------------------------------ under the editor */

/*
 * A band at the bottom of the window. The app gives up the height it
 * takes, so it never sits on top of the work.
 */
.tsite-ad-slot--below {
  display: flex;
  justify-content: center;
  position: fixed;
  left: 0;
  right: var(--tsite-right, 0px);
  bottom: 0;
  width: auto;
  padding: 10px 12px 12px;
  background: var(--tsite-ad-page-bg, #0b0b11);
  border-top: 1px solid var(--tsite-ad-line, #26262f);
  box-sizing: border-box;
  z-index: 5;
}

.tsite-ad-slot--below .tsite-ad {
  width: 100%;
  max-width: 970px;
}

/* ----------------------------------------------------------- the anchor */

/*
 * A bar at the bottom of the screen. It goes from edge to edge, so the
 * ad is as wide as the phone. It is short, so it never covers the work.
 */
.tsite-ad-slot--anchor {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  /* 100vw, not the width of the page: the bar goes under the scroll bar
     as well, so it really is the full width of the screen. */
  width: 100vw;
  max-width: 100vw;
  /* The padding is inside the bar, so the bar is not wider than the
     screen it is on. */
  box-sizing: border-box;
  padding: 4px 8px 8px;
  background: var(--tsite-ad-page-bg, #0b0b11);
  border-top: 1px solid var(--tsite-ad-line, #26262f);
  z-index: 6;
  pointer-events: none;
}

.tsite-ad-slot--anchor > * {
  pointer-events: auto;
}

.tsite-ad-slot--anchor .tsite-ad {
  width: 100%;
  max-width: none;
  min-height: 50px !important;
}

.tsite-ad-slot--anchor .tsite-ad--demo {
  min-height: 50px;
  padding: 6px 10px;
}

/*
 * The anchor is the ad of a phone. On a computer the band at the top,
 * the band at the bottom and the rail are used instead.
 */
@media (min-width: 1024px) {
  .tsite-ad-slot--anchor {
    display: none;
  }
}

/* --------------------------------------------------------------- mobile */

@media (max-width: 1023px) {
  .tsite-ad-slot--top,
  .tsite-ad-slot--below {
    display: none;
  }

  /* On a phone the rail is never shown: there is no room for it and it
     would push the work off the screen. */
  .tsite-ad-rail {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .tsite-ad-slot--anchor {
    padding: 4px 6px 6px;
  }

  .tsite-ad-slot--anchor .tsite-ad--demo {
    min-height: 44px;
    font-size: 11px;
  }
}

/* --------------------------------------------------- the app switcher */

/*
 * The switcher button floats in the corner of the window, so the ads
 * have to make room for it: it is moved above the anchor on a phone and
 * beside the rail on a computer. A button under an ad is a button nobody
 * can press.
 *
 * The button that sits in the header of the page is not floating, so the
 * ads do not have to make room for it.
 */
.tsite-ads-frame .tsite-menu-btn:not(.tsite-tool),
.tsite-ads-landing .tsite-menu-btn:not(.tsite-tool) {
  right: calc(var(--tsite-right, 0px) + 18px) !important;
  bottom: calc(var(--tsite-bottom, 0px) + 18px) !important;
}

@media (max-width: 520px) {
  .tsite-ads-frame .tsite-menu-btn:not(.tsite-tool),
  .tsite-ads-landing .tsite-menu-btn:not(.tsite-tool) {
    right: calc(var(--tsite-right, 0px) + 12px) !important;
    bottom: calc(var(--tsite-bottom, 0px) + 12px) !important;
  }
}

/* --------------------------------------------------- light theme colours */

html[data-theme='light'],
body.light {
  --tsite-ad-page-bg: #ffffff;
  --tsite-ad-bg: #f4f4f7;
  --tsite-ad-line: #d9d9e2;
  --tsite-ad-ink: #1b1b22;
  --tsite-ad-muted: #6b6b78;
}
