/* Doc is a small game in the existing footer, with ordinary-flow fallbacks. */
.footer-track.has-sentient-face:has(.doc-presence) {
  --doc-footer-height: max(760px, calc(100svh - var(--face-pin-top, 90px)));
  /* Clip decorative orbit overflow without creating a scroll container. */
  overflow: clip;
}
.footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene {
  min-height: 760px;
  padding-top: 85px;
  padding-bottom: 105px;
  overflow: clip;
}
.footer-track.has-sentient-face:has(.doc-presence).local-motion {
  height: calc(var(--doc-footer-height) + 100px);
}
.footer-track.has-sentient-face:has(.doc-presence).local-motion .footer.local-scene {
  min-height: var(--doc-footer-height);
}
.footer-track.has-sentient-face .footer.local-scene .sentient-face.doc-presence {
  top: 50%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: stretch;
  gap: 12px;
  width: 46%;
  height: auto;
  max-height: none;
  scroll-margin-top: 20px;
  opacity: 1;
  transform: translateY(-50%);
  pointer-events: none;
}
.footer-track.has-sentient-face .doc-presence .sentient-face-visual {
  grid-column: 1;
  grid-row: 1;
  height: clamp(300px, 39svh, 380px);
  min-height: 0;
  overflow: visible;
}
.footer-track.has-sentient-face .doc-presence .sentient-face-visual::before {
  inset: 4% 15% 0;
  opacity: .6;
}
.doc-presence .doc-visual-label {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  margin: 0;
  color: #c5ae83;
  font: 400 9px/1.5 var(--sans);
  letter-spacing: .15em;
  text-transform: uppercase;
  pointer-events: none;
}
.footer-track.has-sentient-face .doc-presence .doc-hud {
  position: relative;
  z-index: 5;
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 18px 20px 20px;
  border: 1px solid #b59b6c45;
  border-radius: 14px;
  background: linear-gradient(145deg, #282d20ec, #181d14f5 65%);
  box-shadow: inset 0 1px 0 #e5d2a80c, 0 14px 45px #05080326;
  color: #d7d1c1;
  opacity: 1;
  pointer-events: auto;
}
.doc-presence .doc-identity {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  min-width: 0;
}
.doc-presence .doc-identity > .eyebrow {
  grid-column: 1;
  grid-row: 1;
  color: #bfa77f;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: .13em;
}
.doc-presence .doc-identity h2 {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  color: #eee4cf;
  font: 400 clamp(30px, 2.8vw, 39px)/1.03 var(--serif);
  letter-spacing: -.035em;
}
.doc-presence .doc-mood {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  max-width: 112px;
  padding: 3px 8px;
  border: 1px solid #a7997152;
  border-radius: 20px;
  background: #a4996d10;
  color: #cbc5b3;
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: .015em;
  white-space: nowrap;
}
.doc-presence .doc-mood::before {
  content: '';
  width: 4px;
  height: 4px;
  flex: 0 0 4px;
  border-radius: 50%;
  background: #c7b184;
}
.doc-presence .doc-status {
  min-height: 1.6em;
  margin: 0;
  color: #b7beaa;
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.doc-presence .doc-instruction {
  margin: 0;
  padding-top: 11px;
  border-top: 1px solid #b5a37726;
  color: #d1cab7;
  font-size: 12px;
  line-height: 1.6;
}
.doc-presence .doc-game-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 9px 20px;
  padding: 9px 0 1px;
}
.doc-presence :is(.doc-score, .doc-clock) {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  margin: 0;
  color: #aeb59f;
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: .025em;
}
.doc-presence :is([data-doc-score], [data-doc-time]) {
  color: #e2d3af;
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  letter-spacing: -.015em;
}
.doc-presence .doc-controls {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 8px;
}
.doc-presence .doc-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 80px;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #9f906a66;
  border-radius: 6px;
  background: #a69c7310;
  color: #d5cebc;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  text-align: center;
  touch-action: manipulation;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
  pointer-events: auto;
}
.doc-presence .doc-controls [data-doc-action="play"] {
  flex-basis: 105px;
  border-color: #d3ba8b;
  background: #ddc79f;
  color: #202719;
  box-shadow: inset 0 1px 0 #fff4;
}
.doc-presence .doc-controls [data-doc-action="pause"] {
  border-style: dashed;
  border-color: #a899705e;
  background: transparent;
}
.doc-presence .doc-controls button[aria-pressed="true"] {
  border-color: #d2bc8e;
  background: #ac9c6f28;
  color: #f0e1c1;
}
.doc-presence .doc-controls button:disabled {
  color: #979d8a;
  border-color: #8890753b;
  background: #9298770a;
  box-shadow: none;
  cursor: default;
}
.doc-presence :is(.doc-controls button, .doc-spark):focus-visible {
  outline: 2px solid #efcf97;
  outline-offset: 4px;
}
.doc-presence .doc-controls button:active:not(:disabled) {
  background: #d6bf9140;
}
.doc-presence .doc-controls [data-doc-action="play"]:active:not(:disabled) {
  background: #c4aa79;
}
.doc-presence:not(.doc-ready) :is(.doc-controls, .doc-game-info, .doc-instruction) { display: none; }
.doc-presence .doc-controls [hidden],
.doc-presence .doc-spark[hidden],
.doc-presence .doc-sparks[hidden] { display: none !important; }

/* A transparent, keyboard-accessible interaction surface over the portrait. */
.doc-presence .doc-avatar-hit {
  position: absolute;
  z-index: 3;
  inset: 4% 13% 3%;
  display: block;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 42% 42% 24% 24%;
  background: transparent;
  color: transparent;
  box-shadow: none;
  touch-action: manipulation;
  cursor: pointer;
  pointer-events: auto;
}
.doc-presence .doc-avatar-hit:focus-visible {
  outline: 2px solid #e4c596;
  outline-offset: 3px;
  background: transparent;
  box-shadow: 0 0 0 6px #c4a16a14;
}
.doc-presence .doc-avatar-hit:disabled { cursor: default; }
.doc-presence .doc-sparks {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}
.doc-presence .doc-spark {
  position: absolute;
  top: var(--spark-y, 50%);
  left: var(--spark-x, 50%);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid #d1b17b7a;
  border-radius: 50%;
  background: radial-gradient(circle, #e7c48c33, #a48f5415 53%, #151b0f14 72%);
  color: #f0d8a6;
  font: 400 25px/1 Georgia, serif;
  text-shadow: 0 0 13px #e3b66b40;
  box-shadow: inset 0 0 11px #f0ce8c0f, 0 3px 15px #0003;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  pointer-events: auto;
  cursor: pointer;
}
.doc-presence .doc-spark::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid #f3dca927;
  border-radius: 50%;
  pointer-events: none;
}
.doc-presence[data-game="playing"] .doc-spark:not([hidden])::after {
  animation: doc-spark-breathe 2.6s ease-in-out infinite;
}
@keyframes doc-spark-breathe {
  0%, 100% { opacity: .55; transform: scale(.98); }
  50% { opacity: .9; transform: scale(1.06); }
}
.doc-presence[data-game="playing"] .doc-hud { border-color: #c1a47073; }
.doc-presence[data-game="paused"] .doc-mood { background: #8f967818; border-color: #9b9f804d; }
.doc-presence[data-game="paused"] .doc-spark { color: #c6c5b1; border-color: #acae905c; }
.doc-presence[data-game="won"] .doc-mood { color: #d7dcc0; border-color: #b0ba7b6b; background: #a1b27413; }
.doc-presence[data-game="won"] .doc-mood::before { background: #c4cd91; }
.doc-presence[data-game="lost"] .doc-mood { color: #dcc9b2; border-color: #b3987573; background: #bb97720e; }

@media (hover: hover) and (pointer: fine) {
  .doc-presence .doc-controls button:hover:not(:disabled) {
    border-color: #cbb583;
    background: #bba57228;
    color: #f0dfba;
  }
  .doc-presence .doc-controls [data-doc-action="play"]:hover:not(:disabled) {
    background: #ead5ac;
    color: #202719;
  }
  .doc-presence .doc-spark:hover {
    border-color: #f0d0a0;
    background: radial-gradient(circle, #e7c48c52, #a48f5421 53%, #151b0f14 72%);
  }
}

/* The expanded game stays in ordinary document flow when a pin would crop it. */
@media (max-height: 860px) {
  .footer-track.has-sentient-face:has(.doc-presence).local-motion { height: auto; min-height: 0; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene {
    position: relative;
    top: auto;
    min-height: 760px;
    height: auto;
    overflow: clip;
  }
}
@media (max-width: 900px) {
  .footer-track.has-sentient-face:has(.doc-presence),
  .footer-track.has-sentient-face:has(.doc-presence).local-motion { height: auto; min-height: 0; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene {
    position: relative;
    top: auto;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    row-gap: 20px;
    min-height: 0;
    height: auto;
    padding: 28px var(--gutter) max(95px, env(safe-area-inset-bottom));
    overflow: clip;
  }
  .footer-track.has-sentient-face .footer.local-scene .sentient-face.doc-presence {
    position: relative;
    grid-column: 1;
    grid-row: 1;
    top: auto;
    right: auto;
    width: 100%;
    max-height: none;
    height: auto;
    margin-bottom: 6px;
    transform: none;
  }
  .footer-track.has-sentient-face .doc-presence .sentient-face-visual { height: clamp(250px, 37svh, 350px); }
  .footer-track.has-sentient-face .doc-presence .doc-hud { padding: 17px 18px 18px; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene .wordmark { grid-column: 1; grid-row: 2; margin-bottom: 0; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene .copyright { grid-column: 1; grid-row: 3; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene .footer-links { grid-column: 1; grid-row: 4; }
  .doc-presence .doc-identity h2 { font-size: clamp(31px, 5vw, 39px); }
  .doc-presence .doc-avatar-hit { inset: 3% 16% 3%; }
}
@media (max-width: 430px) {
  .footer-track.has-sentient-face .doc-presence .doc-hud { gap: 11px; padding: 16px; border-radius: 12px; }
  .doc-presence .doc-identity h2 { font-size: 30px; }
  .doc-presence .doc-mood { max-width: 100px; padding-inline: 7px; font-size: 10px; }
  .doc-presence .doc-controls { gap: 7px; }
  .doc-presence .doc-controls button { flex-basis: 73px; padding-inline: 8px; }
  .doc-presence .doc-controls [data-doc-action="play"] { flex-basis: 95px; }
}
@media (max-height: 600px) and (min-width: 901px) {
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene {
    min-height: 710px;
    padding-top: 70px;
    padding-bottom: 85px;
  }
  .footer-track.has-sentient-face .doc-presence .sentient-face-visual { height: 240px; }
}

/* Pausing decorative motion never disables the untimed/static game controls. */
.motion-paused .doc-presence .doc-spark::after,
.doc-presence[data-game="paused"] .doc-spark::after {
  animation: none;
  transform: none;
}
.motion-paused .doc-presence :is(.doc-controls button, .doc-spark) { transition: none; }
.motion-paused .footer-track.has-sentient-face:has(.doc-presence).local-motion { height: auto; min-height: 0; }
.motion-paused .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene { position: relative; top: auto; height: auto; }
@media (prefers-reduced-motion: reduce) {
  .doc-presence .doc-spark::after { animation: none; transform: none; }
  .doc-presence :is(.doc-controls button, .doc-spark) { transition: none; }
  .footer-track.has-sentient-face:has(.doc-presence).local-motion { height: auto; min-height: 0; }
  .footer-track.has-sentient-face:has(.doc-presence) .footer.local-scene { position: relative; top: auto; height: auto; }
}
@media (forced-colors: active) {
  .doc-presence .doc-hud,
  .doc-presence .doc-mood,
  .doc-presence .doc-controls button,
  .doc-presence .doc-spark { border-color: ButtonText; background: Canvas; color: CanvasText; box-shadow: none; text-shadow: none; }
  .doc-presence .doc-spark::after { display: none; }
  .doc-presence .doc-avatar-hit:focus-visible { outline-color: Highlight; box-shadow: none; }
  .doc-presence :is(.doc-controls button, .doc-spark):focus-visible { outline-color: Highlight; }
}
