.p-pn-container.pn-dice-roller {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2), 0 2px 2px rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    /* background: linear-gradient(165deg, #ffffff 0%, #f0f2f5 55%, #e8ebef 100%); */
    background: #c1e3ec;
    position: relative;
    margin: 20px;
    padding: 20px;
    font-size: 1rem;
}

.pn-dice-roller__inner {
    width: 100%;
    margin: 0 auto;
}

.pn-dice-roller__head {
    text-align: center;
    margin: 0.35rem 0 1rem;
}

.pn-dice-roller__title {
    font-weight: 600;
    font-size: clamp(1.45rem, 4vw, 1.85rem);
    letter-spacing: 0.02em;
    margin: 0 0 0.5rem;
    color: #2c333c;
    line-height: 1.2;
}

.pn-dice-roller__hint {
    font-size: 0.8125rem;
    line-height: 1.5;
    color: #5a6570;
    margin: 0;
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
}

.pn-dice-roller__hint code {
    font-size: 0.8em;
    padding: 0.12em 0.35em;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.06);
    color: #1e2930;
}

.pn-dice-roller__stage {
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: 16px;
    padding: clamp(1rem, 2.5vw, 1.5rem) clamp(0.75rem, 2vw, 1.25rem);
    margin: 0 0 1.25rem;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        0 1px 3px rgba(0, 0, 0, 0.04);
}

.pn-dice-roller__primary {
    text-align: center;
    margin: 0 0 1.35rem;
}

.pn-dice-roller__roll-btn {
    min-width: 9rem;
    padding: 0.65rem 1.35rem;
}

.pn-dice-roller__hint--kbd {
    margin-top: 0.7rem;
    font-size: 0.78rem;
    color: #6b7580;
}

.pn-dice-toolbar,
.pn-dice-roller__bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: center;
    margin-bottom: 1.35rem;
}

/* ---------- Custom popup (dialog) ---------- */
.pn-dice-modal {
    position: fixed;
    inset: 0;
    z-index: 10060;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) 1rem max(12px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.pn-dice-modal[hidden] {
    display: none !important;
}

.pn-dice-modal__backdrop {
    position: absolute;
    inset: 0;
    /* background: rgba(20, 24, 32, 0.52); */
    backdrop-filter: blur(3px);
}

.pn-dice-modal__panel {
    position: relative;
    z-index: 1;
    width: min(100%, 26rem);
    max-height: min(88vh, 36rem);
    overflow: auto;
    background: #fff;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

.pn-dice-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem 0.65rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.pn-dice-modal__title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #2c333c;
    margin: 0;
    letter-spacing: 0.01em;
}

.pn-dice-modal__close {
    appearance: none;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 10px;
    font-size: 1.5rem;
    line-height: 1;
    color: #5a6570;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.pn-dice-modal__close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #2c333c;
}

.pn-dice-modal__close:focus-visible {
    outline: 2px solid var(--dice-accent, #e8a838);
    outline-offset: 2px;
}

.pn-dice-modal__body {
    padding: 0.85rem 1rem 1.1rem;
}

.pn-dice-modal__note {
    font-size: 0.72rem;
    color: #7a8490;
    text-align: center;
    margin: 0 0 1rem;
    line-height: 1.35;
}

.pn-dice-modal__hint {
    font-size: 0.75rem;
    color: #6b7580;
    text-align: center;
    margin: 0 0 0.65rem;
    line-height: 1.4;
}

.pn-dice-custom__dice-row--empty {
    justify-content: center;
    border-style: dashed;
    background: transparent;
    font-size: 0.85rem;
    color: #7a8490;
    font-weight: 500;
}

.pn-dice-custom__top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 1.25rem 2rem;
    margin-bottom: 1.1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.pn-dice-custom__field {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    min-width: 8rem;
}

.pn-dice-custom__field--sound {
    justify-content: center;
}

.pn-dice-custom__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5560;
}

.pn-dice-custom__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;
}

.pn-dice-custom__color-btn {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    border-radius: 12px;
    padding: 0.35rem 0.5rem 0.45rem;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: linear-gradient(180deg, #fff 0%, #f4f5f7 100%);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pn-dice-custom__color-btn:hover {
    border-color: rgba(232, 168, 56, 0.55);
    box-shadow: 0 2px 8px rgba(232, 168, 56, 0.18);
}

.pn-dice-custom__color-btn:focus-within {
    outline: 2px solid var(--dice-accent, #e8a838);
    outline-offset: 2px;
}

.pn-dice-custom__color-btn--sm {
    padding: 0.3rem 0.4rem 0.4rem;
    min-width: 4.25rem;
}

.pn-dice-custom__color-native {
    position: absolute;
    opacity: 0;
    width: 2.75rem;
    height: 2.75rem;
    cursor: pointer;
    margin: 0;
    padding: 0;
    border: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -65%);
}

.pn-dice-custom__color-btn--sm .pn-dice-custom__color-native {
    width: 2.5rem;
    height: 2.5rem;
    transform: translate(-50%, -58%);
}

.pn-dice-custom__color-swatch {
    display: block;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0.12);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5);
    margin-top: 0.15rem;
    pointer-events: none;
    background-color: #e8eaed;
}

.pn-dice-custom__color-btn--sm .pn-dice-custom__color-swatch {
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 8px;
}

.pn-dice-custom__chip-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7580;
}

.pn-dice-custom__sound {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c333c;
    user-select: none;
}

.pn-dice-custom__sound input {
    width: 1.5rem;
    height: 1.5rem;
    accent-color: var(--dice-accent, #e8a838);
    cursor: pointer;
}

.pn-dice-custom__subhead {
    font-size: 0.82rem;
    font-weight: 600;
    color: #4a5560;
    margin: 0 0 0.6rem;
    text-align: center;
}

.pn-dice-custom__dice-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.pn-dice-custom__dice-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem 1rem;
    padding: 0.55rem 0.65rem;
    border-radius: 10px;
    background: #f6f7f9;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.pn-dice-custom__dice-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c333c;
    min-width: 4.5rem;
}

.pn-dice-custom__color-pair {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-left: auto;
}

.pn-dice-roller__log-panel {
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    padding: 1rem 1rem 1.1rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.pn-dice-roller__log-heading {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c333c;
    margin: 0 0 0.75rem;
    text-align: center;
    letter-spacing: 0.01em;
}

.pn-dice-roller .pn-dice-container {
    margin: 1rem 0;
}

.pn-dice-roller .dice-result strong {
    color: #c2780a;
}

.dice-log-format-row {
    max-width: 42rem;
    margin: 0 auto 0.5rem;
    padding: 0 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pn-dice-roller .dice-log-format-row {
    max-width: none;
    margin-bottom: 0.65rem;
}

.dice-log-format-label {
    font-size: 0.85rem;
    color: #4a5560;
}

.dice-log-format-select {
    font: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    background: #fff;
    color: #222;
}

.pn-dice-log {
    max-width: 42rem;
    margin: 0 auto 2rem;
    padding: 0 1rem;
    max-height: 12rem;
    overflow-y: auto;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.85rem;
    color: #2a2a2a;
    text-align: left;
}

.pn-dice-roller .pn-dice-log {
    max-width: none;
    margin: 0;
    padding: 0.5rem 0.65rem;
    max-height: 11rem;
    border-radius: 10px;
    background: #f6f7f921;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.pn-dice-log .dice-log__line {
    margin: 0.35rem 0;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.pn-dice-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1.75rem 2.25rem;
    margin: 3rem 0px;
    justify-content: center;
    align-items: flex-start;
    overflow: visible;
}

.pn-dice-toolbar__btn {
    appearance: none;
    border: none;
    padding: 0.6rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    background: #2a3544;
    color: #e6edf3;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: background 0.15s ease, transform 0.12s ease;
}

.pn-dice-toolbar__btn:hover {
    background: #354252;
}

.pn-dice-toolbar__btn:active {
    transform: scale(0.98);
}

.pn-dice-toolbar__btn:disabled,
.pn-dice-toolbar__btn:disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    background: #2a3544;
}

.pn-dice-toolbar__btn--accent {
    background: linear-gradient(180deg, #f0b84a 0%, var(--dice-accent, #e8a838) 100%);
    color: #1a1208;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(232, 168, 56, 0.3);
    padding: 1rem 5rem;
}

.pn-dice-toolbar__btn--accent:hover {
    filter: brightness(1.05);
}

/* Một viên xúc xắc — bọc trong .dice-root
   Ô rộng hơn cạnh khối vì perspective + tilt làm hình nhô ra ngoài box 112px — nếu chỉ 112px các viên sẽ chồng lên nhau */
.dice-root {
    --dice-size: 180px;
    --dice-slot: calc(var(--dice-size) * 1.68);
    --dice-half: calc(var(--dice-size) / 2 + 0.85px);
    --dice-face-fill: #65c871;
    --dice-pip: #1a1a1a;
    --dice-accent: #e8a838;
    --dice-muted: #8b9aab;
    /* Phối cảnh: càng lớn càng gần “nhìn thẳng” (ít tụ điểm). Bỏ hẳn = none thì 3D dễ méo/lạ khi xoay */
    --dice-perspective: 2000px;
    --dice-perspective-origin-x: 50%;
    --dice-perspective-origin-y: 50%;
    flex: 0 0 var(--dice-slot);
    width: var(--dice-slot);
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dice-scene {
    width: var(--dice-size);
    height: var(--dice-size);
    perspective: var(--dice-perspective);
    perspective-origin: var(--dice-perspective-origin-x) var(--dice-perspective-origin-y);
    margin-bottom: 0.65rem;
}

.dice-scene--interactive {
    cursor: pointer;
    border-radius: 16px;
    outline-offset: 4px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.dice-scene--interactive:hover:not(.dice-scene--rolling) {
    filter: brightness(1.06);
}

.dice-scene--interactive:focus-visible {
    outline: 2px solid var(--dice-accent, #e8a838);
}

.dice-scene--rolling {
    pointer-events: none;
    cursor: default;
    filter: none;
}

.dice-tilt {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    /* transform: rotateX(-22deg) rotateY(-28deg); */
    transform: rotateX(0deg) rotateY(0deg);
}

.dice-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(0deg) rotateX(0deg);
    transition: transform 1.15s cubic-bezier(0.2, 0.85, 0.25, 1);
}

.dice-cube--rolling {
    transition: transform 1.65s cubic-bezier(0.15, 0.75, 0.15, 1);
}

.dice-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: linear-gradient(145deg, #fffef8 0%, var(--dice-face-fill) 45%, #dcd8cf 100%);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 14px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 14%;
    gap: 0;
}

.dice-face .dice-pip {
    width: 18%;
    height: 18%;
    min-width: 25px;
    min-height: 25px;
    margin: auto;
    background: var(--dice-pip);
    border-radius: 50%;
    box-shadow: inset 0 -1px 2px rgba(255, 255, 255, 0.25);
    opacity: 0;
}

.dice-face .dice-pip.dice-pip--on {
    opacity: 1;
}

.dice-pip--p1 {
    grid-column: 1;
    grid-row: 1;
}

.dice-pip--p2 {
    grid-column: 2;
    grid-row: 1;
}

.dice-pip--p3 {
    grid-column: 3;
    grid-row: 1;
}

.dice-pip--p4 {
    grid-column: 1;
    grid-row: 2;
}

.dice-pip--p5 {
    grid-column: 2;
    grid-row: 2;
}

.dice-pip--p6 {
    grid-column: 3;
    grid-row: 2;
}

.dice-pip--p7 {
    grid-column: 1;
    grid-row: 3;
}

.dice-pip--p8 {
    grid-column: 2;
    grid-row: 3;
}

.dice-pip--p9 {
    grid-column: 3;
    grid-row: 3;
}

.dice-face--front {
    transform: rotateY(0deg) translateZ(var(--dice-half));
}

.dice-face--right {
    transform: rotateY(90deg) translateZ(var(--dice-half));
}

.dice-face--back {
    transform: rotateY(180deg) translateZ(var(--dice-half));
}

.dice-face--left {
    transform: rotateY(-90deg) translateZ(var(--dice-half));
}

.dice-face--top {
    transform: rotateX(90deg) translateZ(var(--dice-half));
}

.dice-face--bottom {
    transform: rotateX(-90deg) translateZ(var(--dice-half));
}

.dice-result {
    font-variant-numeric: tabular-nums;
    font-size: 1.1rem;
    color: var(--dice-muted);
}

.dice-result strong {
    color: #fff;
    font-size: 1.35rem;
}