/* Secret Santa: the julmarknad guide map. Flat lobes divide the page by coastline,
   capsules are the controls, one grotesk carries every voice. */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../fonts/bricolage-grotesque-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --red: #c8102e;
  --red-deep: #a00c24;
  --red-text: #fde7e9;
  --cream: #f7f1e6;
  --paper: #fffdf8;
  --green: #2d6a3e;
  --green-deep: #245632;
  --green-text: #eef4e8;
  --yellow: #f2c230;
  --yellow-deep: #e0ac12;
  --ink: #2a2522;
  --ink-soft: #5b514c;
  --brown: #b5652a;
  --line: #2a2522;

  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --measure: 40rem;
  --wide: 72rem;
  --gutter: clamp(1.25rem, 5vw, 2.5rem);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --out: cubic-bezier(0.16, 1, 0.3, 1);
  --focus: var(--ink);

  color-scheme: light;
  accent-color: var(--red);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-color: var(--green) var(--cream);
}

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.125rem;
  line-height: 1.55;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--yellow); color: var(--ink); }

h1, h2, h3, p, ol { margin: 0; }
h1, h2, h3 { line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; }
p { text-wrap: pretty; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

/* Lobes leave the map past the right edge; the page never scrolls sideways for them. */
.shell { overflow-x: clip; }

/* --- Map head: the lobe each page stands on (red: giving, green: Din tomte) ----------- */

.map-head {
  --focus: var(--yellow);
  --land: var(--red);
  position: relative;
  isolation: isolate;
  color: var(--paper);
  padding: 1.25rem var(--gutter) clamp(4.5rem, 14vw, 7rem);
}

.map-head--green { --land: var(--green); }

.coast {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  fill: var(--land);
}

.map-head__inner {
  max-width: var(--wide);
  margin-inline: auto;
}

.map-head__grid {
  display: grid;
  gap: 1.5rem;
  align-items: end;
}

.wordmark {
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  margin-bottom: clamp(2rem, 8vw, 3.5rem);
}

.topline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

/* The page switch: the current page is a filled capsule, the other an outline. */
.pages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: clamp(1.75rem, 7vw, 3rem);
}

.page-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.4rem 1.15rem;
  border: 2px solid var(--paper);
  border-radius: 999px;
  color: var(--paper);
  font-weight: 700;
  font-size: 1.0625rem;
  line-height: 1.15;
  text-decoration: none;
  transition: transform 0.4s var(--spring), background-color 0.2s var(--out);
}

.page-link:hover { background: color-mix(in srgb, var(--paper) 16%, transparent); }
.page-link:active { transform: scale(0.96); }
.page-link[aria-current="page"] { background: var(--paper); color: var(--ink); }

.page-title {
  font-weight: 800;
  font-size: clamp(3rem, 15vw, 6rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  margin-bottom: 0.9rem;
}

.group-name {
  flex: 1 1 12rem;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  min-width: 0;
  overflow-wrap: anywhere;
}

.entry-title {
  font-weight: 800;
  font-size: clamp(2.5rem, 11vw, 4.75rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  margin-bottom: 1rem;
}

.on-red { color: var(--red-text); max-width: 32rem; }
.on-green { color: var(--green-text); max-width: 32rem; }

.recipient {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

/* Each view's heading is focused by script when the view opens (and the name after the
   reveal), so screen readers start there; it is not a control, so it draws no ring. */
.recipient:focus,
.page-title:focus,
.chat-head__title:focus { outline: none; }

.recipient__lead {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.recipient__name {
  font-weight: 800;
  font-size: clamp(2.5rem, 17vw, 6rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  overflow-wrap: break-word;
  hyphens: auto;
}

.recipient__name.is-long { font-size: clamp(2rem, 11vw, 4.75rem); }
.recipient__name.is-very-long { font-size: clamp(1.75rem, 8vw, 3.5rem); }

/* The green lobe with the market illustration. */
.lobe-art {
  justify-self: end;
  width: min(100%, 15rem);
  margin-bottom: -1.5rem;
  /* The lobe swells past the right edge of the screen, like land leaving the map. */
  margin-right: calc(-1 * var(--gutter) - max(0px, (100vw - var(--wide) - 2 * var(--gutter)) / 2));
  transform: translateX(12%);
}

.market-art { display: block; width: 100%; height: auto; }

.art-green { fill: var(--green); }
.art-cream { fill: var(--cream); }
.art-yellow { fill: var(--yellow); }
.art-brown { fill: var(--brown); }
.art-red { fill: var(--red); }
.art-icing, .art-steam { fill: none; stroke: var(--cream); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.art-steam { opacity: 0.85; }
.art-stick { fill: none; stroke: #7a3f17; stroke-width: 5; stroke-linecap: round; }
.art-handle { fill: none; stroke: var(--red); stroke-width: 5; }

@media (min-width: 40rem) {
  .map-head__grid { grid-template-columns: minmax(0, 1fr) auto; gap: 2rem; }
  /* Crosses the red coast decisively into the cream. */
  .lobe-art { width: clamp(17rem, 36vw, 30rem); margin-bottom: calc(-1 * clamp(5rem, 9vw, 8rem)); }
  /* The julklapp lobe is taller than the market one; narrower keeps the head the same height. */
  .map-head--green .lobe-art { width: clamp(14rem, 24vw, 20rem); }
}

@media (max-width: 39.99rem) {
  /* On phones the illustration tucks in beside the tagline, and drops below it when
     large text leaves no room. */
  .view--home .map-head__grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
  .view--home .map-head__grid > :first-child { display: contents; }
  .view--home .recipient,
  .view--home .page-title { flex-basis: 100%; margin-bottom: 0; }
  .view--home .on-red,
  .view--home .on-green { flex: 1 1 9rem; align-self: center; }
  .view--home .lobe-art { flex: 0 1 11rem; min-width: 8rem; margin-bottom: -2.5rem; margin-left: auto; }
  #view-entry .lobe-art { width: min(70%, 14rem); margin-top: -0.5rem; }
}

#view-entry .ground { padding-top: clamp(1.5rem, 5vw, 2.5rem); }

/* --- Capsules ---------------------------------------------------------------------------- */

.capsule {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.6rem 1.35rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 1.0625rem;
  line-height: 1.15;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.4s var(--spring), background-color 0.2s var(--out);
}

.capsule:active { transform: scale(0.96); }
.capsule:disabled { cursor: progress; opacity: 0.7; }

.capsule--red { background: var(--red); color: var(--paper); }
.capsule--red:hover { background: var(--red-deep); }
.capsule--yellow { background: var(--yellow); color: var(--ink); }
.capsule--yellow:hover { background: var(--yellow-deep); }
.capsule--paper { background: var(--paper); color: var(--ink); }
.capsule--paper:hover { background: var(--cream); }
.capsule--green { background: var(--green); color: var(--paper); }
.capsule--green:hover { background: var(--green-deep); }

.capsule--small { min-height: 2.75rem; padding: 0.45rem 1.1rem; font-size: 1rem; white-space: nowrap; flex: none; }
.capsule--large { min-height: 3.5rem; padding: 0.8rem 2rem; font-size: 1.25rem; }

.icon {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* The round chip riding a capsule's trailing edge. */
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.1rem 0.65rem;
  margin-right: -0.7rem;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 800;
}

/* --- Cream ground ------------------------------------------------------------------------ */

/* Content shares the head's left edge, at a readable measure. */
.ground {
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin-inline: auto;
  padding: clamp(2.5rem, 8vw, 4rem) var(--gutter) clamp(3rem, 10vw, 5rem);
}

.ground > * { max-width: var(--measure); }

.ground-land { display: none; }

@media (min-width: 64rem) {
  /* Land carried down the right of the reading column: a yellow lobe with a julgran
     whose star breaks over its coast. */
  .ground--home {
    display: grid;
    grid-template-columns: minmax(0, var(--measure)) minmax(0, 1fr);
    column-gap: clamp(3rem, 6vw, 6rem);
    align-items: start;
  }
  .ground--home > .block { grid-column: 1; }
  .ground--home > .ground-land {
    display: block;
    grid-column: 2;
    grid-row: 1 / span 3;
    position: sticky;
    top: 2rem;
    max-width: none;
    margin-right: calc(-1 * var(--gutter) - max(0px, (100vw - var(--wide) - 2 * var(--gutter)) / 2));
  }
  .ground-land svg { display: block; width: min(100%, 24rem); height: auto; margin-left: auto; transform: translateX(18%); }
}

.block + .block { margin-top: clamp(3rem, 10vw, 4.5rem); }

.block__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 0.9rem;
}

/* Map-legend headings: the dot matches the capsule that jumps here. */
.legend {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: clamp(1.5rem, 6vw, 1.875rem);
  font-weight: 800;
}

.legend::before {
  content: "";
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  transform: translateY(-0.08em);
}

.legend--yellow::before { background: var(--yellow); box-shadow: 0 0 0 2px var(--ink); }
.legend--ring::before { background: var(--paper); box-shadow: 0 0 0 2px var(--ink); }
.legend label { cursor: pointer; }

.meta {
  color: var(--ink-soft);
  font-size: 1rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.help { color: var(--ink-soft); font-size: 1rem; margin-bottom: 1rem; max-width: 36rem; }
.lead-text { font-size: 1.25rem; margin-bottom: 1.5rem; max-width: 34rem; }

.wishlist-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1.1875rem;
  line-height: 1.6;
  max-width: 38rem;
}

.wishlist-text.is-empty { color: var(--ink-soft); }

.pill-new {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 800;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

.pill-new::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--ink);
}

/* --- Forms ------------------------------------------------------------------------------- */

.field {
  display: block;
  width: 100%;
  padding: 0.85rem 1.1rem;
  border: 2px solid var(--line);
  border-radius: 1.25rem;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  caret-color: var(--red);
  resize: vertical;
}

.field::placeholder { color: #7a706a; }
.field:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.field[aria-invalid="true"] { border-color: var(--red); border-width: 3px; }

.field--code {
  border-radius: 999px;
  min-height: 3.5rem;
  padding-inline: 1.4rem;
  font-size: 1.3125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.code-form { max-width: 30rem; }
.code-form .legend { margin-bottom: 0.4rem; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  margin-top: 1.25rem;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.35;
}

.check input {
  position: absolute;
  opacity: 0;
  width: 1.75rem;
  height: 1.75rem;
  margin: 0;
}

.check__box {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
  transition: background-color 0.2s var(--out);
}

.check__box svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: var(--paper);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.check input:checked + .check__box { background: var(--green); border-color: var(--green); }
.check input:checked + .check__box svg { opacity: 1; }
.check input:focus-visible + .check__box { outline: 3px solid var(--focus); outline-offset: 3px; }

.check__help {
  display: block;
  font-weight: 400;
  font-size: 1rem;
  color: var(--ink-soft);
  margin-top: 0.15rem;
}

.form-row { margin-top: 1.5rem; }
.form-row--end { display: flex; justify-content: flex-end; }

/* Optional parts of the own wishlist (images, sizes), each under its own small legend. */
.option-group {
  margin: 1.75rem 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.option-group__legend {
  padding: 0;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

.option-group__optional { font-weight: 400; font-size: 1rem; color: var(--ink-soft); }
.option-group .help { margin-bottom: 0.75rem; }

.option-group__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.75rem;
}

/* Wishlist images: square crops in a grid; tapping one shows it whole. */
.wish-images {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(7.5rem, 40%), 1fr));
  gap: 0.6rem;
  max-width: 34rem;
}

.wish-images:empty { display: none; }
.wishlist-text + .wish-images { margin-top: 1.25rem; }

.wish-image {
  position: relative;
  aspect-ratio: 1;
  border-radius: 1rem;
  overflow: hidden;
  background: var(--paper);
  border: 2px solid var(--line);
}

.wish-image img,
.wish-image__open {
  display: block;
  width: 100%;
  height: 100%;
}

.wish-image img { object-fit: cover; }

.wish-image__open {
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}

.wish-image__open:focus-visible { outline-offset: -5px; }

.wish-image__missing,
.wish-image__uploading {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.wish-image__remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.4s var(--spring), background-color 0.2s var(--out);
}

.wish-image__remove:hover { background: var(--cream); }
.wish-image__remove:active { transform: scale(0.92); }

/* A paper capsule with an ink stroke, for secondary actions on the cream ground. */
.capsule--outline { background: var(--paper); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.capsule--outline:hover { background: var(--cream); }

/* The file input is visually hidden inside its label; the label shows its focus. */
.add-image:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.add-image[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.lightbox {
  max-width: min(94vw, 60rem);
  max-height: 94vh;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

.lightbox::backdrop { background: color-mix(in srgb, var(--ink) 88%, transparent); }

.lightbox__img {
  display: block;
  max-width: 100%;
  max-height: calc(94vh - 5rem);
  margin-inline: auto;
  border-radius: 1rem;
  background: var(--paper);
}

.lightbox__close { display: flex; justify-content: center; margin-top: 1rem; }

.size-field { display: block; }
.size-field__label { display: block; font-weight: 700; margin-bottom: 0.35rem; }

.field--size {
  border-radius: 999px;
  min-height: 3rem;
  padding: 0.55rem 1.1rem;
  font-weight: 700;
}

/* The recipient's sizes: one pill per known size, label then value. */
.sizes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1.25rem 0 0;
}

.sizes__item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.45rem 1.1rem;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}

.sizes__item dt { font-size: 1rem; color: var(--ink-soft); }
.sizes__item dd { margin: 0; font-weight: 800; font-size: 1.1875rem; overflow-wrap: anywhere; }

.status { min-height: 1.5em; margin-top: 0.75rem; font-size: 1rem; font-weight: 700; }
.status:empty { min-height: 0; margin-top: 0; }
.status[data-tone="error"] { color: var(--status-error, var(--red-deep)); }
.status[data-tone="error"]::before,
.status[data-tone="pending"]::before {
  content: "";
  display: inline-block;
  vertical-align: -0.15em;
  margin-right: 0.4em;
  background: currentColor;
}
.status[data-tone="error"]::before {
  width: 1.1em;
  height: 1.1em;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.25' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5M12 16.5v.01'/%3E%3C/svg%3E") center / contain no-repeat;
}
.status[data-tone="pending"]::before {
  width: 0.6em;
  height: 0.6em;
  vertical-align: 0.05em;
  border-radius: 50%;
  background: var(--status-pending, var(--red-deep));
}

.count { color: var(--ink-soft); font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.count--under { margin-top: 0.5rem; text-align: right; }
.count[data-tone="near"] { color: var(--red-deep); font-weight: 700; }

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

/* The way into a chat from its section page; messages themselves only show in the chat. */
.chat-link .chip { margin-right: 0; }

/* --- Home screen guide: numbered steps, each with a schematic of the phone's screen where
   the yellow highlight marks what to tap. ----------------------------------------------------- */

.guide-steps {
  counter-reset: step;
  max-width: 34rem;
  margin-bottom: 1rem;
  list-style: none;
  padding: 0;
  display: grid;
  gap: 2rem;
}

.guide-steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  column-gap: 0.9rem;
  row-gap: 0.5rem;
  align-items: start;
}

.guide-steps > li > * { grid-column: 2; }

.guide-steps > li::before {
  content: counter(step);
  grid-column: 1;
  grid-row: 1 / span 3;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 2px var(--ink);
  font-size: 1.125rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.guide-steps strong { font-weight: 800; }
.guide-step__aside { color: var(--ink-soft); font-size: 1rem; }

/* A phone button named in the text, drawn as it looks on the phone. */
.guide-key {
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  margin-block: -0.2em;
  margin-inline: 0.1em;
  vertical-align: -0.45em;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--ink);
  color: var(--ink);
}

.guide-key .icon { width: 1.05em; height: 1.05em; }

#install-button { margin-bottom: 0.5rem; }

.guide-fig { display: block; width: 100%; max-width: 20rem; height: auto; margin-top: 0.5rem; color: var(--ink); }
.guide-fig text { font-family: var(--font); font-size: 15px; fill: var(--ink); }
.guide-fig .t-b { font-weight: 700; }
.guide-fig .t-soft { fill: var(--ink-soft); }
.guide-fig .t-small { font-size: 12px; }
.guide-fig .ui { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.guide-fig .dim { fill: color-mix(in srgb, var(--ink) 12%, var(--paper)); }
.guide-fig .hl { fill: var(--yellow); stroke: var(--ink); stroke-width: 2.5; }
.guide-fig .ln { fill: none; stroke: var(--ink); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.guide-fig .app { fill: var(--green); }
.guide-fig .star { fill: var(--yellow); }
.guide-fig .on { fill: var(--green); }
.guide-fig .knob { fill: var(--paper); }

/* --- Chat pages ---------------------------------------------------------------------------- */

/* Full-height column: a compact land header, the scrolling thread, and the reply box pinned
   at the bottom. The thread opens scrolled to its newest message. */
.chat__view:not([hidden]) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat-head {
  --focus: var(--yellow);
  --land: var(--red);
  flex: none;
  position: relative;
  isolation: isolate;
  color: var(--paper);
  padding: 0.9rem var(--gutter) 1.9rem;
}

.chat-head__inner { max-width: var(--measure); margin-inline: auto; }
.chat-head--green { --land: var(--green); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.75rem;
  padding: 0.35rem 1rem 0.35rem 0.7rem;
  border: 2px solid var(--paper);
  border-radius: 999px;
  color: var(--paper);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.4s var(--spring), background-color 0.2s var(--out);
}

.back-link:hover { background: color-mix(in srgb, var(--paper) 16%, transparent); }
.back-link:active { transform: scale(0.96); }

.chat-head__title {
  margin: 0.8rem 0 0.3rem;
  font-weight: 800;
  font-size: clamp(1.6rem, 6.5vw, 2.5rem);
  line-height: 1;
  letter-spacing: -0.03em;
  overflow-wrap: break-word;
}

.chat-head__lead { display: block; font-size: 1rem; letter-spacing: 0; margin-bottom: 0.2rem; }
/* Context for the chat, scrolled away with the oldest messages so the pinned header stays small. */
.chat-intro {
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto 1.25rem;
  color: var(--ink-soft);
  font-size: 1rem;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 1rem var(--gutter) 1.25rem;
}

.chat-scroll:focus { outline: none; }

/* margin-top: auto keeps a short thread at the bottom, next to the reply box. */
.chat-thread { width: 100%; max-width: var(--measure); margin: auto auto 0; }

.chat-composer {
  flex: none;
  background: var(--paper);
  padding: 0.75rem var(--gutter) calc(0.6rem + env(safe-area-inset-bottom));
}

.chat-composer__inner { max-width: var(--measure); margin-inline: auto; }

/* At large text sizes the button drops under the field instead of squeezing it. */
.chat-composer__row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: flex-end; gap: 0.6rem; }

.chat-composer__field {
  flex: 1 1 12rem;
  min-width: 0;
  min-height: 3rem;
  max-height: 9rem;
  padding: 0.65rem 1.1rem;
  border-radius: 1.5rem;
  resize: none;
  field-sizing: content;
}

.chat-composer__meta {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-top: 0.35rem;
}

.chat-composer .status { margin-top: 0; min-height: 0; }
.chat-composer .count { margin-left: auto; }

/* --- Threads ----------------------------------------------------------------------------- */

.thread {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.thread[data-empty]:not([data-empty=""])::before {
  content: attr(data-empty);
  color: var(--ink-soft);
}

.msg {
  max-width: min(88%, 30rem);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.msg--mine { align-self: flex-end; align-items: flex-end; text-align: right; }
.msg--theirs { align-self: flex-start; }

.msg__who {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.msg__text {
  padding: 0.75rem 1.1rem;
  border-radius: 1.25rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left;
}

.msg--mine .msg__text { background: var(--red); color: var(--paper); border-bottom-right-radius: 0.4rem; }
.msg--theirs .msg__text { background: var(--paper); border: 2px solid var(--line); border-bottom-left-radius: 0.4rem; }

.msg__time { font-size: 0.875rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* --- Loading --------------------------------------------------------------------------- */

.view--loading {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  background: var(--red);
  color: var(--paper);
  padding: var(--gutter);
}

.view--loading-green { background: var(--green); --status-error: #ffd76a; }

.loading-text { font-size: 1.5rem; font-weight: 800; text-align: center; }

/* --- First reveal: Tomten's red curtain ------------------------------------------------ */

.reveal {
  --focus: var(--yellow);
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--red);
  color: var(--paper);
  overflow: hidden;
}

/* Scrolls on its own so large text never pushes "Visa vem" out of reach; the curtain's
   coast stays outside it. */
.reveal__scroll {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: var(--gutter);
}

@media (max-height: 36rem) {
  .reveal__tree { display: none; }
}

.reveal__inner {
  margin: auto;
  max-width: 30rem;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 1rem;
}

.reveal__tree { width: clamp(7rem, 30vw, 10rem); height: auto; }
.reveal__tree .art-green { fill: var(--green); }

.reveal__title {
  font-size: clamp(2.75rem, 13vw, 5rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.reveal .capsule { margin-top: 1rem; }

/* During the reveal the rest of the page stays blank, so the first thing the coast
   uncovers is never the recipient's name in a smaller heading. */
.is-unveiling .ground { opacity: 0; }
.ground { transition: opacity 0.4s var(--out); }

/* The name lands once the curtain is gone, with the map's small overshoot. */
.is-revealing .recipient__name { animation: name-land 0.4s var(--spring); }

@keyframes name-land {
  from { opacity: 0; transform: translateY(0.4em) scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* --- Arrangera: name tokens on green land, a sheet per person ------------------------------ */

.board-head { --status-error: #ffd76a; }
.board-head .on-green { margin-bottom: 1.5rem; }

.tokens {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.tokens:empty { display: none; }

.token {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 3rem;
  max-width: 100%;
  padding: 0.6rem 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 1.0625rem;
  line-height: 1.15;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 0.4s var(--spring), background-color 0.2s var(--out);
}

.token:hover { background: var(--cream); }
.token:active { transform: scale(0.96); }
.token.is-open { outline: 3px solid var(--yellow); outline-offset: 3px; }
.token__chip { margin-right: -0.6rem; font-variant-numeric: tabular-nums; }

.add-person {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  max-width: 30rem;
}

.field--token,
.field--short {
  border-radius: 999px;
  min-height: 3rem;
  padding-block: 0.6rem;
  padding-inline: 1.25rem;
  font-weight: 700;
}

.field--token { flex: 1 1 12rem; width: auto; }
.field:disabled { opacity: 0.6; cursor: not-allowed; }

/* "Dra lotter" straddles the head's coast, half on the land and half on the ground. */
.drawbar {
  position: relative;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: -1.75rem auto 0;
  padding-inline: var(--gutter);
}

.drawbar__inner { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 1rem; }
.drawbar .count { padding-bottom: 0.3rem; font-size: 1rem; }
.drawbar__status { max-width: var(--measure); }

.board-head + .drawbar + .ground { padding-top: clamp(2rem, 6vw, 3rem); }

.rules,
.saved,
.codes {
  list-style: none;
  padding: 0;
  margin: 0;
}

.rules { display: grid; gap: 0.5rem; font-weight: 700; }

.rules li { display: flex; gap: 0.7rem; align-items: baseline; }

.rules li::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 2px var(--ink);
  transform: translateY(-0.12em);
}

.rules[data-empty]:not([data-empty=""])::before,
.excl[data-empty]:not([data-empty=""])::before {
  content: attr(data-empty);
  color: var(--ink-soft);
  font-weight: 400;
}

.saved { display: grid; gap: 1rem; }

.saved__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.saved__item strong { display: block; overflow-wrap: anywhere; }
.saved__meta { display: block; color: var(--ink-soft); font-size: 1rem; font-variant-numeric: tabular-nums; }

/* The codes: the name small, the code large enough to read aloud across a table. */
.codes { display: grid; gap: 1.5rem; }

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 1rem;
}

.code-row__name { font-weight: 700; overflow-wrap: anywhere; }

.code-row__code {
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 1.875rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  user-select: all;
}

.code-row__status { grid-column: 1 / -1; margin-top: 0; }

#codes-title:focus { outline: none; }

/* --- Sheets: paper rising from the bottom edge ------------------------------------------- */

.sheet {
  width: 100%;
  max-width: var(--measure);
  max-height: none;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 1.25rem 1.25rem 0 0;
  background: var(--paper);
  color: var(--ink);
  overflow: visible;
}

/* Paper under the bottom edge, so the spring's overshoot never shows a gap. */
.sheet::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 4rem;
  background: var(--paper);
}

.sheet::backdrop { background: color-mix(in srgb, var(--ink) 60%, transparent); }
.sheet[open] { animation: sheet-rise 0.4s var(--spring); }
.sheet[open]::backdrop { animation: backdrop-in 0.2s var(--out); }

@keyframes sheet-rise {
  from { transform: translateY(45%); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes backdrop-in { from { opacity: 0; } }

.sheet__inner {
  max-height: min(88dvh, 52rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.75rem var(--gutter) calc(1.5rem + env(safe-area-inset-bottom));
}

.sheet__title {
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 1.875rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  overflow-wrap: anywhere;
}

.sheet__field { display: block; margin-top: 1.25rem; }
.sheet__label { display: block; font-weight: 700; margin-bottom: 0.4rem; padding: 0; }
.sheet .help { margin-bottom: 0; }

.excl-set { border: 0; padding: 0; margin: 1.5rem 0 0; min-width: 0; }
.excl { list-style: none; padding: 0; margin: 0; }

.excl__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 1rem;
}

.excl__check { margin-top: 0; align-items: center; min-height: 3rem; flex: 1 1 10rem; overflow-wrap: anywhere; }

/* "Båda håll": a capsule switch that turns yellow, the highlighter's colour. */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 3rem;
  margin-left: auto;
  color: var(--ink-soft);
  font-size: 1rem;
  cursor: pointer;
}

.switch input {
  position: absolute;
  left: 0;
  width: 2.9rem;
  height: 1.7rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch__track {
  position: relative;
  flex: none;
  width: 2.9rem;
  height: 1.7rem;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--ink);
  transition: background-color 0.2s var(--out);
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.4s var(--spring);
}

.switch input:checked + .switch__track { background: var(--yellow); }
.switch input:checked + .switch__track::after { transform: translateX(1.2rem); }
.switch input:checked ~ .switch__label { color: var(--ink); font-weight: 700; }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--focus); outline-offset: 3px; }

.sheet__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .capsule { transition: background-color 0.2s; }
  .capsule:active { transform: none; }
  .is-revealing .recipient__name { animation: none; }
  .token { transition: background-color 0.2s; }
  .token:active { transform: none; }
  .sheet[open] { animation: backdrop-in 0.25s var(--out); }
  .switch__track::after { transition: none; }
}
