:root {
    --primary: #1e40af;
    --secondary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --light: #f3f4f6;
    --dark: #1f2937;
    --bg: #ffffff;
    --text: #1f2937;
    --border: #e5e7eb;
    
    /* カテゴリ色 */
    --alkali-metal: #ff6b6b;
    --alkaline-earth-metal: #feca57;
    --transition-metal: #48dbfb;
    --post-transition-metal: #0abde3;
    --metalloid: #00d2d3;
    --nonmetal: #1dd1a1;
    --halogen: #ffc048;
    --noble-gas: #a29bfe;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

header {
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.controls {
    display: flex;
    gap: 1rem;
}

select {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.3s;
}

select:hover {
    background: rgba(255, 255, 255, 0.3);
}

select option {
    background: var(--dark);
}

main {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    gap: 2px;
    margin-bottom: 2rem;
}

.table-cell {
    aspect-ratio: 1;
    position: relative;
}

.element {
    width: 100%;
    height: 100%;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.element:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.element::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.3) 50%, transparent 60%);
    transform: translateX(-100%);
    transition: transform 0.6s;
}

.element:hover::before {
    transform: translateX(100%);
}

.atomic-number {
    font-size: 0.625rem;
    position: absolute;
    top: 2px;
    left: 4px;
    opacity: 0.7;
}

.symbol {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.125rem;
}

.name {
    font-size: 0.625rem;
    text-align: center;
    opacity: 0.8;
}

.mass {
    font-size: 0.5rem;
    opacity: 0.6;
}

/* カテゴリ別の色 */
.alkali-metal { background: var(--alkali-metal); color: white; }
.alkaline-earth-metal { background: var(--alkaline-earth-metal); color: var(--dark); }
.transition-metal { background: var(--transition-metal); color: var(--dark); }
.post-transition-metal { background: var(--post-transition-metal); color: white; }
.metalloid { background: var(--metalloid); color: white; }
.nonmetal { background: var(--nonmetal); color: white; }
.halogen { background: var(--halogen); color: var(--dark); }
.noble-gas { background: var(--noble-gas); color: white; }

/* 物質の状態別の色 */
.color-phase .element {
    background: var(--light) !important;
    color: var(--dark) !important;
}

.color-phase .gas {
    background: #dbeafe !important;
    border: 2px solid #3b82f6;
}

.color-phase .solid {
    background: #fef3c7 !important;
    border: 2px solid #f59e0b;
}

.color-phase .liquid {
    background: #d1fae5 !important;
    border: 2px solid #10b981;
}

/* 詳細パネル */
.element-detail {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -40%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.element-detail.hidden {
    display: none;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark);
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.close-btn:hover {
    background: var(--light);
}

.element-detail h2 {
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 0.875rem;
    color: var(--dark);
    opacity: 0.7;
    margin-bottom: 0.25rem;
}

.value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary);
}

.electron-shell {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 2rem;
}

.electron-shell svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

footer {
    text-align: center;
    padding: 2rem;
    color: var(--dark);
    opacity: 0.7;
    font-size: 0.875rem;
}

/* レスポンシブ */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .periodic-table {
        grid-template-columns: repeat(9, 1fr);
        overflow-x: auto;
    }
    
    .element {
        min-width: 50px;
    }
    
    .symbol {
        font-size: 1rem;
    }
    
    .name {
        display: none;
    }
    
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* アクセシビリティ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ダークモード */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111827;
        --text: #f3f4f6;
        --border: #374151;
    }
    
    .element-detail {
        background: var(--dark);
        color: var(--light);
    }
    
    select option {
        background: var(--bg);
    }
}