:root {
    --rd-bg-dark: #070d19;
    --rd-card-bg: #f5f6f8;
    --rd-panel-bg: #ffffff;
    --rd-text-main: #333;
    --rd-text-light: #888;
    --rd-primary-gradient: linear-gradient(135deg, #7c4dff, #448aff);
    --rd-dice-cube: #2c3e50;
    --rd-dice-face-glow: rgba(68, 138, 255, 0.3);
}

/* Инкапсуляция box-sizing */
.rand-dice-app, .rand-dice-app *, .rand-dice-app *::before, .rand-dice-app *::after {
    box-sizing: border-box;
}

.rand-dice-app {
    background-color: var(--rd-bg-dark);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--rd-text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    border-radius: 0;
    min-height: 100vh;
    width: 100%;
    margin: 0;
}

.rand-dice-app .app-container {
    width: 100%;
    max-width: 1200px;
    background-color: var(--rd-card-bg);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.rand-dice-app .app-header {
    background: #fff;
    padding: 20px 40px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    font-size: 1.2rem;
}

.rand-dice-app .main-card { display: flex; flex-wrap: wrap; }

.rand-dice-app .parameters-panel {
    width: 300px;
    background: var(--rd-panel-bg);
    padding: 40px;
    border-right: 1px solid #eee;
    flex-shrink: 0;
}

.rand-dice-app .results-area { flex: 1; padding: 40px; min-width: 300px; }

.rand-dice-app h2 {
    font-size: 0.9rem;
    color: var(--rd-text-light);
    text-transform: uppercase;
    margin-bottom: 30px;
    letter-spacing: 1px;
    margin-top: 0;
}

.rand-dice-app .input-group { margin-bottom: 25px; }
.rand-dice-app .input-group .field-label {
    display: block; font-size: 0.8rem; color: var(--rd-text-light); margin-bottom: 8px;
}
.rand-dice-app .inputs-row { display: flex; align-items: center; gap: 10px; }

.rand-dice-app input[type="number"] {
    width: 100%; padding: 12px; border: 1px solid #ddd;
    border-radius: 8px; background: #f9f9f9; font-size: 1rem; color: #333;
}

.rand-dice-app #draw-btn {
    width: 100%; padding: 18px; border: none; border-radius: 12px;
    background: var(--rd-primary-gradient); color: white; font-weight: bold;
    font-size: 1rem; cursor: pointer; transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 5px 15px rgba(124, 77, 255, 0.3);
}

.rand-dice-app #draw-btn:active { transform: scale(0.98); }
.rand-dice-app #draw-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.rand-dice-app .dice-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 30px; perspective: 1000px;
}

.rand-dice-app .dice-scene { width: 60px; height: 60px; margin: 10px auto; }
.rand-dice-app .cube {
    width: 100%; height: 100%; position: relative;
    transform-style: preserve-3d; transform: rotateX(0deg) rotateY(0deg);
}

.rand-dice-app .face {
    position: absolute; width: 60px; height: 60px;
    background: var(--rd-dice-cube); border: 2px solid rgba(255,255,255,0.1);
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 800; font-size: 1.4rem; box-shadow: inset 0 0 15px rgba(0,0,0,0.5);
}

.rand-dice-app .front  { transform: rotateY(  0deg) translateZ(30px); }
.rand-dice-app .back   { transform: rotateY(180deg) translateZ(30px); }
.rand-dice-app .right  { transform: rotateY( 90deg) translateZ(30px); }
.rand-dice-app .left   { transform: rotateY(-90deg) translateZ(30px); }
.rand-dice-app .top    { transform: rotateX( 90deg) translateZ(30px); }
.rand-dice-app .bottom { transform: rotateX(-90deg) translateZ(30px); }

.rand-dice-app .front {
    color: #fff; text-shadow: 0 0 10px #448aff, 0 0 20px #448aff;
    background: radial-gradient(circle, #3a536b 0%, var(--rd-dice-cube) 100%);
    border: 2px solid #448aff;
}

.rand-dice-app .cube.rolling { animation: randomRoll 1.5s cubic-bezier(0.2, 0.8, 0.3, 1) forwards; }

@keyframes randomRoll {
    0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    30% { transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg); }
    60% { transform: rotateX(1080deg) rotateY(1440deg) rotateZ(720deg); }
    100% { transform: rotateX(1440deg) rotateY(1800deg) rotateZ(1080deg); }
}

.rand-dice-app .hidden-btn {
    position: absolute;
    bottom: 30px;
    left: 30px;
    padding: 15px 25px;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.8);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 50;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.3s ease, background 0.3s ease;
}

.rand-dice-app .hidden-btn:hover {
    color: rgba(255, 255, 255, 0.8);
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.rand-dice-app .modal {
    display: none; position: absolute; z-index: 100; left: 0; top: 0;
    width: 100%; height: 100%; background-color: rgba(7, 13, 25, 0.85);
    backdrop-filter: blur(5px); align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.3s ease;
}
.rand-dice-app .modal.show { display: flex; opacity: 1; }

.rand-dice-app .modal-content {
    background-color: var(--rd-panel-bg); padding: 40px; border-radius: 20px;
    width: 450px; max-width: 90%; position: relative;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5); transform: translateY(20px); transition: transform 0.3s ease;
}
.rand-dice-app .modal.show .modal-content { transform: translateY(0); }
.rand-dice-app .modal-content h2 { color: var(--rd-text-main); font-size: 1.5rem; margin-bottom: 25px; text-transform: none; }

.rand-dice-app .close-btn {
    position: absolute; top: 20px; right: 25px; color: #aaa;
    font-size: 28px; line-height: 1; cursor: pointer; transition: color 0.2s;
}
.rand-dice-app .close-btn:hover { color: #333; }

.rand-dice-app .preset-toggle { display: flex; align-items: center; gap: 15px; font-size: 1.1rem; font-weight: 500; }
.rand-dice-app .switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.rand-dice-app .switch input { opacity: 0; width: 0; height: 0; }
.rand-dice-app .slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 34px;
}
.rand-dice-app .slider:before {
    position: absolute; content: ""; height: 20px; width: 20px;
    left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%;
}
.rand-dice-app input:checked + .slider { background: var(--rd-primary-gradient); }
.rand-dice-app input:checked + .slider:before { transform: translateX(22px); }

.rand-dice-app .preset-fields-container { margin-top: 20px; padding-top: 20px; border-top: 1px solid #eee; }
.rand-dice-app .preset-fields-container label { display: block; margin-bottom: 10px; font-weight: 500; }
.rand-dice-app #preset-values {
    width: 100%; padding: 15px; border: 1px solid #ddd; border-radius: 12px;
    background: #f9f9f9; font-size: 1rem; color: #333; resize: vertical; transition: border-color 0.2s;
}
.rand-dice-app #preset-values:focus { outline: none; border-color: #7c4dff; box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.1); }
.rand-dice-app .preset-stats { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 0.85rem; }
.rand-dice-app .info-text { color: var(--rd-text-light); }
.rand-dice-app .counter-badge { background: #eef2ff; color: #448aff; padding: 6px 12px; border-radius: 20px; font-weight: bold; }

/* Адаптивность панели настроек для маленьких экранов */
@media (max-width: 768px) {
    .rand-dice-app .parameters-panel { width: 100%; border-right: none; border-bottom: 1px solid #eee; }
}

/* Даем пространство сверху для бейджа */
.rand-dice-app .dice-scene {
    width: 60px;
    height: 60px;
    margin: 25px 10px 10px 10px;
    position: relative;
}

/* Стилизация всплывающего номера */
.rand-dice-app .dice-order {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--rd-primary-gradient);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(124, 77, 255, 0.4);
    z-index: 10;
    opacity: 0;
    /* Плавное появление с задержкой 1.2s, чтобы дождаться остановки кубика */
    animation: fadeBadgeIn 0.4s ease forwards;
    animation-delay: 1.2s;
}

@keyframes fadeBadgeIn {
    0% { opacity: 0; transform: translate(-50%, 10px); }
    100% { opacity: 1; transform: translate(-50%, 0); }
}