:root {
  --paper:      #f3efe6;
  --paper-sink: #ece6d9;
  --ink:        #251f1a;
  --ink-soft:   #6f655a;
  --muted:      #a59a8b;
  --line:       #ddd4c4;
  --line-soft:  #e7dfd0;

  --lived:   #c25e3a;
  --current: #f3a738;
  --summer:  #e0b75a;
  --future:  #e5ddcd;

  --shadow: 0 1px 2px rgba(60, 45, 30, .05), 0 12px 40px -16px rgba(70, 50, 30, .18);
  --maxw: 740px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* faint paper texture: two offset radial washes */
  background-image:
    radial-gradient(120% 80% at 12% -8%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(120% 90% at 100% 0%, rgba(214,178,120,.10), transparent 55%);
  background-attachment: fixed;
}

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 5.5rem) clamp(1.25rem, 5vw, 2rem) 4rem;
}

/* ---------- masthead ---------- */
.masthead { margin-bottom: clamp(2rem, 5vw, 3rem); }

.eyebrow {
  margin: 0 0 1rem;
  font-size: .72rem;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

h1 {
  font-family: "Fraunces", Georgia, "Times New Roman", serif;
  font-weight: 460;
  font-size: clamp(2.5rem, 9vw, 4.25rem);
  line-height: .98;
  letter-spacing: -0.015em;
  margin: 0 0 1.1rem;
}

.lede {
  margin: 0;
  max-width: 34ch;
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
  margin-bottom: clamp(2rem, 5vw, 2.75rem);
}

.field { display: inline-flex; flex-direction: column; gap: .5rem; }

.field__label {
  font-size: .72rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

input[type="date"],
input#country {
  font-family: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: #fbf9f3;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: .7rem .9rem;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
  min-width: 12rem;
}
input[type="date"]:focus-visible,
input#country:focus-visible {
  outline: none;
  border-color: var(--lived);
  box-shadow: 0 0 0 3px rgba(194, 94, 58, .14);
}

input#country { min-width: 16rem; }
input#country::placeholder { color: var(--muted); }

.note {
  margin: 0;
  font-size: .92rem;
  color: var(--ink-soft);
  min-height: 1.3em;
  flex: 1 1 12rem;
}
.note[data-tone="warn"] { color: var(--lived); }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: clamp(2.25rem, 6vw, 3.25rem);
}

.stat {
  background: #fbf9f3;
  padding: 1.2rem 1.1rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: .28rem;
}

.stat__value {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 460;
  font-size: clamp(1.5rem, 5vw, 2.05rem);
  line-height: 1;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.stat__label {
  font-size: .76rem;
  color: var(--ink-soft);
  line-height: 1.3;
}

/* ---------- grid ---------- */
.grid-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  margin-bottom: 1rem;
}

.legend {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem 1rem;
  font-size: .8rem;
  color: var(--ink-soft);
}
.legend .swatch {
  display: inline-block;
  width: .68rem; height: .68rem;
  border-radius: 3px;
  margin-right: .3rem;
  vertical-align: -1px;
}
.swatch--lived   { background: var(--lived); }
.swatch--current { background: var(--current); box-shadow: 0 0 0 2px rgba(243,167,56,.3); }
.swatch--future  { background: var(--future); }

.grid-meta__rows { font-size: .8rem; color: var(--muted); }

.canvas-host { position: relative; }

canvas#grid {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
}

.tooltip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, calc(-100% - 12px));
  background: var(--ink);
  color: #f6f1e8;
  font-size: .82rem;
  line-height: 1.35;
  padding: .5rem .7rem;
  border-radius: 9px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.4);
}
.tooltip::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -5px;
  width: 10px; height: 10px;
  background: var(--ink);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px;
}
.tooltip strong { font-weight: 600; color: #fff; }

/* ---------- actions ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  margin-top: clamp(2rem, 5vw, 2.75rem);
}

.btn {
  font-family: inherit;
  font-size: .98rem;
  font-weight: 500;
  color: var(--ink);
  background: #fbf9f3;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .8rem 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(194,94,58,.18); }

.btn--primary {
  color: #fff;
  background: var(--lived);
  border-color: transparent;
}
.btn--primary:hover { background: #b1502f; }
.btn.is-done { background: #2f6f47; color:#fff; border-color: transparent; }

/* ---------- colophon ---------- */
.colophon {
  margin-top: clamp(3rem, 8vw, 4.5rem);
  padding-top: 1.5rem;
  border-top: 1px solid var(--line-soft);
}
.colophon p {
  margin: 0;
  font-size: .82rem;
  color: var(--muted);
}

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
