:root {
  /* Stone & Bone — cool dark slate, parchment-bone text, crimson sand. */
  --bg:         #16161B;
  --bg-2:       #1B1B22;
  --bg-3:       #21212A;

  --surface:    #22232B;
  --surface-2:  #2A2B34;
  --surface-3:  #33343F;

  --text:       #E6DDC8;
  --text-2:     #CFC4A6;
  --text-3:     #B0A584;

  --muted:      #7C746A;
  --muted-2:    #565148;

  --accent:        #B23A2E;
  --accent-bright: #C8503F;
  --accent-deep:   #7E2520;
  --accent-glow:   rgba(178, 58, 46, 0.32);
  --accent-soft:   rgba(178, 58, 46, 0.16);
  --accent-faint:  rgba(178, 58, 46, 0.06);

  --brass:        #B59550;
  --brass-deep:   #8C7035;
  --brass-glow:   rgba(181, 149, 80, 0.32);

  --border:           rgba(230, 221, 200, 0.10);
  --border-strong:    rgba(230, 221, 200, 0.22);
  --border-accent:    rgba(178, 58, 46, 0.42);

  /* Layout */
  --col:        min(100% - 1.25rem, 480px);
  --gutter:     0.625rem;
  --radius:     6px;
  --radius-sm:  3px;
  --radius-pill: 999px;

  /* Type */
  --font-display: "Iowan Old Style", "Hoefler Text", "Cochin",
                  Georgia, "Times New Roman", serif;
  --font-body:    "Iowan Old Style", "Hoefler Text", "Charter",
                  Georgia, serif;
  --font-mono:    ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  padding-top:    max(var(--gutter), env(safe-area-inset-top));
  padding-bottom: calc(76px + max(var(--gutter), env(safe-area-inset-bottom)));
  padding-left:   max(var(--gutter), env(safe-area-inset-left));
  padding-right:  max(var(--gutter), env(safe-area-inset-right));
  position: relative;
  overflow-x: hidden;
}

/* Stone grain — fine flecks of bone-cream and crimson */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(1.1px 1.1px at 8%  12%, rgba(230, 221, 200, 0.18), transparent 60%),
    radial-gradient(1px   1px   at 23% 34%, rgba(230, 221, 200, 0.12), transparent 60%),
    radial-gradient(1.2px 1.2px at 67% 22%, rgba(230, 221, 200, 0.16), transparent 60%),
    radial-gradient(0.8px 0.8px at 85% 58%, rgba(230, 221, 200, 0.12), transparent 60%),
    radial-gradient(1.3px 1.3px at 45% 75%, rgba(230, 221, 200, 0.20), transparent 60%),
    radial-gradient(1px   1px   at 15% 88%, rgba(230, 221, 200, 0.12), transparent 60%),
    radial-gradient(1.2px 1.2px at 92% 32%, rgba(230, 221, 200, 0.16), transparent 60%),
    radial-gradient(0.9px 0.9px at 32% 60%, rgba(230, 221, 200, 0.10), transparent 60%),
    radial-gradient(1.1px 1.1px at 75% 85%, rgba(230, 221, 200, 0.14), transparent 60%),
    radial-gradient(0.9px 0.9px at 55%  8%, rgba(178,  58, 46, 0.42), transparent 60%),
    radial-gradient(1.1px 1.1px at 18% 45%, rgba(178,  58, 46, 0.34), transparent 60%),
    radial-gradient(0.9px 0.9px at 88% 78%, rgba(178,  58, 46, 0.30), transparent 60%);
  background-size: 600px 600px;
}

/* Cathedral light — faint amber above, deeper black corners */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 110% 35% at 50% 0%,
      rgba(181, 149, 80, 0.10), transparent 70%),
    radial-gradient(ellipse 100% 100% at 50% 50%,
      transparent 50%, rgba(0, 0, 0, 0.32) 100%);
}

main {
  width: var(--col);
  margin-inline: auto;
  position: relative;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  margin: 0;
  letter-spacing: 0;
}

button {
  min-height: 44px;
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

input, select {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  width: 100%;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

input::placeholder {
  color: var(--muted);
  font-style: italic;
  opacity: 0.9;
}

/* ──── Header + tabs ─────────────────────────────────── */

.app-header {
  padding: 0.5rem 0 0.1rem;
  text-align: center;
}

.app-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.1rem;
}

.app-logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  margin-bottom: 0;
  line-height: 1.05;
  text-shadow: 0 0 18px rgba(181, 149, 80, 0.22);
}

.app-subtitle {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--text-3);
  letter-spacing: 0.02em;
  opacity: 0.85;
}

.tab-bar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.7rem;
}

.tab-bar::before {
  content: "✦";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  font-size: 0.72rem;
  pointer-events: none;
  opacity: 0.85;
}

.tab-bar button {
  background: transparent;
  color: var(--text-3);
  border: none;
  padding: 0.5rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-size: 0.7rem;
  position: relative;
  min-height: 38px;
  text-indent: 0.32em;
  transition: color 0.15s;
}

.tab-bar button.active {
  color: var(--text);
}

.tab-bar button.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 28%;
  right: 28%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ──── Section header ─────────────────────────────────── */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0.85rem 0.25rem 0.85rem;
}

.section-head h2 {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-3);
  text-indent: 0.32em;
}

.btn-add {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-accent);
  padding: 0.4rem 1.1rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  font-weight: 700;
  font-family: var(--font-body);
  text-transform: uppercase;
  min-height: 34px;
  text-indent: 0.18em;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn-add:active {
  background: var(--accent);
  color: var(--text);
  box-shadow: 0 0 18px var(--accent-glow);
}

/* ──── Counter card ───────────────────────────────────── */

.counter-list {
  display: flex;
  flex-direction: column;
  /* gap → per-card margin-bottom so the spacing can animate during remove */
}

.counter-card {
  position: relative;
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem 0.85rem;
  margin-bottom: 0.65rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 0.85rem;
  row-gap: 0.85rem;
  align-items: center;
  overflow: hidden;
  max-height: 260px;
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.4),
    0 3px 10px rgba(0, 0, 0, 0.20);
  transition:
    border-color 0.2s,
    box-shadow 0.2s,
    margin-bottom 240ms ease;
}

.counter-card:last-child {
  margin-bottom: 0;
}

.counter-card.removing {
  animation: counterRemove 280ms cubic-bezier(0.4, 0, 0.7, 0.4) forwards;
  pointer-events: none;
}

@keyframes counterRemove {
  0%   { opacity: 1; transform: scale(1);    max-height: 260px; margin-bottom: 0.65rem; padding-top: 0.95rem; padding-bottom: 0.85rem; }
  45%  { opacity: 0; transform: scale(0.94); max-height: 260px; margin-bottom: 0.65rem; padding-top: 0.95rem; padding-bottom: 0.85rem; }
  100% { opacity: 0; transform: scale(0.94); max-height: 0;     margin-bottom: 0;       padding-top: 0;       padding-bottom: 0; }
}

.counter-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(230, 221, 200, 0.04) 0%, transparent 40%);
}

.counter-card.confirming-delete {
  border-color: var(--accent);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.4),
    0 0 22px rgba(178, 58, 46, 0.30);
}

.counter-icon {
  grid-column: 1;
  grid-row: 1;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: rgba(230, 221, 200, 0.05);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.counter-icon svg {
  width: 26px;
  height: 26px;
  opacity: 0.95;
  filter: drop-shadow(0 0 8px currentColor);
}

.counter-meta {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.counter-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  letter-spacing: 0.005em;
}

.counter-range {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 2px;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.counter-value {
  grid-column: 3;
  grid-row: 1;
  font-family: var(--font-display);
  font-size: 2.55rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 0.92;
  color: var(--accent);
  padding-right: 0.1rem;
  letter-spacing: -0.01em;
  text-shadow:
    0 0 18px rgba(178, 58, 46, 0.40),
    0 1px 0 rgba(0, 0, 0, 0.6);
}

.counter-value.at-min {
  color: var(--accent-deep);
  text-shadow: 0 0 14px rgba(126, 37, 32, 0.55), 0 1px 0 rgba(0, 0, 0, 0.6);
}

.counter-value.at-max {
  color: var(--brass);
  text-shadow: 0 0 14px var(--brass-glow), 0 1px 0 rgba(0, 0, 0, 0.6);
}

.counter-actions {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.counter-actions button {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.counter-actions button:active:not(:disabled) {
  background: var(--accent-faint);
  border-color: var(--border-accent);
  color: var(--accent-bright);
}

.counter-actions button.btn-remove {
  background: transparent;
  color: var(--text-3);
  font-size: 1.05rem;
  font-weight: 300;
  font-family: var(--font-body);
}

.counter-actions button.btn-remove.confirming {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 18px var(--accent-glow);
  animation: pulseAccent 1.1s ease-in-out infinite;
}

@keyframes pulseAccent {
  0%, 100% { box-shadow: 0 0 14px var(--accent-glow); }
  50%      { box-shadow: 0 0 24px var(--accent-glow); }
}

.counter-actions button:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ──── Empty state ────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-3);
}

.empty h3 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin-bottom: 0.55rem;
  color: var(--text);
  font-weight: 700;
  font-style: italic;
}

.empty p {
  font-size: 0.94rem;
  margin: 0;
  font-style: italic;
}

.empty strong {
  color: var(--accent);
  font-weight: 700;
  font-style: normal;
}

/* ──── Footer toolbar ─────────────────────────────────── */

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(22, 22, 27, 0.85);
  backdrop-filter: blur(18px) saturate(110%);
  -webkit-backdrop-filter: blur(18px) saturate(110%);
  border-top: 1px solid var(--border);
  padding: 0.5rem max(var(--gutter), env(safe-area-inset-left))
           calc(0.5rem + env(safe-area-inset-bottom))
           max(var(--gutter), env(safe-area-inset-right));
  display: flex;
  justify-content: center;
  z-index: 30;
}

.toolbar-inner {
  width: var(--col);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}

.toolbar button {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0 0.4rem;
  min-height: 42px;
  text-indent: 0.18em;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.toolbar button:disabled {
  opacity: 0.32;
  pointer-events: none;
}

.toolbar button:active:not(:disabled) {
  background: var(--accent-faint);
  color: var(--accent-bright);
  border-color: var(--border-accent);
}

.toolbar svg {
  width: 16px;
  height: 16px;
  opacity: 0.85;
}

/* ──── Sheet / dialog ─────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet-backdrop.entering { animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0.4; }
  to   { transform: translateY(0);    opacity: 1; }
}

.sheet {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 80%);
  border-top: 2px solid var(--accent);
  border-radius: 14px 14px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  padding: 1.1rem max(var(--gutter), env(safe-area-inset-left))
           calc(1rem + env(safe-area-inset-bottom))
           max(var(--gutter), env(safe-area-inset-right));
  position: relative;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
}

.sheet.entering {
  animation: slideUp 0.26s cubic-bezier(0.2, 0.85, 0.3, 1);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.15rem;
  padding: 0.15rem 0.1rem 0.4rem;
}

.sheet-head h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.02em;
  font-style: italic;
}

.sheet-close {
  font-size: 1.5rem;
  width: 36px;
  height: 36px;
  min-height: 36px;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
}

.sheet-close:active {
  background: var(--accent-soft);
  color: var(--accent-bright);
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  min-height: 48px;
  text-indent: 0.2em;
  transition: background 0.15s, transform 0.06s, box-shadow 0.15s;
  box-shadow:
    0 3px 0 var(--accent-deep),
    0 4px 14px rgba(178, 58, 46, 0.30);
}

.btn-primary:active {
  transform: translateY(2px);
  background: var(--accent-bright);
  box-shadow:
    0 1px 0 var(--accent-deep),
    0 2px 6px rgba(178, 58, 46, 0.30);
}

.btn-primary:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 48px;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 600;
  text-indent: 0.2em;
}

/* ──── Form ─────────────────────────────────────────── */

.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  margin-bottom: 0.4rem;
  font-weight: 600;
  text-indent: 0.22em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.icon-pick {
  aspect-ratio: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  color: var(--text-2);
  transition: all 0.15s;
}

.icon-pick svg { width: 26px; height: 26px; }

.icon-pick.selected {
  border-color: var(--accent);
  background: var(--accent-faint);
  box-shadow: inset 0 0 12px var(--accent-soft), 0 0 14px var(--accent-soft);
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.55rem;
}

.color-pick {
  aspect-ratio: 1;
  border-radius: var(--radius-pill);
  border: 1.5px solid transparent;
  min-height: 0;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.color-pick::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: var(--radius-pill);
  background: var(--swatch);
}

.color-pick.selected {
  border-color: var(--text);
  box-shadow: 0 0 14px var(--accent-glow);
}

/* ──── Dice view ──────────────────────────────────────── */

body[data-view="dice"] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-view="dice"] main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

body[data-view="dice"] #dice-mount {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dice-view {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

body[data-view="dice"] .dice-view {
  flex: 1;
  min-height: 0;
}

.dice-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.5rem 0;
}

body[data-view="dice"] .dice-stage {
  flex: 1;
}

.result-placeholder {
  text-align: center;
  color: var(--text-3);
}

.placeholder-hint {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.2rem;
  letter-spacing: 0.03em;
  opacity: 0.65;
}

.placeholder-hint::before,
.placeholder-hint::after {
  content: "✦";
  color: var(--accent);
  opacity: 0.85;
  font-style: normal;
  margin: 0 0.6em;
  font-size: 0.65em;
  vertical-align: 0.18em;
}

.die-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.die-pick {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.5rem 0.3rem;
  min-height: 44px;
  transition: all 0.15s;
}

.die-pick.selected {
  background: var(--accent-faint);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: inset 0 0 12px var(--accent-soft), 0 0 14px var(--accent-soft);
}

.die-pick:disabled { opacity: 0.4; pointer-events: none; }
.die-pick:active:not(:disabled) { background: var(--accent-faint); }

.count-stepper {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 48px;
}

.count-stepper button {
  background: transparent;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-display);
}

.count-stepper button:disabled { opacity: 0.35; pointer-events: none; }
.count-stepper button:active:not(:disabled) {
  background: var(--accent-faint);
  color: var(--accent-bright);
}

.count-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3rem;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 14px var(--accent-glow);
}

.count-display .count-die {
  font-size: 0.85rem;
  color: var(--text-3);
  font-style: italic;
  font-weight: 400;
  text-shadow: none;
}

.btn-roll {
  width: 100%;
  background: var(--accent);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  min-height: 60px;
  text-indent: 0.36em;
  transition: background 0.15s, transform 0.06s, box-shadow 0.15s;
  box-shadow:
    0 4px 0 var(--accent-deep),
    0 5px 18px rgba(178, 58, 46, 0.34);
}

.btn-roll:active:not(:disabled) {
  transform: translateY(2px);
  background: var(--accent-bright);
  box-shadow:
    0 2px 0 var(--accent-deep),
    0 3px 10px rgba(178, 58, 46, 0.34);
}

.btn-roll:disabled { opacity: 0.7; pointer-events: none; }

/* Result card */

.result-card {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 0.85rem 0.85rem 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  position: relative;
  overflow: hidden;
  width: 100%;
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.4),
    0 4px 18px rgba(0, 0, 0, 0.25);
}

.result-card.entering {
  animation: resultIn 0.28s cubic-bezier(0.2, 0.85, 0.3, 1.15);
}

.result-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 50%, transparent);
  box-shadow: 0 0 10px var(--accent-glow);
}

@keyframes resultIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.result-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  align-items: center;
  align-content: center;
  height: 120px;
  width: 100%;
}

.result-dice.grid-2row {
  display: grid;
  grid-template-columns: repeat(var(--col-count), 56px);
  grid-template-rows: 56px 56px;
  grid-auto-flow: row;
  gap: 0.45rem;
  justify-content: safe center;
  align-content: center;
  height: 120px;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: initial;
  scrollbar-width: thin;
  scrollbar-color: rgba(230, 221, 200, 0.22) transparent;
}

.result-dice.grid-2row::-webkit-scrollbar { height: 4px; }
.result-dice.grid-2row::-webkit-scrollbar-track { background: transparent; }
.result-dice.grid-2row::-webkit-scrollbar-thumb {
  background: rgba(230, 221, 200, 0.22);
  border-radius: 2px;
}

.die-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  position: relative;
  color: var(--accent-bright);
}

.die-face .die-shape {
  width: 52px;
  height: 52px;
  transform-origin: center;
  filter:
    drop-shadow(0 0 6px var(--accent-glow))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}

.die-face.crit  { color: var(--brass); }
.die-face.crit .die-shape {
  filter:
    drop-shadow(0 0 8px var(--brass-glow))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}

.die-face.fumble { color: var(--accent-deep); }
.die-face.fumble .die-shape {
  filter:
    drop-shadow(0 0 6px rgba(126, 37, 32, 0.45))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}

.die-face .die-face-top    { fill: currentColor; opacity: 0.55; }
.die-face .die-face-side   { fill: currentColor; opacity: 0.38; }
.die-face .die-face-side-2 { fill: currentColor; opacity: 0.24; }
.die-face .die-face-shadow { fill: currentColor; opacity: 0.12; }

.die-face .die-poly-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linejoin: round;
  opacity: 1;
}

.die-face .die-facet {
  stroke: currentColor;
  stroke-width: 0.6;
  opacity: 0.55;
  stroke-linecap: round;
  fill: none;
}

.die-face .die-num {
  font-family: var(--font-display);
  font-weight: 900;
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.85);
  stroke-width: 0.7;
}

.die-face.crit .die-num   { fill: #1A1208; stroke: rgba(0, 0, 0, 0.55); }
.die-face.fumble .die-num { fill: var(--text); stroke: rgba(0, 0, 0, 0.9); }

@keyframes diceTumble {
  0%   { transform: translateY(-48px) rotate(-22deg) scale(0.72); opacity: 0; }
  12%  { transform: translateY(0)     rotate(150deg)  scale(1.10); opacity: 1; }
  26%  { transform: translateY(-18px) rotate(290deg)  scale(0.90); }
  42%  { transform: translateY(0)     rotate(440deg)  scale(1.08); }
  58%  { transform: translateY(-9px)  rotate(560deg)  scale(0.96); }
  72%  { transform: translateY(0)     rotate(660deg)  scale(1.04); }
  86%  { transform: translateY(-3px)  rotate(710deg)  scale(1.01); }
  100% { transform: translateY(0)     rotate(720deg)  scale(1); opacity: 1; }
}

.die-face.rolling .die-shape {
  animation: diceTumble 750ms cubic-bezier(0.22, 0.85, 0.3, 1.05) both;
}

.die-face.rolling:nth-child(2)  .die-shape { animation-delay: 35ms; }
.die-face.rolling:nth-child(3)  .die-shape { animation-delay: 70ms; }
.die-face.rolling:nth-child(4)  .die-shape { animation-delay: 105ms; }
.die-face.rolling:nth-child(5)  .die-shape { animation-delay: 140ms; }
.die-face.rolling:nth-child(6)  .die-shape { animation-delay: 170ms; }
.die-face.rolling:nth-child(7)  .die-shape { animation-delay: 195ms; }
.die-face.rolling:nth-child(8)  .die-shape { animation-delay: 220ms; }
.die-face.rolling:nth-child(9)  .die-shape { animation-delay: 240ms; }
.die-face.rolling:nth-child(10) .die-shape { animation-delay: 260ms; }
.die-face.rolling:nth-child(11) .die-shape { animation-delay: 280ms; }
.die-face.rolling:nth-child(12) .die-shape { animation-delay: 300ms; }

.result-sum {
  font-family: var(--font-body);
  font-size: 0.7rem;
  color: var(--text-3);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-indent: 0.2em;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  line-height: 1;
}

.result-sum strong {
  font-family: var(--font-display);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 900;
  text-shadow: 0 0 14px var(--accent-glow);
  letter-spacing: 0;
  text-indent: 0;
}

/* ──── Log ──────────────────────────────────────────── */

.log-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.btn-clear-log {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-3);
  border-radius: var(--radius-sm);
  padding: 0 0.7rem;
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  min-height: 32px;
  text-indent: 0.18em;
  transition: all 0.15s;
}

.btn-clear-log:active {
  background: var(--accent-soft);
  color: var(--accent-bright);
  border-color: var(--accent);
}

.btn-clear-log.confirming {
  background: var(--accent);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

.log-list {
  display: flex;
  flex-direction: column;
}

.log-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.8rem;
  font-size: 0.92rem;
  font-family: var(--font-body);
}

.log-row:last-child { border-bottom: none; }

.log-text {
  color: var(--text-2);
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

.log-text::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  align-self: center;
}

.log-row.log-roll .log-text::before {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.log-time {
  color: var(--text-3);
  font-size: 0.74rem;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  flex-shrink: 0;
  opacity: 0.7;
}

.log-empty {
  text-align: center;
  padding: 2.5rem 0;
  color: var(--text-3);
  font-style: italic;
}

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
