:root {
  /* Catalogs, game entrances and accounts share a frame. Guides use a shorter line length. */
  --page-content-width: 72rem;
  --reading-width: 44rem;
  --page-gutter: 1rem;
  --icon-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.64 7.584H.47l8.6-9.835L0 1.154h7.594l5.243 6.932 6.064-6.933zm-1.29 19.49h2.039L6.495 3.24H4.307l13.304 17.403z'/%3E%3C/svg%3E");
  --page-shell-width: min(var(--page-content-width), calc(100% - 2 * var(--page-gutter)));
}
@media (max-width: 720px) {
  :root { --page-gutter: .75rem; }
}
:root:has(.masthead, .play-guide) { scrollbar-gutter: stable; }
.game-entry-summary { width:min(var(--reading-width), var(--page-shell-width)); margin:clamp(2rem, 8vh, 5rem) auto; line-height:1.7; }
.game-entry-summary a { color:inherit; }
.game-layout {
  display: grid;
  min-height: 100dvh;
  --banner-height: calc(59px + env(safe-area-inset-bottom));
  padding-bottom: var(--banner-height);
  grid-template: "header" auto "game" 1fr "credit" auto / minmax(0, 1fr);
}
.site-credit {
  grid-area: credit; display: flex; justify-content: center; align-items: center; gap: .35em;
  padding-inline: 8px;
}
.site-credit, .drawer-credit { color: var(--credit-color); font: 500 16px/1.4 system-ui, sans-serif; }
footer:is(.site-credit, .drawer-credit) > a {
  display: inline-flex; align-items: center; vertical-align: middle; gap: 6px;
  min-height: 44px; padding-inline: 6px; border-radius: 6px;
  color: inherit; font-weight: 650; text-decoration: none;
}
footer:is(.site-credit, .drawer-credit) > a::before {
  content: ''; flex: none; width: 1em; height: 1em; background: currentColor;
  mask: var(--icon-x) center / contain no-repeat;
}
footer:is(.site-credit, .drawer-credit) > a:is(:hover, :focus-visible) {
  background: color-mix(in srgb, currentColor 10%, transparent); text-decoration: none;
}
/* Keep room for the 600px desktop ad beside the drawing canvas on short screens. */
@media (min-width: 1001px) and (min-height: 720px) and (max-height: 760px) {
  .with-canvas-ad > .site-credit > a { min-height: 24px; }
}
.game-layout > header { grid-area: header; }
.page-loading { display: grid; min-height: min(60dvh,28rem); place-items: center; }
.page-loading > p, .room-connection-notice { animation: show-load-status 0s .5s backwards; }
@keyframes show-load-status { from { opacity: 0; } to { opacity: 1; } }
.game-layout:has(.page-loading) > .site-credit { visibility: hidden; }
.room-connection-notice {
  position: fixed; z-index: 5; inset-inline-start: 50%; transform: translateX(-50%);
  bottom: calc(var(--banner-height, 0px) + 8px); padding: 4px 12px; border-radius: 8px;
  font-size: 14px; color: white; background: #302e38; white-space: nowrap; pointer-events: none;
}
.game-viewport {
  grid-area: game;
  min-width: 0;
  min-height: 0;
}
.game-ad {
  position: fixed; inset: auto 0 0; z-index: 3; height: var(--banner-height);
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
}
.game-ad { pointer-events:none; }
.game-ad, .ad-frame { background: transparent; }
/* Keep the page visible behind the empty ad frame, including on dark game pages.
   Chromium paints a contrasting canvas for an iframe with a mismatched color scheme. */
ins.adsbygoogle iframe { color-scheme: only light; }
ins.adsbygoogle:not([data-ad-status]),
ins.adsbygoogle:not([data-ad-status]) > :is(ins, div),
ins.adsbygoogle:not([data-ad-status]) iframe { background-color: transparent !important; }
.pico-desktop-unit { display:none; pointer-events:auto; }
ins.adsbygoogle[data-ad-status="unfilled"] { display:none !important; }
@media (max-width: 1000px) {
  .ad-frame > .pico-desktop-unit { display:none !important; }
}
.ad-frame {
  width: min(320px, 100%);
  height: 50px;
  display: grid;
  place-content: center;
}
/* The wide drawing studio sizes its working area to the available screen. */
@media (min-width: 850px), (min-width: 700px) and (max-height: 550px) {
  .with-canvas-ad { height: 100dvh; }
}
@media (pointer: coarse) and (orientation: landscape) and (min-width: 700px) and (max-width: 1000px) and (max-height: 550px) {
  /* Let the page scroll past the canvas instead of shrinking the paper between both toolbars and the ad. */
  .with-canvas-ad { min-height: calc(72svh + 12rem + var(--banner-height)); }
}
/* AdSense's mobile anchor is configured for viewports up to 1000px wide. */
@media (min-width: 1001px) {
  .game-layout {
    --ad-width: 300px;
    --ad-height: 600px;
    --page-width: calc(var(--page-content-width) + 2 * var(--page-gutter));
    --ad-rail: max(316px, calc((100% - var(--page-width)) / 2));
    /* Center the page when its side margins can accommodate a desktop ad. */
    --right-gutter: clamp(0px, calc(100% - var(--ad-rail) - var(--page-width)), var(--ad-rail));
    padding-bottom: 0;
    grid-template: "header header header" auto "ad game ." 1fr "ad credit ." auto
      / var(--ad-rail) minmax(0, 1fr) var(--right-gutter);
  }
  .game-layout > .page-header { display: grid; grid-template-columns: subgrid; column-gap: 0; }
  .page-header > :first-child { grid-column: 2; min-width: 0; }
  .game-ad {
    grid-area: ad; position: sticky; inset: auto; top: max(0px, calc(50dvh - var(--ad-height) / 2 - 8px));
    height: auto; align-self: start; justify-self: end; padding: 8px; z-index: auto;
  }
  .ad-frame { width: var(--ad-width); height: var(--ad-height); }
  .pico-desktop-unit { display:inline-block; width:var(--ad-width); height:var(--ad-height); }
  .with-canvas-ad { grid-template: "header" auto "game" minmax(0, 1fr) "credit" auto / minmax(0, 1fr); }
  .game-layout.with-canvas-ad .studio {
    --ad-column: calc(var(--ad-width) + 24px);
    grid-template-rows: auto minmax(var(--ad-height), 1fr);
  }
  .game-layout.with-canvas-ad .studio.phase-draw { grid-template-rows: minmax(0,1fr); }
  .with-canvas-ad .studio .boards > .drawing-editor {
    grid-template: "settings stage sponsor" minmax(var(--ad-height),1fr) "settings caption caption" auto
      / var(--sidebar) minmax(0,1fr) var(--ad-column);
  }
  .with-canvas-ad .studio.phase-draw .boards > .drawing-editor {
    grid-template: "settings bar bar" auto "settings stage sponsor" minmax(var(--ad-height),1fr) "settings caption caption" auto
      / var(--sidebar) minmax(0,1fr) var(--ad-column);
  }
  .with-canvas-ad .studio .drawing-replay {
    container: replay-workspace / size;
    grid-template: "stage sponsor" minmax(0,1fr) "caption caption" auto "playback playback" auto
      / minmax(0,1fr) var(--ad-column);
  }
  /* Reserve room for the expanded playback controls and result actions.
     Size the ad from the whole replay so starting playback does not resize it. */
  @container replay-workspace (height < 800px) {
    .game-ad { --ad-height: 250px; }
  }
  .with-canvas-ad .studio .paper-stage { grid-column: stage-start / -1; padding: 12px; }
  .with-canvas-ad .studio .paper {
    --ad-gutter: calc(var(--ad-width) + 12px);
    --paper-width: min(var(--paper-limit),133.33333cqh, calc(100cqw - var(--ad-gutter)));
    width: var(--paper-width);
    justify-self: start;
    /* Keep the paper centered until its right edge would meet the ad. */
    margin-inline-start: min(calc((100cqw - var(--paper-width)) / 2), calc(100cqw - var(--paper-width) - var(--ad-gutter)));
  }
  html:has(script[src="/lobby/display-ads.js"][data-slot]) .with-canvas-ad .studio .paper { --ad-gutter:calc(var(--ad-width) + 150px); }
  .with-canvas-ad .game-ad {
    position: relative; inset: auto; z-index: auto; grid-area: sponsor;
    align-self: safe center; justify-self: center;
    width: var(--ad-width); height: var(--ad-height); padding: 0;
    border: 0; background: transparent;
  }
}
@media (min-width: 1001px) and (max-height: 719px) {
  .game-layout { --ad-height: 250px; }
}
@media (min-width: 1001px) and (pointer: coarse) {
  .game-layout:not(.with-canvas-ad) > .game-ad { position:static; }
}
@media (min-width: 1001px) and (min-height: 720px) and (max-height: 749px) {
  /* Keep the entire 600px ad above the editor's status bar on short desktops. */
  .with-canvas-ad:has(.drawing-editor) .game-header[data-workspace] .game-bar { min-height: 48px; }
  .with-canvas-ad .drawing-editor > figcaption { padding-block: 2px; }
  .with-canvas-ad .drawing-editor > .site-credit > a { min-height: 26px; }
}
