/* Layout: one centered column — a sentence-form hero you answer, a strip of the years left, then a grid of count cards.
   Concept: each remaining time is a small light (山吹), each spent one is a dim dot, on night-indigo (藍) paper. */
:root {
  --paper: #edf1f6;
  --surface: #f9fbfd;
  --ink: #18223d;
  --muted: #55607b;
  --line: #d2d9e5;
  --gold: #c98b12;
  --gold-soft: #e9cf98;
  --gold-ink: #845800;
  --spent: #c3cad8;
  --danger: #b3261e;
  --focus: #2f5bd3;

  --display: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  --body: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", sans-serif;

  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1322;
    --surface: #141c30;
    --ink: #e6eaf3;
    --muted: #9ca6bf;
    --line: #27314b;
    --gold: #f0b443;
    --gold-soft: #6b5426;
    --gold-ink: #f3c467;
    --spent: #2e3853;
    --danger: #ff8a80;
    --focus: #8fb0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1322;
  --surface: #141c30;
  --ink: #e6eaf3;
  --muted: #9ca6bf;
  --line: #27314b;
  --gold: #f0b443;
  --gold-soft: #6b5426;
  --gold-ink: #f3c467;
  --spent: #2e3853;
  --danger: #ff8a80;
  --focus: #8fb0ff;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.7;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-text-size-adjust: 100%;
  accent-color: var(--gold);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding-block: 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--gold-ink); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

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

input, select, button { font: inherit; color: inherit; }
input[type="number"], input[type="text"], select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  min-width: 0;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input:user-invalid { border-color: var(--danger); }

.hint { color: var(--muted); font-size: 0.8125rem; line-height: 1.6; }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
}
@media (min-width: 880px) {
  .hero { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; gap: 48px; }
  .brand { grid-column: 1 / -1; }
}

.brand {
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.125rem;
  letter-spacing: 0.12em;
  color: var(--gold-ink);
}

.ask { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ask-line {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.75rem, 1.1rem + 2.6vw, 3rem);
  line-height: 1.45;
  word-break: auto-phrase;
  overflow-wrap: anywhere;
}
.num-field { display: inline-block; }
#lifespan {
  width: 2.6em;
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.45em;
  line-height: 1;
  text-align: center;
  color: var(--gold-ink);
  background: transparent;
  border: none;
  border-bottom: 3px solid var(--gold);
  border-radius: 0;
  padding: 0 0 2px;
  -moz-appearance: textfield;
  appearance: textfield;
}
#lifespan::-webkit-inner-spin-button,
#lifespan::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#lifespan:user-invalid { border-bottom-color: var(--danger); }

.range { width: 100%; max-width: 30rem; margin: 0; }

.field-error { color: var(--danger); font-size: 0.875rem; font-weight: 500; }

.now-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 1.0625rem; }
#age { width: 4.5em; font-size: 1.0625rem; }
.example-note {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gold-ink);
  border-left: 3px solid var(--gold);
  padding-left: 10px;
}

/* Featured line */
.feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.feature-line {
  word-break: auto-phrase; /* 日本語を文節で改行（対応ブラウザーのみ） */
  overflow-wrap: anywhere;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.625rem);
  line-height: 1.6;
}
.feature-line strong {
  font-weight: 900;
  font-size: 1.9em;
  color: var(--gold-ink);
  font-variant-numeric: tabular-nums;
  padding-inline: 0.12em;
}
.feature-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.feature .dots i { width: 10px; height: 10px; }
.feature-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

/* Share dialog */
.share-dialog {
  width: min(calc(100% - 32px), 34rem);
  max-height: calc(100% - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.share-dialog::backdrop { background: rgb(8 12 24 / 0.6); }
.share-inner { display: flex; flex-direction: column; gap: 14px; padding: 18px; }
.share-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.share-head h2 { font-family: var(--display); font-weight: 900; font-size: 1.25rem; }
#share-pick { width: 100%; }
.share-preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 8px;
  background: #0d1322;
}
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Dots & bars ---------- */
.dots { display: flex; flex-wrap: wrap; gap: 4px; }
.dots i { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.dots i.spent { background: var(--spent); }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--gold);
  overflow: hidden;
  display: flex;
}
.bar span { display: block; height: 100%; background: var(--spent); }

/* ---------- Summary ---------- */
.summary { display: flex; flex-direction: column; gap: 14px; }
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.stats div { min-width: 0; border-top: 1px solid var(--line); padding-top: 8px; }
.stats dt { font-size: 0.8125rem; color: var(--muted); letter-spacing: 0.04em; }
.stats dd {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(1.25rem, 0.9rem + 1.6vw, 2.125rem);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.stats dd small { font-family: var(--body); font-size: 0.5em; font-weight: 500; margin-left: 2px; }
@media (max-width: 520px) {
  .stats { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
}

.years {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 2px;
  height: 36px;
  align-items: end;
}
.years i { display: block; height: 100%; border-radius: 2px; background: var(--gold); }
.years i.lived { background: var(--spent); height: 70%; }
.years i.later { background: var(--gold-soft); }
.years i.now { background: var(--ink); }
.years i.decade { box-shadow: inset 0 -6px 0 0 color-mix(in srgb, var(--ink) 18%, transparent); }
.years-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.8125rem; color: var(--muted); }
.years-legend span { display: inline-flex; align-items: center; gap: 6px; }
.years-legend b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--gold); }
.years-legend b.lived { background: var(--spent); }
.years-legend b.later { background: var(--gold-soft); }
.summary-error { color: var(--danger); font-weight: 500; }

/* ---------- More (optional) ---------- */
.more {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.more > summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 700;
  list-style-position: inside;
}
.optional {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  margin-left: 10px;
}
.more-body {
  padding: 0 18px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}
@media (min-width: 880px) { .more-body { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); } }
.more-section { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.more-section h3 { font-size: 1rem; }
.inline-field { display: flex; align-items: center; gap: 8px; }
#active-age { width: 4.5em; }

.about-me { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; }
.about-me .about-hint { flex-basis: 100%; }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.person .role { font-weight: 700; min-width: 5.5em; }
.person label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; color: var(--muted); }
.person input[type="text"] { width: 8em; color: var(--ink); }
.person input[type="number"] { width: 4.2em; color: var(--ink); }
.person select { color: var(--ink); }
.person .remove { margin-left: auto; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
.btn, .chip {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.875rem;
  line-height: 1.5;
}
.btn:hover, .chip:hover { border-color: var(--gold); }
.chip { border-radius: 999px; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--gold)); }
.btn.quiet { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.linkish {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.linkish:hover { color: var(--gold-ink); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.cat-nav { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.cat-nav a {
  text-decoration: none;
  font-size: 0.8125rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
  background: var(--surface);
}
.cat-nav a:hover { border-color: var(--gold); color: inherit; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; }

/* ---------- List ---------- */
.list { display: flex; flex-direction: column; gap: 36px; }
.cat { display: flex; flex-direction: column; gap: 14px; scroll-margin-top: 16px; }
.cat-head { display: flex; align-items: baseline; gap: 12px; }
.cat-head h2 {
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.375rem;
  letter-spacing: 0.04em;
}
.cat-head span { color: var(--muted); font-size: 0.8125rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16.5rem), 1fr));
  gap: 12px;
}

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-title { font-size: 0.9375rem; font-weight: 700; line-height: 1.5; }
.count {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.count .pre, .count .unit { font-size: 0.875rem; color: var(--muted); }
.count .n {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2rem, 1.7rem + 0.8vw, 2.5rem);
  line-height: 1.1;
  color: var(--gold-ink);
}
.meta { font-size: 0.8125rem; color: var(--muted); line-height: 1.6; }
.meta + .meta { margin-top: -6px; }
.card.ended .count .n { color: var(--muted); }
.card.upcoming .count .n { color: var(--ink); }
.status {
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0 8px;
  align-self: flex-start;
  border: 1px solid var(--line);
  color: var(--muted);
}

.edit { margin-top: auto; border-top: 1px dashed var(--line); padding-top: 8px; }
.edit > summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--muted);
  list-style: none;
}
.edit > summary::-webkit-details-marker { display: none; }
.edit > summary::before { content: "＋ "; }
.edit[open] > summary::before { content: "－ "; }
.edit-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.edit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.875rem; }
.edit-row input[type="number"] { width: 4.6em; }
.edit-actions { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.invite {
  border: 1px dashed var(--gold);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
}
.invite p { max-width: 40rem; }

/* ---------- Custom ---------- */
.custom { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 24px; }
.custom h2 { font-family: var(--display); font-weight: 900; font-size: 1.25rem; }
.custom-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}
@media (min-width: 760px) {
  .custom-form { grid-template-columns: minmax(0, 2fr) auto auto auto; gap: 16px; }
}
.cf-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cf-field > label { font-size: 0.8125rem; color: var(--muted); }
.cf-title input { width: 100%; }
.cf-pair { display: flex; align-items: center; gap: 6px; }
#cf-times, #cf-to { width: 5em; }

.hidden-box { display: flex; flex-direction: column; gap: 10px; }
.hidden-box h2 { font-size: 1rem; }
.hidden-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.hidden-list li {
  display: inline-flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 6px 2px 14px; font-size: 0.875rem;
}

/* ---------- Footer ---------- */
.foot {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
  max-width: 48rem;
}

@media (prefers-reduced-motion: no-preference) {
  .dots i, .bar span, .years i { transition: background-color 0.25s ease; }
}
.nowrap { white-space: nowrap; }
