/*
 * Friends for Adam Hamilton
 * A warm, homespun, prairie-and-paper look. Nothing slick or corporate.
 */

:root {
  --paper:      #fbf7ee;  /* warm cream page */
  --paper-2:    #f4ecda;  /* aged paper panel */
  --card:       #fffdf8;  /* index-card white */
  --ink:        #2c2a24;  /* soft black ink */
  --ink-soft:   #5c574c;  /* faded ink */
  --line:       #ddd0b4;  /* dry-grass border */
  --gold:       #e0a92e;  /* sunflower gold */
  --gold-deep:  #b9801a;  /* deeper sunflower */
  --sky:        #2f5d86;  /* prairie sky blue */
  --sky-soft:   #eaf1f6;
  --barn:       #a4432f;  /* barn red, used sparingly */
  --leaf:       #5b7a3a;  /* prairie green */
  --shadow:     0 2px 0 rgba(120, 96, 40, 0.10), 0 8px 24px rgba(90, 70, 30, 0.10);
  --serif:      "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:       "Segoe UI", Tahoma, Verdana, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 12% 20%, rgba(224, 169, 46, 0.06), transparent 40%),
    radial-gradient(circle at 88% 12%, rgba(47, 93, 134, 0.05), transparent 42%);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
}

a { color: var(--sky); }

/* ---------- Masthead ---------- */
.masthead {
  border-bottom: 3px double var(--line);
  background: linear-gradient(180deg, #fffdf7, var(--paper));
}
.masthead__inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 24px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.mark {
  font-size: 2rem;
  line-height: 1;
  filter: saturate(1.05);
}
.masthead__titles { flex: 1 1 auto; }
.masthead h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.2px;
  color: var(--ink);
}
.masthead h1 .accent { color: var(--gold-deep); }
.masthead .tagline {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
  font-style: italic;
}

/* ---------- Layout shell ---------- */
.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 24px 60px;
}

/* ---------- Name notecard ---------- */
.namecard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 24px;
  position: relative;
}
.namecard::before {
  content: "";
  position: absolute;
  left: 18px; right: 18px; top: 8px;
  height: 0;
  border-top: 1px dashed var(--line);
}
.namecard__label {
  display: block;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin-bottom: 10px;
  font-weight: 700;
}
.namecard__fields {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.field { flex: 1 1 240px; }
.field label {
  display: block;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink);
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.field input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(224, 169, 46, 0.22);
}
.namecard__hint {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-style: italic;
}

/* ---------- Two-column reader ---------- */
.reader {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 26px;
  align-items: start;
}

/* Left: the index / table of contents */
.toc {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  position: sticky;
  top: 16px;
}
.toc__head {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-deep);
  font-weight: 700;
  padding: 6px 10px 10px;
}
.toc__list { list-style: none; margin: 0; padding: 0; }
.toc__item { margin: 0; }
.toc__btn {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 1.02rem;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1.35;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.toc__btn:hover { background: rgba(224, 169, 46, 0.14); }
.toc__btn.is-active {
  background: #fff;
  border-left-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 600;
}

/* Right: the letter on paper */
.letter {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.letter__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 22px;
  background: linear-gradient(180deg, #fffdf7, var(--paper-2));
  border-bottom: 1px solid var(--line);
}
.letter__title {
  margin: 0;
  font-size: 1.3rem;
  color: var(--ink);
}
.subjectline {
  padding: 14px 22px 4px;
}
.subjectline__label,
.bodyblock__label {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}
.subjectline__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}
.subjectline__text {
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--ink);
}
.bodyblock { padding: 8px 22px 22px; }
.bodyblock__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.bodyblock__text {
  white-space: pre-wrap;
  font-size: 1.06rem;
  line-height: 1.62;
  color: #33302a;
  background: repeating-linear-gradient(
    transparent,
    transparent 32px,
    rgba(47, 93, 134, 0.05) 33px
  );
  padding-top: 2px;
}

/* Copy buttons */
.copybtn {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--sky);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0,0,0,0.12);
  transition: background 0.12s ease, transform 0.06s ease;
}
.copybtn:hover { background: #274c6e; }
.copybtn:active { transform: translateY(1px); }
.copybtn.is-copied { background: var(--leaf); }
.copybtn--big { padding: 10px 20px; font-size: 0.9rem; }

/* Placeholder highlight so blanks are easy to spot */
.tok {
  background: rgba(224, 169, 46, 0.28);
  border-radius: 4px;
  padding: 0 3px;
}

/* ---------- Masthead nav link ---------- */
.masthead__nav {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--sky);
  border: 1px solid var(--line);
  background: var(--card);
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.masthead__nav:hover { background: var(--paper-2); }

/* ---------- About page ---------- */
.about { max-width: 900px; }
.disclaimer {
  background: var(--sky-soft);
  border: 1px solid #cfe0ec;
  border-left: 4px solid var(--sky);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 0.98rem;
  color: #244a68;
  margin-bottom: 26px;
  line-height: 1.55;
}
.about__card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.about__figure {
  float: right;
  width: 300px;
  max-width: 42%;
  margin: 6px 0 16px 26px;
  text-align: center;
}
.about__figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  border: 5px solid #fff;
  box-shadow: var(--shadow);
}
.about__figure figcaption {
  margin-top: 8px;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-soft);
}
.about__name { margin: 0; font-size: 1.7rem; }
.about__role { margin: 2px 0 16px; color: var(--gold-deep); font-style: italic; }
.about__body p { margin: 0 0 14px; }
.about__sign { font-style: italic; color: var(--ink-soft); }
.about__back { margin-top: 22px; clear: both; }

@media (max-width: 600px) {
  .about__figure {
    float: none;
    width: 240px;
    max-width: 100%;
    margin: 0 auto 18px;
  }
}

/* ---------- Footer ---------- */
.foot {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
  border-top: 3px double var(--line);
  color: var(--ink-soft);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.foot a { color: var(--ink-soft); }

/* ---------- Flash ---------- */
.flash {
  max-width: 1120px;
  margin: 12px auto 0;
  padding: 10px 18px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.flash--notice { background: #e7f2e0; border: 1px solid var(--leaf); color: #34521f; }
.flash--alert  { background: #f6e2dd; border: 1px solid var(--barn); color: #7a2c1c; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  body { font-size: 17px; }
  .reader { grid-template-columns: 1fr; }
  .toc { position: static; }
  .toc__list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
}
@media (max-width: 520px) {
  .toc__list { grid-template-columns: 1fr; }
  .masthead h1 { font-size: 1.5rem; }
}

/* ---------- Admin ---------- */
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 24px; }
.admin-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.admin-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table th { font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); background: var(--paper-2); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.order-arrows { display: flex; gap: 6px; }
.btn {
  font-family: var(--sans); font-size: 0.85rem; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--paper-2); }
.btn--primary { background: var(--sky); border-color: var(--sky); color: #fff; }
.btn--primary:hover { background: #274c6e; }
.btn--gold { background: var(--gold); border-color: var(--gold-deep); color: #3a2c07; }
.btn--danger { color: var(--barn); border-color: #e2c3ba; }
.btn--small { padding: 5px 10px; font-size: 0.78rem; }
.form-field { margin-bottom: 18px; }
.form-field label { display: block; font-family: var(--sans); font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.form-field input[type=text],
.form-field textarea {
  width: 100%; font-family: var(--serif); font-size: 1.02rem; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form-field textarea { min-height: 380px; line-height: 1.5; }
.form-field input:focus, .form-field textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224,169,46,0.22); }
.form-help { font-size: 0.85rem; color: var(--ink-soft); margin-top: 6px; font-style: italic; }
.errors { background: #f6e2dd; border: 1px solid var(--barn); color: #7a2c1c; padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; }
.errors ul { margin: 6px 0 0 18px; }
.admin-note { background: var(--sky-soft); border: 1px solid #cfe0ec; border-radius: 8px; padding: 12px 16px; font-size: 0.92rem; color: #244a68; margin-bottom: 20px; }

/* ---------- Welcome modal ---------- */
body.no-scroll { overflow: hidden; }

.welcome {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.welcome[hidden] { display: none; }

.welcome__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 42, 36, 0.55);
  backdrop-filter: blur(2px);
  animation: welcome-fade 0.25s ease both;
}

.welcome__card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card);
  background-image:
    radial-gradient(circle at 10% 0%, rgba(224, 169, 46, 0.08), transparent 45%),
    radial-gradient(circle at 100% 100%, rgba(47, 93, 134, 0.06), transparent 45%);
  border: 1px solid var(--line);
  border-top: 5px solid var(--gold);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(60, 45, 20, 0.35);
  padding: 34px 40px 32px;
  animation: welcome-rise 0.3s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

/* How It Works page */
.howto { max-width: 980px; }

.howto__top { margin-bottom: 22px; }
.howto__back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 22px;
  box-shadow: 0 2px 0 rgba(120, 96, 40, 0.15);
}
.howto__back:hover { background: var(--paper-2); }
.howto__back:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.howto__arrow { font-size: 1.35rem; line-height: 1; }

.howto__title {
  font-family: var(--serif);
  font-size: 2.1rem;
  color: var(--ink);
  margin: 0 0 10px;
}
.howto__intro {
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.6;
  margin: 0 0 22px;
  max-width: 70ch;
}

.loom {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 30px rgba(60, 45, 20, 0.22);
}
.loom__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.welcome__x {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}
.welcome__x:hover { color: var(--barn); background: rgba(164, 67, 47, 0.08); }
.welcome__x:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.welcome__mark {
  font-size: 2.4rem;
  line-height: 1;
  margin-bottom: 6px;
}
.welcome__title {
  font-family: var(--serif);
  font-size: 1.9rem;
  color: var(--ink);
  margin: 0 0 14px;
}
.welcome__body p {
  margin: 0 0 14px;
  color: var(--ink);
  line-height: 1.6;
}
.welcome__body p:last-child { margin-bottom: 0; }
.welcome__aside {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.welcome__go {
  margin-top: 22px;
  display: inline-block;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: var(--gold-deep);
  border: none;
  border-radius: 10px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(120, 96, 40, 0.25);
}
.welcome__go:hover { background: #a6710f; }
.welcome__go:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

@keyframes welcome-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes welcome-rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 560px) {
  .welcome__card { padding: 30px 22px 26px; }
  .welcome__title { font-size: 1.6rem; }
}

/* ---------- Admin analytics dashboard ---------- */
.dash-note {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
  padding: 16px 18px;
  color: var(--ink-soft);
  font-size: 0.98rem;
}
.dash-note code {
  font-family: var(--sans);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.85em;
}

.dash-period { display: flex; gap: 6px; margin-bottom: 18px; }
.dash-period__btn {
  font-family: var(--sans); font-size: 0.82rem; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); text-decoration: none;
}
.dash-period__btn:hover { background: var(--paper-2); }
.dash-period__btn.is-active {
  background: var(--sky); border-color: var(--sky); color: #fff;
}

.dash-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 14px; margin-bottom: 18px;
}
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow);
}
.stat__num {
  font-family: var(--serif); font-weight: 700; color: var(--gold-deep);
  font-size: 2.2rem; line-height: 1.1; word-break: break-word;
}
.stat__label {
  font-family: var(--sans); font-size: 0.78rem; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-soft); margin-top: 4px;
}

.dash-chart {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px 12px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.dash-chart__head, .dash-card__head {
  font-family: var(--sans); font-size: 0.82rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft);
  margin: 0 0 12px;
}
.dash-chart__svg-wrap { width: 100%; }
.dash-chart__svg { width: 100%; height: 200px; display: block; overflow: visible; }
.dash-chart__axis { stroke: var(--line); stroke-width: 1; }
.dash-chart__area { fill: rgba(224, 169, 46, 0.16); stroke: none; }
.dash-chart__line { fill: none; stroke: var(--gold-deep); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dash-chart__peak { fill: var(--barn); }
.dash-chart__xlabel { font-family: var(--sans); font-size: 11px; fill: var(--ink-soft); }

.dash-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 16px;
}
.dash-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow);
}
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list__row {
  display: grid; grid-template-columns: minmax(0, 1fr) 90px auto;
  align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}
.dash-list__row:last-child { border-bottom: 0; }
.dash-list__label {
  font-size: 0.96rem; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dash-list__count { font-family: var(--sans); font-weight: 700; color: var(--ink); font-size: 0.9rem; text-align: right; }
.dash-bar { display: block; height: 8px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.dash-bar__fill { display: block; height: 100%; background: var(--sky); border-radius: 999px; }

.dash-empty { color: var(--ink-soft); font-style: italic; margin: 6px 0; }
.dash-foot { color: var(--ink-soft); font-size: 0.88rem; margin-top: 16px; }

@media (max-width: 680px) {
  .dash-stats { grid-template-columns: 1fr; }
  .dash-cols { grid-template-columns: 1fr; }
  .stat__num { font-size: 1.9rem; }
}

/* ---------- Admin rich-text editor (message body) ---------- */
.editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.editor__toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
.editor__bold {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.05rem;
  width: 34px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}
.editor__bold:hover { background: var(--paper); }
.editor__bold.is-active {
  background: var(--gold);
  border-color: var(--gold-deep);
  color: #fff;
}
.editor__bold:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.editor__hint { font-family: var(--sans); font-size: 0.82rem; color: var(--ink-soft); }
.editor__area {
  min-height: 380px;
  padding: 12px 14px;
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
}
.editor__area:focus { box-shadow: inset 0 0 0 2px rgba(224, 169, 46, 0.22); }
.editor__area strong, .editor__area b { font-weight: 700; }
