/* App shell & components. Consumes tokens.css only — no raw values. */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--dusk-1), var(--dusk-2));
  background-attachment: fixed;
  color: var(--moon);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.wrap {
  max-width: 34rem;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-4) var(--sp-16);
}

/* ---------------------------------------------------------- header */

.masthead {
  text-align: center;
  margin-bottom: var(--sp-10);
}

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-2xl);
  letter-spacing: 0.01em;
  margin: 0 0 var(--sp-2);
  color: var(--paper);
}

.masthead .sub {
  font-size: var(--text-sm);
  color: var(--moon-soft);
  margin: 0;
}

.masthead .sub strong {
  color: var(--brass);
  font-weight: 600;
}

/* ------------------------------------------------------ status card */

.notice {
  background: rgb(255 255 255 / 0.04);
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: var(--radius-card);
  padding: var(--sp-4) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--moon-soft);
  margin-bottom: var(--sp-6);
  text-align: center;
}

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

/* --------------------------------------------------------- months */

.month {
  margin-bottom: var(--sp-8);
}

.month-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.month-head h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-xl);
  margin: 0;
  color: var(--moon);
}

.month-head .meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--moon-soft);
  letter-spacing: 0.08em;
}

/* sealed month = dusk card with outlined stamp */
.sealed {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  text-align: left;
  background: rgb(255 255 255 / 0.03);
  border: 1px dashed var(--slate);
  border-radius: var(--radius-card);
  color: var(--moon-soft);
  padding: var(--sp-4);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease);
}

.sealed:hover, .sealed:focus-visible { border-color: var(--brass); }

.sealed .stamp { flex: none; }

/* --------------------------------------------------------- stamps */

.stamp {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: var(--radius-stamp);
  border: 2px solid currentColor;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1.15;
  text-align: center;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: relative;
}

.stamp::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: inherit;
  border: 1px dashed currentColor;
  opacity: 0.6;
}

.stamp .d { display: block; font-size: 0.95em; }
.stamp .m { display: block; font-size: 0.7em; opacity: 0.85; }

/* ---------------------------------------------------------- cards */

.letters { display: grid; gap: var(--sp-3); }

.card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  text-align: left;
  font: inherit;
  border: none;
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  cursor: pointer;
  position: relative;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-fast) var(--ease);
}

.card:active { transform: scale(0.99); }

.card:focus-visible,
.sealed:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.card .stamp { flex: none; color: var(--wax); }

.card .body { min-width: 0; }

.card h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-lg);
  margin: 0 0 var(--sp-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

/* new-arrival wax dot */
.card.unread::after {
  content: "";
  position: absolute;
  top: calc(var(--sp-3) * -0.4);
  right: calc(var(--sp-3) * -0.2);
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--wax-bright), var(--wax));
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
}

/* upcoming ghost card */
.card.ghost {
  background: transparent;
  border: 1px dashed rgb(243 236 221 / 0.25);
  box-shadow: none;
  color: var(--moon-soft);
  cursor: default;
}

.card.ghost .stamp { color: var(--slate); }
.card.ghost h3 { color: var(--moon-soft); font-style: italic; }
.card.ghost .meta { color: var(--moon-soft); }

/* -------------------------------------------------------- the gate */

.gate {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-6) var(--sp-4);
  margin-top: var(--sp-3);
}

.gate p { margin: 0 0 var(--sp-3); font-size: var(--text-sm); color: var(--ink-soft); }

.gate form { display: flex; gap: var(--sp-2); }

.gate input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-card);
  background: #fffdf7;
  color: var(--ink);
}

.gate button {
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--sp-2) var(--sp-4);
  border: none;
  border-radius: var(--radius-card);
  background: var(--brass);
  color: #fff;
  cursor: pointer;
}

.gate button[disabled] { opacity: 0.6; cursor: wait; }

.gate .error {
  color: var(--wax);
  font-size: var(--text-sm);
  margin: var(--sp-2) 0 0;
  min-height: 1.2em;
}

.gate.shake { animation: shake var(--t-slow) var(--ease); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* seal-break flourish on unlock */
.month.unsealing .letters,
.month.unsealing .gate { animation: unseal var(--t-slow) var(--ease); }

@keyframes unseal {
  from { opacity: 0; transform: translateY(0.5rem); }
  to   { opacity: 1; transform: none; }
}

/* -------------------------------------------------------- reader */

.reader {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  box-shadow: var(--shadow-sheet);
  animation: sheet-in var(--t-slow) var(--ease);
}

@keyframes sheet-in {
  from { transform: translateY(4rem); opacity: 0.6; }
  to   { transform: none; opacity: 1; }
}

.reader .inner {
  max-width: 34rem;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6) var(--sp-16);
}

.reader .close {
  position: sticky;
  top: var(--sp-4);
  margin-left: auto;
  display: block;
  font: inherit;
  font-size: var(--text-sm);
  background: rgb(42 36 22 / 0.08);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
}

.reader .textsize {
  position: sticky;
  top: var(--sp-4);
  float: left;
  font: inherit;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  background: rgb(42 36 22 / 0.08);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
}

.reader footer {
  margin-top: var(--sp-10);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--paper-edge);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-soft);
  text-align: center;
  letter-spacing: 0.06em;
}

/* ----------------------------------------------------- installer */

.a2hs {
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  font-size: var(--text-sm);
  color: var(--moon-soft);
  margin-bottom: var(--sp-6);
}

.a2hs b { color: var(--moon); font-weight: 600; }

.a2hs .dismiss {
  background: none;
  border: none;
  color: var(--moon-soft);
  font: inherit;
  font-size: var(--text-xs);
  text-decoration: underline;
  cursor: pointer;
  margin-top: var(--sp-2);
  padding: 0;
}

/* ------------------------------------------------------ keepsake */

.keepsake { border-style: double; border-width: 3px; border-color: var(--brass); }

/* ------------------------------------------------------- footer */

.colophon {
  margin-top: var(--sp-16);
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--moon-soft);
  letter-spacing: 0.08em;
}

.colophon .cal {
  color: var(--brass);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The constellation: one mark per opened parcel, in that month's colour.
 * Unlabelled and unexplained — it just accumulates. */
.constellation {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-top: var(--sp-4);
}

.constellation .mark {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mark, var(--brass));
  opacity: 0.75;
}

/* On completion the marks gather into the emblem the finished app wears. */
.constellation.emblem {
  gap: 0;
  margin: 0 auto var(--sp-4);
  width: 3.25rem;
  height: 3.25rem;
  position: relative;
  animation: gather var(--t-slow) var(--ease);
}

.constellation.emblem .mark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  opacity: 1;
  /* seven marks around a small ring, in series order */
  transform:
    rotate(calc(var(--i, 0) * 51.43deg)) translateY(-1.35rem);
}

.constellation.emblem .mark:nth-child(1) { --i: 0; }
.constellation.emblem .mark:nth-child(2) { --i: 1; }
.constellation.emblem .mark:nth-child(3) { --i: 2; }
.constellation.emblem .mark:nth-child(4) { --i: 3; }
.constellation.emblem .mark:nth-child(5) { --i: 4; }
.constellation.emblem .mark:nth-child(6) { --i: 5; }
.constellation.emblem .mark:nth-child(7) { --i: 6; }

.colophon .cline { display: block; }

@keyframes gather {
  from { opacity: 0; transform: scale(0.6); }
  to   { opacity: 1; transform: none; }
}

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