/* The comic book page around the game. */

body {
  margin: 0;
  padding-bottom: 30px;
  color: #111;
  font-family: system-ui, sans-serif;
  text-align: center;
  /* Black paper with halftone dots: a small light gray dot every 14 pixels. */
  background-color: #111;
  background-image: radial-gradient(circle, #6e6e6e 1.8px, transparent 2.2px);
  background-size: 14px 14px;
}

/* The title: red comic letters with a black outline and a hard yellow shadow. */
h1 {
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-weight: normal;
  font-size: 72px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #ff3b3b;
  -webkit-text-stroke: 3px #111;
  paint-order: stroke fill;               /* the outline goes behind the letters */
  text-shadow: 5px 5px 0 #ffe14d;
  margin: 18px 0 14px;
  transform: rotate(-2deg);               /* a little crooked, like a comic cover */
}

/* The comic page: 3 columns. The middle one (the game) is 4 times as wide. */
.comic-page {
  display: grid;
  grid-template-columns: 1.2fr 4fr 1.2fr;
  gap: 34px;
  align-items: start;
  max-width: 1700px;
  margin: 0 auto;
  padding: 0 30px;
}

/* Every panel: black ink border, a white frame, a hard yellow shadow. */
canvas {
  display: block;
  width: 100%;          /* fill its column; the height follows (16 : 9) */
  background: #a8e0ff;
  border: 4px solid #111;
  box-shadow: 0 0 0 4px #f5f5f5, 10px 10px 0 4px #ffe14d;
  box-sizing: border-box;
}

/* The game panel. */
#game {
  cursor: crosshair;
  touch-action: none;   /* on a phone, dragging aims instead of scrolling */
}

/* The small panels sit a bit lower and crooked, like a real comic page. */
.side-panel {
  margin-top: 40px;
}
#last-panel { transform: rotate(-2deg); }
#next-panel { transform: rotate(2deg); }

/* A small screen (a phone): no side panels, the game uses the whole width. */
@media (max-width: 900px) {
  .comic-page { grid-template-columns: 1fr; padding: 0 12px; }
  .side-panel { display: none; }
}

/* ---------- Phones and tablets ---------- */
/* (pointer: coarse) = the main input is a finger, not a mouse. */

/* Hidden, except on a phone held upright (see below). */
#turn-phone { display: none; }

#game {
  -webkit-user-select: none;      /* a long press does not select or open a menu */
  user-select: none;
  -webkit-touch-callout: none;
}

/* A phone held upright: hide the game and ask to turn the phone. */
/* ("body > p" and not just "p": the p rule further down must not win.) */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 700px) {
  .comic-page, body > p { display: none; }
  h1 { font-size: 46px; -webkit-text-stroke: 2px #111; text-shadow: 3px 3px 0 #ffe14d; }
  #turn-phone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    margin: 40px 20px;
  }
  /* The phone drawing turns sideways, waits, and turns back. */
  #turn-phone .phone {
    transform-origin: 60px 60px;
    animation: turn-phone 2.4s ease-in-out infinite;
  }
  .turn-words {
    font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
    font-size: 34px;
    color: #ffe14d;
    -webkit-text-stroke: 2px #111;
    paint-order: stroke fill;
    text-shadow: 4px 4px 0 #ff3b3b;
    transform: rotate(-3deg);
  }
  .turn-small {
    background: #fff;
    border: 3px solid #111;
    box-shadow: 5px 5px 0 #ffe14d;
    padding: 6px 14px;
    font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
    font-size: 20px;
    text-transform: uppercase;
  }
}
@keyframes turn-phone {
  0%, 20%   { transform: rotate(0deg); }
  50%, 80%  { transform: rotate(-90deg); }
  100%      { transform: rotate(0deg); }
}

/* A phone held sideways: the screen is low, so only the game, as big as it fits.
   16 / 9 = the shape of the game (960 x 540). dvh = the height you really see
   (without the browser bars); old browsers use vh. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  body { padding-bottom: 0; overflow: hidden; }
  h1, body > p, .side-panel { display: none; }
  .comic-page { display: block; padding: 0; }
  #game {
    width: min(calc(100vw - 16px), calc((100vh - 16px) * 16 / 9));
    width: min(calc(100vw - 16px), calc((100dvh - 16px) * 16 / 9));
    margin: 8px auto 0;
    border-width: 3px;
    box-shadow: none;
  }
}

/* The help text: a white caption box. */
p {
  display: inline-block;
  margin-top: 26px;
  padding: 8px 16px;
  background: #fff;
  border: 3px solid #111;
  box-shadow: 5px 5px 0 #ffe14d;
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-size: 20px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
