/* ===== THEME: change colors, fonts, and spacing here ===== */
:root {
  --g-font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --g-font-size: 1rem;
  --g-title-size: clamp(1.4rem, 2.3vw, 1.9rem);
  --g-line-height: 1.5;

  --g-surface: #ffffff;
  --g-text: #182536;
  --g-muted: #526174;
  --g-accent: #174e91;
  --g-border: #c5ced8;
  --g-button-bg: #f4f7fb;
  --g-button-hover: #e5eef9;
  --g-notice-bg: #fff4d9;
  --g-notice-border: #a66b00;
  --g-focus: #174e91;

  --g-space-1: 0.375rem;
  --g-space-2: 0.75rem;
  --g-space-3: 1rem;
  --g-space-4: 1.5rem;
  --g-space-5: 2rem;

  --g-radius: 0.75rem;
  --g-panel-width: 26rem;
  --g-touch-size: 2.75rem;
  --g-shadow: 0 0.5rem 2rem rgb(0 0 0 / 16%);
}

/* ===== LAYOUT: desktop panel over the existing application ===== */
.g-guide,
.g-guide * {
  box-sizing: border-box;
}

.g-guide {
  position: fixed;
  z-index: 20;
  top: var(--g-space-4);
  right: var(--g-space-4);
  width: min(var(--g-panel-width), calc(100% - 3rem));
  max-height: calc(100vh - 3rem);
  max-height: calc(100dvh - 3rem);
  overflow-y: auto;
  padding: var(--g-space-4);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  background: var(--g-surface);
  color: var(--g-text);
  box-shadow: var(--g-shadow);
  font-family: var(--g-font);
  font-size: var(--g-font-size);
  line-height: var(--g-line-height);
  overflow-wrap: anywhere;
}

/* Puzzles sets pointer-events on this ONE wrapper. */
.g-controls {
  pointer-events: auto;
}

/* Children inherit the wrapper's locked or unlocked pointer state. */
.g-controls * {
  pointer-events: inherit;
}

.g-navigation {
  margin-top: var(--g-space-4);
  padding-top: var(--g-space-3);
  border-top: 1px solid var(--g-border);
}

/* ===== SCREENS: Puzzles changes only display during navigation ===== */
.g-screen {
  display: none;
}

.g-start {
  display: block;
}

.g-stage,
.g-label,
.g-source {
  color: var(--g-muted);
  font-size: 0.875rem;
}

.g-stage,
.g-label {
  margin: 0 0 var(--g-space-2);
}

.g-label {
  font-weight: 700;
  letter-spacing: 0.08em;
}

.g-title {
  margin: 0 0 var(--g-space-3);
  font-size: var(--g-title-size);
  line-height: 1.2;
}

.g-description {
  margin: 0 0 var(--g-space-3);
}

.g-source {
  margin: var(--g-space-2) 0 var(--g-space-3);
}

.g-notice {
  padding: var(--g-space-3);
  border-left: 0.25rem solid var(--g-notice-border);
  border-radius: var(--g-radius);
  background: var(--g-notice-bg);
}

.g-message {
  margin: var(--g-space-3) 0 0;
  color: var(--g-muted);
}

.g-message:empty {
  display: none;
}

/* ===== BUTTONS ===== */
.g-choices {
  display: grid;
  gap: var(--g-space-2);
}

.g-button {
  display: flex;
  align-items: center;
  gap: var(--g-space-3);
  width: 100%;
  min-height: var(--g-touch-size);
  padding: var(--g-space-2) var(--g-space-3);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  background: var(--g-button-bg);
  color: var(--g-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* A click on a label/icon must report the BUTTON as target.id. */
.g-controls .g-button * {
  pointer-events: none;
}

.g-button:hover:not(:disabled) {
  background: var(--g-button-hover);
  border-color: var(--g-accent);
}

.g-button:focus-visible {
  outline: 3px solid var(--g-focus);
  outline-offset: 3px;
}

.g-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.g-symbol {
  display: grid;
  place-items: center;
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--g-accent);
  color: var(--g-surface);
  font-weight: 700;
}

.g-button-copy,
.g-hint {
  display: block;
}

.g-hint {
  margin-top: var(--g-space-1);
  color: var(--g-muted);
  font-size: 0.875rem;
}

.g-back-button {
  width: auto;
  min-width: 6rem;
  justify-content: center;
}

/* ===== RESPONSIVE ===== */

/* Tablet: narrower panel leaves more of the model visible. */
@media (max-width: 64rem) {
  .g-guide {
    top: var(--g-space-3);
    right: var(--g-space-3);
    width: min(23rem, calc(100% - 2rem));
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    padding: var(--g-space-3);
  }
}

/* Phone: bottom panel leaves the upper viewport for the model. */
@media (max-width: 40rem) {
  .g-guide {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 55vh;
    max-height: 55dvh;
    padding: var(--g-space-3);
    padding-bottom:
      calc(var(--g-space-3) + env(safe-area-inset-bottom, 0px));
    border-radius: var(--g-radius) var(--g-radius) 0 0;
  }
}

/* Short landscape screens: side panel preserves usable vertical space. */
@media (max-height: 32rem) and (orientation: landscape) {
  .g-guide {
    top: var(--g-space-2);
    right: var(--g-space-2);
    bottom: auto;
    left: auto;
    width: min(23rem, 48vw);
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    border-radius: var(--g-radius);
  }
}
/* ==========================================================
   STARTUP SLICE — append after all existing guide rules.
   Reuses the existing g- theme variables.
   ========================================================== */

/* ===== LAYOUT: mobile first ===== */

/*
 * Two separate rows reserve real space for the menu.
 * The shell passes pointer input through to the model;
 * the menu and guide panel receive their own input.
 */
.g-shell {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--g-space-2);
  padding-top:
    calc(var(--g-space-2) + env(safe-area-inset-top, 0px));
  pointer-events: none;
}

.g-shell,
.g-menu,
.g-menu * {
  box-sizing: border-box;
}

/* Override the earlier fixed-panel positioning within this shell. */
.g-shell > .g-guide {
  position: relative;
  inset: auto;
  z-index: auto;
  align-self: end;
  justify-self: stretch;
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-height: min(55vh, 100%);
  max-height: min(55dvh, 100%);
  margin: 0;
  padding: var(--g-space-3);
  padding-bottom:
    calc(var(--g-space-3) + env(safe-area-inset-bottom, 0px));
  border-radius: var(--g-radius) var(--g-radius) 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
}

/* ===== MENU: outside the aside and its click-handler selector ===== */

.g-menu {
  display: flex;
  align-items: stretch;
  justify-self: center;
  width: max-content;
  max-width: calc(100% - 2 * var(--g-space-2));
  min-width: 0;
  padding: var(--g-space-1);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius);
  background: var(--g-surface);
  color: var(--g-text);
  box-shadow: var(--g-shadow);
  font-family: var(--g-font);
  font-size: var(--g-font-size);
  line-height: var(--g-line-height);
  pointer-events: auto;
}

.g-menu-button {
  flex: 1 1 auto;
  min-width: 0;
  min-height: max(44px, var(--g-touch-size));
  padding: var(--g-space-2);
  border: 0;
  border-radius: var(--g-radius);
  background: transparent;
  color: var(--g-text);
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.g-menu-button + .g-menu-button {
  margin-left: var(--g-space-1);
}

.g-menu-button[aria-current="page"] {
  background: var(--g-accent);
  color: var(--g-surface);
}

.g-menu-button:hover:not(:disabled):not([aria-current="page"]) {
  background: var(--g-button-hover);
}

.g-menu-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.g-menu-button:focus-visible,
.g-guide .g-button:focus-visible {
  outline: 3px solid var(--g-focus);
  outline-offset: 3px;
}

/* ===== STARTUP SCREENS ===== */

.g-progress {
  margin: 0 0 var(--g-space-2);
  color: var(--g-muted);
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Hide every fuel-dependent item until Puzzles selects a fuel. */
.g-guide .g-for-gas,
.g-guide .g-for-prop,
.g-guide .g-for-ng {
  display: none;
}

/* Text spans: show only the active fuel's progress text. */
.g-guide.g-fuel-gas .g-for-gas,
.g-guide.g-fuel-prop .g-for-prop,
.g-guide.g-fuel-ng .g-for-ng {
  display: inline;
}

/* Buttons: preserve the existing flex button layout. */
.g-guide.g-fuel-gas .g-button.g-for-gas,
.g-guide.g-fuel-prop .g-button.g-for-prop,
.g-guide.g-fuel-ng .g-button.g-for-ng {
  display: flex;
}

/* ===== BUTTON HIERARCHY ===== */

.g-guide .g-button {
  min-height: max(44px, var(--g-touch-size));
}

.g-guide .g-button.g-primary {
  justify-content: center;
  margin-top: var(--g-space-4);
  border-color: var(--g-accent);
  background: var(--g-accent);
  color: var(--g-surface);
  font-weight: 700;
  text-align: center;
}

.g-guide .g-button.g-primary:hover:not(:disabled) {
  border-color: var(--g-accent);
  background: var(--g-accent);
  color: var(--g-surface);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Shared navigation remains below, separate from Continue. */
.g-guide .g-navigation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--g-space-2) var(--g-space-3);
}

/* Quiet text-link appearance; retain button semantics and touch size. */
.g-guide .g-button.g-restart {
  display: flex;
  justify-content: center;
  width: auto;
  min-height: max(44px, var(--g-touch-size));
  margin: 0;
  padding: var(--g-space-2);
  border: 1px solid transparent;
  border-radius: var(--g-radius);
  background: transparent;
  box-shadow: none;
  color: var(--g-muted);
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.g-guide .g-button.g-restart:hover:not(:disabled) {
  border-color: transparent;
  background: transparent;
  color: var(--g-accent);
}

/* ===== RESPONSIVE ===== */

/* Tablet and larger: menu above a right-hand panel. */
@media (min-width: 40.01rem) {
  .g-shell {
    gap: var(--g-space-3);
    padding: var(--g-space-3);
    padding-top:
      calc(var(--g-space-3) + env(safe-area-inset-top, 0px));
    padding-bottom:
      calc(var(--g-space-3) + env(safe-area-inset-bottom, 0px));
  }

  .g-shell > .g-guide {
    align-self: start;
    justify-self: end;
    width: min(23rem, 100%);
    max-height: 100%;
    padding: var(--g-space-3);
    border-radius: var(--g-radius);
  }
}

/* Desktop: restore the existing full panel width and roomier spacing. */
@media (min-width: 64.01rem) {
  .g-shell {
    gap: var(--g-space-4);
    padding: var(--g-space-4);
    padding-top:
      calc(var(--g-space-4) + env(safe-area-inset-top, 0px));
    padding-bottom:
      calc(var(--g-space-4) + env(safe-area-inset-bottom, 0px));
  }

  .g-shell > .g-guide {
    width: min(var(--g-panel-width), 100%);
    padding: var(--g-space-4);
  }
}

/*
 * Short landscape displays: use a side panel within the second row.
 * The menu still has its own row, even when labels wrap.
 */
@media (max-height: 32rem) and (orientation: landscape) {
  .g-shell {
    gap: var(--g-space-2);
    padding-right: var(--g-space-2);
    padding-bottom:
      calc(var(--g-space-2) + env(safe-area-inset-bottom, 0px));
    padding-left: var(--g-space-2);
  }

  .g-shell > .g-guide {
    align-self: start;
    justify-self: end;
    width: min(23rem, 48vw);
    max-height: 100%;
    padding: var(--g-space-3);
    border-radius: var(--g-radius);
  }
}

/* Respect reduced motion for this HTML interface. */
@media (prefers-reduced-motion: reduce) {
  .g-shell,
  .g-shell *,
  .g-shell *::before,
  .g-shell *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Current menu tab, set by Puzzles through className (not aria-current). */
.g-menu-button.g-current,
.g-menu-button.g-current:hover:not(:disabled) {
  background: var(--g-accent);
  color: var(--g-surface);
}

/* ===== SHARED STARTUP PROGRESS =====
 * Puzzles supplies the text for numbered Startup screens.
 * Empty text hides the line, including its existing margins.
 */
#g-progress:empty {
  display: none;
}