:root {
    --primary-color: #6366f1;
    --secondary-color: #a78bfa;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #fbbf24;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 0;
    position: relative;
}

h1 {
    font-size: 3em;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.2em;
}

.language-selector {
    position: absolute;
    right: 0;
    top: 20px;
}

#language-select {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--surface-light);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

/* 夢の入力セクション */
.dream-input {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.dream-input h2 {
    margin-bottom: 20px;
    color: var(--secondary-color);
}

.input-methods {
    margin-bottom: 20px;
}

.voice-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
}

.voice-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

.voice-btn.recording {
    background: var(--danger);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.voice-btn svg {
    fill: currentColor;
}

.text-input-area {
    position: relative;
}

#dream-text {
    width: 100%;
    min-height: 150px;
    background: var(--surface-light);
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 15px;
    border-radius: 8px;
    resize: vertical;
    transition: var(--transition);
    font-size: 16px;
}

#dream-text:focus {
    outline: none;
    border-color: var(--primary-color);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

#char-count {
    color: var(--text-secondary);
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
    font-weight: 500;
}

.primary-btn:hover {
    background: var(--secondary-color);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 分析結果セクション */
.analysis-result {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.analysis-result.hidden {
    display: none;
}

.analysis-result h2 {
    margin-bottom: 20px;
    color: var(--secondary-color);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}

.metric-card h3 {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 15px;
    text-transform: uppercase;
}

.emotion-chart {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.emotion-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.emotion-bar-fill {
    width: 30px;
    background: var(--primary-color);
    border-radius: 4px;
    transition: var(--transition);
}

.emotion-label {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.stress-meter {
    position: relative;
    height: 30px;
    background: var(--background);
    border-radius: 15px;
    overflow: hidden;
}

.stress-bar {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
    border-radius: 15px;
    transition: width 1s ease;
}

#stress-value {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: bold;
}

.creativity-score {
    font-size: 2em;
    font-weight: bold;
}

.score-value {
    color: var(--accent);
}

.score-max {
    color: var(--text-secondary);
    font-size: 0.7em;
}

.themes {
    margin-bottom: 20px;
}

.theme-tags {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.theme-tag {
    background: var(--surface-light);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.9em;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.interpretation {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 8px;
}

.interpretation h3 {
    margin-bottom: 10px;
    color: var(--secondary-color);
}

#interpretation-text {
    line-height: 1.8;
}

/* 夢の履歴セクション */
.dream-history {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.dream-history h2 {
    margin-bottom: 20px;
    color: var(--secondary-color);
}

.history-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

#search-dreams, #filter-emotion {
    flex: 1;
    background: var(--surface-light);
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 10px 15px;
    border-radius: 8px;
    transition: var(--transition);
}

#search-dreams:focus, #filter-emotion:focus {
    outline: none;
    border-color: var(--primary-color);
}

.dream-list {
    display: grid;
    gap: 15px;
}

.dream-item {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.dream-item:hover {
    transform: translateX(5px);
    border-left: 3px solid var(--primary-color);
}

.dream-date {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 5px;
}

.dream-preview {
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.dream-meta {
    display: flex;
    gap: 15px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* 統計セクション */
.statistics {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--border-radius);
}

.statistics h2 {
    margin-bottom: 20px;
    color: var(--secondary-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.stat-card {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 8px;
}

.stat-card h3 {
    margin-bottom: 15px;
    color: var(--text-secondary);
}

canvas {
    max-width: 100%;
    height: 200px;
}

.theme-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 20px 0;
}

.theme-cloud-item {
    padding: 5px 15px;
    background: var(--surface);
    border-radius: 20px;
    transition: var(--transition);
}

.theme-cloud-item:hover {
    background: var(--primary-color);
    transform: scale(1.1);
}

footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
}

.privacy-note {
    margin-top: 10px;
    font-size: 0.9em;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
    
    .container {
        padding: 10px;
    }
    
    .dream-input, .analysis-result, .dream-history, .statistics {
        padding: 20px;
    }
    
    .history-controls {
        flex-direction: column;
    }
}