:root {
  --paper: #f5efe3;
  --paper-deep: #ebe2d0;
  --ink: #2a241d;
  --ink-soft: #6d6355;
  --line: #d8ccb6;
  --accent: #c2492b;
  --accent-deep: #9c3519;
  --green: #2a8a6e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 14px;

  color-scheme: light;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 0%, #fbf7ef 0%, var(--paper) 55%, var(--paper-deep) 100%) fixed;
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

a { color: var(--accent-deep); }

h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.15; }

.muted { color: var(--ink-soft); }

/* Masthead ---------------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  font: 600 1.2rem var(--serif);
  text-decoration: none;
}


.masthead__nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.masthead__nav a:not(.button) { color: var(--ink); text-decoration: none; }
.brand, .masthead__nav a, .masthead__nav button { white-space: nowrap; }

@media (max-width: 520px) {
  .masthead__nav { gap: 0.75rem; }
}

/* The three ways to look at your jars. */
.views {
  display: flex;
  gap: 0.25rem;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  max-width: 1200px;
  margin: 0 auto 1rem;
  overflow-x: auto;
}

.views__tab {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  color: var(--ink-soft);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.views__tab:hover { color: var(--ink); background: rgb(255 255 255 / 0.5); }
.views__tab[aria-current="page"] { color: var(--paper); background: var(--ink); }

.page {
  padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem;
  max-width: 1200px;
  margin: 0 auto;
}

.page__title { font-size: clamp(1.8rem, 4vw, 2.4rem); margin: 0.5rem 0 1.5rem; }

.narrow { max-width: 32rem; margin: 1rem auto; }

.flash {
  max-width: 40rem;
  margin: 0 auto 1rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  background: #fffaf0;
  border: 1px solid var(--line);
  text-align: center;
}

.flash--alert { border-color: #e0a090; color: var(--accent-deep); }

/* Buttons and forms ------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: 600 1rem var(--sans);
  text-decoration: none;
  cursor: pointer;
}

.button:hover { background: #000; }
.button--small { padding: 0.4rem 0.9rem; font-size: 0.9rem; }
.button--quiet { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.button--quiet:hover { background: #fffaf0; }

.link-button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.link-button--danger { color: var(--accent-deep); margin-top: 2rem; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}

input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.stacked-form { display: grid; gap: 1rem; }
.stacked-form label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.95rem; }
.stacked-form__actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.sign-in { text-align: center; }
.sign-in .stacked-form { text-align: left; }

/* The jar ----------------------------------------------------------------- */

.jar { display: block; overflow: visible; }
.jar--large { width: 100%; height: min(56vh, 560px); }
.jar--medium { width: 100%; height: 240px; }
.jar--small { width: 100%; height: 150px; }
.jar--tiny { width: 66px; height: 86px; }

.jar__back { fill: rgb(255 255 255 / 0.45); }

.jar__glass {
  fill: none;
  stroke: rgb(120 140 150 / 0.55);
  stroke-width: 3;
  stroke-linejoin: round;
}

.jar__shine {
  fill: none;
  stroke: rgb(255 255 255 / 0.75);
  stroke-width: 9;
  stroke-linecap: round;
}

.jar__shine--thin { stroke-width: 4; stroke: rgb(255 255 255 / 0.55); }

.jar__rim {
  fill: rgb(255 255 255 / 0.6);
  stroke: rgb(120 140 150 / 0.55);
  stroke-width: 2.5;
}

.marble { filter: drop-shadow(0 1px 1px rgb(40 30 20 / 0.25)); }

/* The marble designs live in one hidden sprite; jars and icons <use> them.
   Not display: none, which would switch off their gradients. */
.marble-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.marble-icon { flex: none; display: inline-block; vertical-align: middle; overflow: visible; filter: drop-shadow(0 1px 1px rgb(40 30 20 / 0.25)); }
.marble-icon--tiny { width: 0.8rem; height: 0.8rem; }
.marble-icon--small { width: 1.1rem; height: 1.1rem; }
.marble-icon--brand { width: 1.4rem; height: 1.4rem; }
.marble-icon--avatar { width: 1.6rem; height: 1.6rem; margin-right: 0.4rem; }
.marble-icon--medium { width: 2rem; height: 2rem; }

/* New marbles fall in once and settle; nothing loops. */
.marble--dropping {
  animation: marble-drop 650ms cubic-bezier(0.3, 0, 0.6, 1) both;
}

@keyframes marble-drop {
  0%   { transform: translateY(calc(-1px * var(--drop))); }
  70%  { transform: translateY(0); }
  85%  { transform: translateY(-6px); }
  100% { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .marble--dropping { animation: none; }
}

/* Contacts list ----------------------------------------------------------- */

.contact-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.25rem;
}

.contact-card {
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  padding: 1rem 0.75rem;
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  transition: background 150ms;
}

.contact-card:hover { background: rgb(255 255 255 / 0.55); }
.contact-card__name { font: 600 1.1rem var(--serif); text-align: center; }
.contact-card__count { color: var(--ink-soft); font-size: 0.9rem; }

.empty { max-width: 28rem; margin: 2rem auto; text-align: center; }

[hidden] { display: none !important; }

/* Photos ------------------------------------------------------------------ */

.avatar {
  display: block;
  object-fit: cover;
  border-radius: 50%;
  background: var(--paper-deep);
  box-shadow: 0 0 0 3px rgb(255 255 255 / 0.8), 0 2px 8px rgb(0 0 0 / 0.12);
}
.avatar--large { flex: none; width: clamp(3rem, 8vw, 4.5rem); height: clamp(3rem, 8vw, 4.5rem); }
.avatar--small { display: inline-block; width: 1.6rem; height: 1.6rem; margin-right: 0.4rem; vertical-align: -0.35rem; }

.photo-form { display: flex; align-items: center; gap: 0.5rem; }
.photo-form label { cursor: pointer; }
.photo-form label:focus-within { outline: 2px solid var(--accent-deep); outline-offset: 2px; }

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

/* One contact: the jar is the stage ------------------------------------- */

.contact {
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 900px) {
  .contact { grid-template-columns: minmax(0, 1.6fr) minmax(18rem, 1fr); align-items: start; }
  .details { position: sticky; top: 1rem; }
}

.stage { display: grid; justify-items: center; text-align: center; }
.stage__header { display: flex; align-items: center; justify-content: center; gap: 0.9rem; }
.stage__name { font-size: clamp(2rem, 5vw, 3.2rem); margin: 0; }

.stage__count { margin: 0.25rem 0 1rem; color: var(--ink-soft); font-size: 1.1rem; }
.stage__count strong { display: block; color: var(--ink); font: 600 clamp(3rem, 8vw, 4.5rem)/1 var(--serif); }

.marble-controls { display: grid; gap: 0.75rem; width: min(100%, 26rem); }

.marble-controls__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

/* "+" comes first in the markup so Enter adds; "−" is shown on the left. */
.marble-button--remove { order: -1; }

.marble-controls .marble-controls__count { width: 5rem; flex: none; text-align: center; font-size: 1.2rem; }

.marble-button {
  flex: none;
  width: 4rem;
  height: 4rem;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font: 600 2rem/1 var(--sans);
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.2), 0 3px 8px rgb(60 40 20 / 0.2);
  transition: transform 100ms;
}

.marble-button:active { transform: translateY(2px); }
.marble-button--add { background: radial-gradient(circle at 35% 30%, #5cc4a5, var(--green)); width: 4.75rem; height: 4.75rem; }
.marble-button--remove { background: radial-gradient(circle at 35% 30%, #a99c8a, #776b5b); }
.marble-button:disabled { opacity: 0.35; cursor: not-allowed; }

/* Details sidebar ---------------------------------------------------------- */

.details {
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  background: rgb(255 253 248 / 0.8);
  box-shadow: 0 1px 0 var(--line), 0 10px 30px rgb(80 60 30 / 0.08);
}

.details__actions { display: flex; justify-content: flex-end; }

.detail-section + .detail-section { margin-top: 1.5rem; }
.detail-section h2 { font-size: 1.1rem; margin: 0 0 0.5rem; color: var(--ink-soft); }

.detail-list { list-style: none; padding: 0; margin: 0 0 0.5rem; display: grid; gap: 0.35rem; }
.detail-list li { display: flex; align-items: center; gap: 0.5rem; }
.detail-list form { margin-left: auto; }

.remove-button {
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}

.remove-button:hover { color: var(--accent-deep); background: var(--paper); }

.add-detail summary { cursor: pointer; color: var(--ink-soft); font-size: 0.9rem; }
.inline-form { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form .button { justify-self: start; }

.notes p { margin: 0 0 0.6rem; }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; font-size: 0.95rem; }
.history__item { display: grid; padding-left: 1rem; border-left: 3px solid var(--line); }
.history__item--added-marbles { border-color: var(--green); }
.history__item--removed-marbles { border-color: #a99c8a; }
.history__description { font-style: italic; }
.history time { color: var(--ink-soft); font-size: 0.8rem; }

/* Groups ------------------------------------------------------------------- */

.lede { font-size: 1.1rem; max-width: 36rem; }

.chips { list-style: none; padding: 0; margin: 0 0 0.5rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.3rem 0.2rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--group, var(--line)) 16%, white);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--group, var(--line)) 45%, transparent);
  font-size: 0.9rem;
}

.chip a { color: var(--ink); text-decoration: none; font-weight: 600; }
.chip .remove-button { font-size: 1rem; padding: 0 0.3rem; }

.chip--button { border: 0; padding-right: 0.7rem; color: var(--ink); font: 600 0.9rem var(--sans); cursor: pointer; }
.chip--button:hover { background: color-mix(in srgb, var(--group) 30%, white); }
.chip--button[aria-pressed="true"] { background: var(--group); color: white; }
.chips--add { margin-top: 0.6rem; }

.stage__groups { justify-content: center; margin: 0.6rem 0 0; }

.shelf { margin-bottom: 2.5rem; }
.shelf__header { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.shelf__name { margin: 0; font-size: 1.5rem; }
.shelf__edit { margin-left: auto; }
.shelf__empty { padding: 1rem 0 1.25rem; border-bottom: 10px solid #b98e5c; }

/* Jars stand on a wooden plank in the group's colour-tinted light. */
.shelf__jars {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0 0.5rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  border-bottom: 12px solid #b98e5c;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(to top, color-mix(in srgb, var(--group, #b98e5c) 14%, transparent), transparent 70%);
  box-shadow: 0 10px 14px -8px rgb(80 50 20 / 0.45);
}

.shelf__jars li { flex: 0 0 9.5rem; }
.shelf__jars .contact-card { padding-bottom: 0.5rem; }
.shelf--loose .shelf__jars { border-bottom-color: var(--line); box-shadow: none; }

.new-group {
  max-width: 30rem;
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  background: rgb(255 253 248 / 0.8);
  box-shadow: 0 1px 0 var(--line), 0 10px 30px rgb(80 60 30 / 0.08);
}

.new-group h2 { margin-top: 0; }

.color-picker, .member-picker { border: 0; padding: 0; margin: 0; }
.color-picker legend, .member-picker legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.35rem; }
.color-picker__marbles { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.color-picker__option {
  padding: 0.3rem;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 120ms;
}

.color-picker__option:hover { transform: translateY(-2px); }
.color-picker__option:has(:checked) { box-shadow: 0 0 0 3px var(--ink); }
.color-picker__option:has(:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }

.member-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.35rem; }

.stacked-form .member-picker__option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-radius: 10px;
  font-weight: 400;
  cursor: pointer;
}

.member-picker__option:has(:checked) { background: rgb(255 255 255 / 0.75); box-shadow: inset 0 0 0 1px var(--line); }
.member-picker__option .avatar { margin: 0; }

.acquaintance { display: inline-flex; align-items: center; color: var(--ink); text-decoration: none; font-weight: 600; }
.acquaintance:hover { text-decoration: underline; }

/* Who knows who -------------------------------------------------------------- */

.network__legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }

/* Without JavaScript the jars simply line up; the controller adds --ready and
   places each one. */
.network__board {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 1px 1px, rgb(120 100 70 / 0.18) 1px, transparent 0) 0 0 / 22px 22px,
    rgb(255 253 248 / 0.6);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}

.network__strings { display: none; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.network__board--ready .network__strings { display: block; }

.network__string {
  fill: none;
  stroke: var(--string, #a8875c);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 1200;
  stroke-dashoffset: 0;
  animation: string-tie 900ms ease-out both;
  transition: opacity 200ms, stroke-width 200ms;
}

.network__jar {
  display: grid;
  justify-items: center;
  width: 108px;
  padding: 0.35rem 0.25rem;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 200ms, background 150ms;
}

.network__board--ready .network__jar {
  position: absolute;
  translate: -50% -50%;
  cursor: grab;
  animation: jar-pop 450ms cubic-bezier(0.3, 1.4, 0.6, 1) both;
  animation-delay: calc(var(--i) * 25ms);
}

.network__jar:hover, .network__jar:focus-visible { background: rgb(255 255 255 / 0.7); z-index: 2; }
.network__jar--held { cursor: grabbing; z-index: 3; background: rgb(255 255 255 / 0.85); box-shadow: 0 8px 20px rgb(60 40 20 / 0.18); }

.network__name { font: 600 0.9rem/1.2 var(--serif); text-align: center; }
.network__name .avatar--small { width: 1.2rem; height: 1.2rem; margin-right: 0.25rem; vertical-align: -0.25rem; }
.network__groups { display: flex; gap: 2px; margin-top: 2px; }

.network__board--tracing .network__jar:not(.is-traced),
.network__board--lit .network__jar:not(.is-lit) { opacity: 0.28; }
.network__board--tracing .network__string:not(.is-traced),
.network__board--lit .network__string:not(.is-lit) { opacity: 0.15; }
.network__string.is-traced, .network__string.is-lit { stroke-width: 4.5; }

.network__hint { text-align: center; margin-top: 0.75rem; }

/* Strings are tied once and jars pop into place once; nothing loops. */
@keyframes string-tie { from { stroke-dashoffset: 1200; } }
@keyframes jar-pop { from { scale: 0.4; opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .network__string, .network__board--ready .network__jar { animation: none; }
}
