/* Base styles */
:root {
    --primary: #BB86FC;
    --background: #121212;
    --surface: #272727;
    --on-surface: #FFFFFF;
    --on-surface-medium: #BBBBBB;
    --on-surface-disabled: #666666;
    --error: #F44336;
    --success: #4CAF50;
    --border-radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--background);
    color: var(--on-surface);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 16px;
}

h1, h2 {
    font-weight: 600;
}

h1 {
    color: var(--primary);
    font-size: 24px;
}

h2 {
    font-size: 18px;
    margin-bottom: 12px;
}

.hidden {
    display: none !important;
}

/* Header styles */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.status-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.offline-indicator {
    display: flex;
    align-items: center;
    background-color: var(--error);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
}

.offline-indicator .material-icons {
    font-size: 16px;
    margin-right: 4px;
}

.install-button {
    background-color: var(--surface);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.install-button .material-icons {
    color: var(--primary);
}

/* Dice selector styles */
.dice-selector {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dice-types {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.dice-button {
    background-color: var(--background);
    border: none;
    color: var(--on-surface-medium);
    padding: 12px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.dice-button:hover {
    background-color: #1a1a1a;
}

.dice-button.selected {
    background-color: var(--primary);
    color: var(--background);
}

.dice-button.selected .dice-icon {
    border-color: var(--background);
}

.dice-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--on-surface-medium);
    position: relative;
}

.dice-button.selected .dice-icon {
    border-color: var(--background);
}

/* D4 - Triangle */
.d4-icon {
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 20px solid var(--on-surface-medium);
    border-top: none;
    background: none;
}

.dice-button.selected .d4-icon {
    border-bottom-color: var(--background);
}

/* D6 - Square */
.d6-icon {
    width: 20px;
    height: 20px;
    background-color: var(--on-surface-medium);
    border: none;
}

.dice-button.selected .d6-icon {
    background-color: var(--background);
}

/* D8 - Diamond */
.d8-icon {
    width: 20px;
    height: 20px;
    background-color: var(--on-surface-medium);
    transform: rotate(45deg);
    border: none;
}

.dice-button.selected .d8-icon {
    background-color: var(--background);
}

/* D10 - Pentagon */
.d10-icon {
    width: 0;
    height: 0;
    background: var(--on-surface-medium);
    position: relative;
    border: none;
    border-radius: 2px;
    clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
    width: 20px;
    height: 20px;
}

.dice-button.selected .d10-icon {
    background-color: var(--background);
}

/* D12 - Hexagon */
.d12-icon {
    width: 20px;
    height: 20px;
    background: var(--on-surface-medium);
    border: none;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.dice-button.selected .d12-icon {
    background-color: var(--background);
}

/* D20 - Icosahedron shape approximation */
.d20-icon {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 17px solid var(--on-surface-medium);
    position: relative;
    border-radius: 2px;
    border-top: none;
    background: none;
}

.d20-icon:after {
    content: "";
    position: absolute;
    left: -10px;
    top: 5.7px;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 17px solid var(--on-surface-medium);
}

.dice-button.selected .d20-icon {
    border-bottom-color: var(--background);
}

.dice-button.selected .d20-icon:after {
    border-top-color: var(--background);
}

.dice-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dice-count {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dice-count label {
    font-size: 14px;
    color: var(--on-surface-medium);
}

.counter {
    display: flex;
    align-items: center;
}

.counter-button {
    background-color: var(--background);
    border: none;
    color: var(--on-surface);
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
}

.counter-button:hover {
    background-color: #1a1a1a;
}

#dice-count-input {
    background-color: transparent;
    border: none;
    text-align: center;
    color: var(--on-surface);
    width: 60px;
    font-size: 16px;
    -moz-appearance: textfield;
}

#dice-count-input::-webkit-outer-spin-button,
#dice-count-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.roll-button {
    background-color: var(--primary);
    border: none;
    color: var(--background);
    padding: 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s ease;
}

.roll-button:hover {
    background-color: #c79aff;
}

.roll-button .material-icons {
    font-size: 20px;
}

/* Results styles */
.results-container {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.individual-dice {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.individual-dice .placeholder {
    text-align: center;
    color: var(--on-surface-medium);
    font-size: 14px;
    width: 100%;
}

.dice {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--background);
    border-radius: 8px;
    border: 2px solid #3a3a3a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    font-weight: bold;
    font-size: 24px;
    color: var(--primary);
    transition: transform 0.2s ease;
    position: relative;
}

.dice span {
    position: relative;
    z-index: 2;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

.dice .material-icons {
    font-size: 30px;
}

.dice:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

.dice.d20 {
    transform: rotate(45deg);
}

.dice.d20 span {
    transform: rotate(-45deg);
    font-weight: 800;
}

.total-result {
    text-align: center;
    margin-bottom: 8px;
}

.total-result .placeholder {
    color: var(--on-surface-medium);
    font-size: 14px;
}

.total-result .total-box {
    background-color: var(--background);
    border-radius: 4px;
    padding: 8px 16px;
    display: inline-block;
}

.total-result .label {
    color: var(--on-surface-medium);
    font-size: 14px;
    margin-bottom: 4px;
}

.total-result .value {
    color: var(--primary);
    font-size: 36px;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: 1px;
}

.total-result .calculation {
    color: var(--on-surface-medium);
    font-size: 12px;
    margin-top: 4px;
}

.dice-details {
    text-align: center;
    color: var(--on-surface-medium);
    font-size: 14px;
}

/* History styles */
.history-container {
    background-color: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.clear-button {
    background-color: var(--background);
    border: none;
    color: var(--on-surface-medium);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.clear-button:hover {
    background-color: #1a1a1a;
}

.history-list {
    max-height: 240px;
    overflow-y: auto;
}

.history-list .placeholder {
    text-align: center;
    color: var(--on-surface-medium);
    font-size: 14px;
    padding: 16px;
}

.history-entry {
    background-color: var(--background);
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 8px;
    transition: background-color 0.2s ease;
}

.history-entry:hover {
    background-color: #1a1a1a;
}

.history-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.history-result {
    display: flex;
    align-items: center;
}

.history-result .value {
    color: var(--primary);
    font-weight: 500;
    font-size: 18px;
}

.history-result .dice-info {
    color: var(--on-surface-medium);
    font-size: 12px;
    margin-left: 8px;
}

.history-time {
    color: var(--on-surface-medium);
    font-size: 12px;
}

.history-dice {
    margin-top: 8px;
}

.history-dice-label {
    color: var(--on-surface-medium);
    font-size: 12px;
    margin-bottom: 4px;
}

.history-dice-values {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.history-dice-value {
    background-color: #1e1e1e;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    font-weight: bold;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    border: 1px solid #2a2a2a;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

/* D4 - Triangle */
.history-dice-value.history-d4 {
    width: 26px;
    height: 26px;
    background-color: transparent;
    position: relative;
    padding: 0;
}

.history-dice-value.history-d4:before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 13px solid transparent;
    border-right: 13px solid transparent;
    border-bottom: 22px solid #1e1e1e;
    z-index: 0;
}

.history-dice-value.history-d4:after {
    content: attr(textContent);
    position: relative;
    z-index: 1;
}

/* D6 - Square */
.history-dice-value.history-d6 {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 3px;
}

/* D8 - Diamond */
.history-dice-value.history-d8 {
    width: 24px;
    height: 24px;
    padding: 0;
    transform: rotate(45deg);
}

.history-dice-value.history-d8:after {
    content: attr(textContent);
    transform: rotate(-45deg);
}

/* D10 - Pentagon */
.history-dice-value.history-d10 {
    width: 26px;
    height: 26px;
    padding: 0;
    clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
}

/* D12 - Hexagon */
.history-dice-value.history-d12 {
    width: 26px;
    height: 26px;
    padding: 0;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

/* D20 - Icosahedron approximation */
.history-dice-value.history-d20 {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
}

.history-calculation {
    color: #8a8a8a;
    font-size: 12px;
    margin-top: 8px;
}

/* Animations */
@keyframes dice-roll {
    0% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(90deg);
    }
    50% {
        transform: rotate(180deg);
    }
    75% {
        transform: rotate(270deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.dice-rolling {
    animation: dice-roll 0.8s ease-in-out;
}

.fade-in {
    animation: fade-in 0.3s ease-in-out;
}

/* Responsive styles */
@media (max-width: 480px) {
    .dice-types {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dice {
        width: 48px;
        height: 48px;
    }
}

@media (max-width: 360px) {
    .container {
        padding: 8px;
    }
    
    .dice-button {
        padding: 8px;
    }
}