/* CSS Variables & Reset */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a25;
    --bg-overlay: rgba(10, 10, 15, 0.95);

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);

    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    --success: #22c55e;
    --danger: #ef4444;

    --border-radius: 16px;
    --border-radius-sm: 10px;
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: 16px;
    padding-left: 24px;
    position: relative;
    overflow: hidden;
}

/* Progress Bar */
.progress-bar-container {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 60%;
    max-height: 400px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: height 0.05s linear;
}

.progress-glow {
    position: absolute;
    bottom: 0;
    left: -4px;
    width: 14px;
    height: 0%;
    background: var(--accent-glow);
    filter: blur(8px);
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progress-bar-container.active .progress-glow {
    opacity: 1;
}

/* Cooldown mode - gray progress bar */
.progress-bar-container.cooldown-mode .progress-bar {
    background: linear-gradient(to top, #52525b 0%, #71717a 100%);
}

.progress-bar-container.cooldown-mode .progress-glow {
    background: rgba(82, 82, 91, 0.4);
}

/* Settings Button */
.settings-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    background: var(--bg-card);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-medium);
    z-index: 10;
}

.settings-btn svg {
    width: 24px;
    height: 24px;
}

.settings-btn:hover,
.settings-btn:focus {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: rotate(45deg);
}

.settings-btn:active {
    transform: scale(0.95) rotate(45deg);
}

/* Fullscreen Toggle Button */
.fullscreen-btn {
    position: absolute;
    top: 16px;
    right: 72px;
    width: 48px;
    height: 48px;
    background: var(--bg-card);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-medium);
    z-index: 10;
}

.fullscreen-btn svg {
    width: 24px;
    height: 24px;
}

.fullscreen-btn .icon-collapse {
    display: none;
}

.fullscreen-btn:hover,
.fullscreen-btn:focus {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.fullscreen-btn:active {
    transform: scale(0.95);
}

/* Fullscreen Mode - only toggle button icon */
.app-container.fullscreen-mode .fullscreen-btn .icon-expand {
    display: none;
}

.app-container.fullscreen-mode .fullscreen-btn .icon-collapse {
    display: block;
}

/* Dice Presets */
.dice-presets {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    margin-top: 60px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.dice-presets::-webkit-scrollbar {
    display: none;
}

.preset-btn {
    flex-shrink: 0;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-medium);
}

.preset-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.preset-btn.active {
    background: var(--accent-gradient);
    color: var(--text-primary);
    border-color: transparent;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.preset-btn:active {
    transform: scale(0.95);
}

/* Number Display */
.number-display-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.number-display {
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: 50%;
    box-shadow:
        0 0 0 3px var(--bg-secondary),
        0 0 60px var(--accent-glow),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
}

.number-display::before {
    content: '';
    position: absolute;
    inset: -4px;
    background: var(--accent-gradient);
    border-radius: 50%;
    z-index: -1;
    opacity: 0.6;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.02);
    }
}

.number-display.running::before {
    animation: pulse-fast 0.3s ease-in-out infinite;
}

@keyframes pulse-fast {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* 3D Dice Animation */
.number-display-wrapper {
    perspective: 600px;
}

.number-display {
    transform-style: preserve-3d;
    transition: transform 0.3s ease-out;
}

.number-display.running {
    animation: dice-tumble 0.4s ease-in-out infinite;
}

@keyframes dice-tumble {
    0% {
        transform: rotateX(0deg) rotateY(0deg) scale(1);
    }

    25% {
        transform: rotateX(15deg) rotateY(-10deg) scale(1.02);
    }

    50% {
        transform: rotateX(-10deg) rotateY(15deg) scale(1);
    }

    75% {
        transform: rotateX(10deg) rotateY(-5deg) scale(1.02);
    }

    100% {
        transform: rotateX(0deg) rotateY(0deg) scale(1);
    }
}

.number {
    font-size: 72px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: transform 0.1s ease;
}

.number.changing {
    animation: number-pop 0.15s ease;
}

@keyframes number-pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

/* Dice Face Styles */
.dice-face {
    position: absolute;
    width: 140px;
    height: 140px;
    display: none;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    box-shadow:
        inset 0 2px 10px rgba(255, 255, 255, 0.1),
        inset 0 -4px 10px rgba(0, 0, 0, 0.3);
}

.number-display.show-dice .dice-face {
    display: block;
}

.number-display.show-dice .number {
    display: none;
}

/* Pip (Dot) Styles */
.pip {
    position: absolute;
    width: 24px;
    height: 24px;
    background: var(--accent-gradient);
    border-radius: 50%;
    box-shadow:
        0 2px 8px var(--accent-glow),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
    opacity: 0;
    transform: scale(0);
    transition: all 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pip.active {
    opacity: 1;
    transform: scale(1);
}

/* Pip Positions for Standard Dice Faces */
/* Center pip (used for 1, 3, 5) */
.pip-1 {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
}

.pip-1.active {
    transform: translate(-50%, -50%) scale(1);
}

/* Top-left (used for 2, 3, 4, 5, 6) */
.pip-2 {
    top: 20px;
    left: 20px;
}

/* Top-right (used for 2, 3, 4, 5, 6) */
.pip-3 {
    top: 20px;
    right: 20px;
}

/* Bottom-left (used for 2, 3, 4, 5, 6) */
.pip-4 {
    bottom: 20px;
    left: 20px;
}

/* Bottom-right (used for 2, 3, 4, 5, 6) */
.pip-5 {
    bottom: 20px;
    right: 20px;
}

/* Middle-left (used for 6) */
.pip-6 {
    top: 50%;
    left: 20px;
    transform: translateY(-50%) scale(0);
}

.pip-6.active {
    transform: translateY(-50%) scale(1);
}

/* Middle-right (used for 6) */
.pip-7 {
    top: 50%;
    right: 20px;
    transform: translateY(-50%) scale(0);
}

.pip-7.active {
    transform: translateY(-50%) scale(1);
}

/* Responsive dice face */
@media (min-height: 750px) {
    .dice-face {
        width: 170px;
        height: 170px;
        border-radius: 24px;
    }

    .pip {
        width: 28px;
        height: 28px;
    }

    .pip-2,
    .pip-3 {
        top: 25px;
    }

    .pip-2,
    .pip-4 {
        left: 25px;
    }

    .pip-3,
    .pip-5 {
        right: 25px;
    }

    .pip-4,
    .pip-5 {
        bottom: 25px;
    }

    .pip-6,
    .pip-7 {
        top: 50%;
    }

    .pip-6 {
        left: 25px;
    }

    .pip-7 {
        right: 25px;
    }
}

.dice-range {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 20px;
    background: var(--bg-card);
    border-radius: 20px;
}

/* Action Button */
.action-btn {
    position: relative;
    width: 100%;
    padding: 20px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    overflow: hidden;
    transition: all var(--transition-medium);
    box-shadow: 0 8px 32px var(--accent-glow);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px var(--accent-glow);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.running {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.4);
}

.action-btn.cooldown {
    background: linear-gradient(135deg, #52525b 0%, #3f3f46 100%);
    box-shadow: 0 8px 32px rgba(82, 82, 91, 0.3);
    cursor: not-allowed;
    opacity: 0.7;
}

.action-btn.cooldown:hover {
    transform: none;
}

.btn-ripple {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: inherit;
    transform: scale(0);
    opacity: 0;
}

.action-btn:active .btn-ripple {
    animation: ripple 0.4s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }

    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-medium);
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

.overlay-content {
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: 24px 24px 0 0;
    padding: 24px;
    transform: translateY(100%);
    transition: transform var(--transition-medium);
    overflow-y: auto;
}

.overlay.visible .overlay-content {
    transform: translateY(0);
}

.overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.overlay-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.close-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.close-btn svg {
    width: 20px;
    height: 20px;
}

.close-btn:hover {
    background: var(--danger);
    color: var(--text-primary);
}

/* Setting Groups */
.setting-group {
    margin-bottom: 24px;
}

.setting-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    padding: 8px;
}

.input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}

.input-wrapper input::-webkit-outer-spin-button,
.input-wrapper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.step-btn {
    width: 48px;
    height: 48px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.step-btn:hover {
    background: var(--accent-primary);
}

.step-btn:active {
    transform: scale(0.9);
}

/* Mode Selector */
.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-medium);
}

.mode-btn svg {
    width: 28px;
    height: 28px;
}

.mode-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-gradient);
    color: var(--text-primary);
    border-color: transparent;
}

/* Order Buttons */
.order-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-medium);
}

.order-btn svg {
    width: 28px;
    height: 28px;
}

.order-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.order-btn.active {
    background: var(--accent-gradient);
    color: var(--text-primary);
    border-color: transparent;
}

/* Apply Button */
.apply-btn {
    width: 100%;
    padding: 16px;
    margin-top: 16px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-medium);
}

.apply-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.apply-btn:active {
    transform: translateY(0);
}

/* Responsive Adjustments */
@media (min-width: 480px) {
    .app-container {
        max-width: 480px;
        margin: 0 auto;
    }
}

@media (min-height: 750px) {
    .number-display {
        width: 240px;
        height: 240px;
    }

    .number {
        font-size: 88px;
    }
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .app-container {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .overlay-content {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
}