/* Spud & Root: town/christmas-market.html. Loaded after site.css. The square
   is a canvas; everything else here is laid over it: the buttons for what
   you can tap, the speech box, the pocket, a counter's stage, the cards,
   the way out and the sound button. market.js sets data-state on .market:
   loading -> arriving -> open (or eve, or closed), and adds in-stage,
   is-walking and is-talking as the visit goes on.
   docs/pages/christmas-market.md. */

html.js,
html.js body.market-page {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
.market-page {
  margin: 0;
  background: #0d1330;
  color: var(--ink);
  font-family: var(--font-body);
}
/* Pinned to the screen as it is now: a viewport unit (100svh) can stay at
   the smallest the page was ever squeezed to, by the keyboard or the share
   sheet in some iPhone browsers, leaving the market short with nothing
   under it */
.market {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  background: #0d1330;
  -webkit-tap-highlight-color: transparent;
}
/* Nothing on the page is for selecting: an iPhone starts selecting text
   (and offers Copy and Look Up) when a finger's held down, which turning
   slowly does. Set on every element, not left to inheritance from .market,
   which iOS doesn't always honour; the boxes you type in or copy a link
   from still select (an iPhone won't let you type in one that can't), and
   market.js stops any selection that starts anywhere else. */
html.js body.market-page,
.market * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.market input,
.market textarea {
  -webkit-user-select: text;
  user-select: text;
}
html:not(.js) .market {
  position: relative;
  height: auto;
  min-height: 100vh;
  overflow: visible;
}

.world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
.world.is-dragging {
  cursor: grabbing;
}
html:not(.js) .world,
html:not(.js) .topbar,
html:not(.js) .veil {
  display: none;
}

/* ---------- Things you can tap ---------- */
/* (its own stacking layer, under the speech box, the pocket and the cards:
   a spot's z-index only orders the spots among themselves) */
.spots {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.spot {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  border-radius: 14px;
  -webkit-tap-highlight-color: transparent;
}
.spot[hidden] {
  display: none;
}
.spot:focus {
  outline: none;
}
.spot:focus-visible {
  outline: 3px solid var(--logo-yellow);
  outline-offset: -3px;
}
.market.is-walking .spot,
.market.in-stage .spot,
.market.is-carded .spot {
  pointer-events: none;
}
.spot--glow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  background: rgba(255, 236, 170, 0.92);
  box-shadow: 0 0 0 3px var(--ink), 0 0 18px 6px rgba(255, 214, 120, 0.7);
  animation: spot-glow 2.6s ease-in-out infinite;
}
.spot__label {
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  padding: 0.12em 0.7em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  pointer-events: none;
}
.spot:not(.spot--labelled) .spot__label {
  display: none;
}
@keyframes spot-glow {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.18); opacity: 0.7; }
}

/* ---------- A remark over someone's head ---------- */
.bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: min(260px, 70vw);
  margin: 0;
  padding: 0.35em 0.8em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: 3px 3px 0 var(--ink);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.bubble.is-on {
  opacity: 1;
}

/* ---------- Way out, the pocket button, sound ---------- */
.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  pointer-events: none;
  z-index: 5;
}
.leave,
.sound,
.pocket-btn,
.chip {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  color: var(--ink);
  background: var(--white);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
}
.leave {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  padding: 0.3em 0.9em;
}
.topbar__right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}
.sound {
  display: inline-grid;
  place-items: center;
  width: 2.4em;
  height: 2.1em;
  padding: 0;
}
.sound .off,
.sound[aria-pressed="false"] .on {
  display: none;
}
.sound[aria-pressed="false"] .off {
  display: inline;
}
.sound[aria-pressed="false"] {
  background: #d9cfb8;
}
.pocket-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.3em 0.9em;
  background: var(--herb-light);
}
.pocket-btn[hidden] {
  display: none;
}
.pocket-btn__n:empty {
  display: none;
}
.pocket-btn__n {
  min-width: 1.5em;
  padding: 0 0.35em;
  font-size: 0.85em;
  text-align: center;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
}
.pocket-btn.is-bump {
  animation: bump 0.45s var(--ease-spring);
}
.leave:hover,
.sound:hover,
.pocket-btn:hover,
.chip:hover {
  background: var(--logo-yellow);
}
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.16) rotate(-3deg); }
  100% { transform: scale(1); }
}

.chips {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}
.chip {
  padding: 0.35em 1em;
}
.chip[hidden] {
  display: none;
}
.chip[aria-pressed="true"] {
  background: var(--logo-yellow);
}
.market.is-talking .chips,
.market.in-stage .chips,
.market.is-carded .chips {
  display: none;
}
/* while you do what you picked (look up, sit down, step back), the talk
   steps aside */
.talk.is-aside {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ---------- The hint ---------- */
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 52px);
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35em 1em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  color: var(--white);
  background: rgba(13, 19, 48, 0.78);
  border-radius: var(--radius-pill);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
  z-index: 4;
}
.hint.is-on {
  opacity: 1;
}

/* ---------- The pocket ---------- */
.pocket {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  right: max(12px, env(safe-area-inset-right));
  width: min(100% - 24px, 360px);
  max-height: calc(100% - 140px);
  overflow: auto;
  padding: 14px 16px 16px;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  z-index: 7;
  touch-action: pan-y;
}
.pocket[hidden] {
  display: none;
}
.pocket__title {
  margin: 0 36px 6px 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.pocket__close,
.talk__close,
.card__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font: 700 1.3rem/1 var(--font-display);
  cursor: pointer;
}
.pocket__close:hover,
.talk__close:hover {
  background: var(--white);
}
.pocket__cash {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 600;
}
.pocket__slip {
  margin: 0 0 12px;
  padding: 10px 12px;
  font-family: var(--font-script);
  font-size: 1.15rem;
  line-height: 1.25;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 4px;
  transform: rotate(-1deg);
}
.pocket__slip[hidden] {
  display: none;
}
.pocket__slip b {
  display: block;
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.pocket__where {
  display: block;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.pocket__find {
  margin-top: 6px;
  padding: 0.3em 0.9em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--logo-yellow);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.pocket__slip ul {
  margin: 4px 0 0;
  padding-left: 1.1em;
}
.pocket__items {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.pocket__item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pocket__item button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
}
.pocket__item button[aria-pressed="true"] {
  background: var(--logo-yellow);
}
.pocket__send {
  flex: none;
  padding: 0.35em 0.9em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--logo-yellow);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.pocket__send:hover {
  background: var(--logo-green);
}
.pocket__icon {
  flex: none;
  width: 30px;
  height: 30px;
}
.pocket__icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.pocket__empty {
  margin: 0;
  color: var(--ink-soft);
}
.pocket__items:not(:empty) + .pocket__empty {
  display: none;
}

/* ---------- The speech box ---------- */
.talk {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  translate: -50% 0;
  width: min(100% - 24px, 520px);
  padding: 12px 14px 12px;
  background: var(--white);
  color: var(--ink);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 8;
  animation: talk-in 0.22s var(--ease-out);
}
.talk[hidden] {
  display: none;
}
@keyframes talk-in {
  from { opacity: 0; translate: -50% 10px; }
  to { opacity: 1; translate: -50% 0; }
}
.talk__who {
  margin: 0 36px 4px 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
}
.talk__say {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.35;
}
.talk__say p {
  margin: 0 0 0.35em;
}
.talk__say p:last-child {
  margin-bottom: 0;
}
.talk__say .talk__other {
  color: var(--ink-soft);
}
.talk__say .talk__other b {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
}
.talk__opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.talk__opts:empty {
  display: none;
}
.talk__opt {
  padding: 0.4em 0.9em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  cursor: pointer;
  text-align: left;
}
.talk__opt:hover {
  background: var(--logo-yellow);
}
.talk__opt.is-heard {
  color: var(--ink-soft);
  border-color: #b8ad95;
  background: #f4efe3;
}
.talk__opt.is-doing {
  font-style: italic;
  background: var(--white);
}
.talk__opt.talk__done {
  margin-left: auto;
}

/* ---------- A counter or a craft: the stage ---------- */
.stage-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #120f1a;
}
.stage-layer[hidden] {
  display: none;
}
.stage-layer__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.stage-layer__ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.stage-layer__ui > * {
  pointer-events: auto;
}
.gamebar {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  top: max(8px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: var(--white);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  z-index: 2;
}
.gamebar__done {
  padding: 0.25em 0.9em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--logo-yellow);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.gamebar__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 1rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.gamebar__cash {
  font-family: var(--font-display);
  padding: 0.1em 0.7em;
  background: var(--herb-light);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
}
/* What's going on, in a line under the bar (so it never crowds the title) */
.gamebar__status {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  max-width: calc(100% - 16px);
  padding: 0.15em 0.9em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
}
.gamebar__status:empty {
  display: none;
}
/* At a counter, the keeper's lines come under the bar, out of the way of
   your hands, and touches go through them to the counter */
.market.in-stage .talk {
  top: calc(max(8px, env(safe-area-inset-top)) + 92px);
  bottom: auto;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
}
.market.in-stage .talk .talk__close,
.market.in-stage .talk .talk__opt {
  pointer-events: auto;
}
.market.in-stage .topbar,
.market.in-stage .bubble,
.market.in-stage .hint {
  display: none;
}

/* ---------- Cards ---------- */
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(100% - 28px, 460px);
  max-height: calc(100% - 120px);
  overflow: auto;
  padding: 20px 20px 18px;
  background: var(--cream);
  color: var(--ink);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 9;
  touch-action: pan-y;
  animation: card-in 0.25s var(--ease-out);
}
@keyframes card-in {
  from { opacity: 0; translate: -50% calc(-50% + 10px); }
  to { opacity: 1; translate: -50% -50%; }
}
.card[hidden] {
  display: none;
}
.card__title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.4rem;
  line-height: 1.15;
}
.card__body p {
  margin: 0 0 0.7em;
  line-height: 1.45;
}
.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
.card__actions:empty {
  display: none;
}
.card .btn:focus:not(:focus-visible) {
  outline: none;
}
.card .btn {
  min-height: 44px;
  padding: 8px 20px;
  font-size: 1rem;
}

/* Pictures in cards: a present, a calendar window, a gift */
.card__pic,
.advent__pic {
  display: flex;
  justify-content: center;
  margin: 4px 0 12px;
}
.advent__pic canvas {
  border: var(--stroke) solid var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
  background: #f6d98a;
}
.advent__date {
  margin: -4px 0 6px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink-soft);
}
.advent__new {
  padding: 8px 12px;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.card__note {
  font-family: var(--font-script);
  font-size: 1.35rem;
  line-height: 1.2;
  padding: 10px 14px;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 4px;
  transform: rotate(-1deg);
}
.card__slip {
  font-family: var(--font-script);
  font-size: 1.3rem;
}
.gift__row label {
  display: grid;
  gap: 4px;
  font-family: var(--font-display);
  font-weight: 600;
}
.gift__row select,
.gift__row input,
.gift__link input {
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  font: 1rem var(--font-body);
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 10px;
  user-select: text;
  -webkit-user-select: text;
}
.gift__link[hidden] {
  display: none;
}

/* ---------- Loading, and with JavaScript off ---------- */
.veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0d1330;
  z-index: 20;
  transition: opacity 1.2s ease;
}
.veil.is-gone {
  opacity: 0;
  pointer-events: none;
}
.veil__text {
  margin: 0;
  font-family: var(--font-script);
  font-size: 1.6rem;
  color: #f6e3b4;
  animation: veil-breathe 2.2s ease-in-out infinite;
}
@keyframes veil-breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.nojs {
  display: none;
}
html:not(.js) .nojs,
.market.is-broken .nojs {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: #0d1330;
}
.market.is-broken .nojs {
  position: absolute;
  inset: 0;
  z-index: 30;
}
.nojs__card {
  max-width: 460px;
  padding: 24px;
  background: var(--cream);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.nojs__card h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
}

@media (prefers-reduced-motion: reduce) {
  .spot--glow::before,
  .veil__text,
  .pocket-btn.is-bump {
    animation: none;
  }
  .talk,
  .card {
    animation: none;
  }
}
