/* ===== リセットCSS ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== CSS変数（カラーテーマ） ===== */
:root {
    --primary-color: #FF6B9D;
    --primary-dark: #E84A7F;
    --secondary-color: #66D9EF;
    --accent-color: #FFC93D;
    --danger-color: #DC3545;
    --danger-hover: #C82333;
    --background-color: #FAFAFA;
    --text-color: #000000;
    --text-secondary: #333333;
    --border-color: #E0E0E0;
    --button-bg: #F0F0F0;
    --button-hover-bg: #E0E0E0;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.12);
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

/* ===== 基本スタイル ===== */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== レイアウト ===== */
.header {
    background: white;
    border-bottom: 2px solid var(--border-color);
    box-shadow: var(--shadow-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.header-nav {
    display: flex;
    gap: 1rem;
    flex: 1;
    justify-content: center;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    font-size: 0.9rem;
}

.nav-btn:hover {
    background: rgba(255, 107, 157, 0.1);
    color: var(--primary-color);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    gap: 2rem;
}

.toolbar {
    width: 200px;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    padding: 1.5rem;
    height: fit-content;
    position: sticky;
    top: 100px;
    border: 1px solid var(--border-color);
}

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.canvas-container {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    padding: 2rem;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: auto;
    border: 1px solid var(--border-color);
}

.main-canvas {
    display: block;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    position: relative;
}

.footer {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 2rem;
}

/* ===== ボタンスタイル ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    background: transparent;
    outline: none;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    border: 2px solid var(--primary-color);
}

.btn-primary:hover:not(:disabled) {
    background: #FF5687;
    border-color: #FF5687;
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.btn-secondary {
    background: #E8E8E8;
    color: #000000;
    border: 2px solid #666666;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-secondary:hover:not(:disabled) {
    background: #D0D0D0;
    border-color: #333333;
    color: #000000;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.btn-icon {
    font-size: 1.1rem;
}

/* ===== ツールバー ===== */
.tool-group {
    margin-bottom: 2rem;
}

.tool-group:last-child {
    margin-bottom: 0;
}

.tool-group-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.tool-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border: 2px solid #666666;
    background: #F5F5F5;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 0.5rem;
    text-align: left;
    color: #000000;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tool-btn:hover {
    background: #FFE8F0;
    border-color: var(--primary-dark);
    color: var(--primary-dark);
    transform: translateX(2px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.tool-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-dark);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateX(2px);
    font-weight: 700;
}

.tool-icon {
    font-size: 1.2rem;
}

.tool-text {
    font-size: 0.9rem;
    font-weight: 600;
}

/* ===== ファイルアップロードエリア ===== */
.file-upload-area {
    max-width: 600px;
    margin: 0 auto;
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 3rem 2rem;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(255, 107, 157, 0.05);
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-weight: 400;
    line-height: 1;
    display: inline-block;
    width: 80px;
    height: 80px;
    border: 2px dashed var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-text {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.file-select-btn {
    color: var(--primary-color);
    text-decoration: underline;
    background: linear-gradient(135deg, #FFF5F8 0%, #FFE8F0 100%);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: inherit;
    font-weight: 600;
    pointer-events: all;
    box-shadow: 0 2px 6px rgba(255, 107, 157, 0.15);
    transition: var(--transition);
    text-decoration: none;
}

.file-select-btn:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, #FF5687 100%);
    color: white;
    border-color: #FF5687;
    box-shadow: 0 3px 10px rgba(255, 107, 157, 0.3);
    transform: translateY(-2px);
    text-decoration: none;
}

.upload-info {
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.8;
    font-weight: 500;
}

/* ===== ローディング表示 ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: white;
    margin-top: 1rem;
    font-size: 1.1rem;
}

/* ===== エラーメッセージ ===== */
.error-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #DC3545;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    z-index: 1001;
    max-width: 400px;
    animation: slideInRight 0.3s ease-out;
    transition: all 0.3s ease;
}

.error-message.warning {
    background: #FFC107;
    color: #212529;
}

.error-message.info {
    background: #17A2B8;
    color: white;
}

.error-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.error-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    font-weight: bold;
    background: white;
    color: #DC3545;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.error-text {
    flex: 1;
    line-height: 1.4;
    min-width: 200px;
}

.error-action {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: inherit;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 0.5rem;
}

.error-action:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.error-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.error-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== ユーティリティクラス ===== */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== フォーカス表示 ===== */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===== タッチデバイス最適化 ===== */
@media (pointer: coarse) {
    /* タッチ操作の改善 */
    * {
        -webkit-tap-highlight-color: rgba(255, 107, 107, 0.2);
    }
    
    /* スクロール改善 */
    body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }
    
    /* タッチ遅延削除 */
    .btn,
    .tool-btn,
    .file-upload-area,
    .selection-handle {
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* 入力フィールドでのユーザー選択は許可 */
    .setting-input,
    .download-filename {
        -webkit-user-select: text;
        user-select: text;
        touch-action: manipulation;
    }
    
    /* 選択範囲の操作改善 */
    .selection-box {
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Canvas操作の改善 */
    .main-canvas {
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* タッチホバー効果 */
    .touch-hover {
        background: var(--primary-color) !important;
        color: white !important;
        transform: scale(0.98);
        transition: all 0.1s ease;
    }
    
    .tool-btn.touch-hover {
        background: var(--primary-color) !important;
        color: white !important;
    }
}

/* ===== タブレット専用スタイル ===== */
.tablet-device {
    /* タブレット向けの基本設定 */
}

.tablet-device .tool-btn {
    transition: all 0.2s ease;
}

.tablet-device .tool-btn:active {
    transform: scale(0.97);
    background: var(--primary-color);
    color: white;
}

/* ===== 横向きレイアウト ===== */
.landscape-layout .main-content {
    flex-direction: row;
    height: calc(100vh - 120px);
}

.landscape-layout .toolbar {
    width: 240px;
    height: 100%;
    overflow-y: auto;
}

.landscape-layout .canvas-area {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.landscape-layout .canvas-container {
    flex: 1;
    min-height: 0;
}