:root {
  color-scheme: light dark;
  --bg: #f6f4ee; --surface: #fffdf8; --fg: #1d2a1f; --muted: #5b6b5d;
  --line: #e2ddd0; --accent: #2f6b3a; --accent-fg: #ffffff; --warn: #a3471c;
  --chip: #ece8dc; --bar: #d9d4c6;
  --good: #3f8a4c; --mid: #c08a1e; --bad: #b6452c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121812; --surface: #1a221a; --fg: #e8efe6; --muted: #9db09f;
    --line: #2b372b; --accent: #8fd19c; --accent-fg: #102010; --warn: #f0a37c;
    --chip: #243024; --bar: #2b372b;
    --good: #7cc98a; --mid: #e0b45a; --bad: #ef8a72;
  }
}
:root[data-theme="dark"] {
  --bg: #121812; --surface: #1a221a; --fg: #e8efe6; --muted: #9db09f;
  --line: #2b372b; --accent: #8fd19c; --accent-fg: #102010; --warn: #f0a37c;
  --chip: #243024; --bar: #2b372b;
  --good: #7cc98a; --mid: #e0b45a; --bad: #ef8a72;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: system-ui, "Noto Sans Thai", sans-serif; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
p { margin: 0; }

.screen { max-width: 36rem; margin: 0 auto; padding: 24px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.center { min-height: 100vh; justify-content: center; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.sci { font-style: italic; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font: inherit; border-radius: 12px; padding: 12px 16px; cursor: pointer; text-align: left;
  transition: border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); text-align: center; font-weight: 600; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.actions { display: flex; flex-direction: column; gap: 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.notice { background: var(--chip); border-radius: 12px; padding: 12px 16px; font-size: .9rem; }
.error { color: var(--bad); }

.badge { display: inline-block; font-size: .8rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; }
.badge.warn { color: var(--warn); border-color: currentColor; }

/* หน้าแรก */
.title { font-size: 2.25rem; }
.lead { font-size: 1.05rem; }

/* หน้าเปิดผลสุ่ม */
.reveal-step { opacity: 0; transform: translateY(8px); animation: reveal .5s ease forwards; }
.reveal-step.d1 { animation-delay: .2s; }
.reveal-step.d2 { animation-delay: 1s; }
.reveal-step.d3 { animation-delay: 1.8s; }
.reveal-step.d4 { animation-delay: 2.5s; }
.reveal-label { font-size: .9rem; color: var(--muted); }
.reveal-value { font-size: 1.4rem; font-weight: 600; }
.reveal-name { font-size: 2.2rem; font-weight: 700; }
@keyframes reveal { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .reveal-step { animation: none; opacity: 1; transform: none; }
}

/* การ์ดสัตว์ */
.species-name { font-size: 2rem; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.odds { font-size: 1.1rem; font-weight: 600; }

/* หน้าใช้ชีวิต */
.life-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stats { display: grid; gap: 8px; }
.stat { display: grid; grid-template-columns: 6.5rem 1fr 2.5rem; align-items: center; gap: 8px; font-size: .9rem; }
.stat-bar { height: 10px; background: var(--bar); border-radius: 999px; overflow: hidden; }
.stat-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.stat-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.feed { display: flex; flex-direction: column; gap: 6px; }
.feed p { padding-left: 12px; border-left: 3px solid var(--line); }
.feed p.fresh { border-left-color: var(--accent); }
.event-text { font-size: 1.15rem; font-weight: 600; }
.fact { margin-top: 8px; font-size: .9rem; color: var(--muted); background: var(--chip); border-radius: 8px; padding: 8px 12px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.timeline li { display: grid; grid-template-columns: 5.5rem 1fr; gap: 8px; font-size: .9rem; }
.timeline .age { color: var(--muted); font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; color: var(--muted); }

/* หน้าสรุป */
.summary-big { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 12px; }
.summary-big b { display: block; font-size: 1.4rem; }
