:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --bg-color: #f5f7fa;
    --text-color: #333;
    --border-color: #ddd;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

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

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

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

header {
    text-align: center;
    margin-bottom: 40px;
    padding: 20px 0;
    background: white;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

h1 {
    font-size: 2.5em;
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 20px;
}

.lang-switcher {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.lang-btn {
    padding: 8px 16px;
    border: 2px solid var(--primary-color);
    background: white;
    color: var(--primary-color);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

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

.lang-btn.active {
    background: var(--primary-color);
    color: white;
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.canvas-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

#drawingCanvas {
    border: 2px solid var(--border-color);
    border-radius: 5px;
    cursor: crosshair;
    width: 100%;
    display: block;
    background: white;
}

.toolbar {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.btn-clear {
    background: var(--danger-color);
    color: white;
}

.btn-clear:hover {
    background: #c0392b;
}

.btn-undo {
    background: var(--secondary-color);
    color: white;
}

.btn-undo:hover {
    background: #34495e;
}

.btn-copy {
    background: var(--success-color);
    color: white;
    padding: 5px 15px;
    font-size: 14px;
}

.btn-copy:hover {
    background: #229954;
}

.pen-options {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.pen-options label {
    font-size: 14px;
    color: #666;
}

#penSize {
    width: 100px;
}

#penSizeValue {
    font-weight: bold;
    color: var(--primary-color);
}

.result-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

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

.result-display {
    min-height: 200px;
}

.math-display {
    text-align: center;
    font-size: 24px;
    padding: 30px;
    background: #f8f9fa;
    border-radius: 5px;
    margin-bottom: 20px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.latex-output {
    margin-top: 20px;
}

.latex-output label {
    display: block;
    font-weight: bold;
    margin-bottom: 10px;
    color: #666;
}

.latex-code-container {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid var(--border-color);
}

#latexCode {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    color: var(--secondary-color);
}

.examples {
    grid-column: 1 / -1;
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

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

.example-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.example-list li {
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
    border-left: 3px solid var(--primary-color);
}

footer {
    text-align: center;
    padding: 20px;
    color: #666;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--success-color);
    color: white;
    padding: 15px 30px;
    border-radius: 5px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .toolbar {
        justify-content: space-between;
    }
    
    .pen-options {
        margin-left: 0;
        margin-top: 10px;
        width: 100%;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --border-color: #444;
    }
    
    body {
        background-color: var(--bg-color);
        color: var(--text-color);
    }
    
    header, .canvas-container, .result-container, .examples {
        background: #2a2a2a;
    }
    
    #drawingCanvas {
        background: #333;
        border-color: #555;
    }
    
    .math-display, .latex-code-container, .example-list li {
        background: #333;
    }
}