/* =========================================================
   Rolemaster Reborn — UI additions
   Load AFTER css/styles.css
   ========================================================= */

:root {
  --rm-success: #355f23;
  --rm-success-bright: #5f9b3c;
  --rm-warning: #9a6420;
  --rm-warning-bright: #d59a38;
  --rm-danger: #8b2500;
  --rm-danger-bright: #c2512b;
  --rm-arcane: #5b3aa6;
  --rm-steel: #5f646e;
  --rm-ink-soft: #5a4328;
  --rm-overlay: rgba(9, 7, 5, 0.82);
  --rm-success-veil: rgba(63, 111, 42, 0.12);
  --rm-warning-veil: rgba(168, 108, 31, 0.14);
  --rm-danger-veil: rgba(139, 37, 0, 0.12);
  --rm-arcane-veil: rgba(91, 58, 166, 0.12);
}

.rm-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

.rm-overlay-shell {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 197, 92, 0.08), transparent 28%),
    var(--rm-overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.rm-overlay-shell[hidden] {
  display: none !important;
}

.rm-modal-panel,
.rm-session-panel,
.rm-compare-shell {
  position: relative;
  width: min(100%, 68rem);
  color: var(--color-parchment-text);
  background:
    linear-gradient(rgba(255,255,255,0.08), rgba(0,0,0,0.04)),
    #f4e8cb url('../assets/ui/backgrounds/parchment_texture_1024.webp') center center repeat;
  border: 1px solid rgba(120, 78, 20, 0.35);
  box-shadow:
    0 24px 72px rgba(0,0,0,0.48),
    inset 0 0 0 1px rgba(255, 230, 176, 0.16),
    inset 0 10px 26px rgba(255,255,255,0.12);
  overflow: hidden;
}

.rm-modal-panel::before,
.rm-session-panel::before,
.rm-compare-shell::before {
  content: '';
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(138, 92, 20, 0.22);
  pointer-events: none;
}

.rm-modal-panel {
  max-width: 44rem;
  max-height: min(86vh, 52rem);
  overflow: auto;
  border-radius: 0.75rem;
}

.rm-modal-header,
.rm-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem 0.875rem;
  border-bottom: 1px solid rgba(138, 92, 20, 0.18);
  background: linear-gradient(to bottom, rgba(88, 55, 17, 0.1), rgba(255,255,255,0));
}

.rm-modal-title,
.rm-sheet-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #4e2d0d;
  text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}

.rm-modal-subtitle,
.rm-sheet-subtitle {
  margin: 0.25rem 0 0;
  color: var(--rm-ink-soft);
  font-size: 0.95rem;
}

.rm-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid rgba(138, 92, 20, 0.25);
  border-radius: 999px;
  background: rgba(255,255,255,0.32);
  color: #4c3318;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.rm-icon-btn:hover {
  transform: translateY(-1px);
  border-color: var(--color-gold);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.12);
}

.rm-icon-btn:focus-visible,
.rm-action-btn:focus-visible,
.rm-result-toggle:focus-visible,
.rm-filter-chip:focus-visible,
.rm-tabbed-chip:focus-visible,
.rm-field:focus-visible,
.rm-inline-input:focus-visible,
.rm-btn-scroll:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

.rm-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.rm-action-btn,
.rm-btn-scroll {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  padding: 0.625rem 1rem;
  font-family: var(--font-title);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff5d6;
  cursor: pointer;
  border: 1px solid #946a1e;
  border-radius: 0.55rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.14), rgba(0,0,0,0.12)),
    linear-gradient(135deg, #7b5418, #b07c22 48%, #6a4310);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 8px 18px rgba(60,36,10,0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.rm-action-btn:hover,
.rm-btn-scroll:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 12px 24px rgba(60,36,10,0.28),
    0 0 0 3px rgba(212,160,23,0.12);
}

.rm-action-btn:active,
.rm-btn-scroll:active {
  transform: translateY(0);
}

.rm-action-btn.is-secondary {
  color: #43260d;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22), rgba(0,0,0,0.06)),
    linear-gradient(135deg, #d7c29e, #c5a56b 48%, #a88349);
  text-shadow: none;
}

.rm-action-btn.is-subtle {
  color: #573819;
  background: rgba(255,255,255,0.34);
  border-color: rgba(138, 92, 20, 0.25);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
}

.rm-action-btn[aria-busy="true"],
.rm-btn-scroll[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.88;
}

.rm-spinner {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(255,245,214,0.28);
  border-top-color: #fff5d6;
  animation: rm-spin 0.85s linear infinite;
}

@keyframes rm-spin {
  to { transform: rotate(360deg); }
}

.rm-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.875rem 1rem;
  padding: 1rem 1.25rem 1.25rem;
}

.rm-field-group {
  display: grid;
  gap: 0.375rem;
}

.rm-field-group.is-span-2 {
  grid-column: 1 / -1;
}

.rm-field-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #5b4022;
  letter-spacing: 0.02em;
}

.rm-field,
.rm-inline-input,
.rm-select {
  width: 100%;
  min-height: 2.5rem;
  border-radius: 0.45rem;
  border: 1px solid rgba(138, 92, 20, 0.24);
  background: rgba(255,255,255,0.42);
  color: #2b1806;
  padding: 0.55rem 0.7rem;
  font: inherit;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.2);
}

.rm-inline-input {
  min-height: 2.2rem;
  padding: 0.4rem 0.55rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rm-help {
  font-size: 0.78rem;
  color: #6e5538;
}

.rm-npc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(16rem, 0.85fr);
  gap: 1rem;
  padding: 1rem 1.25rem 1.25rem;
}

.rm-preview-card {
  align-self: start;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.2), transparent),
    rgba(112, 78, 24, 0.09);
  border: 1px solid rgba(138, 92, 20, 0.18);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16);
}

.rm-preview-crest {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.rm-preview-icon {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.22));
}

.rm-preview-name {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: #4d3011;
}

.rm-preview-meta {
  margin: 0.15rem 0 0;
  color: #72583c;
  font-size: 0.88rem;
}

.rm-preview-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.875rem;
}

.rm-preview-stat {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.45rem;
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(138, 92, 20, 0.14);
  font-variant-numeric: tabular-nums;
}

.rm-npc-badge {
  position: absolute;
  top: 0.85rem;
  right: -0.3rem;
  z-index: 2;
  padding: 0.28rem 0.7rem 0.28rem 0.9rem;
  font-family: var(--font-title);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff5d6;
  background: linear-gradient(135deg, #8b2500, #b34115 48%, #7e2000);
  border: 1px solid rgba(97,20,0,0.55);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 14% 100%);
  box-shadow: 0 8px 18px rgba(83, 20, 3, 0.24);
}

.rm-compare-shell {
  width: min(100%, 76rem);
  max-height: min(88vh, 56rem);
  overflow: auto;
  border-radius: 0.85rem;
}

.rm-compare-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid rgba(138, 92, 20, 0.18);
}

.rm-compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
  padding: 1rem 1.25rem 1.25rem;
}

.rm-compare-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    rgba(104, 68, 18, 0.08);
  border: 1px solid rgba(138, 92, 20, 0.18);
  border-radius: 0.9rem;
  padding: 1rem;
  box-shadow: 0 12px 22px rgba(60, 34, 10, 0.08);
}

.rm-compare-card.is-best-overall {
  box-shadow:
    0 14px 28px rgba(60, 34, 10, 0.14),
    0 0 0 2px rgba(212,160,23,0.18);
}

.rm-compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.rm-card-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.02rem;
  color: #4b2f12;
}

.rm-card-meta {
  margin: 0.15rem 0 0;
  color: #735a3c;
  font-size: 0.84rem;
}

.rm-score-pill,
.rm-sim-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.8rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5b3a0e;
  background: rgba(212,160,23,0.12);
  border: 1px solid rgba(212,160,23,0.26);
}

.rm-compare-section {
  margin-top: 0.75rem;
}

.rm-compare-section h4 {
  margin: 0 0 0.45rem;
  font-family: var(--font-title);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6a4a18;
}

.rm-stat-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.45rem;
}

.rm-stat-key {
  font-size: 0.82rem;
  color: #684b2a;
  font-weight: 700;
}

.rm-stat-meter {
  position: relative;
  height: 0.78rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(111, 79, 25, 0.14);
  border: 1px solid rgba(138, 92, 20, 0.16);
}

.rm-stat-meter > span {
  display: block;
  height: 100%;
  width: var(--meter, 50%);
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(255,228,173,0.34), rgba(255,255,255,0.06)),
    linear-gradient(90deg, #8b6914, #d4a017 54%, #8c5a12);
  box-shadow: inset 0 0 6px rgba(255,255,255,0.12);
}

.rm-stat-meter.is-best > span {
  background:
    linear-gradient(90deg, rgba(255,244,199,0.44), rgba(255,255,255,0.12)),
    linear-gradient(90deg, #a57b15, #f0c040 56%, #b77712);
}

.rm-stat-value {
  min-width: 2.8rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #422610;
}

.rm-session-shell {
  position: fixed;
  inset: 0;
  z-index: 125;
  pointer-events: none;
}

.rm-session-shell[hidden] {
  display: none !important;
}

.rm-session-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 4, 0.56);
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: auto;
}

.rm-session-shell.is-open .rm-session-backdrop {
  opacity: 1;
}

.rm-session-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(100%, 28rem);
  height: 100%;
  border-left: 1px solid rgba(138, 92, 20, 0.28);
  border-radius: 0;
  transform: translateX(100%);
  transition: transform 0.26s ease;
  pointer-events: auto;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.rm-session-shell.is-open .rm-session-panel {
  transform: translateX(0);
}

.rm-session-top {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(138, 92, 20, 0.18);
}

.rm-session-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.12rem;
  color: #4e2e0f;
}

.rm-session-subtitle {
  margin: 0.25rem 0 0;
  color: #72583c;
  font-size: 0.86rem;
}

.rm-tool-tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(138, 92, 20, 0.14);
}

.rm-tabbed-chip,
.rm-filter-chip {
  appearance: none;
  border: 1px solid rgba(138, 92, 20, 0.2);
  border-radius: 999px;
  background: rgba(255,255,255,0.3);
  color: #5d3d17;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.42rem 0.72rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.rm-tabbed-chip:hover,
.rm-filter-chip:hover {
  border-color: var(--color-gold);
  background: rgba(212,160,23,0.12);
}

.rm-tabbed-chip.is-active,
.rm-filter-chip.is-active {
  color: #fff5d6;
  border-color: #946a1e;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.1), rgba(0,0,0,0.08)),
    linear-gradient(135deg, #7b5418, #b07c22 48%, #6a4310);
}

.rm-session-content {
  overflow: auto;
  padding: 1rem;
}

.rm-tool-pane {
  display: none;
}

.rm-tool-pane.is-active {
  display: block;
}

.rm-tool-card {
  border: 1px solid rgba(138, 92, 20, 0.18);
  border-radius: 0.75rem;
  background: rgba(255,255,255,0.18);
  padding: 0.85rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.14);
}

.rm-tool-card + .rm-tool-card {
  margin-top: 0.85rem;
}

.rm-tool-card h4 {
  margin: 0 0 0.65rem;
  font-family: var(--font-title);
  font-size: 0.88rem;
  text-transform: uppercase;
  color: #5d3a10;
}

.rm-tool-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.rm-roller-big {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 7rem;
  margin-bottom: 0.8rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(138, 92, 20, 0.2);
  background:
    radial-gradient(circle at center, rgba(255,215,104,0.08), transparent 55%),
    rgba(115, 77, 23, 0.08);
  overflow: hidden;
}

.rm-roller-value {
  font-family: var(--font-title);
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 700;
  color: #4b2b0c;
  text-shadow: 0 0 12px rgba(255,210,120,0.18);
  font-variant-numeric: tabular-nums;
}

.rm-roller-value.is-rolling {
  animation: rm-d100-roll 0.65s steps(8, end) 1;
}

.rm-history-stack {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
  max-height: 22rem;
  overflow: auto;
  padding-right: 0.2rem;
}

.rm-result-card {
  position: relative;
  border-radius: 0.8rem;
  padding: 0.95rem 1rem;
  border: 1px solid rgba(138, 92, 20, 0.18);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    rgba(255,255,255,0.34);
  box-shadow:
    0 10px 18px rgba(60, 36, 10, 0.08),
    inset 0 1px 0 rgba(255,255,255,0.14);
  animation: rm-card-rise 0.28s ease both;
}

.rm-result-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-left: 5px solid transparent;
  border-radius: inherit;
  pointer-events: none;
}

.rm-result-card.is-success {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    var(--rm-success-veil);
}

.rm-result-card.is-success::before {
  border-left-color: var(--rm-success);
}

.rm-result-card.is-partial {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    var(--rm-warning-veil);
}

.rm-result-card.is-partial::before {
  border-left-color: var(--rm-warning);
}

.rm-result-card.is-failure {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    var(--rm-danger-veil);
}

.rm-result-card.is-failure::before {
  border-left-color: var(--rm-danger);
}

.rm-result-card.is-arcane {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    var(--rm-arcane-veil);
}

.rm-result-card.is-arcane::before {
  border-left-color: var(--rm-arcane);
}

.rm-result-card.is-critical {
  animation:
    rm-card-rise 0.28s ease both,
    rm-critical-flash 0.42s ease 1;
}

.rm-result-card.is-fumble {
  animation:
    rm-card-rise 0.28s ease both,
    rm-fumble-shake 0.32s ease 1;
}

.rm-result-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
}

.rm-result-type {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-width: 0;
}

.rm-result-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.18));
}

.rm-result-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: 0.98rem;
  color: #4d2f10;
}

.rm-result-meta {
  margin: 0.15rem 0 0;
  color: #73583b;
  font-size: 0.8rem;
}

.rm-result-state {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 1.9rem;
  padding: 0.22rem 0.62rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1px solid rgba(138, 92, 20, 0.18);
  background: rgba(255,255,255,0.24);
}

.rm-result-state.is-success {
  color: var(--rm-success);
  background: rgba(63, 111, 42, 0.1);
}

.rm-result-state.is-partial {
  color: var(--rm-warning);
  background: rgba(168, 108, 31, 0.12);
}

.rm-result-state.is-failure {
  color: var(--rm-danger);
  background: rgba(139, 37, 0, 0.1);
}

.rm-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.85rem 0 0.65rem;
}

.rm-result-cell {
  padding: 0.45rem 0.55rem;
  border-radius: 0.45rem;
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(138, 92, 20, 0.14);
}

.rm-result-key {
  display: block;
  font-size: 0.72rem;
  color: #715639;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rm-result-val {
  display: block;
  margin-top: 0.16rem;
  font-variant-numeric: tabular-nums;
  color: #35200b;
  font-weight: 700;
}

.rm-result-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0;
  border: 0;
  background: none;
  color: #6f522d;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.rm-result-details {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed rgba(138, 92, 20, 0.24);
  color: #5c4528;
  font-size: 0.88rem;
}

.rm-result-details[hidden] {
  display: none !important;
}

.rm-journal-shell {
  display: grid;
  gap: 0.9rem;
}

.rm-journal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.rm-filter-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.rm-timeline {
  position: relative;
  display: grid;
  gap: 0.85rem;
  padding-left: 1.4rem;
}

.rm-timeline::before {
  content: '';
  position: absolute;
  top: 0.35rem;
  bottom: 0.35rem;
  left: 0.4rem;
  width: 2px;
  background: linear-gradient(to bottom, rgba(212,160,23,0.38), rgba(138,92,20,0.08));
}

.rm-timeline-item {
  position: relative;
  padding: 0.9rem 1rem 0.9rem 1rem;
  border-radius: 0.8rem;
  background: rgba(255,255,255,0.26);
  border: 1px solid rgba(138, 92, 20, 0.16);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
}

.rm-timeline-item::before {
  content: '';
  position: absolute;
  left: -1.35rem;
  top: 1rem;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  background: #b07c22;
  border: 2px solid #f3e2bd;
  box-shadow: 0 0 0 2px rgba(176, 124, 34, 0.18);
}

.rm-timeline-item[data-type="stats"]::before { background: #946a1e; }
.rm-timeline-item[data-type="skills"]::before { background: #72511b; }
.rm-timeline-item[data-type="spells"]::before { background: var(--rm-arcane); }
.rm-timeline-item[data-type="combat"]::before { background: var(--rm-danger); }
.rm-timeline-item[data-type="notes"]::before { background: var(--rm-steel); }

.rm-timeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 0.65rem;
}

.rm-timeline-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: 0.92rem;
  color: #4e2e0f;
}

.rm-timeline-meta {
  margin: 0.15rem 0 0;
  color: #73583c;
  font-size: 0.78rem;
}

.rm-timeline-body {
  margin-top: 0.5rem;
  color: #4d3b24;
}

.rm-timeline-tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(212,160,23,0.12);
  color: #705112;
}

.rm-projection-box {
  display: grid;
  gap: 0.95rem;
  padding: 1rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(138, 92, 20, 0.18);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    rgba(115, 77, 23, 0.07);
}

.rm-projection-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.75rem;
  align-items: end;
}

.rm-level-output {
  font-family: var(--font-title);
  font-weight: 700;
  color: #4f3113;
}

.rm-sparkline-card {
  padding: 0.8rem;
  border-radius: 0.75rem;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(138, 92, 20, 0.14);
}

.rm-sparkline {
  width: 100%;
  height: auto;
  display: block;
}

.rm-sparkline path,
.rm-sparkline polyline {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rm-line-hp { stroke: #8b2500; }
.rm-line-pp { stroke: var(--rm-arcane); }
.rm-line-db { stroke: var(--rm-success); }

.rm-btn-scroll .rm-btn-icon {
  width: 1.15rem;
  height: 1.15rem;
  object-fit: contain;
  filter: brightness(1.2) drop-shadow(0 1px 2px rgba(0,0,0,0.35));
}

@keyframes rm-d100-roll {
  0%   { transform: scale(0.94) rotate(-4deg); filter: blur(3px); }
  20%  { transform: scale(1.06) rotate(4deg); filter: blur(1px); }
  40%  { transform: scale(0.98) rotate(-3deg); filter: blur(2px); }
  60%  { transform: scale(1.04) rotate(3deg); filter: blur(1px); }
  80%  { transform: scale(0.99) rotate(-1deg); filter: blur(0.5px); }
  100% { transform: scale(1) rotate(0deg); filter: blur(0); }
}

@keyframes rm-card-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rm-critical-flash {
  0%   { box-shadow: 0 0 0 rgba(240,192,64,0), 0 10px 18px rgba(60,36,10,0.08); }
  30%  { box-shadow: 0 0 0 3px rgba(240,192,64,0.28), 0 0 28px rgba(240,192,64,0.28), 0 10px 18px rgba(60,36,10,0.12); }
  100% { box-shadow: 0 10px 18px rgba(60,36,10,0.08), inset 0 1px 0 rgba(255,255,255,0.14); }
}

@keyframes rm-fumble-shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .rm-roller-value.is-rolling,
  .rm-result-card,
  .rm-result-card.is-critical,
  .rm-result-card.is-fumble,
  .rm-spinner {
    animation: none !important;
  }

  .rm-action-btn,
  .rm-btn-scroll,
  .rm-tabbed-chip,
  .rm-filter-chip,
  .rm-session-panel,
  .rm-session-backdrop {
    transition: none !important;
  }
}

@media (max-width: 1199px) {
  .rm-compare-grid {
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  }
}

@media (max-width: 767px) {
  .rm-overlay-shell {
    padding: 0.6rem;
    align-items: start;
    padding-top: 1rem;
  }

  .rm-modal-panel,
  .rm-compare-shell {
    max-width: 100%;
    max-height: 92vh;
  }

  .rm-npc-layout,
  .rm-form-grid,
  .rm-projection-controls,
  .rm-result-grid {
    grid-template-columns: 1fr;
  }

  .rm-preview-stats,
  .rm-tool-inline {
    grid-template-columns: 1fr 1fr;
  }

  .rm-compare-toolbar,
  .rm-journal-toolbar,
  .rm-timeline-head,
  .rm-result-head {
    align-items: flex-start;
  }

  .rm-session-panel {
    width: min(100%, 100vw);
  }

  .rm-history-stack {
    max-height: none;
  }
}

/* ============================================
   A5 — Hero crystal ball container (Sora)
   ============================================ */

.rm-hero-video {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1a1208 0%, #0a0806 60%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0 0;
}

.rm-hero-title {
  font-family: var(--font-title, 'Cinzel', serif);
  font-size: clamp(1.5rem, 5vw, 3rem);
  color: #f5c842;
  text-shadow: 0 2px 12px rgba(0,0,0,0.8);
  letter-spacing: 0.08em;
  margin: 0.25rem 0 0.25rem;
}

/* Masquer le hero sur toutes les vues sauf accueil */
body[data-view]:not([data-view="home"]) .rm-hero-video {
  display: none !important;
}

/* ============================================
   A2 — Visual effects (A1 palette upgrade)
   ============================================ */

/* Subtle grain overlay on parchment panels */
.rm-parchment::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.04;
  pointer-events: none;
  mix-blend-mode: multiply;
  border-radius: inherit;
}

/* Gold divider between stacked panels */
.panel + .panel {
  border-top: 1px solid rgba(201, 154, 46, 0.2);
}

/* Hover glow on tab icons */
.rm-tab-icon:hover img {
  filter: drop-shadow(0 0 6px rgba(240, 192, 64, 0.5));
  transition: filter 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .rm-tab-icon:hover img {
    filter: none;
    transition: none;
  }
}

@media (max-width: 640px) {
  .rm-session-top,
  .rm-tool-tabs,
  .rm-session-content,
  .rm-modal-header,
  .rm-sheet-header,
  .rm-compare-toolbar,
  .rm-compare-grid {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }

  .rm-preview-stats,
  .rm-tool-inline {
    grid-template-columns: 1fr;
  }

  .rm-stat-row {
    grid-template-columns: 4rem 1fr 2.5rem;
  }
}

/* === Projection sparklines === */
.rm-projection-box {
  display: grid;
  gap: 0.95rem;
  padding: 1rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(138, 92, 20, 0.18);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent),
    rgba(115, 77, 23, 0.07);
}

.rm-projection-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: end;
}

.rm-level-output {
  font-family: var(--font-title, 'Cinzel', serif);
  font-weight: 700;
  color: #4f3113;
  white-space: nowrap;
}

.rm-sparkline-card {
  padding: 0.8rem;
  border-radius: 0.75rem;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(138, 92, 20, 0.14);
}

.rm-sparkline {
  width: 100%;
  height: auto;
  display: block;
}

.rm-sparkline path,
.rm-sparkline polyline {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rm-line-hp { stroke: #8b2500; }
.rm-line-pp { stroke: var(--rm-arcane, #5b3aa6); }
.rm-line-db { stroke: var(--rm-success, #355f23); }

@media (max-width: 480px) {
  .rm-modal-title,
  .rm-sheet-title,
  .rm-session-title {
    font-size: 1rem;
  }

  .rm-card-title,
  .rm-result-title {
    font-size: 0.92rem;
  }

  .rm-score-pill,
  .rm-sim-badge,
  .rm-tabbed-chip,
  .rm-filter-chip {
    font-size: 0.72rem;
  }

  .rm-action-btn,
  .rm-btn-scroll {
    width: 100%;
  }
}

/* GM Edit Mode banner */
.gm-edit-banner {
  background: rgba(196,154,32,0.15);
  border: 1px solid #c49a20;
  border-radius: 6px;
  padding: 6px 12px;
  text-align: center;
  font-size: 0.8rem;
  color: #8b6914;
  font-weight: bold;
  margin-bottom: 8px;
}

/* B84 — GM edit toggle button */
.rm-btn-gm-edit {
  background-image: linear-gradient(180deg, rgba(196,154,32,0.10), rgba(60,40,15,0.55));
  border-color: #8b6914;
  color: #d4c5a9;
}
.rm-btn-gm-edit.is-active {
  background-image: linear-gradient(180deg, rgba(220,50,50,0.25), rgba(80,15,15,0.6));
  border-color: #c44343;
  color: #ffd2d2;
  box-shadow: 0 0 8px rgba(220,50,50,0.4);
}

/* ============================================
   Crystal Ball Video Medallion
   ============================================ */

.rm-crystal-ball {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.2rem auto;
}

.rm-crystal-ball-container {
  position: relative;
  width: 300px;
  height: 350px;
}

/* Video layer — behind the overlay */
.rm-crystal-ball-container video {
  position: absolute;
  top: 12%;
  left: 19%;
  width: 62%;
  height: 44%;
  clip-path: circle(48% at 50% 50%);
  object-fit: cover;
  z-index: 1;
  filter: contrast(1.05) saturate(1.1);
}

/* Hero variant video (hero-sora.mp4 on Home) — same as base, no override needed */

/* Standard medallion video (IntroSmall.mp4 on Encounters/Party) — larger & higher */
.rm-crystal-ball-container:not(.rm-crystal-ball-hero) video {
  top: 3%;
  left: 10%;
  width: 80%;
  height: 60%;
  clip-path: circle(43% at 50% 48%);
}

/* PNG overlay — the crystal ball frame with transparent center */
.rm-crystal-ball-container .rm-crystal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  background-image: url('../assets/ui/decorations/crystal_ball_overlay.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Subtle ambient glow beneath the ball */
.rm-crystal-ball-container::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 12px;
  background: radial-gradient(ellipse, rgba(196, 154, 32, 0.15) 0%, transparent 70%);
  z-index: 0;
}

/* Mobile: slightly smaller */
@media (max-width: 480px) {
  .rm-crystal-ball-container {
    width: 240px;
    height: 280px;
  }
}

/* ============================================
   Crystal Ball — Hero variant (2× size, home page)
   ============================================ */

.rm-crystal-ball-hero {
  width: 500px;
  height: 585px;
  max-width: 90vw;
  max-height: calc(90vw * 1.17);
}

/* Suppress the base crystal-ball margin in the hero context */
.rm-hero-video .rm-crystal-ball {
  margin: 0 auto;
}

/* Mobile: hero ball scales down */
/* Tablet: hero ball medium */
@media (max-width: 680px) {
  .rm-crystal-ball-hero {
    width: 380px;
    height: 445px;
  }
  .rm-crystal-ball-hero video {
    top: 6%;
    left: 13%;
    width: 74%;
    height: 52%;
    clip-path: circle(46% at 50% 50%);
  }
}
/* Smartphone: hero ball compact */
@media (max-width: 440px) {
  .rm-crystal-ball-hero {
    width: 300px;
    height: 351px;
  }
  .rm-crystal-ball-hero video {
    top: 4%;
    left: 10%;
    width: 80%;
    height: 56%;
    clip-path: circle(44% at 50% 50%);
  }
}

/* ============================================
   Collapsible skill category headers
   ============================================ */

.skill-cat-row {
  cursor: pointer;
  user-select: none;
}

.skill-cat-row:hover .skill-category-header {
  background: rgba(196, 154, 32, 0.15) !important;
}

.cat-toggle-icon {
  display: inline-block;
  width: 1em;
  text-align: center;
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  margin-right: 0.3rem;
  color: #8b6914;
}

.cat-collapsed .cat-toggle-icon {
  color: #6b5030;
}

.cat-collapsed .skill-category-header {
  opacity: 0.7;
}

/* ============================================
   Ornate metal-plaque buttons (3 size tiers)
   ============================================ */

.rm-btn-ornate {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0 6% 0 8%;
  color: #fef3c7;
  font-family: var(--font-title, 'Cinzel', serif);
  font-weight: 600;
  text-shadow: 0 2px 5px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.7), 0 0 3px rgba(0,0,0,0.9);
  transition: filter 0.2s ease, transform 0.2s ease;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  text-decoration: none;
  text-align: center;
  overflow: hidden;
}

.rm-btn-ornate:hover {
  filter: brightness(1.2) drop-shadow(0 0 6px rgba(196,154,32,0.4));
  transform: translateY(-2px);
}

.rm-btn-ornate:active {
  filter: brightness(0.9);
  transform: scale(0.97);
}

.rm-btn-ornate:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
  transform: none;
}

/* Tier A — Large (Home page) */
.rm-btn-ornate-lg {
  width: 380px;
  height: 114px;
  font-size: 1.1rem;
  white-space: normal;
  line-height: 1.3;
}

/* Tier B — Medium (Footer) */
.rm-btn-ornate-md {
  width: 280px;
  height: 78px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Tier C — Small (Tab buttons) */
.rm-btn-ornate-sm {
  width: 250px;
  height: 75px;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Individual button backgrounds (WebP) */
.rm-btn-create-char  { background-image: url('../assets/ui/buttons/webp/btn_create_character.webp'); }
.rm-btn-gen-npc      { background-image: url('../assets/ui/buttons/webp/btn_generate_npc.webp'); }
.rm-btn-load-file    { background-image: url('../assets/ui/buttons/webp/btn_load_file.webp'); }
.rm-btn-download     { background-image: url('../assets/ui/buttons/webp/btn_download_json.webp'); }
.rm-btn-save-local   { background-image: url('../assets/ui/buttons/webp/btn_save_local.webp'); }
.rm-btn-print        { background-image: url('../assets/ui/buttons/webp/btn_print.webp'); }
.rm-btn-export-pdf   { background-image: url('../assets/ui/buttons/webp/btn_export_pdf.webp'); }
.rm-btn-roll-dice    { background-image: url('../assets/ui/buttons/webp/btn_roll_dice.webp'); }
.rm-btn-auto-assign  { background-image: url('../assets/ui/buttons/webp/btn_auto_assign.webp'); }
.rm-btn-validate     { background-image: url('../assets/ui/buttons/webp/btn_validate.webp'); }
.rm-btn-edit-mode    { background-image: url('../assets/ui/buttons/webp/btn_edit_mode.webp'); }
.rm-btn-end-phase    { background-image: url('../assets/ui/buttons/webp/btn_end_dev_phase.webp'); }
.rm-btn-next-level   { background-image: url('../assets/ui/buttons/webp/btn_next_level.webp'); }
.rm-btn-auto-dp      { background-image: url('../assets/ui/buttons/webp/btn_auto_assign_dp.webp'); }
.rm-btn-spell-rank   { background-image: url('../assets/ui/buttons/webp/btn_spell_rank.webp'); }
.rm-btn-spell-sgr    { background-image: url('../assets/ui/buttons/webp/btn_spell_sgr.webp'); }
.rm-btn-wpn-auto     { background-image: url('../assets/ui/buttons/webp/btn_wpn_auto.webp'); }

/* Per-button padding/size tweaks */
.rm-btn-roll-dice    { padding-left: 10%; }
.rm-btn-print        { padding-left: 12%; }
.rm-btn-download     { padding-left: 10%; }
.rm-btn-export-pdf   { padding-left: 11%; }
.rm-btn-load-file    { font-size: 1.04rem; }

/* Mobile: scale down slightly */
@media (max-width: 480px) {
  .rm-btn-ornate-lg { width: 300px; height: 90px; font-size: 0.95rem; }
  .rm-btn-ornate-md { width: 220px; height: 62px; font-size: 0.75rem; }
  .rm-btn-ornate-sm { width: 200px; height: 60px; font-size: 0.7rem; }
}
