@font-face { font-family: 'Bagel Fallback'; src: local('Arial Black'), local('Arial-Black'); size-adjust: 83%; }
/* Layout: one column — the dice tray first, the total, the settings, and the roll button floating in thumb reach */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --text: #f7ede1;
  --muted: #b5a191;
  --die: #fbf7ef;
  --die-shade: #d9cfbe;
  --pip: #241813;
  --worm: #f2877b;
  --tray-pattern: repeating-linear-gradient(90deg, transparent 0 13px, rgba(0, 0, 0, .28) 13px 16px);
  --glow: rgba(255, 107, 44, .16);
  --display: 'Bagel Fat One', 'Bagel Fallback', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main {
  max-width: 560px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 120px;
  display: grid; gap: 16px;
}
h1 { min-width: 0; margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(38px, 11vw, 52px); line-height: 1; overflow-wrap: anywhere; }

/* tray and dice */
.tray {
  border-radius: 22px; padding: 18px 18px 26px; min-height: 180px;
  display: grid; align-items: center;
  background: var(--tray-pattern), linear-gradient(180deg, var(--surface-2), var(--surface));
}
.dice { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 14px; justify-items: center; }
.die {
  appearance: none; border: 0; cursor: pointer; position: relative;
  width: 100%; max-width: 104px; aspect-ratio: 1; border-radius: 22%; padding: 13%;
  transition: transform .15s ease, box-shadow .15s ease;
  background: var(--die); box-shadow: inset 0 -4px 0 var(--die-shade), 0 3px 0 rgba(0, 0, 0, .45);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
}
.die i { margin: 14%; border-radius: 50%; }
.die i.on { background: var(--pip); }
.die.art { grid-template-columns: 1fr; grid-template-rows: 1fr; place-items: center; padding: 7%; }
.die.art svg { width: 94%; height: auto; aspect-ratio: 26 / 14; }
.die.held { transform: translateY(-5px); box-shadow: inset 0 -4px 0 var(--die-shade), 0 0 0 3px var(--accent), 0 8px 16px rgba(0, 0, 0, .35); }
.die.held::after {
  content: "vast"; position: absolute; left: 50%; bottom: -11px; translate: -50% 0;
  padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font: 800 11px/1.5 var(--body); letter-spacing: .04em;
}
.die.ghost { background: transparent; box-shadow: none; border: 2px dashed var(--line); cursor: default; }
.die.tumble { animation: tumble .28s ease-in-out infinite; animation-delay: calc(var(--d) * -1s); }
.die.land { animation: land .38s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: calc(var(--d) * .2s); }

/* hold row */
.hold-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 36px; padding-inline: 4px; color: var(--muted); font-size: 14.5px; }
.release { appearance: none; border: 1.5px solid var(--line); background: none; border-radius: 999px; min-height: 36px; padding: 0 14px; font-weight: 700; cursor: pointer; }

/* total */
.total { display: flex; justify-content: space-between; align-items: baseline; padding-inline: 4px; }
.total .label { font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.total strong { font-family: var(--display); font-weight: 400; font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; }
.note { margin: -10px 4px 0; color: var(--muted); font-size: 14px; text-align: right; }

/* settings */
.panel { border-radius: 18px; padding: 14px 16px; background: var(--surface); display: grid; gap: 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-label { font-weight: 800; }
.stepper { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); }
.stepper button { appearance: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--surface-2); font-size: 24px; font-weight: 700; cursor: pointer; }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output { width: 40px; text-align: center; font-family: var(--display); font-size: 26px; font-variant-numeric: tabular-nums; }
.themes-block { display: grid; gap: 10px; }
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-btn {
  appearance: none; cursor: pointer; min-height: 52px; padding: 0 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: none; text-align: left; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.theme-btn .swatch { width: 26px; height: 26px; flex: none; border-radius: 7px; display: grid; place-items: center; background: #fbf7ef; box-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
.theme-btn .swatch svg { width: 22px; height: 12px; }
.theme-btn .swatch i { width: 6px; height: 6px; border-radius: 50%; background: #241813; }
.theme-btn[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* roll button */
.roll {
  position: fixed; z-index: 5; left: 50%; translate: -50% 0;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 2 * max(16px, env(safe-area-inset-left, 0px))), 528px);
  min-height: 60px; border: 0; border-radius: 16px; cursor: pointer;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep), 0 10px 30px rgba(0, 0, 0, .4);
  font-family: var(--display); font-size: 22px;
}
.roll:active { transform: translateY(2px); }
.roll:disabled { opacity: .6; }

/* header and settings sheet */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.icon-btn {
  appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(8, 5, 4, .55); }
.sheet {
  position: fixed; z-index: 20; left: 50%; translate: -50% 0; bottom: 0;
  width: min(100%, 560px); max-height: 88%; overflow-y: auto; border-radius: 22px 22px 0 0;
  padding-top: 14px;
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .5);
  animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.sheet-head .icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); border: 0; }
.sheet-head .icon-btn svg { width: 18px; height: 18px; }
/* yahtzee */
.toggle-row {
  appearance: none; border: 0; background: none; cursor: pointer; text-align: left; padding: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.toggle-row > span:first-child { display: grid; gap: 2px; }
.toggle-row .muted { color: var(--muted); font-size: 14px; }
.switch { flex: none; width: 52px; height: 32px; border-radius: 999px; position: relative; background: var(--line); transition: background .2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--text); transition: transform .2s ease; }
[aria-checked="true"] .switch { background: var(--accent); }
[aria-checked="true"] .switch::after { transform: translateX(20px); }
.combo { border-radius: 18px; padding: 14px 16px; background: var(--surface); display: grid; gap: 12px; }
.combo-head { display: grid; gap: 2px; }
.combo-head .label { font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.combo-head strong { font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.05; }
.combo-head span:last-child { color: var(--muted); font-weight: 700; }
.combo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.combo-grid h3 { margin: 0 0 6px; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.combo-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.combo-grid li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 8px; color: var(--muted); font-size: 14.5px; }
.combo-grid li b { font-variant-numeric: tabular-nums; }
.combo-grid li.hit { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); font-weight: 700; }
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--bg); }
.segmented button { appearance: none; flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 700; cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.home-link {
  display: flex; align-items: center; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--line); color: var(--text); font-weight: 700; text-decoration: none;
}
.home-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes tumble { 0% { transform: rotate(-16deg) translateY(-3px); } 50% { transform: rotate(14deg) translateY(3px); } 100% { transform: rotate(-16deg) translateY(-3px); } }
@keyframes land { from { transform: translateY(-14px) rotate(-20deg); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
