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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow-x: hidden;
}

.calculator-container {
    width: 100%;
    max-width: 500px;
}

.calculator {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

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

.header h1 {
    font-size: 24px;
    color: #333;
    font-weight: 600;
}

.mode-indicator {
    background: #667eea;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
}

.display-container {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
}

.memory-indicator {
    position: absolute;
    top: 10px;
    left: 15px;
    color: #667eea;
    font-size: 12px;
    font-weight: 600;
    display: none;
}

.memory-indicator.active {
    display: block;
}

.expression {
    font-size: 14px;
    color: #666;
    min-height: 20px;
    text-align: right;
    margin-bottom: 8px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.display {
    font-size: 36px;
    font-weight: 600;
    color: #333;
    text-align: right;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-height: 48px;
    line-height: 1.2;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.btn {
    padding: 20px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-number {
    background: #ffffff;
    color: #333;
    border: 2px solid #e9ecef;
}

.btn-number:hover {
    background: #f8f9fa;
    border-color: #667eea;
}

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

.btn-operator:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.btn-function {
    background: #e9ecef;
    color: #495057;
}

.btn-function:hover {
    background: #dee2e6;
}

.btn-equals {
    grid-column: span 3;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    font-size: 24px;
}

.btn-equals:hover {
    background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
}

/* タブレット対応 */
@media (max-width: 768px) {
    .calculator {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 22px;
    }
    
    .display {
        font-size: 32px;
    }
    
    .expression {
        font-size: 13px;
    }
    
    .btn {
        padding: 18px;
        font-size: 17px;
        min-height: 55px;
    }
    
    .btn-equals {
        font-size: 22px;
    }
}

/* モバイル（縦画面）対応 */
@media (max-width: 600px) {
    body {
        padding: 8px;
        align-items: flex-start;
        padding-top: 20px;
    }
    
    .calculator-container {
        max-width: 100%;
    }
    
    .calculator {
        padding: 15px;
        border-radius: 16px;
    }
    
    .header {
        margin-bottom: 15px;
    }
    
    .header h1 {
        font-size: 18px;
    }
    
    .mode-indicator {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .display-container {
        padding: 15px;
        min-height: 100px;
        margin-bottom: 15px;
    }
    
    .display {
        font-size: 28px;
        min-height: 42px;
    }
    
    .expression {
        font-size: 12px;
        margin-bottom: 6px;
    }
    
    .memory-indicator {
        font-size: 11px;
        top: 8px;
        left: 12px;
    }
    
    .buttons {
        gap: 10px;
    }
    
    .btn {
        padding: 16px 12px;
        font-size: 15px;
        min-height: 52px;
        border-radius: 10px;
    }
    
    .btn-equals {
        font-size: 20px;
        min-height: 56px;
    }
}

/* 小さなモバイル対応 */
@media (max-width: 480px) {
    body {
        padding: 5px;
        padding-top: 15px;
    }
    
    .calculator {
        padding: 12px;
        border-radius: 12px;
    }
    
    .header {
        margin-bottom: 12px;
    }
    
    .header h1 {
        font-size: 16px;
    }
    
    .mode-indicator {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    .display-container {
        padding: 12px;
        min-height: 90px;
        margin-bottom: 12px;
        border-radius: 10px;
    }
    
    .display {
        font-size: 24px;
        min-height: 36px;
    }
    
    .expression {
        font-size: 11px;
        margin-bottom: 5px;
    }
    
    .buttons {
        gap: 8px;
    }
    
    .btn {
        padding: 14px 8px;
        font-size: 14px;
        min-height: 48px;
        border-radius: 8px;
    }
    
    .btn-equals {
        font-size: 18px;
        min-height: 52px;
    }
    
    .memory-indicator {
        font-size: 10px;
        top: 6px;
        left: 10px;
    }
}

/* 非常に小さな画面対応 */
@media (max-width: 360px) {
    .btn {
        padding: 12px 6px;
        font-size: 13px;
        min-height: 44px;
    }
    
    .display {
        font-size: 22px;
    }
    
    .header h1 {
        font-size: 15px;
    }
    
    .btn-equals {
        font-size: 16px;
        min-height: 48px;
    }
}

/* 横画面（ランドスケープ）対応 */
@media (max-width: 900px) and (orientation: landscape) {
    body {
        padding: 10px;
        align-items: flex-start;
        padding-top: 10px;
    }
    
    .calculator {
        padding: 15px;
        max-width: 100%;
    }
    
    .display-container {
        min-height: 80px;
        padding: 12px;
    }
    
    .display {
        font-size: 24px;
        min-height: 32px;
    }
    
    .expression {
        font-size: 11px;
    }
    
    .buttons {
        gap: 8px;
    }
    
    .btn {
        padding: 12px 8px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .btn-equals {
        font-size: 18px;
        min-height: 48px;
    }
}

/* タッチデバイス向けの最適化 */
@media (hover: none) and (pointer: coarse) {
    .btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .btn:active {
        transform: scale(0.95);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    
    .btn:hover {
        transform: none;
    }
}

/* 高解像度ディスプレイ対応 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .calculator {
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    }
}

