/* Lunar Death Anniversary Calculator: quiet memorial look. Stone and ivory, charcoal ink, one candle-amber accent. */
:root {
  --bg: #f3f2ef;          /* stone */
  --surface: #fbfaf7;     /* ivory, used only for the result */
  --ink: #1e2124;         /* charcoal */
  --ink-2: #464b51;
  --muted: #5d6268;
  --line: #dcdbd6;
  --line-strong: #8c9095; /* input borders, 3:1 on bg */
  --amber: #c27a1e;       /* candle: decoration and markers only */
  --amber-text: #8a4e0a;  /* amber that passes AA as text */
  --amber-wash: #f6ecdc;
  --focus: #b0640f;
  --warn: #8a3d12;
  --r-ctl: 4px;
  --r-card: 8px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, "Apple SD Gothic Neo", "Malgun Gothic", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Noto Serif", "Noto Serif CJK KR", Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151719;
    --surface: #1d2023;
    --ink: #e8e6e1;
    --ink-2: #c4c7ca;
    --muted: #a0a5aa;
    --line: #2f3337;
    --line-strong: #6f757b;
    --amber: #e3a54e;
    --amber-text: #f0b766;
    --amber-wash: #2a2419;
    --focus: #f0b766;
    --warn: #f2ae7c;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--sans); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
a { color: var(--ink); text-decoration-color: var(--amber); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--amber-text); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
small { font-size: .9em; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }

/* Header */
.site-head { padding: 56px 0 8px; }
h1, h2, h3 { font-weight: 600; line-height: 1.25; color: var(--ink); letter-spacing: -.01em; }
h1 { font-size: clamp(1.75rem, 5vw, 2.4rem); margin: 0 0 10px; display: flex; align-items: flex-start; gap: 14px; }
.site-head .flame { margin-top: .4em; }
.flame {
  flex: none; width: 11px; height: 18px; background: var(--amber);
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  box-shadow: 0 0 12px color-mix(in srgb, var(--amber) 55%, transparent);
}
.lede { margin: 0; max-width: 36em; color: var(--ink-2); font-size: 1.1rem; }

/* Form: no card, just rhythm */
.tool { padding-top: 28px; }
.form { display: grid; gap: 26px; padding-bottom: 8px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field > label, .field > .label { font-weight: 600; padding: 0; margin-bottom: 8px; display: block; }
.seg { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 0; }
.seg-2 { grid-template-columns: 1fr 1fr; }
.seg label { position: relative; display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label > span {
  display: flex; flex-direction: column; justify-content: center; height: 100%;
  min-height: 52px; padding: 8px 14px; border: 1px solid var(--line-strong); background: transparent; line-height: 1.3;
}
.seg label + label > span { border-left-width: 0; }
.seg label:first-child > span { border-radius: var(--r-ctl) 0 0 var(--r-ctl); }
.seg label:last-child > span { border-radius: 0 var(--r-ctl) var(--r-ctl) 0; }
.seg b { font-weight: 500; }
.seg small { font-size: .95rem; color: var(--ink-2); }
.seg input:checked + span { background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink); border-color: var(--ink); }
.seg input:checked + span b { font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; position: relative; z-index: 1; }
.row { display: grid; gap: 14px; }
.lunar-row { grid-template-columns: 1.2fr 1fr .8fr; align-items: end; }
.lunar-row .check, .lunar-row .hint { grid-column: 1 / -1; }
@media (min-width: 700px) { .row.two { grid-template-columns: 1.2fr 1fr; } }
.field { display: grid; min-width: 0; }
input[type=date], input[type=number], input[type=text], select {
  width: 100%; min-width: 0; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl); padding: 10px 12px; min-height: 48px;
}
input[type=date] { -webkit-appearance: none; appearance: none; max-width: 22rem; }
input::placeholder { color: var(--muted); }
input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.years-in { display: flex; gap: 10px; align-items: center; }
.years-in input { flex: 1; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.check input, .rules input[type=radio] { width: 18px; height: 18px; accent-color: var(--ink); flex: none; margin: 0; }
.hint { margin: 0; font-size: .95rem; color: var(--muted); }

.rules { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.rules > summary { padding: 10px 0; min-height: 44px; font-weight: 600; }
.rules > summary, .faq summary, .ms > summary { cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
.rules > summary::-webkit-details-marker, .faq summary::-webkit-details-marker, .ms > summary::-webkit-details-marker { display: none; }
.rules > summary::before, .faq summary::before, .ms > summary::before { content: "+"; flex: none; width: 1em; font-weight: 400; color: var(--muted); }
.rules[open] > summary::before, .faq details[open] summary::before, .ms[open] > summary::before { content: "\2212"; }
.rules-grid { display: grid; gap: 22px; padding: 4px 0 20px; }
.rules legend { margin-bottom: 2px; }
.rules label { display: flex; gap: 10px; align-items: center; min-height: 44px; line-height: 1.4; cursor: pointer; }

.actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--r-ctl); padding: 10px 16px; min-height: 44px;
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); padding: 12px 24px; font-weight: 600; }
.btn.primary:hover { background: var(--ink-2); }
.err { color: var(--warn); margin: 0; font-weight: 600; }

/* Result: the one card */
.results { margin-top: 36px; }
.summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 28px 28px 24px; border-top: 3px solid var(--amber);
}
.summary:focus { outline: none; }
.summary:focus-visible { outline: 3px solid var(--focus); }
.summary h2 { margin: 0; font-size: 1rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.summary p { margin: 0; }
.when { font-family: var(--serif); font-weight: 400; font-size: clamp(2rem, 7vw, 3.1rem); line-height: 1.12; margin: 6px 0 10px !important; letter-spacing: -.015em; }
.meta { color: var(--ink-2); }
.meta + .meta { margin-top: 2px !important; }
.death { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.lunar-big { font-family: var(--serif); font-size: 1.3rem; line-height: 1.3; }
.note { margin-top: 12px !important; font-size: .95rem; color: var(--ink-2); }
.note .btn { margin-top: 8px; display: flex; width: fit-content; }

.dates { margin-top: 44px; }
.table-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.table-head h2 { margin: 0; font-size: 1.3rem; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.share-msg { min-height: 1.5em; margin: 6px 0 0; color: var(--ink-2); font-size: .95rem; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 10px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: .9rem; color: var(--muted); font-weight: 500; border-bottom-color: var(--line-strong); }
td .sub { display: block; font-size: .9rem; color: var(--muted); }
td strong { font-weight: 600; }
td.lead { padding-left: 12px; }
tr.is-next td { background: var(--amber-wash); }
tr.is-next td.lead { box-shadow: inset 3px 0 0 var(--amber); }
tr.is-past td, tr.is-past td strong { color: var(--muted); font-weight: 400; }
.flag { color: var(--warn); font-weight: 700; cursor: help; }
.table-notes { font-size: .95rem; color: var(--ink-2); }
.table-notes p { margin: 10px 0 0; }

.ms { margin-top: 36px; border-top: 1px solid var(--line); }
.ms > summary { cursor: pointer; min-height: 44px; padding: 12px 0; font-weight: 600; font-size: 1.1rem; }
.ms .hint { margin-bottom: 4px; }

/* Phone: each year is a compact block, no column labels except where needed */
@media (max-width: 620px) {
  .site-head { padding: 36px 0 4px; }
  .seg { grid-template-columns: 1fr; }
  .seg-2 { grid-template-columns: 1fr 1fr; }
  .seg:not(.seg-2) label + label > span { border-left-width: 1px; border-top-width: 0; }
  .seg:not(.seg-2) label > span { flex-direction: row; justify-content: space-between; align-items: center; min-height: 48px; }
  .seg:not(.seg-2) label:first-child > span { border-radius: var(--r-ctl) var(--r-ctl) 0 0; }
  .seg:not(.seg-2) label:last-child > span { border-radius: 0 0 var(--r-ctl) var(--r-ctl); }
  .lunar-row { grid-template-columns: 1fr 1fr; }
  .lunar-row .field:first-child { grid-column: 1 / -1; }
  .summary { padding: 22px 18px 20px; }
  .tools { width: 100%; }
  .tools .btn { flex: 1 1 auto; padding: 8px 10px; }
  .actions .btn.primary { width: 100%; }
  table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack, table.stack tbody { display: block; }
  table.stack tr {
    display: grid; grid-template-columns: 3.6rem 1fr 1fr; column-gap: 10px;
    grid-template-areas: "y d d" "y a l" "y e e"; padding: 12px 0; border-bottom: 1px solid var(--line);
  }
  table.stack td { border: 0; padding: 0; background: none !important; min-width: 0; }
  table.stack td .sub { display: inline; margin-left: 6px; }
  table.stack td.lead { grid-area: y; padding-left: 8px; font-weight: 600; }
  table.stack td.date { grid-area: d; }
  table.stack td.ann { grid-area: a; font-size: .95rem; }
  table.stack td.lun { grid-area: l; font-size: .95rem; color: var(--ink-2); }
  table.stack td.lun::before { content: "Lunar "; color: var(--muted); }
  table.stack td.eve { grid-area: e; font-size: .95rem; color: var(--ink-2); }
  table.stack td.eve::before { content: attr(data-label) ": "; color: var(--muted); }
  table.stack td.eve > div, table.stack td.lun > div { display: inline; }
  table.stack td.lun .sub { display: none; }
  table.stack tr.is-next { background: var(--amber-wash); box-shadow: inset 3px 0 0 var(--amber); }
  table.stack tr.is-next td.lead { box-shadow: none; }
  #ms-table.stack tr { grid-template-areas: "y n n" "y d l"; grid-template-columns: 4.2rem 1fr auto; }
  #ms-table.stack td:nth-child(2) { grid-area: n; }
  #ms-table.stack td:nth-child(3) { grid-area: d; }
  #ms-table.stack td:nth-child(4) { grid-area: l; color: var(--muted); }
}

/* Prose */
.prose { padding-top: 64px; padding-bottom: 40px; }
.prose section { margin: 0 0 44px; }
.prose h2 { font-size: 1.4rem; margin: 0 0 12px; }
.prose p, .prose li, .prose dd { max-width: 68ch; }
.terms { margin: 18px 0; display: grid; gap: 14px; }
.terms div { padding-left: 16px; border-left: 2px solid var(--line); }
.terms dt { font-weight: 600; }
.terms .native { font-weight: 400; color: var(--muted); }
.terms dd { margin: 2px 0 0; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details:first-of-type { border-top: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 12px 0; min-height: 44px; font-weight: 500; }
.faq details p { margin: 0 0 16px; color: var(--ink-2); }
.local h2 { font-size: 1.2rem; }
.sources h2 { font-size: 1.1rem; }
.sources p { font-size: .95rem; color: var(--ink-2); }

/* Footer (shared Smart Badgers block) */
.site-foot { border-top: 1px solid var(--line); padding: 28px 0 40px; color: var(--muted); font-size: .95rem; }
.sb-footer p { margin: 6px 0; max-width: 60ch; }
.sb-more a { display: inline-block; padding: 10px 2px; font-weight: 500; }
.sb-privacy { color: var(--ink-2); }
.sb-credit a { color: var(--ink-2); }

/* 404 */
.notfound { padding: 80px 0; min-height: calc(100vh - 200px); }
.notfound .lede { margin-bottom: 28px; }

@media print {
  .site-head .lede, .form, .tools, .prose, .site-foot, .skip, .share-msg, .note .btn, .ms:not([open]) { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .site-head { padding: 0 0 6px; }
  h1 { font-size: 16pt; }
  .flame { box-shadow: none; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .tool, .results { padding: 0; margin: 0; }
  .summary { border: 0; border-top: 2px solid #000; border-radius: 0; padding: 10px 0 0; background: none; }
  .when { font-size: 22pt; }
  .dates { margin-top: 18px; }
  tr { break-inside: avoid; }
  table.stack thead { position: static !important; width: auto !important; height: auto !important; clip: auto !important; display: table-header-group !important; }
  table.stack, table.stack tbody { display: table !important; }
  table.stack tbody { display: table-row-group !important; }
  table.stack tr { display: table-row !important; padding: 0; box-shadow: none !important; }
  table.stack td { display: table-cell !important; padding: 5px 8px 5px 0 !important; border-bottom: 1px solid #bbb !important; }
  table.stack td::before { content: none !important; }
  table.stack td .sub { display: block !important; margin: 0 !important; }
  tr.is-next td { background: none !important; box-shadow: none !important; font-weight: 700; }
  tr.is-past td, tr.is-past td strong { color: #000; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
.nowrap { white-space: nowrap; }
