:root {
  color-scheme: dark;
  --background: #131817;
  --surface: #1c2521;
  --surface-deep: #141c19;
  --border: #3b4a41;
  --text: #f3ebdc;
  --muted: #c1c9bf;
  --accent: #f2bf83;
  --accent-strong: #262016;
  font: 100%/1.55 system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.page {
  width: min(100% - 2.5rem, 69rem);
  margin-inline: auto;
  padding-block: 1.4rem 3rem;
}
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.brand { color: var(--accent); font-weight: 700; }
.masthead a { color: var(--muted); text-underline-offset: .25em; }
.intro { padding-block: clamp(2.5rem, 8vw, 5.4rem) 2rem; }
h1, h2 { margin: 0; font-family: Georgia, serif; line-height: 1.09; font-weight: 500; }
h1 { max-width: 15ch; font-size: clamp(2.6rem, 7.8vw, 5.8rem); letter-spacing: -.065em; }
h2 { font-size: clamp(1.65rem, 4vw, 2.35rem); }
p { margin: 0; }
.intro p { max-width: 48ch; margin-top: 1rem; color: var(--muted); font-size: 1.1rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, .88fr);
  gap: 1rem;
  align-items: start;
}
.card {
  min-width: 0;
  padding: clamp(1.15rem, 3vw, 1.8rem);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}
.entry-card { display: grid; gap: 1.25rem; }
.card-header { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.controls { display: grid; gap: 1rem; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.field { display: grid; gap: .35rem; }
.field, legend { font-size: .95rem; font-weight: 650; }
.field input, .field textarea {
  width: 100%;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--surface-deep);
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
}
.field textarea { min-height: 5.3rem; resize: vertical; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { margin-bottom: .5rem; }
.dice-options { display: flex; flex-wrap: wrap; gap: .45rem; }
.die-option { position: relative; }
.die-option input { position: absolute; inset: 0; margin: 0; width: 100%; opacity: 0; cursor: pointer; }
.die-option span {
  display: block;
  min-width: 2.9rem;
  text-align: center;
  padding: .45rem .55rem;
  background: var(--surface-deep);
  border: 1px solid var(--border);
  border-radius: .45rem;
  font-weight: 650;
  font-size: .92rem;
}
.die-option input:checked + span { color: var(--accent); border-color: var(--accent); }
.die-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

.primary, .quiet {
  padding: .65rem .9rem;
  border-radius: .55rem;
  font-weight: 700;
  min-height: 2.7rem;
}
.primary {
  justify-self: start;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-strong);
}
.primary:hover { background: #ffd6a2; }
.quiet { background: transparent; color: var(--muted); border: 1px solid var(--border); font-size: .9rem; }
.quiet:hover:enabled { color: var(--text); border-color: var(--muted); }
.quiet:disabled { opacity: .55; cursor: default; }
.result {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: 1rem;
  align-items: center;
  padding: .85rem 1rem;
  border-radius: .75rem;
  background: var(--surface-deep);
}
.score {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: Georgia, serif;
  font-size: clamp(2.6rem, 8vw, 4rem);
  line-height: 1;
  overflow-wrap: anywhere;
}
.result p, .muted { color: var(--muted); }
.result p, .history p { overflow-wrap: anywhere; }
.history { margin: 0; padding: 1rem 0 0; list-style: none; }
.history li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
  align-items: start;
  padding: .65rem 0;
  border-top: 1px solid var(--border);
}
.history strong { display: block; }
.history p, .small { font-size: .88rem; }
.history .total { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { margin-top: 1rem; color: var(--muted); }
[hidden] { display: none !important; }

.session {
  --background: #171a23;
  --surface: #232835;
  --surface-deep: #1a1e29;
  --border: #424b60;
  --text: #f1edf7;
  --muted: #c6ccda;
  --accent: #b9caf6;
  --accent-strong: #192238;
  background: var(--background);
}
.session .primary:hover { background: #d1dcfb; }
.progress-text { color: var(--muted); font-size: .92rem; margin-top: .65rem; }
progress { display: block; width: 100%; height: .5rem; margin-top: .6rem; accent-color: var(--accent); }
.checklist { list-style: none; margin: .9rem 0 0; padding: 0; }
.checklist label {
  display: flex;
  align-items: baseline;
  gap: .65rem;
  padding-block: .7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.checklist li:last-child label { border-bottom: 0; }
.checklist input { flex: none; width: 1rem; height: 1rem; accent-color: var(--accent); }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }
.save-state { color: var(--muted); }

@media (max-width: 46rem) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 26rem) {
  .page { width: min(100% - 1.5rem, 69rem); }
  .masthead { gap: .5rem; }
  .fields { grid-template-columns: minmax(0, 1fr); }
}
