:root {
  --bg: #15201a;
  --card: #1f2d25;
  --card-2: #273a2f;
  --line: #3a5143;
  --text: #ecebe0;
  --muted: #a9b5a8;
  --accent: #e0b45a;
  --accent-text: #241a05;
  --good: #7fd18b;
  --bad: #f08a7a;
  --white: #f3f1ea;
  --yellow: #f2c84b;
  --red: #d8463b;
  --black: #1b1b1b;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0e8;
    --card: #ffffff;
    --card-2: #f3f5ee;
    --line: #d3d9cc;
    --text: #1b241e;
    --muted: #5d6b60;
    --accent: #8a5a00;
    --accent-text: #ffffff;
    --good: #1f7a33;
    --bad: #b3261e;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
header, main, footer { max-width: 560px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 18px; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: .01em; }
.sub { margin: 2px 0 12px; color: var(--muted); }
footer { color: var(--muted); font-size: .8rem; padding-bottom: 28px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.rules summary { font-weight: 650; cursor: pointer; }
.rules ul { margin: 10px 0 0; padding-left: 1.1em; }
.rules li { margin-bottom: 7px; }

fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
legend { font-weight: 650; margin-bottom: 8px; padding: 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-top: 1px solid var(--line);
}
fieldset .row:first-of-type { border-top: 0; }
.lbl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lbl small { flex-basis: 100%; color: var(--muted); font-size: .8rem; margin-top: -4px; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 6px 8px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--line);
  font-size: .9rem; font-weight: 600; cursor: pointer; line-height: 1.2;
}
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg.small span { min-height: 42px; }
.reliable-only .lbl { margin: 6px 0; }

.step { display: flex; align-items: center; gap: 4px; flex: none; }
.step button {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.step button:disabled { opacity: .35; }
.step output { min-width: 2.2em; text-align: center; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

#go {
  width: 100%; min-height: 52px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text);
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
#go:disabled { opacity: .6; }

.die {
  display: inline-block; width: 22px; height: 22px; border-radius: 6px; flex: none;
  border: 1.5px solid rgba(128, 128, 128, .6); vertical-align: middle;
}
.die.white { background: var(--white); }
.die.yellow { background: var(--yellow); }
.die.red { background: var(--red); }
.die.black { background: var(--black); border-color: #777; }
.dice { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.dice .die { width: 30px; height: 30px; border-radius: 8px; }

.best h2 { margin: 0 0 4px; font-size: 1.25rem; }
.steps { margin: 8px 0 0; padding-left: 1.2em; }
.steps li { margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--card-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .8rem; }
.warn { border-color: var(--bad); }
.warn h2 { color: var(--bad); }
.ok { color: var(--good); }
.error { color: var(--bad); }

h3 { font-size: 1rem; margin: 0 0 8px; }
.alt { padding: 10px 0; border-top: 1px solid var(--line); }
.alt:first-of-type { border-top: 0; }
.alt .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.alt .dice { margin: 6px 0 2px; }
.alt .dice .die { width: 22px; height: 22px; border-radius: 6px; }
.alt p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .85rem; border-top: 0; }
td.num, th.num { text-align: right; }

.busy { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
[hidden] { display: none !important; }
