/* Scale the classic canvas as a unit, keeping the same playfield and collisions. */
body:is(.home-page, .fullscreen-page) {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body:is(.home-page, .fullscreen-page) .top-bar { top: env(safe-area-inset-top); }

.offline #main-frame-error[data-dino-view].interstitial-wrapper {
  min-height: 225px;
  margin: 0;
  padding: 10px 8px;
  border: 1px solid var(--play-panel-line);
  border-radius: 13px;
  background: var(--play-track);
  box-shadow: none;
}

.dino-view-screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
}

[data-dino-view="auto"] .dino-view-screen { touch-action: manipulation; }
/* The old mobile .controller spans 100vw × 100vh and can sit over game buttons.
   Pointer controls now live on the game screen itself. */
[data-dino-view] .controller { display: none; }
[data-dino-view="manual"] .dino-view-screen { touch-action: manipulation; }

.dino-view-track {
  position: absolute;
  inset-inline: 8px;
  top: 35px;
  height: 150px;
}

.offline .dino-view-track .runner-container {
  top: 0;
  left: 0;
  max-width: none;
  transform: scale(var(--dino-view-scale, 1));
  transform-origin: left top;
}

.offline .dino-view-track canvas {
  /* The older global stylesheet caps runner-canvas at 900px.
     Remove that cap so its painted width matches the track and hitboxes. */
  max-width: none;
  image-rendering: pixelated;
}

/* Let the playfield extend through the card's horizontal padding.
   Keep the heading and controls padded, but remove the empty green side strips. */
body.home-page .home-play-panel #main-frame-error[data-dino-view] {
  --dino-card-gutter: clamp(12px, 2.7vw, 26px);
  width: calc(100% + var(--dino-card-gutter) + var(--dino-card-gutter) - 2px);
  max-width: none;
  margin-inline: calc(1px - var(--dino-card-gutter));
}

:is(html.dark, html[data-theme="dark"]) .dino-view-track canvas,
body.inverted [data-dino-view="manual"] .dino-view-track canvas,
body.inverted .dino-view-expanded .dino-view-track canvas {
  filter: invert(1);
}

:is(html.dark, html[data-theme="dark"]) .dino-view-screen {
  --dino-night-track: #0d1613;
}

.dino-play-actions {
  position: absolute;
  z-index: 4;
  bottom: 12px;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 16px);
  transform: translateX(-50%);
}

.dino-play-actions .sendmessage {
  position: static;
  max-width: none;
  transform: none;
}

.dino-play-actions .sendmessage.is-hidden,
[data-dino-view] [hidden],
.dino-view-enter[hidden] {
  display: none;
}

.dino-view-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 46px;
  padding: .45rem .8rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--portal-ink);
  font: inherit;
  font-size: .9rem;
  font-weight: 750;
  line-height: 1.25;
  cursor: pointer;
}

.dino-view-button:hover,
.dino-view-button:active {
  border-color: var(--portal-action);
  color: var(--portal-action);
}

.home-play-panel .dino-view-toolbar {
  margin-block: .6rem 0;
}

.dino-view-options {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: .2rem .75rem;
  margin-inline-start: auto;
}

.home-play-panel .dino-view-options a { margin-inline-start: 0; }

.dino-view-enter {
  min-height: 34px;
  padding: .25rem .65rem;
  border-color: var(--play-panel-line);
  background: #233e31;
  color: #eff8ed;
  font-size: .8rem;
}

.dino-view-enter:hover,
.dino-view-enter:active {
  border-color: var(--play-button);
  color: var(--play-button);
}

.dino-view-enter:focus-visible { outline-color: var(--play-button); }
.fullscreen-page .home-play-panel .dino-view-toolbar { margin-block-start: 0; }
.fullscreen-page .dino-view-enter { margin-block-start: .6rem; }

@media (any-pointer: coarse) {
  .dino-view-enter { min-height: 44px; }
}

.dino-fullscreen-help h2 { margin: 0 0 .65rem; }
.dino-fullscreen-help p { margin: 0 0 .7rem; }
.dino-fullscreen-help a { font-weight: 750; text-underline-offset: 3px; }
.dino-no-script { color: var(--play-panel-muted); }

.dino-round-result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .35rem .85rem;
  width: max-content;
  max-width: 100%;
  color: var(--portal-ink);
}

.dino-round-result strong { font-variant-numeric: tabular-nums; }

html.dino-view-open,
html.dino-view-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

html.dino-view-open .swal2-container { z-index: 6500; }

.offline #main-frame-error[data-dino-view].dino-view-expanded {
  overflow: visible;
}

[data-dino-view].dino-view-expanded .dino-view-screen {
  position: fixed;
  z-index: 4000;
  top: var(--dino-fullscreen-top, 0px);
  left: var(--dino-fullscreen-left, 0px);
  right: auto;
  bottom: auto;
  width: var(--dino-fullscreen-width, 100vw);
  height: var(--dino-fullscreen-height, 100dvh);
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--play-track);
  touch-action: none;
  user-select: none;
}

body.inverted :is([data-dino-view="manual"], .dino-view-expanded) .dino-view-screen {
  background-color: var(--dino-night-track, #202824);
}

/* True edge-to-edge playfield in mobile landscape: the runner canvas,
   not just its background, must occupy the entire viewport width. */
.dino-view-expanded .dino-view-track {
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.offline .dino-view-expanded .runner-container {
  top: 50%;
  left: 50%;
  width: var(--dino-view-width) !important;
  transform: translate(-50%, -50%) scale(var(--dino-view-scale, 1));
  transform-origin: center;
}

.dino-view-expanded .controller { display: none; }

.dino-view-exit,
.dino-view-duck {
  position: absolute;
  z-index: 5;
  right: max(10px, env(safe-area-inset-right));
}

.dino-view-exit { top: max(10px, env(safe-area-inset-top)); }
.dino-view-duck {
  bottom: max(10px, env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Keep the hold-to-duck button outside the moving track on narrow screens. */
@media (any-pointer: coarse) {
  .offline #main-frame-error[data-dino-view="manual"].interstitial-wrapper {
    min-height: 250px;
  }
}
.dino-view-expanded .dino-play-actions { bottom: max(12px, env(safe-area-inset-bottom)); }
body.inverted .dino-view-expanded .dino-round-result { color: #f4f8f5; }

@media (max-width: 450px) {
  .home-play-panel .dino-play-actions .start-game-button { padding-inline: .75rem; }
  .dino-view-options { justify-content: flex-start; }
}

/* On mobile, the TOP of the game jumps and the BOTTOM ducks. */
.dino-touch-split .dino-view-screen {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dino-touch-split .dino-view-duck { display: none !important; }
.dino-touch-zone-hints { display: none; }
.dino-touch-split .dino-touch-zone-hints {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.dino-touch-zone-hint {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid rgba(40, 90, 63, .18);
  border-radius: 100px;
  color: #244433;
  background: rgba(244, 248, 244, .90);
  font: 700 11px/1.2 system-ui, sans-serif;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 5px rgba(0,0,0,.05);
}
.dino-touch-zone-hint-top {
  top: max(8px, env(safe-area-inset-top));
  left: max(9px, env(safe-area-inset-left));
}
.dino-touch-zone-hint-bottom {
  bottom: max(8px, env(safe-area-inset-bottom));
  left: max(9px, env(safe-area-inset-left));
}
.dino-touch-zone-hint small { opacity: .7; font-size: 10px; font-weight: 500; }
.dino-touch-zone-arrow { font-size: 16px; line-height: 1; }
:is(html.dark, html[data-theme="dark"]), body.inverted) .dino-touch-zone-hint {
  background: rgba(29, 46, 37, .9);
  color: #ecf7ed;
  border-color: rgba(231, 255, 231, .2);
}
/* The two hints remain at the two opposite edges in fullscreen mode. */
.dino-view-expanded .dino-touch-zone-hint-top {
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
}
.dino-view-expanded .dino-touch-zone-hint-bottom {
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
}
@media (max-width: 370px) {
  .dino-touch-zone-hint { padding: 4px 6px; font-size: 10px; }
  .dino-touch-zone-hint small { font-size: 9px; }
}

/* v7 — mobile landscape: the fullscreen action must be VISIBLE ON THE GAME,
   not hidden in the toolbar underneath its card. It is the original button
   moved by fullscreen.js, so all existing click/keyboard logic still applies. */
.dino-view-screen > .dino-floating-enter {
  display: inline-flex;
  position: absolute;
  z-index: 8;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  width: auto;
  min-height: 40px;
  max-width: calc(100% - 16px);
  margin: 0;
  background: rgba(35,62,49,.94);
  color: #eff8ed;
  border: 1px solid rgba(208,239,203,.45);
  border-radius: 9px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Explicitly preserve the HTML hidden attribute after moving the button. */
.dino-view-screen > .dino-floating-enter[hidden] { display: none !important; }
@media (orientation: landscape) and (max-height: 550px) and (any-pointer: coarse) {
  .dino-view-screen > .dino-floating-enter {
    top: max(6px, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
    min-height: 40px;
    font-size: 13px;
  }
  .dino-view-expanded .dino-view-exit {
    top: max(6px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    min-height: 40px;
  }
}

/* Short, nonblocking suggestion on phones held vertically. */
.dino-view-screen > .dino-rotate-tip {
  position: absolute; z-index: 10;
  top: calc(max(9px, env(safe-area-inset-top)) + 45px);
  left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 7px;
  border: 1px solid rgba(219,246,221,.48); border-radius: 9px;
  padding: 6px 6px 6px 10px; background: rgba(29,58,42,.95);
  color: white; box-shadow: 0 4px 14px rgba(0,0,0,.18);
  font: 600 12px/1.25 system-ui,sans-serif;
}
.dino-view-screen > .dino-rotate-tip[hidden] { display: none !important; }
.dino-view-screen > .dino-rotate-tip button {
  min-width: 30px; min-height: 30px; border: 0; border-radius: 6px;
  padding: 0; background: transparent; color: white; font: 500 22px/1 system-ui,sans-serif;
  cursor: pointer; touch-action: manipulation;
}
@media (orientation: landscape) { .dino-view-screen > .dino-rotate-tip { display: none !important; } }

/* v9: Never cover HI/score HUD. Actions live at bottom-right BELOW the runner line. */
.dino-view-screen > .dino-floating-enter {
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom));
  right: max(8px, env(safe-area-inset-right));
}
.dino-view-expanded .dino-view-exit {
  top: auto;
  bottom: max(10px, env(safe-area-inset-bottom));
  right: max(10px, env(safe-area-inset-right));
}
@media (orientation: landscape) and (max-height: 550px) and (any-pointer: coarse) {
  .dino-view-screen > .dino-floating-enter {
    top: auto;
    bottom: max(6px, env(safe-area-inset-bottom));
  }
  .dino-view-expanded .dino-view-exit {
    top: auto;
    bottom: max(6px, env(safe-area-inset-bottom));
  }
}
