/*
 * panels.css - the panels that open over a scene (the almanac now; binder and twine
 * in M3) and Grandma's little notes.
 *
 * Talks to: js/panels.js (wrapper, backdrop, close button, notes) and js/almanac.js.
 *
 * Say it to a judge: "Each panel is drawn on a picture of a real object - an
 * almanac, a binder - and the controls are ordinary form inputs restyled to look
 * handwritten, so keyboards and screen readers still understand them."
 */

.panel-wrapper {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.panel-backdrop {
  position: absolute;
  inset: 0;
  background: var(--night);
  opacity: 0.55;
}

/* The X in the top-right corner. */
.panel-close {
  position: absolute;
  top: 3%;
  right: 2.5%;
  width: calc(var(--u) * 4);
  height: calc(var(--u) * 4);
  font-family: var(--font-hand);
  font-size: calc(var(--u) * 3.6);
  line-height: 1;
  color: var(--cream);
}

/* ---------- Grandma's note ---------- */
.grandma-note {
  position: absolute;
  left: 50%;
  bottom: 6%;
  max-width: 46%;
  margin: 0;
  padding: 0.5em 1em;
  transform: translateX(-50%) rotate(-1.2deg);
  font-family: var(--font-hand);
  font-size: calc(var(--u) * 1.9);
  line-height: 1.2;
  text-align: center;
  color: var(--ink);
  background: var(--paper);
  border-radius: calc(var(--u) * 0.2);
  box-shadow: 0 calc(var(--u) * 0.3) calc(var(--u) * 0.8) rgba(23, 17, 13, 0.45);
  pointer-events: none;
}

/* ---------- The almanac ---------- */
.almanac {
  position: relative;
  width: 72%;
  aspect-ratio: 984 / 669;          /* the shape of obj-almanac-open.png */
  display: grid;
  grid-template-columns: 1fr 1fr;
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: calc(var(--u) * 1.9);
}

/* The open-book picture sits behind both pages. */
.almanac > .asset {
  position: absolute;
  inset: 0;
  height: 100%;
}
.almanac > .asset .asset-label { align-self: end; padding-bottom: 0.4em; }

.almanac-page {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  padding: 15% 13% 12% 17%;        /* keeps the writing inside the page's printed border */
}
.almanac-page + .almanac-page { padding: 15% 17% 12% 13%; }

.almanac-heading {
  margin: 0;
  font-family: var(--font-typed);
  font-weight: 400;
  font-size: 1.15em;
  letter-spacing: 0.04em;
  border-bottom: calc(var(--u) * 0.1) solid var(--walnut);
  padding-bottom: 0.2em;
}

.almanac-group {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.15em 0.6em;
}
.almanac-group legend {
  padding: 0;
  font-family: var(--font-typed);
  font-size: 0.7em;
  color: var(--walnut);
}

/* A choice is a real radio button that we hide, and a word we show.
   The chosen word gets a pencil circle. */
.almanac-choice { position: relative; }
.almanac-choice input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
}
.almanac-choice span {
  display: inline-block;
  min-height: calc(var(--u) * 3.8);   /* about 45px on an iPad */
  padding: 0.15em 0.6em;
  border: calc(var(--u) * 0.16) solid transparent;
  border-radius: 50% 45% 55% 48% / 60% 55% 60% 50%;  /* a wobbly hand-drawn oval */
  transition: border-color 0.4s ease;
}
.almanac-choice input:checked + span { border-color: var(--pencil); }
.almanac-choice input:focus-visible + span {
  outline: calc(var(--u) * 0.3) solid var(--burnt-orange);
  outline-offset: calc(var(--u) * 0.2);
}

.almanac-slider {
  display: grid;
  grid-template-columns: 5.2em 1fr;
  align-items: center;
  gap: 0.4em;
}
.almanac-slider input {
  width: 100%;
  height: calc(var(--u) * 2.6);
  margin: 0;
  accent-color: var(--burnt-orange);
}

.almanac-switch {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.4em;
  line-height: 1.1;
}
.almanac-switch input {
  flex: none;
  width: calc(var(--u) * 2.2);
  height: calc(var(--u) * 2.2);
  margin: 0;
  accent-color: var(--avocado);
}

/* The four background-sound switches sit two by two, tucked under the Ambiance slider. */
.almanac-ambient {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.6em;
  margin: 0 0 0.3em;
  padding: 0 0 0 0.9em;
  border: 0;
  font-size: 0.86em;
}
/* WHY the padding: it makes each row tall enough to hit with a thumb on the iPad. */
.almanac-ambient .almanac-switch { margin-top: 0; padding: 0.42em 0; }

/* "Show me around again": a handwritten line, underlined in pencil like a link. */
.almanac-replay {
  display: block;
  margin-top: 1.1em;
  padding: 0.45em 0.2em;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--pencil);
  text-underline-offset: 0.18em;
  cursor: pointer;
}

/* The makers' credit: small typewriter print at the foot of the right-hand page. */
.almanac-credit {
  margin: 1.6em 0 0;
  font-family: var(--font-typed);
  font-size: 0.62em;
  line-height: 1.3;
  color: var(--pencil);
}

/* On the cream paper the gold outline would vanish, so use burnt orange here. */
.almanac :focus-visible { outline-color: var(--burnt-orange); }

/* ---------- The binder: add a recipe ---------- */
.binder {
  position: relative;
  width: 88%;
  aspect-ratio: 1265 / 670;            /* the shape of obj-binder-spread.png */
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 100%;            /* pages are exactly as tall as the binder */
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: calc(var(--u) * 1.7);
}
.binder > .asset {
  position: absolute;
  inset: 0;
  height: 100%;
  aspect-ratio: auto !important;
}
.binder > .asset .asset-label { align-self: end; }

/* Each page keeps its writing inside the plastic sleeve painted on the binder. */
.binder-page {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  min-height: 0;
  padding: 10% 8% 9% 18%;
  overflow: hidden;
}
.binder-page + .binder-page { padding: 10% 18% 9% 10%; }

/* The three sleeves' tabs. */
.binder-tabs {
  display: flex;
  gap: 0.3em;
}
.binder-tab {
  flex: 1;
  min-height: calc(var(--u) * 3.8);
  padding: 0 0.3em;
  font-family: var(--font-typed);
  font-size: 0.62em;
  color: var(--walnut);
  background: rgba(201, 168, 118, 0.45);
  border-radius: calc(var(--u) * 0.5) calc(var(--u) * 0.5) 0 0;
  border-bottom: calc(var(--u) * 0.2) solid transparent;
  transition: background 0.4s ease;
}
.binder-tab[aria-selected='true'] {
  color: var(--ink);
  background: #c9a876;
  border-bottom-color: var(--burnt-orange);
}

.binder-sleeve {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4em;
  min-height: 0;
  padding-top: 0.4em;
}
.binder-sleeve .binder-field { width: 100%; flex: none; }
.binder-hint,
.binder-status {
  margin: 0;
  line-height: 1.2;
}
.binder-status { color: var(--burnt-orange); min-height: 1.2em; }
.binder-photo {
  min-height: 0;
  max-height: 58%;
  max-width: 100%;
  object-fit: contain;
  align-self: center;
  border-radius: calc(var(--u) * 0.3);
}

/* Form fields: a small typed label over a handwritten, underlined answer. */
.binder-field {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.binder-field span {
  font-family: var(--font-typed);
  font-size: 0.5em;
  color: var(--walnut);
}
.binder-field input,
.binder-field textarea,
.binder-divider select {
  width: 100%;
  min-height: calc(var(--u) * 2.8);
  padding: 0 0.2em;
  border: 0;
  border-bottom: calc(var(--u) * 0.1) solid var(--pencil);
  border-radius: 0;
  resize: none;
  background: rgba(250, 243, 224, 0.55);
  font-family: var(--font-hand);
  font-size: 1em;
  line-height: 1.25;
  color: var(--ink);
}
.binder-form .binder-field:has(textarea) { flex: 1; }
.binder-form textarea { flex: 1; }
.binder-row {
  display: grid;
  grid-template-columns: 1fr 5em;
  gap: 0.6em;
}
.binder-next { align-self: flex-end; color: var(--burnt-orange); font-weight: 700; }
.binder :focus-visible { outline-color: var(--burnt-orange); }

/* A file picker: the real input is invisible but still focusable, and the label
   around it looks like any other pencil mark. */
.binder-picker { position: relative; }
.binder-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.binder-picker:focus-within {
  outline: calc(var(--u) * 0.3) solid var(--burnt-orange);
  outline-offset: calc(var(--u) * 0.2);
  border-radius: calc(var(--u) * 0.5);
}

/* The preview: the finished card laid on the open binder. */
.binder-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 0.9);
}
.binder-preview-card {
  --card-w: 46;
  filter: drop-shadow(0 calc(var(--u) * 0.4) calc(var(--u) * 0.8) rgba(23, 17, 13, 0.45));
}
.binder-preview-card .card { --card-w: 46; }
.binder-divider {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.1em 0.8em;
  background: var(--paper);
  border-radius: calc(var(--u) * 0.3);
}
.binder-divider select { width: auto; min-width: 9em; background: transparent; }
.binder-preview-buttons {
  display: flex;
  gap: 1.5em;
  padding: 0 0.8em;
  background: var(--paper);
  border-radius: calc(var(--u) * 0.3);
}

/* The little card that slides into the recipe box when a recipe is filed. */
.flying-card {
  position: absolute;
  left: 50%;
  top: 42%;
  width: calc(var(--u) * 30);
  aspect-ratio: 5 / 3;
  margin-left: calc(var(--u) * -15);
  margin-top: calc(var(--u) * -9);
  padding: 0.5em 0.8em;
  font-size: calc(var(--u) * 1.9 * var(--font-scale, 1));
  color: var(--ink);
  background:
    linear-gradient(to bottom, transparent 16%, rgba(181, 82, 74, 0.55) 16% 17%, transparent 17%),
    var(--paper);
  border-radius: calc(var(--u) * 0.3);
  box-shadow: 0 calc(var(--u) * 0.4) calc(var(--u) * 1) rgba(23, 17, 13, 0.5);
  pointer-events: none;
}

/* ---------- The twine stack: a note about bundles ---------- */
.twine-slip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4em;
  width: 44%;
  padding: calc(var(--u) * 2) calc(var(--u) * 2.5);
  transform: rotate(-1deg);
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: calc(var(--u) * 1.8);
  background: var(--cream);
  border-radius: calc(var(--u) * 0.3);
  box-shadow: 0 calc(var(--u) * 0.5) calc(var(--u) * 1.5) rgba(23, 17, 13, 0.6);
}
.twine-heading {
  margin: 0;
  font-family: var(--font-typed);
  font-weight: 400;
  font-size: 1.05em;
}
.twine-slip .binder-status { align-self: stretch; }

/* ---------- First-visit notes (intro.js) ---------- */
/* WHY pointer-events: none: the notes only point. Every click and tap goes straight
   through them to the kitchen underneath. */
.intro-layer {
  position: absolute;
  inset: 0;
  z-index: 5;            /* above the scenes and the lamp, below any open panel */
  pointer-events: none;
}
.intro-arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
/* A dark pencil line with a pale edge, so it reads on the dark kitchen and the lit one. */
.intro-arrow {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;   /* the path's length is set to 1, so this is "one whole line" */
  filter: drop-shadow(0 0 calc(var(--u) * 0.18) var(--paper)) drop-shadow(0 0 calc(var(--u) * 0.1) var(--paper));
}
/* A scrap of cream paper with slightly uneven edges. */
.intro-note {
  position: absolute;
  margin: 0;
  max-width: calc(var(--u) * 19);
  padding: 0.3em 0.75em 0.38em;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(var(--u) * 1.75);
  line-height: 1.08;
  text-align: center;
  clip-path: polygon(1% 6%, 34% 0, 68% 4%, 99% 1%, 100% 52%, 98% 96%, 61% 100%, 30% 95%, 0 99%, 2% 47%);
  filter: drop-shadow(0 calc(var(--u) * 0.2) calc(var(--u) * 0.3) rgba(23, 17, 13, 0.45));
}
.intro-pointing { transform: translate(-50%, -50%) rotate(var(--tilt, -1.5deg)); }
/* The last line has no arrow and sits low, clear of the cat. */
.intro-encouragement {
  left: 72%;
  top: 92%;
  max-width: calc(var(--u) * 34);
  transform: translate(-50%, -50%) rotate(-1deg);
  font-size: calc(var(--u) * 1.9);
}
/* The one-line hints inside the box and at the stove sit at the top, out of the way. */
.intro-hint {
  left: 50%;
  top: 5%;
  max-width: calc(var(--u) * 46);
  transform: translate(-50%, -50%) rotate(-0.6deg);
}
/* Only for screen readers: one sentence per step. */
.intro-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
