/* リセットとベース設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

/* ダークモード */
body.dark-mode {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.container {
    width: 100%;
    max-width: 1400px;
    padding: 20px;
}

/* ヘッダー */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 20px;
}

.title {
    font-size: 28px;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.language-selector {
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.language-selector:hover {
    background: rgba(255, 255, 255, 0.3);
}

.language-selector option {
    background: #4a5568;
    color: white;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(360deg);
}

/* 電卓ラッパー */
.calculator-wrapper {
    display: flex;
    gap: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

body.dark-mode .calculator-wrapper {
    background: rgba(30, 30, 45, 0.95);
    color: white;
}

/* 左パネル */
.left-panel {
    flex: 1;
    min-width: 500px;
}

/* ディスプレイセクション */
.display-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

body.dark-mode .display-section {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
}

.formula-display {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    min-height: 30px;
    margin-bottom: 10px;
    word-wrap: break-word;
    text-align: right;
}

.result-display {
    font-size: 36px;
    font-weight: 700;
    color: white;
    text-align: right;
    min-height: 50px;
    word-wrap: break-word;
}

/* モードタブ */
.mode-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.mode-tab {
    padding: 10px 16px;
    border: none;
    background: #e2e8f0;
    color: #4a5568;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

body.dark-mode .mode-tab {
    background: #2d3748;
    color: #a0aec0;
}

.mode-tab:hover {
    background: #cbd5e0;
}

body.dark-mode .mode-tab:hover {
    background: #4a5568;
}

.mode-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* キーパッドコンテナ */
.keypad-container {
    min-height: 400px;
}

.keypad-mode {
    display: none;
}

.keypad-mode.active {
    display: block;
}

/* 基本キーパッド */
.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.key {
    padding: 20px;
    border: none;
    background: #f7fafc;
    color: #2d3748;
    font-size: 20px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

body.dark-mode .key {
    background: #4a5568;
    color: white;
}

.key:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.key:active {
    transform: translateY(0);
}

.key-operator {
    background: #e6fffa;
    color: #00b5d8;
}

body.dark-mode .key-operator {
    background: #2c5282;
    color: #90cdf4;
}

.key-clear {
    background: #fed7d7;
    color: #e53e3e;
}

body.dark-mode .key-clear {
    background: #742a2a;
    color: #fc8181;
}

.key-equals {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    grid-column: span 2;
}

.key-zero {
    grid-column: span 2;
}

.key-func {
    padding: 15px 10px;
    font-size: 14px;
}

/* 科学関数キーパッド */
.scientific-functions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

/* 行列入力 */
.matrix-input {
    padding: 15px;
    background: #f7fafc;
    border-radius: 12px;
}

body.dark-mode .matrix-input {
    background: #2d3748;
}

.matrix-size-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.matrix-size-selector select {
    padding: 6px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background: white;
}

body.dark-mode .matrix-size-selector select {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.matrix-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 15px;
}

.matrix-cell {
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    text-align: center;
    font-size: 14px;
}

body.dark-mode .matrix-cell {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.matrix-operations {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* 統計入力 */
.stats-input {
    padding: 15px;
    background: #f7fafc;
    border-radius: 12px;
}

body.dark-mode .stats-input {
    background: #2d3748;
}

#stats-data {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 15px;
    resize: vertical;
}

body.dark-mode #stats-data {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.stats-operations {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

/* 複素数入力 */
.complex-input {
    padding: 15px;
    background: #f7fafc;
    border-radius: 12px;
}

body.dark-mode .complex-input {
    background: #2d3748;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
}

.input-group label {
    min-width: 80px;
    font-size: 14px;
    font-weight: 600;
}

.input-group input {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
}

body.dark-mode .input-group input {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.complex-operations {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

/* 微積分入力 */
.calculus-input {
    padding: 15px;
    background: #f7fafc;
    border-radius: 12px;
}

body.dark-mode .calculus-input {
    background: #2d3748;
}

.calculus-operations {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* 単位変換 */
.converter-input {
    padding: 15px;
    background: #f7fafc;
    border-radius: 12px;
}

body.dark-mode .converter-input {
    background: #2d3748;
}

.converter-category {
    margin-bottom: 20px;
}

.converter-category select {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 16px;
}

body.dark-mode .converter-category select {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.converter-fields {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.converter-from,
.converter-to {
    flex: 1;
}

.converter-from input,
.converter-to input {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 10px;
}

body.dark-mode .converter-from input,
body.dark-mode .converter-to input {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.converter-from select,
.converter-to select {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 14px;
}

body.dark-mode .converter-from select,
body.dark-mode .converter-to select {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.converter-arrow {
    font-size: 24px;
    color: #4a5568;
}

body.dark-mode .converter-arrow {
    color: #a0aec0;
}

.key-convert {
    width: 100%;
    padding: 15px;
    font-size: 16px;
}

/* 右パネル */
.right-panel {
    width: 350px;
}

/* パネルタブ */
.panel-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.panel-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: #e2e8f0;
    color: #4a5568;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.dark-mode .panel-tab {
    background: #2d3748;
    color: #a0aec0;
}

.panel-tab:hover {
    background: #cbd5e0;
}

body.dark-mode .panel-tab:hover {
    background: #4a5568;
}

.panel-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* パネルコンテンツ */
.panel-content {
    display: none;
    background: #f7fafc;
    border-radius: 12px;
    padding: 15px;
    min-height: 500px;
    max-height: 600px;
    overflow-y: auto;
}

body.dark-mode .panel-content {
    background: #2d3748;
}

.panel-content.active {
    display: block;
}

/* 履歴パネル */
.history-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.btn-small {
    padding: 8px 12px;
    border: none;
    background: #4299e1;
    color: white;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-small:hover {
    background: #3182ce;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    padding: 10px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

body.dark-mode .history-item {
    background: #4a5568;
}

.history-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.history-expression {
    font-size: 14px;
    color: #4a5568;
    margin-bottom: 5px;
}

body.dark-mode .history-expression {
    color: #a0aec0;
}

.history-result {
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
}

body.dark-mode .history-result {
    color: white;
}

/* 変数パネル */
.variable-input {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.variable-input input {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
}

body.dark-mode .variable-input input {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

.variables-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.variable-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

body.dark-mode .variable-item {
    background: #4a5568;
}

.variable-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.var-name {
    font-weight: 600;
    color: #4299e1;
    margin-right: 10px;
}

.var-value {
    flex: 1;
    color: #4a5568;
}

body.dark-mode .var-value {
    color: #a0aec0;
}

.btn-delete {
    width: 24px;
    height: 24px;
    border: none;
    background: #e53e3e;
    color: white;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-delete:hover {
    background: #c53030;
    transform: rotate(90deg);
}

/* グラフパネル */
.graph-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.graph-controls input {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
}

body.dark-mode .graph-controls input {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

#graph-canvas {
    width: 100%;
    height: 300px;
    background: white;
    border-radius: 8px;
    margin-bottom: 15px;
}

body.dark-mode #graph-canvas {
    background: #1a202c;
}

.graph-settings {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.graph-settings label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.graph-settings input {
    width: 80px;
    padding: 6px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 14px;
}

body.dark-mode .graph-settings input {
    background: #4a5568;
    color: white;
    border-color: #4a5568;
}

/* スクロールバー */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

body.dark-mode ::-webkit-scrollbar-track {
    background: #2d3748;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* レスポンシブデザイン */
@media (max-width: 1200px) {
    .calculator-wrapper {
        flex-direction: column;
    }
    
    .right-panel {
        width: 100%;
    }
    
    .left-panel {
        min-width: auto;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .mode-tabs {
        overflow-x: scroll;
    }
    
    .keypad {
        gap: 8px;
    }
    
    .key {
        padding: 15px;
        font-size: 18px;
    }
    
    .scientific-functions {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stats-operations,
    .complex-operations {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 24px;
    }
    
    .mode-tab {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .key {
        padding: 12px;
        font-size: 16px;
    }
    
    .result-display {
        font-size: 28px;
    }
    
    .formula-display {
        font-size: 16px;
    }
}