/*
 * Shared game chrome for all Daily Games.
 *
 * Contract:
 *   .game-page-header  brand + site navigation only
 *   .game-action-set   contextual help and hint actions
 *   .toolbar/.hud/.game-toolbar  play actions, progress and timer
 *   .status/.hintmsg/.hint-msg   board feedback
 *   .hint-toast/.game-notice     transient actionable feedback
 */

.game-page-header {
  display: grid !important;
  box-sizing: border-box;
  max-width: 100% !important;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center !important;
  column-gap: 10px !important;
  row-gap: 10px !important;
  margin-bottom: 8px !important;
}

.game-page-header.game-header-compact {
  margin-bottom: 4px !important;
  padding-bottom: 0 !important;
}

/* The component-based older games put a flex gap between every root child.
 * Offset that gap here so their visible header-to-board spacing is still 4px. */
.sc-root > .game-page-header.game-header-compact {
  margin-bottom: calc(4px - clamp(10px, 2.4vw, 16px)) !important;
}

.tw-root > .game-page-header.game-header-compact {
  margin-bottom: calc(4px - clamp(9px, 2.1vw, 14px)) !important;
}

.game-page-header .header-tools,
.game-page-header .header-controls,
.game-page-header .sc-header-tools,
.game-page-header div.hdr-actions {
  display: contents !important;
}

.game-page-header > .brand,
.game-page-header > .sc-brand,
.game-page-header > :first-child:not(.header-tools):not(.header-controls):not(.sc-header-tools) {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}

.game-page-header .site-nav-shell,
.game-page-header .sc-site-shell,
.game-page-header > nav,
.game-page-header .header-tools > nav,
.game-page-header .header-controls > nav,
.game-page-header .sc-header-tools > nav {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.game-page-header .nav-toggle,
.game-page-header .site-menu-toggle,
.game-page-header .site-nav-toggle,
.game-page-header .sc-nav-toggle {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.game-action-set {
  grid-column: 1 / -1;
  grid-row: 2;
  position: static !important;
  z-index: 12;
  width: max-content !important;
  max-width: 100%;
  min-height: 0;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 6px !important;
  justify-self: start;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.game-action-set::before {
  content: none;
}

.game-action-set > button {
  width: auto !important;
  min-width: 0 !important;
  min-height: 38px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  padding: 0 12px !important;
  border-radius: 9px !important;
  box-shadow: none !important;
}

.game-action-set > button::after {
  content: attr(aria-label);
  font: 650 12px/1.1 system-ui, -apple-system, sans-serif;
  letter-spacing: .01em;
  white-space: nowrap;
}

.game-action-set > button svg {
  width: 17px !important;
  height: 17px !important;
  flex: 0 0 auto;
}

.toolbar,
.hud,
.game-toolbar {
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: none !important;
  min-height: 54px !important;
  margin: 10px 0 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  flex-wrap: wrap !important;
  gap: 7px !important;
  padding: 6px !important;
  border: 1px solid var(--line, var(--line-strong, #d9dee8)) !important;
  border-radius: 13px !important;
  background: var(--panel, var(--surface, #fff)) !important;
  box-shadow: none !important;
  overflow-anchor: none;
}

.hud {
  max-width: 520px !important;
}

.game-toolbar {
  width: min(94vw, 440px) !important;
  max-width: 440px !important;
}

.toolbar button,
.hud button,
.game-toolbar > button {
  min-height: 40px !important;
  border-radius: 9px !important;
  box-shadow: none !important;
  white-space: nowrap;
}

.toolbar #timer,
.hud #timer,
.game-toolbar > :last-child {
  margin-left: auto !important;
}

.game-toolbar-prioritize-timer > button {
  order: 1;
}

.game-toolbar-prioritize-timer > #timer {
  order: 2;
  margin-left: auto !important;
}

.game-toolbar-prioritize-timer > :not(button):not(#timer),
.game-toolbar-prioritize-timer > #btn-preview {
  order: 3;
}

.status,
.hintmsg,
.hint-msg {
  box-sizing: border-box;
  width: 100%;
  margin: 8px 0 0 !important;
  padding: 9px 11px !important;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--panel-2, var(--surface-2, rgba(120, 130, 150, .08)));
  text-align: left;
}

.hintmsg:empty,
.hint-msg:empty {
  display: none;
}

.hint-toast,
.game-notice {
  position: fixed !important;
  inset: auto max(8px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left)) !important;
  transform: none !important;
  z-index: 80 !important;
  width: min(420px, calc(100vw - 16px)) !important;
  max-width: none !important;
  margin: 0 auto !important;
  border-radius: 14px !important;
  box-shadow: 0 18px 48px rgba(20, 30, 50, .22) !important;
}

.modal,
.overlay,
.game-dialog {
  overscroll-behavior: contain;
}

.modal .card,
.overlay .card,
.game-dialog-card {
  box-sizing: border-box !important;
  width: min(400px, calc(100vw - 36px)) !important;
  max-width: none !important;
  max-height: min(86dvh, 680px) !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}

.modal .help-card,
.overlay .help-card,
.game-dialog-card:not(.game-dialog-win) {
  width: min(400px, calc(100vw - 36px)) !important;
  max-width: none !important;
}

.modal .win-card,
.overlay .win-card,
.game-dialog-win {
  width: min(330px, calc(100vw - 40px)) !important;
  max-width: none !important;
}

.help-card img,
.win-card img,
.help-card figure,
.win-card figure,
.help-card :is(svg.diagram, svg.legend),
.win-card :is(svg.diagram, svg.legend),
.game-dialog-card:not(.game-dialog-win) img,
.game-dialog-card:not(.game-dialog-win) figure,
.game-dialog-card:not(.game-dialog-win) :is(svg.diagram, svg.legend),
.game-dialog-win img,
.game-dialog-win figure,
.game-dialog-win :is(svg.diagram, svg.legend) {
  display: block;
  margin-left: auto !important;
  margin-right: auto !important;
  text-align: center;
}

.help-card > .howto-body > .mini {
  display: grid !important;
  width: max-content;
  margin-left: auto !important;
  margin-right: auto !important;
}

@media (max-width: 520px) {
  .game-page-header {
    width: calc(100vw - 24px) !important;
    row-gap: 8px !important;
  }

  .game-action-set {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .game-action-set::-webkit-scrollbar { display: none; }

  .game-action-set > button {
    min-height: 36px !important;
    padding: 0 10px !important;
  }

  .toolbar,
  .hud,
  .game-toolbar {
    min-height: 52px !important;
    gap: 6px !important;
    padding: 5px !important;
  }

  .toolbar button,
  .hud button,
  .game-toolbar > button {
    min-height: 40px !important;
    padding-inline: 12px !important;
  }
}

@media (max-width: 350px) {
  .game-action-set > button::after { display: none; }
  .game-action-set > button { width: 38px !important; padding: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  .hint-toast,
  .game-notice { animation: none !important; }
}

/*
 * Use Safari's stable small viewport when available. Unlike 100vh, 100svh
 * does not resize as the iPhone browser chrome collapses during a scroll.
 */
@supports (min-height: 100svh) {
  html,
  body,
  .sc-root,
  .tw-root {
    min-height: 100svh !important;
  }
}
