:root {
    --primary: #2c3e50; --primary-hover: #34495e;
    --accent: #007aff; --accent-bg: rgba(0,122,255,0.1);
    --bg: #f5f7fa; --panel-bg: #ffffff; --text: #1d1d1f; 
    --border: #e5e5ea; --input-bg: #ffffff;
    --header-h: 60px;
    --shadow: 0 2px 8px rgba(0,0,0,0.04);
    --radius: 12px;
}
[data-theme="dark"] {
    --primary: #90a4ae; --primary-hover: #b0bec5;
    --accent: #0a84ff; --accent-bg: rgba(10,132,255,0.15);
    --bg: #000000; --panel-bg: #1c1c1e; --text: #f5f5f7; 
    --border: #38383a; --input-bg: #2c2c2e;
    --shadow: 0 2px 8px rgba(0,0,0,0.2);
}

html, body { max-width: 100vw; overflow-x: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 0; transition: background 0.3s; }
body.desktop-mode { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.header { height: var(--header-h); background: var(--panel-bg); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 24px; flex-shrink: 0; z-index: 10; }
h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 700; color: var(--text); }
.header-controls { display: flex; gap: 12px; align-items: center; }

.app-container { display: flex; flex: 1; overflow: hidden; height: calc(100vh - var(--header-h)); }

.app-container > main { flex: 1; display: flex; overflow: hidden; height: 100%; }

.panel-left, .panel-right { width: 340px; min-width: 340px; max-width: 340px; background: var(--panel-bg); overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; border-right: 1px solid var(--border); border-left: 1px solid var(--border); flex-shrink: 0; box-sizing: border-box; contain: layout; }
.panel-right { border-left: 1px solid var(--border); border-right: none; }

.stage-center { 
    flex: 1; background: var(--bg); position: relative; overflow: hidden; 
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: background 0.2s;
    cursor: pointer;
    height: 100%;
}
.stage-center.drag-active { background: var(--accent-bg); border: 2px dashed var(--accent); }

.empty-state { text-align: center; pointer-events: none; opacity: 0.7; transition: 0.2s; display: flex; flex-direction: column; align-items: center; }
.empty-icon { width: 64px; height: 64px; margin-bottom: 16px; color: var(--text); stroke-width: 1.5; }
.empty-text { font-size: 1.1rem; font-weight: bold; color: var(--text); }
.empty-sub { font-size: 0.85rem; margin-top: 6px; color: var(--text); opacity: 0.9; }

.has-image .empty-state { display: none; }
.preview-image { max-width: 90%; max-height: 75vh; box-shadow: 0 4px 24px rgba(0,0,0,0.15); display: none; z-index: 2; pointer-events: none; }
[data-theme="dark"] .preview-image { border: 1px solid rgba(255, 255, 255, 0.25); }
.has-image .preview-image { display: block; }

.preview-badge { 
    position: absolute; 
    bottom: 20px; 
    right: 20px; 
    background: rgba(0,0,0,0.7); 
    color: white; 
    padding: 4px 10px; 
    border-radius: 12px; 
    font-size: 0.75rem; 
    pointer-events: none; 
    display: none;
    z-index: 5; 
}
.preview-badge.show { display: block; }

.setting-box { 
    background: var(--input-bg); 
    border-radius: var(--radius); 
    border: 1px solid var(--border); 
    box-shadow: var(--shadow);
    contain: layout style;
    flex-shrink: 0;
}

.panel-header { padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; }
.panel-header:hover { background: rgba(0,0,0,0.02); }
.panel-title { font-size: 0.8rem; font-weight: 700; color: var(--text); opacity: 0.9; display: flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: 0.05em; margin: 0; }
.panel-title::before { content: ''; display: block; width: 3px; height: 14px; background: var(--primary); border-radius: 2px; opacity: 0.8; }
.panel-toggle-icon { transition: transform 0.3s; font-size: 0.75rem; opacity: 0.4; }

.panel-content { 
    padding: 16px 16px 20px 16px; 
    border-top: 1px solid var(--border); 
}
.setting-box.closed .panel-content { 
    display: none;
}
.setting-box.closed .panel-header { border-bottom: none; }
.panel-toggle-icon { font-size: 0.75rem; opacity: 0.4; }
.setting-box.closed .panel-toggle-icon { transform: rotate(-90deg); }

button, select, input { font-family: inherit; box-sizing: border-box; outline: none; }

.btn-icon { background: transparent; border: 1px solid var(--border); color: var(--text); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; }
.btn-icon:hover { background: rgba(0,0,0,0.05); border-color: var(--text); }

.icon-svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 14px; height: 14px; }

.btn-mini { padding: 8px 12px; background: #e5e5ea; color: #333; border: none; border-radius: 8px; font-size: 0.8rem; cursor: pointer; font-weight: 600; transition: 0.2s; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn-mini:hover { background: #d1d1d6; }
.btn-primary-mini { background: var(--primary); color: #fff; }
.btn-primary-mini:hover { opacity: 0.9; }
.btn-danger { background: #ff3b30; color: white; }
.reset-icon-btn { background: none; border: none; padding: 2px; cursor: pointer; opacity: 0.4; transition: opacity 0.2s; display: flex; align-items: center; justify-content: center; }
.reset-icon-btn:hover { opacity: 0.8; }
.reset-icon-btn svg { width: 14px; height: 14px; color: var(--text); }
[data-theme="dark"] .btn-mini { background: #3a3a3c; color: #fff; }

input[type="text"], select, input[type="color"] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background-color: var(--input-bg); color: var(--text); transition: 0.2s; box-shadow: inset 0 1px 2px rgba(0,0,0,0.02); box-sizing: border-box; font-family: inherit; -webkit-appearance: none; appearance: none; }
textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background-color: var(--input-bg); color: var(--text); transition: 0.2s; box-shadow: inset 0 1px 2px rgba(0,0,0,0.02); box-sizing: border-box; font-family: inherit; -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); outline: none; }

.label-sm { font-size: 0.75rem; font-weight: 700; color: var(--text); opacity: 0.8; display: block; margin-bottom: 6px; margin-top: 14px; letter-spacing: 0.02em; }
.label-sm:first-child { margin-top: 0; }

.layout-hint { font-size: 0.7rem; color: var(--text); opacity: 0.7; margin-top: 4px; font-style: italic; }
.aspect-hint { font-size: 0.7rem; color: var(--text); opacity: 0.7; margin-top: 4px; font-style: italic; }

.logo-row { display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,0.02); padding: 10px 12px; border-radius: 8px; border: 1px solid transparent; margin-bottom: 8px; }
.logo-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.logo-type { font-size: 0.75rem; font-weight: bold; opacity: 0.7; width: 45px; flex-shrink: 0; }
.logo-exif-value { font-size: 0.75rem; color: var(--accent); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.logo-preview-img { height: 24px; background: #fff; padding: 2px; border-radius: 4px; border: 1px solid var(--border); margin-left: 8px; }

.action-area { 
    margin-top: auto; 
    padding-top: 16px; 
    border-top: 1px solid var(--border); 
    text-align: center; 
    background: var(--panel-bg);
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.main-btn { width: 100%; padding: 16px; background: var(--primary); color: white; border: none; border-radius: 14px; font-weight: 700; font-size: 1rem; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 12px rgba(0,0,0,0.1); letter-spacing: 0.05em; }
.main-btn:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
.main-btn:disabled { background: #a0a0a5; cursor: not-allowed; transform: none; box-shadow: none; }

.cancel-btn { width: 100%; margin-top: 10px; padding: 12px; background: transparent; color: #ff3b30; border: 1px solid #ff3b30; border-radius: 14px; font-weight: 700; cursor: pointer; display: none; }

.progress-bar { width: 0%; height: 4px; background: var(--accent); border-radius: 2px; margin-top: 12px; transition: width 0.2s; }
.status-text { font-size: 0.8rem; color: var(--text); opacity: 0.8; font-weight: 700; min-height: 1.2em; margin-top: 6px; text-align: center; }
.status-text:empty { min-height: 0; margin: 0; }

.download-link-area { margin-bottom: 20px; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.download-link-area:empty { margin-bottom: 0; }
.dl-btn-group { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }

.btn-action { flex: 1; min-width: 80px; display: flex; justify-content: center; align-items: center; box-sizing: border-box; padding: 12px 8px; color: white; text-decoration: none; border-radius: 12px; font-weight: 700; font-size: 0.85rem; box-shadow: 0 4px 12px rgba(0,0,0,0.1); transition: 0.2s; border: none; cursor: pointer; gap: 6px; }
.btn-dl { background: #2e8b57; }
.btn-dl:hover { background: #246e45; transform: translateY(-2px); }
.btn-share { background: #007aff; }
.btn-share:hover { background: #0063d1; transform: translateY(-2px); }
.btn-x { background: #000000; }
.btn-x:hover { background: #333333; transform: translateY(-2px); }
[data-theme="dark"] .btn-x { background: #ffffff; color: #000000; }
[data-theme="dark"] .btn-x:hover { background: #e0e0e0; }

/* Credits box - パネル最下部に配置 */
.credits-box { 
    text-align: center; 
    font-size: 0.75rem; 
    color: var(--text); 
    opacity: 0.75; 
    padding: 16px;
    margin-top: 8px;
}
.credits-box .disclaimer { margin-top: 6px; font-size: 0.6rem; opacity: 0.85; }
.footer-link { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; font-weight: bold; transition: 0.2s; }
.footer-link:hover { color: var(--accent); }
.x-icon { width: 12px; height: 12px; fill: currentColor; }

@media (max-width: 950px) {
    body.desktop-mode { height: auto; overflow-y: auto; display: block; }
    .app-container { flex-direction: column; height: auto; overflow: visible; }
    .app-container > main { flex: none; order: 1; }
    .panel-left, .panel-right { width: 100%; min-width: 0; max-width: none; border: none; padding: 16px; height: auto; overflow: visible; gap: 12px; background: transparent; contain: none; }
    
    /* スマホでのプレビュー領域 */
    .stage-center { 
        min-height: auto; 
        max-height: 65vh; 
        max-height: 65svh; 
        padding: 12px; 
        border-top: 1px solid var(--border); 
        border-bottom: 1px solid var(--border); 
        overflow: hidden;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
    }
    
    /* プレビュー画像 - 領域内に確実に収める */
    .preview-image { 
        max-width: 92%; 
        max-height: 100%;
        object-fit: contain; 
        width: auto;
        height: auto;
    }
    
    .panel-left { order: 2; padding-bottom: 0; } 
    .panel-right { order: 3; padding-top: 12px; padding-bottom: 160px; }
    
    /* 固定フッター */
    .action-area { 
        position: fixed; 
        bottom: 0; 
        left: 0; 
        right: 0; 
        padding: 10px 16px; 
        background: var(--panel-bg); 
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
        z-index: 100;
    }
    .action-area .download-link-area { max-height: 60px; overflow-y: auto; }
    
    /* Credits box - スマホではパネル最下部でスクロールで見える */
    .credits-box {
        padding: 12px 16px;
        margin-top: 0;
    }
}

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

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* Preview Container */
.preview-container {
    display: flex;
    flex: 1;
    gap: 20px;
    min-height: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* When timeline panel is shown, both preview and panel are centered together */
.preview-container.with-timeline {
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 10px;
    overflow: hidden;
}

.preview-container.with-timeline .stage-center {
    flex: 0 1 auto;
    width: fit-content;
    min-width: 200px;
    max-width: calc(100% - 430px);
    max-height: calc(100vh - 100px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preview-container.with-timeline .stage-center.has-image {
    min-width: auto;
}

.preview-container.with-timeline .preview-image {
    max-width: 100%;
    max-height: calc(100vh - 120px);
    width: auto;
    height: auto;
    object-fit: contain;
}

.preview-container.with-timeline .x-preview-panel {
    flex-shrink: 0;
    max-height: calc(100vh - 100px);
}

/* 小さい画面でタイムライン表示時の調整 */
@media (max-height: 900px) {
    .preview-container.with-timeline .preview-image {
        max-height: calc(100vh - 140px);
    }
    .preview-container.with-timeline .x-preview-panel {
        max-height: calc(100vh - 120px);
    }
}

@media (max-height: 800px) {
    .preview-container.with-timeline .preview-image {
        max-height: calc(100vh - 160px);
    }
    .preview-container.with-timeline .x-preview-panel {
        max-height: calc(100vh - 140px);
    }
}

/* Preview Settings Panel - PC only */
.pc-only {
    display: none;
}

@media (min-width: 1200px) {
    .pc-only {
        display: block;
    }
}

.tool-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.tool-checkbox input {
    cursor: pointer;
}

/* Responsive Preview Image - auto scale based on screen size */
/* Large screens (PC) - bigger preview */
@media (min-width: 1200px) {
    .preview-image {
        max-width: 95%;
        max-height: 80vh;
    }
}

@media (min-width: 1400px) and (min-height: 900px) {
    .preview-image {
        max-height: 85vh;
    }
}

/* X Preview Panel */
.x-preview-panel {
    display: none;
    flex-direction: column;
    width: 390px;
    min-width: 360px;
    max-width: 430px;
    background: var(--panel-bg);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    max-height: 80vh;
    flex-shrink: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.x-preview-panel.show {
    display: flex;
}

/* X Preview Header */
.x-preview-header {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 6px 10px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.x-theme-btn {
    width: 28px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.4;
}

.x-theme-btn:hover {
    opacity: 0.7;
}

.x-theme-btn.active {
    opacity: 1;
    background: var(--bg);
    border-radius: 6px;
}

/* X Timeline */
.x-timeline {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    margin: 0 6px 6px 6px;
}

.x-timeline.light {
    background: #ffffff;
}

.x-timeline.dark {
    background: #000000;
}

.x-post {
    padding: 12px 16px;
    display: flex;
    gap: 12px;
}

.x-timeline.light .x-post {
    border-bottom: 1px solid #eff3f4;
}

.x-timeline.dark .x-post {
    border-bottom: 1px solid #2f3336;
}

.x-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-shrink: 0;
}

.x-post-body {
    flex: 1;
    min-width: 0;
}

.x-post-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}

.x-display-name {
    font-weight: 700;
    font-size: 15px;
}

.x-timeline.light .x-display-name {
    color: #0f1419;
}

.x-timeline.dark .x-display-name {
    color: #e7e9ea;
}

.x-verified {
    flex-shrink: 0;
}

.x-username {
    font-size: 15px;
    font-weight: 400;
}

.x-timeline.light .x-username {
    color: #536471;
}

.x-timeline.dark .x-username {
    color: #71767b;
}

.x-logo {
    margin-left: auto;
    flex-shrink: 0;
}

.x-timeline.light .x-logo {
    color: #0f1419;
}

.x-timeline.dark .x-logo {
    color: #e7e9ea;
}

.x-post-text {
    margin: 0 0 12px 0;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.x-timeline.light .x-post-text {
    color: #0f1419;
}

.x-timeline.dark .x-post-text {
    color: #e7e9ea;
}

.x-hashtag {
    color: #1d9bf0;
}

/* X Post Image */
.x-post-image {
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 12px;
    position: relative;
    max-height: 240px;
}

.x-post-image.no-crop {
    max-height: none;
}

.x-timeline.light .x-post-image {
    border: 1px solid #cfd9de;
}

.x-timeline.dark .x-post-image {
    border: 1px solid #2f3336;
}

.x-post-image img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    object-position: center;
    max-height: 240px;
}

.x-post-image.no-crop img {
    object-fit: contain;
    max-height: none;
}

.x-post-actions {
    display: flex;
    justify-content: space-between;
    max-width: 100%;
}

.x-action {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 50px;
    transition: all 0.2s;
}

.x-timeline.light .x-action {
    color: #536471;
}

.x-timeline.dark .x-action {
    color: #71767b;
}

.x-action:hover {
    color: #1d9bf0;
    background: rgba(29, 155, 240, 0.1);
}

.x-action svg {
    width: 17px;
    height: 17px;
}

/* Hide X preview on smaller screens */
@media (max-width: 1500px) {
    .x-preview-panel {
        display: none !important;
    }
}

/* Trim option checkbox */
.trim-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text);
    opacity: 0.9;
}

.trim-option input {
    cursor: pointer;
}

/* Timeline buttons */
.timeline-buttons {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
}

.timeline-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.timeline-btn:hover {
    border-color: var(--text);
    background: var(--card);
}

.timeline-btn.active {
    border-color: var(--accent);
}

.timeline-check {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.timeline-btn.active .timeline-check {
    display: flex;
}
