/*
 * delights.css  ·  styles for the two small pleasures built by assets/js/delights.js
 *
 *   .chai    the clay tea cup in the running head (scroll progress, back to top)
 *   .doors   the playable Monty Hall doors in the Human Layer section
 *
 * Everything reads the site tokens (--ink, --paper, --surface, --rule, --red,
 * --teal, --gold, --muted, --font-display, --font-sans, --font-mono) and falls
 * back to the day palette when a token is missing.
 *
 * To remove: delete the two mount elements from index.html, the <link> to this
 * file and the <script> for assets/js/delights.js, then delete both files.
 */

.chai,
.doors {
  --chai-tea: #BE8850;   /* ginger milk tea */
  --chai-milk: #DDB98D;  /* its lighter surface */
}

[data-theme="dark"] .chai,
[data-theme="dark"] .doors {
  --chai-tea: #C4905A;
  --chai-milk: #E6C59C;
}

/* ====================================================================
   1. The tea cup
   ==================================================================== */

.chai {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink, #1C1A17);
  cursor: pointer;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.chai:empty { display: none; }

.chai:focus { outline: none; }
.chai:focus-visible {
  outline: 2px solid var(--teal, #0B6B5F);
  outline-offset: 2px;
}

.chai__svg {
  display: block;
  overflow: visible;
  transition: transform 150ms ease-out;
}

.chai:hover .chai__svg { transform: translateY(-1px); }
.chai:active .chai__svg { transform: none; }

.chai__line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chai__liquid { fill: var(--chai-tea); }
.chai__surface { fill: var(--chai-milk); }

.chai__steam path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0;
}

/* two puffs rise, then the wisps settle and stay: nothing loops forever */
.chai.is-full .chai__steam path {
  animation: chai-rise 1.6s ease-out 2, chai-settle 700ms ease-out 3.2s forwards;
}
.chai.is-full .chai__steam path:nth-child(2) { animation-delay: 220ms, 3.42s; }
.chai.is-full .chai__steam path:nth-child(3) { animation-delay: 440ms, 3.64s; }

@keyframes chai-rise {
  0%   { opacity: 0; transform: translateY(3px); }
  35%  { opacity: 0.8; }
  100% { opacity: 0; transform: translateY(-3px); }
}

@keyframes chai-settle {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 0.75; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chai__svg { transition: none; }
  .chai:hover .chai__svg { transform: none; }
  .chai.is-full .chai__steam path,
  .chai.is-full .chai__steam path:nth-child(2),
  .chai.is-full .chai__steam path:nth-child(3) {
    animation: none;
    opacity: 0.75;
  }
}

/* ====================================================================
   2. The Monty Hall doors
   ==================================================================== */

.doors {
  container-type: inline-size;
  container-name: doors;
  box-sizing: border-box;
  margin: 28px 0;
  padding: 16px 18px 18px;
  border: 1px solid var(--rule, #D9CFBD);
  background: var(--surface, #FBF8F1);
  color: var(--ink, #1C1A17);
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 15px;
  line-height: 1.45;
  text-align: left;
}

.doors:empty { display: none; }

.doors *,
.doors *::before,
.doors *::after { box-sizing: border-box; }

.doors .doors__kicker,
.doors .doors__label,
.doors .doors__hint,
.doors .doors__whyhint {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #6B6558);
}

.doors .doors__kicker { margin: 0 0 12px; }
.doors .doors__kicker span { color: var(--red, #B4281E); }

.doors__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: 18px;
}

/* ---- narration ---- */

.doors .doors__say {
  margin: 0 0 16px;
  min-height: 4.35em; /* room for the longest stage text, so the doors never move */
  font-family: var(--font-display, Georgia, serif);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink, #1C1A17);
}

.doors .doors__say strong { font-weight: 600; }

/* ---- the three doors ---- */

.doors__stage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: clamp(12px, 5%, 22px);
  max-width: 372px;
  padding: 0 8px;
}

/* the floor all three doors stand on */
.doors__stage::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  height: 1.5px;
  background: var(--ink, #1C1A17);
  pointer-events: none;
}

.doors .door {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.doors .door[aria-disabled="true"] { cursor: default; }

.doors .door:focus { outline: none; }
.doors .door:focus-visible {
  outline: 2px solid var(--teal, #0B6B5F);
  outline-offset: 4px;
}

.door__frame {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 5 / 8;
  border: 1.5px solid var(--ink, #1C1A17);
  border-bottom: 0;
  background: var(--paper-2, #ECE4D4);
  perspective: 620px;
}

/* at night the room behind the door is darker than the door itself */
[data-theme="dark"] .door__frame { background: var(--paper, #14120F); }

.door__behind {
  position: absolute;
  inset: 0 0 0 22%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 4% 0 0;
}

.door__behind svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.doors__ink {
  fill: none;
  stroke: var(--ink, #1C1A17);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doors__ink--fine { stroke-width: 1.2; opacity: 0.7; }
.doors__dot { fill: var(--ink, #1C1A17); }
.doors__teafill { fill: var(--chai-tea); }

.door__leaf {
  position: absolute;
  inset: 3px 3px 0 3px;
  display: block;
  border: 1.5px solid var(--ink, #1C1A17);
  border-bottom: 0;
  background: var(--surface, #FBF8F1);
  transform-origin: 0 50%;
  transition: transform 520ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

.door__panel {
  position: absolute;
  left: 15%;
  right: 15%;
  display: block;
  border: 1px solid var(--muted, #6B6558);
  opacity: 0.75;
}

.door__panel--top {
  top: 8%;
  height: 36%;
  display: grid;
  place-items: center;
}

.door__panel--low { top: 51%; bottom: 8%; }

.door__num {
  font-family: var(--font-display, Georgia, serif);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  color: var(--ink, #1C1A17);
}

.door__knob {
  position: absolute;
  right: 5%;
  top: 47.5%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border: 1.5px solid var(--ink, #1C1A17);
  border-radius: 50%;
  background: var(--surface, #FBF8F1);
}

/* a closed door gives a little when you reach for it */
@media (hover: hover) {
  .doors .door:not([aria-disabled="true"]):hover .door__leaf { transform: rotateY(12deg); }
}

.doors .door.is-open .door__leaf { transform: rotateY(79deg); }

/* marigold marks the human's choice */
.door.is-picked .door__frame::after {
  content: "";
  position: absolute;
  left: -1.5px;
  right: -1.5px;
  top: calc(100% + 4px);
  height: 3px;
  background: var(--gold, #E2A21C);
}

.doors .door__tag {
  display: block;
  height: 14px;
  margin-top: 12px;
  overflow: hidden;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10.5px;
  line-height: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--muted, #6B6558);
}

.doors .door.is-picked .door__tag { color: var(--ink, #1C1A17); }

/* ---- stay / switch / again: one cell, so nothing moves between stages ---- */

.doors__actions {
  display: grid;
  margin-top: 14px;
  padding: 0 8px;
}

.doors__act {
  grid-area: 1 / 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  visibility: hidden;
}

.doors[data-stage="pick"] .doors__act--pick,
.doors[data-stage="choose"] .doors__act--choose,
.doors[data-stage="done"] .doors__act--done { visibility: visible; }

.doors .doors__btn {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  padding: 9px 18px 8px;
  min-height: 38px;
  border: 1px solid var(--ink, #1C1A17);
  border-radius: 2px;
  background: transparent;
  color: var(--ink, #1C1A17);
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

@media (hover: hover) {
  .doors .doors__btn:hover {
    background: var(--ink, #1C1A17);
    color: var(--surface, #FBF8F1);
  }
}

.doors .doors__btn:active {
  background: var(--ink, #1C1A17);
  color: var(--surface, #FBF8F1);
}

.doors .doors__btn:focus { outline: none; }
.doors .doors__btn:focus-visible,
.doors .doors__reset:focus-visible {
  outline: 2px solid var(--teal, #0B6B5F);
  outline-offset: 2px;
}

.doors .doors__btn--quiet {
  margin-top: 14px;
  font-size: 14px;
  padding: 8px 14px 7px;
  min-height: 36px;
}

/* ---- the tally ---- */

.doors__score {
  display: grid;
  row-gap: 16px;
  align-content: start;
  padding-top: 16px;
  border-top: 1px solid var(--rule, #D9CFBD);
}

.doors__block--sim {
  padding-top: 14px;
  border-top: 1px solid var(--rule, #D9CFBD);
}

.doors__blockhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 18px;
}

.doors .doors__reset {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted, #6B6558);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}

.doors .doors__reset:hover { color: var(--red, #B4281E); }

.doors__row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  column-gap: 12px;
  margin-top: 10px;
}

.doors .doors__name {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink, #1C1A17);
}

.doors .doors__val {
  justify-self: end;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink-2, var(--muted, #6B6558));
}

.doors__bar {
  grid-column: 1 / -1;
  position: relative;
  display: block;
  height: 5px;
  margin-top: 7px;
}

/* a hairline track; the result is a rule that extends along it */
.doors__bar::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 2px;
  height: 1px;
  background: var(--muted, #6B6558);
  opacity: 0.55;
}

.doors__fill {
  position: absolute;
  inset: 0;
  display: block;
  background: var(--gold, #E2A21C);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 450ms ease-out;
}

.doors__bar--sim .doors__fill {
  background: var(--teal, #0B6B5F);
  transition: none;
}

.doors__tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 1.5px;
  margin-left: -0.75px;
  background: var(--ink, #1C1A17);
}

.doors .doors__theory {
  grid-column: 1 / -1;
  position: relative;
  display: block;
  height: 20px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted, #6B6558);
}

.doors .doors__theory span {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* ---- the reason: redacted until the first game is finished ---- */

.doors__why {
  padding-top: 14px;
  border-top: 1px solid var(--rule, #D9CFBD);
}

.doors__whyhead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 14px;
  margin-bottom: 6px;
}

.doors .doors__whyhead .doors__label { color: var(--red, #B4281E); }

.doors .doors__whytext {
  max-width: 68ch;
  font-family: var(--font-display, Georgia, serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink, #1C1A17);
}

.doors__seal {
  color: transparent;
  background-color: var(--rule, #D9CFBD);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  -webkit-user-select: none;
  user-select: none;
  transition: color 600ms ease-out, background-color 600ms ease-out;
}

.doors.has-played .doors__seal {
  color: inherit;
  background-color: transparent;
  -webkit-user-select: text;
  user-select: text;
}

.doors.has-played .doors__whyhint { visibility: hidden; }

.doors__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- wide enough: the game on the left, the tally beside it ---- */

@container doors (min-width: 600px) {
  .doors__grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    column-gap: 28px;
  }
  .doors__score {
    padding-top: 0;
    padding-left: 28px;
    border-top: 0;
    border-left: 1px solid var(--rule, #D9CFBD);
  }
  .doors__why { grid-column: 1 / -1; }
}

/* the narration keeps exactly the room its longest line needs at each width */
@container doors (min-width: 420px) and (max-width: 599px) {
  .doors .doors__say { min-height: 2.9em; }
}

@container doors (min-width: 720px) {
  .doors .doors__say { min-height: 2.9em; }
}

@container doors (max-width: 299px) {
  .doors .doors__say { min-height: 5.8em; }
}

@container doors (max-width: 359px) {
  .door__num { font-size: 22px; }
}

@media (max-width: 420px) {
  .doors { padding: 14px 14px 16px; }
  .doors__stage,
  .doors__actions { padding: 0 2px; }
}

/* touch screens: thumb-sized buttons, and no label smaller than 12px on a phone */
@media (max-width: 899px) {
  .doors .doors__btn { min-height: 44px; }
}

@media (max-width: 599px) {
  .doors .doors__kicker,
  .doors .doors__label,
  .doors .doors__hint,
  .doors .doors__whyhint,
  .doors .doors__theory { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .door__leaf,
  .doors__fill,
  .doors__seal,
  .doors .doors__btn { transition: none; }
  .doors .door:not([aria-disabled="true"]):hover .door__leaf { transform: none; }
}

@media print {
  .chai,
  .doors { display: none; }
}
