:root {
  color-scheme: light;
  font-family: Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow: auto;
  background: #777;
}

.hypercard-app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 8px;
}

.hypercard-app.has-stack-menu {
  padding-top: 32px;
}

.hypercard-app.has-control-hint {
  padding-top: var(--game-top-space);
}

.control-hint {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 8px 10px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  font: 13px Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
}

.control-hint[hidden],
.control-hint button[hidden] {
  display: none;
}

.control-hint-copy {
  flex: 1 1 290px;
}

.control-hint p {
  margin: 4px 0 0;
}

.control-hint-keys {
  font-weight: bold;
}

.control-hint-detail {
  font-size: 12px;
}

.control-hint button {
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid #000;
  border-radius: 0;
  color: #fff;
  background: #000;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.control-hint button:focus-visible {
  outline: 2px dashed #000;
  outline-offset: 3px;
}

.control-hint button:disabled {
  cursor: wait;
}

.game-frame {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
}

.card-inventory {
  position: relative;
  z-index: 20;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

.card-inventory[hidden],
.inventory-item[hidden] {
  display: none;
}

.inventory-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 160px;
  min-height: 48px;
  padding: 5px 10px;
  border: 1px solid #000;
  border-radius: 0;
  box-shadow: 2px 2px 0 #444;
  background: #fff;
  color: #000;
  font: 14px Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.inventory-item img {
  width: 32px;
  height: 28px;
  image-rendering: pixelated;
  pointer-events: none;
}

.inventory-name,
.inventory-status {
  display: block;
}

.inventory-status {
  margin-top: 2px;
  font-size: 11px;
}

.inventory-item[aria-pressed="true"] {
  color: #fff;
  background: #000;
  box-shadow: 2px 2px 0 #fff;
}

.inventory-item[aria-pressed="true"] img {
  filter: invert(1);
}

.inventory-item:focus-visible {
  outline: 2px dashed #000;
  outline-offset: 4px;
}

.inventory-item:disabled {
  cursor: wait;
}

.card-viewport {
  position: relative;
  flex: 0 0 auto;
}

.card-stage {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  transform-origin: top left;
  background: #fff;
  color: #000;
  image-rendering: pixelated;
  isolation: isolate;
}

.card-content,
.card-image,
.parts-layer,
.flash-layer {
  position: absolute;
  inset: 0;
}

.card-content {
  z-index: 1;
}

.outgoing-card-snapshot {
  z-index: 0;
  pointer-events: none;
}

.card-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-drag: none;
}

.card-image[hidden] {
  display: none;
}

.parts-layer {
  /* Keep image and transparent fields in the same stacking context so the
     QuickDraw-like difference blend can see the card bitmap underneath. */
  z-index: auto;
}

.parts-layer.show-hotspots .button-style-0 {
  outline: 1px dashed #000;
  outline-offset: -1px;
  background: rgb(255 255 255 / 45%);
}

.part {
  position: absolute;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  color: #000;
  background: transparent;
  font-family: Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
  white-space: pre-wrap;
  user-select: none;
}

button.part {
  appearance: none;
  cursor: default;
  touch-action: manipulation;
}

button.part[aria-disabled="true"] {
  color: #777;
}

.part-label {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  text-align: inherit;
  pointer-events: none;
}

.part-icon {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  pointer-events: none;
}

.part-icon-fallback {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  line-height: 1;
  pointer-events: none;
}

.button-style-0 {
  background: transparent;
}

/* Explicit, stack-scoped substitutes for lost navigation ICON resources.
   Keep the original button rectangle and handler, including small edge arrows. */
.part.navigation-arrow {
  background: #fff;
  color: #000;
  border: 1px solid #000;
}

.navigation-arrow .part-icon-fallback {
  font-family: Arial, sans-serif;
  font-size: 20px;
  font-weight: 700;
  text-shadow: none;
  -webkit-text-stroke: 0;
  -webkit-text-fill-color: currentColor;
}

.button-style-1,
.button-style-2,
.button-style-3,
.button-style-4,
.button-style-8,
.button-style-9,
.button-style-10,
.button-style-11 {
  display: grid;
  place-items: center;
  padding: 1px 4px;
  background: #fff;
  border: 1px solid #000;
  text-align: center;
}

.button-style-1 {
  border: 0;
}

.button-style-3,
.button-style-8,
.button-style-9 {
  border-radius: 8px;
}

.button-style-4 {
  box-shadow: 3px 3px 0 #000;
}

.button-style-8,
.button-style-9 {
  border-width: 2px;
  box-shadow: inset -1px -1px 0 #888, inset 1px 1px 0 #fff;
}

.button-style-10 {
  border-radius: 50%;
}

.button-style-5,
.button-style-6 {
  display: flex;
  align-items: center;
  gap: 4px;
  text-align: left;
}

.button-style-5::before,
.button-style-6::before {
  content: "";
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border: 1px solid #000;
  background: #fff;
}

.button-style-6::before {
  border-radius: 50%;
}

.part.hilite:not(.button-style-0):not(.button-style-5):not(.button-style-6),
.part.auto-highlight:active:not(.button-style-0):not(.button-style-5):not(.button-style-6) {
  color: #fff;
  background: #000;
  box-shadow: none;
}

.part.hilite .part-icon,
.part.auto-highlight:active .part-icon {
  filter: invert(1);
}

/* HyperCard's transparent icon buttons invert their full icon cell. In
   Hypermind this is the white feedback marker; the unhilited form stays the
   original black cross that denotes an exact-position match. */
.button-style-0.has-icon.hilite,
.button-style-0.has-icon.auto-highlight:active {
  background: #000;
}

/* Adventure, Level 2/dm: the right-hand walk hotspot must leave the white
   corridor visibly open, including when its original hilite bit is stored.
   Keep the state and original geometry; do not change other icon buttons. */
.hypercard-app[data-game="adventure"] .part[data-state-key="level-2:card:11197:card:1"] {
  background: #fff;
}

.button-style-5.hilite::before,
.button-style-6.hilite::before {
  background: #000;
  box-shadow: inset 0 0 0 2px #fff;
}

.part.field {
  overflow: hidden;
  padding: 1px 2px;
  line-height: 1.15;
  user-select: text;
}

/* HyperCard draws transparent field text against the card bitmap. Difference
   blending preserves the original black-on-white and white-on-black result. */
.part.field-style-0 {
  color: #fff;
  mix-blend-mode: difference;
}

.part.field[contenteditable="true"] {
  cursor: text;
}

.part.field-style-1,
.part.field-style-2,
.part.field-style-4,
.part.field-style-7 {
  background: #fff;
}

.part.field-style-2,
.part.field-style-4,
.part.field-style-7 {
  border: 1px solid #000;
}

.part.field-style-4 {
  box-shadow: 3px 3px 0 #000;
}

.part.field-style-7 {
  overflow: auto;
}

.flash-layer {
  z-index: 4;
  pointer-events: none;
  background: #fff;
  opacity: 0;
  mix-blend-mode: difference;
}

.flash-layer.flashing {
  animation: hypercard-flash 160ms steps(2, end);
}

@keyframes hypercard-flash {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}

.hypercard-dialog,
.quit-panel {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(255 255 255 / 35%);
}

.hypercard-dialog[hidden],
.quit-panel[hidden] {
  display: none;
}

.dialog-panel,
.quit-panel > * {
  font: 12px Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
}

.dialog-panel,
.quit-panel {
  color: #000;
}

.dialog-panel {
  min-width: min(330px, 92%);
  max-width: 92%;
  padding: 14px;
  border: 2px solid #000;
  border-radius: 7px;
  background: #fff;
  box-shadow: 3px 3px 0 rgb(0 0 0 / 45%);
}

#dialogMessage {
  display: block;
  margin-bottom: 12px;
  white-space: pre-wrap;
  text-align: center;
}

.dialog-input {
  width: 100%;
  height: 24px;
  margin: 0 0 10px;
  border: 1px solid #000;
  border-radius: 0;
  background: #fff;
  color: #000;
  font: inherit;
}

.dialog-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.dialog-choice,
#restartButton {
  min-width: 72px;
  min-height: 24px;
  padding: 2px 10px;
  border: 2px solid #000;
  border-radius: 6px;
  background: #fff;
  color: #000;
  font: inherit;
}

.quit-panel {
  align-content: center;
  background: #fff;
  text-align: center;
}

.quit-panel p {
  margin: 0 0 12px;
}

.stack-menu {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  display: flex;
  width: 100%;
  height: 24px;
  padding: 1px 10px;
  border-bottom: 1px solid #000;
  background: #fff;
  color: #000;
  font: 13px Chicago, Geneva, "Helvetica Neue", Arial, sans-serif;
}

.stack-menu[hidden] {
  display: none;
}

.stack-menu details {
  position: relative;
}

.stack-menu summary {
  min-width: 72px;
  padding: 3px 10px;
  list-style: none;
  text-align: center;
  cursor: default;
}

.stack-menu summary::-webkit-details-marker {
  display: none;
}

.stack-menu details[open] summary {
  color: #fff;
  background: #000;
}

.stack-menu .menu-items {
  position: absolute;
  top: 22px;
  left: 0;
  min-width: 150px;
  display: grid;
}

.stack-menu button {
  width: 100%;
  padding: 4px 18px;
  border: 1px solid #000;
  margin-top: -1px;
  border-radius: 0;
  background: #fff;
  color: #000;
  font: inherit;
  text-align: left;
  white-space: nowrap;
}

.stack-menu button:first-child {
  margin-top: 0;
}

.stack-menu button:hover,
.stack-menu button:focus-visible {
  color: #fff;
  background: #000;
  outline: 0;
}

.level-indicator {
  margin-left: auto;
  padding: 3px 6px;
  white-space: nowrap;
}

.card-caption {
  position: absolute;
  z-index: 500;
  display: grid;
  place-content: center;
  text-align: center;
  white-space: pre-line;
  font-family: Geneva, Arial, sans-serif;
  line-height: 1.5;
  pointer-events: none;
}

.card-caption[hidden],
.level-indicator[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
