/* === Tokens ============================================================
   :root MUST come before the dark block in this file. shared/style.css
   defines both at the same specificity (0,1,0), so source order alone
   decides the winner -- and this sheet loads second. */

:root {
  --cd-past: #c0392b;
  --cd-future: var(--color-accent);
  --cd-anchor: #b8860b;
  --cd-anchor-ink: #ffffff;
  --cd-today: var(--color-text);
  --cd-dim: var(--color-text-secondary);
}

[data-theme="dark"] {
  --cd-past: #ef7683;
  --cd-anchor: #e0b64a;
  --cd-anchor-ink: #111111;
}

/* === Layout ============================================================ */

.app-container {
  max-width: 1100px;
}

@media (max-width: 480px) {
  .app-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

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

.hidden {
  display: none !important;
}

/* === Controls ========================================================== */

.cd-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.cd-field {
  text-align: left;
  flex: 0 1 auto;
}

.cd-field--label {
  flex: 1 1 16rem;
  min-width: 12rem;
}

.cd-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.cd-optional {
  font-weight: 400;
  text-transform: none;
}

.cd-end-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.cd-actions {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex: 0 0 auto;
}

.cd-ghost-btn,
.cd-preset-btn,
.cd-icon-btn {
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}

.cd-ghost-btn:hover,
.cd-preset-btn:hover,
.cd-icon-btn:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.cd-icon-btn {
  padding: 0.5rem 0.65rem;
  font-size: 1rem;
}

/* Shared input:focus only shifts border-color, which is ~1.5:1 against the
   unfocused border in dark mode. A form-driven tool needs better. */
.cd-controls :focus-visible,
.cd-preset-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* === Summary =========================================================== */

.cd-summary {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-bg);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.cd-headline {
  font-size: 1.35rem;
  line-height: 1.35;
  margin-bottom: 0.25rem;
}

.cd-headline strong {
  color: var(--color-accent);
  font-weight: 700;
}

.cd-sub {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

.stats {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.stat {
  background: var(--color-bg-secondary);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-border);
  flex: 1 1 8rem;
  min-width: 0;
}

.stat__value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.stat__value--sm {
  font-size: 1.05rem;
  line-height: 1.9;
}

.stat__label {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cd-message {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  margin: 1rem 0;
}

/* === Empty state ======================================================= */

.cd-empty {
  margin: 2.5rem 0;
  color: var(--color-text-secondary);
}

.cd-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

/* === Legend ============================================================ */

.cd-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  justify-content: center;
  margin: 1.25rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.cd-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.cd-legend .cd-day {
  width: 1.6rem;
  flex: 0 0 auto;
}

/* === Wall ============================================================== */

.cd-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem 1.25rem;
  margin-top: 1rem;
}

/* A lifetime-length wall is ~18k cells, and laying out that many flex +
   aspect-ratio boxes costs ~2.3s. Skipping layout for off-screen months takes
   it to ~0.25s. 225px is the measured height of a rendered month, so the
   scrollbar is right before anything is actually laid out. */
.cd-month {
  content-visibility: auto;
  contain-intrinsic-size: auto 225px;
}

.cd-month__title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}

.cd-month table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.cd-month th,
.cd-month td {
  padding: 0;
  text-align: center;
}

.cd-month th {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding-bottom: 0.2rem;
}

/* table-cell ignores aspect-ratio and flex centering in every engine, so the
   marker lives on an inner span. The transparent border is reserved up front
   (with shared's global border-box) so no marker ever shifts layout. */
.cd-day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  font-size: 0.8rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  border: 1.5px solid transparent;
  border-radius: 50%;
}

/* Inset from the cell so adjacent rings and X's don't touch. The <td> keeps
   its full width -- only the marker shrinks -- so the grid stays aligned. */
.cd-month .cd-day {
  width: 82%;
  margin: 0 auto;
}

.cd-day.is-out-of-span {
  color: var(--cd-dim);
}

.cd-day.is-future {
  border-color: var(--cd-future);
}

.cd-day.is-anchor {
  background: var(--cd-anchor);
  color: var(--cd-anchor-ink);
  font-weight: 700;
}

/* outline, not border -- it stacks over the anchor fill when the target
   date happens to be today, and costs no layout. */
.cd-day.is-today {
  outline: 2px solid var(--cd-today);
  outline-offset: 1px;
}

/* Full centered diagonals. The original drew these with width:100%; right:0;
   top:50%, an off-center chord that overflowed the corners by ~41%. */
.cd-day.is-past::before,
.cd-day.is-past::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 74%;
  height: 0;
  border-top: 1.5px solid var(--cd-past);
}

.cd-day.is-past::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.cd-day.is-past::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* === Print =============================================================
   Redefining the tokens is enough for color, and source order wins over
   shared/style.css with no !important. */

@media print {
  :root,
  [data-theme="dark"] {
    --color-bg: #fff;
    --color-bg-secondary: #fff;
    --color-text: #000;
    --color-text-secondary: #555;
    --color-border: #999;
    --color-accent: #000;
    --cd-past: #000;
    --cd-future: #666;
    --cd-anchor: #000;
    --cd-anchor-ink: #fff;
    --cd-today: #000;
    --cd-dim: #777;
  }

  body {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  /* Best-effort only: browsers strip backgrounds by default and the user can
     override print-color-adjust, which would erase the single most important
     cell on the page. So the anchor changes mechanism, not just color --
     borders print reliably, fills and shadows do not. */
  .cd-day.is-anchor {
    background: none;
    color: #000;
    border: 3px solid #000;
    font-weight: 700;
  }

  .cd-day.is-today {
    outline: none;
    border: 2px dashed #000;
  }

  .nav,
  .cd-controls,
  .cd-message {
    display: none;
  }

  .app-container {
    max-width: none;
    padding: 0;
  }

  .cd-summary {
    position: static;
    break-after: avoid;
  }

  .cd-wall {
    grid-template-columns: repeat(3, 1fr);
    gap: 8mm 6mm;
  }

  /* content-visibility must be off here or off-screen months print blank. */
  .cd-month {
    content-visibility: visible;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  @page {
    margin: 12mm;
  }
}
