@font-face {
  font-family: "Obcoro Pixel";
  src: url("/assets/fusion-pixel-12px-monospaced-zh_tw.ttf.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #030909;
  --panel: #040B09F7;
  --ink: #70F995;
  --bright: #9AFFB1;
  --muted: #599D72;
  --line: #2A6940;
  --accent: #FA785C;
  --accent-line: #D45B43;
  --hairline: #193d29;
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 "Obcoro Pixel", monospace;
  font-synthesis: none;
}
button, select { margin: 0; font: inherit; }
h1, h2, p, ol { margin: 0; }
h1, h2, strong { font-weight: 400; }
ol { padding: 0; list-style: none; }
:focus-visible { outline: 2px solid #9AFFB1; outline-offset: 3px; }
.symbols, .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.icon { width: 20px; height: 20px; flex: none; }
.page {
  width: min(100%, 53rem);
  margin-inline: auto;
  padding: max(clamp(32px, 8vh, 76px), env(safe-area-inset-top))
           max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
           max(20px, env(safe-area-inset-left));
}
.page-head, .panel-head, .history-head, .action-bar, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.page-head { margin-bottom: 24px; }
h1 { color: var(--bright); font-size: clamp(36px, 4.2vw, 48px); line-height: 1.2; }
h2 { font-size: 20px; line-height: 1.35; }
.modes { display: inline-flex; }
button, select {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: var(--ob-cursor-pointer, pointer);
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}
button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 18px;
}
.modes button + button { margin-left: -1px; }
.modes button[aria-pressed="true"] { z-index: 1; border-color: var(--ink); color: var(--bright); background: #11291b; }
.modes button[aria-pressed="true"]::after {
  content: ""; position: absolute; bottom: 0; width: 22px; height: 2px; background: var(--ink);
}
button:focus-visible { z-index: 2; }
@media (hover: hover) {
  .modes button:hover, select:hover { border-color: var(--ink); background: #11271b; }
}
.modes button:active, select:active { background: #1d3b29; }
.panel { border: 1px solid var(--line); background: var(--panel); }
.panel-head { min-height: 54px; padding: 10px 24px; border-bottom: 1px solid var(--hairline); }
.panel-head h2 { display: flex; align-items: center; gap: 12px; color: var(--bright); }
.panel-head h2::before { content: ""; width: 6px; height: 6px; background: var(--ink); }
#result-round, #history-size, .result-label { color: var(--muted); font-size: 14px; }
.stage {
  display: grid;
  align-items: center;
  min-height: 206px;
  padding: 24px;
  background: #07110d;
}
#dice-result { display: grid; grid-template-columns: minmax(0, 1fr) 148px; align-items: center; gap: 24px; }
.dice-group { min-width: 0; }
.result-label { display: block; margin-bottom: 10px; }
#dice-values { display: flex; flex-wrap: wrap; gap: 10px; }
.die {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 5px;
  width: 68px;
  height: 72px;
  border: 1px solid var(--muted);
  background: #0e2016;
  color: var(--bright);
}
.die-number { font-size: 32px; line-height: 1; }
.die.has-pips .die-number { font-size: 16px; }
.pips { width: 30px; height: 30px; fill: var(--ink); shape-rendering: crispEdges; }
.die.is-empty { border-style: dashed; color: var(--muted); }
.sum { border-left: 1px solid var(--line); text-align: center; }
.sum .result-label { margin-bottom: 2px; }
#total { display: block; font-size: 60px; line-height: 1; color: var(--bright); }
#coin-result { display: flex; align-items: center; justify-content: center; gap: clamp(16px, 4vw, 44px); }
#coin-result::before, #coin-result::after {
  content: ""; width: min(9%, 54px); height: 5px;
  border-bottom: 1px solid var(--hairline);
}
#coin-result::before { border-left: 1px solid var(--line); }
#coin-result::after { border-right: 1px solid var(--line); }
.medallion { display: grid; place-items: center; width: 144px; aspect-ratio: 1; }
.medallion > * { grid-area: 1 / 1; }
.coin-art { display: block; width: 100%; height: 100%; }
#coin-face { color: var(--bright); font-size: 48px; line-height: 1; transform: translate(-3px, -6px); }
.action-bar { border-top: 1px solid var(--hairline); padding: 16px 24px; }
.action-bar.coin { justify-content: center; }
.settings, .settings label { display: flex; align-items: center; gap: 10px; }
.settings { flex-wrap: wrap; gap: 20px; }
.settings label { color: var(--muted); font-size: 15px; }
.select-wrap { position: relative; display: inline-flex; }
.select-wrap::after {
  content: ""; position: absolute; pointer-events: none; right: 12px; top: calc(50% - 4px);
  width: 7px; height: 7px; border: solid var(--ink); border-width: 0 1px 1px 0;
  transform: rotate(45deg);
}
select { width: 91px; appearance: none; padding: 6px 29px 6px 12px; font-size: 18px; }
.primary {
  isolation: isolate;
  min-width: 148px;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 20px;
}
.primary::before, .primary::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  background: var(--accent-line);
  transition: background-color 140ms ease;
}
.primary::after { inset: 1px; background: #281610; }
@media (hover: hover) {
  .primary:hover::before { background: var(--accent); }
  .primary:hover::after { background: #402019; }
}
.primary:active::after { background: #54291e; }
.primary[aria-disabled="true"] { opacity: .55; cursor: wait; }
.history { margin-top: 28px; }
.history-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.history h2 { color: var(--ink); }
#history-size { font-variant-numeric: tabular-nums; }
#history-list li {
  display: grid;
  grid-template-columns: 3ch 124px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  min-height: 47px;
  border-bottom: 1px solid var(--hairline);
}
.entry-number, .entry-spec, .entry-values, #empty-history { color: var(--muted); }
.entry-number { font-size: 14px; }
.entry-mode { display: inline-flex; gap: 8px; align-items: center; }
.entry-mode .icon { width: 16px; height: 16px; color: var(--muted); }
.entry-result { grid-column: -2; grid-row: 1; text-align: right; white-space: nowrap; }
#empty-history { margin: 16px 0; font-size: 14px; }
footer { margin-top: 20px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.rolling #dice-values, .rolling #total { animation: tumble 360ms ease-out; }
.rolling .medallion { animation: flip 360ms ease-in-out; }
@keyframes tumble { 35% { opacity: .62; transform: translateY(-3px); } 70% { transform: translateY(1px); } }
@keyframes flip { 45% { transform: translateY(-3px) scaleX(.67); } }
@media (max-width: 40rem) {
  .page { padding-top: max(28px, env(safe-area-inset-top)); }
  .page-head { align-items: stretch; flex-direction: column; gap: 16px; margin-bottom: 16px; }
  .modes button { flex: 1; }
  .panel-head, .action-bar { padding-inline: 16px; }
  .stage { padding: 20px 16px; min-height: 190px; }
  #dice-result { grid-template-columns: minmax(0, 1fr) 88px; gap: 12px; }
  #dice-values { gap: 8px; max-width: 190px; }
  .die { width: 56px; height: 60px; gap: 3px; }
  .pips { width: 25px; height: 25px; }
  #total { font-size: 48px; }
  .action-bar { align-items: stretch; flex-direction: column; gap: 12px; }
  .settings { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .settings label { align-items: stretch; flex-direction: column; gap: 3px; }
  select { width: 100%; }
  .history { margin-top: 22px; }
  #history-list li { grid-template-columns: 2ch minmax(0, 1fr) auto; gap: 2px 12px; }
  .entry-mode { gap: 8px; }
  .entry-values { grid-column: 2 / -1; grid-row: 2; padding-left: 24px; line-height: 1.35; }
  footer { gap: 4px 12px; margin-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.footer-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}