.gif-anime-app {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #2b2b2b;
    color: #e0e0e0;
    box-sizing: border-box;

    /* PC表示時にWordPressのカラム幅より少し広く表示する調整 */
    width: calc(100% + 100px);
    margin-left: -50px;
    max-width: 100vw; /* 画面幅は超えないように */
    
    /* スマホでのダブルタップ拡大防止 */
    touch-action: manipulation;
}

.gif-anime-app *, .gif-anime-app *::before, .gif-anime-app *::after {
    box-sizing: inherit;
}

.gif-anime-app .app-container {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 1050px; /* Increased height to accommodate larger thumbnails */
    max-height: 98vh;
    border: 1px solid #444;
}

/* Header */
.gif-anime-app .app-header {
    background-color: #3c3c3c;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1a1a1a;
}

.gif-anime-app .app-header .app-title {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0;
    color: #fff;
    display: block;
}

.gif-anime-app .global-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap; /* 画面幅が狭いときに折り返す */
    justify-content: flex-end; /* 右寄せにする */
}

.gif-anime-app .control-group {
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap; /* テキストの折り返しを防ぐ */
}

.gif-anime-app .control-group label {
    font-size: 0.9rem;
    font-weight: bold;
    margin-bottom: 0;
}

.gif-anime-app input[type="number"] {
    background: #444;
    border: 1px solid #555;
    color: #fff;
    padding: 4px;
    border-radius: 4px;
    width: 60px;
}

/* Main Area: Library + Stage */
.gif-anime-app .app-main {
    display: grid;
    grid-template-columns: 250px 1fr;
    overflow: hidden;
    position: relative;
    height: 100%; /* Ensure main area takes full height */
}

/* Library Panel */
.gif-anime-app .library-panel {
    background-color: #333;
    border-right: 1px solid #1a1a1a;
    display: flex;
    flex-direction: column;
    padding: 10px;
    overflow: hidden; /* Prevent whole panel scrolling */
    height: 100%; /* Match parent height */
}

.gif-anime-app .library-tabs {
    flex-shrink: 0; /* Tabs never shrink */
    z-index: 10;
}

/* Limit content area scrolling */
.gif-anime-app #content-images,
.gif-anime-app #content-text,
.gif-anime-app #content-paint {
    overflow-y: auto;
    flex: 1; /* Take remaining height */
    min-height: 0; /* Allow flex child scrolling */
    height: 100%;
}


.gif-anime-app .library-panel .panel-title {
    font-size: 1rem;
    font-weight: bold;
    margin-top: 0;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
    display: block;
    margin-bottom: 10px;
}

.gif-anime-app .asset-drop-zone {
    border: 2px dashed #555;
    padding: 20px;
    text-align: center;
    color: #888;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 10px;
}

.gif-anime-app .asset-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.gif-anime-app .asset-item {
    width: 100px;
    height: 100px;
    object-fit: contain;
    background: #444;
    border: 1px solid #555;
    cursor: grab;
    transition: transform 0.2s;
}

.gif-anime-app .asset-item:hover {
    transform: scale(1.05);
    border-color: #007bff;
}

.gif-anime-app .asset-item:active {
    cursor: grabbing;
}

/* Stage Panel */
.gif-anime-app .stage-panel {
    background-color: #1e1e1e;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
}

.gif-anime-app .canvas-wrapper {
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    /* Transparency Grid Background */
    background-image: 
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%), 
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%), 
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px; 
    margin-bottom: 20px;
    text-align: center;
    
    /* Responsive sizing */
    width: 100%;
    flex: 1;
    min-height: 0; /* Important for flex child scrolling */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Canvas scales instead of scrolling */
}

.gif-anime-app #editor-canvas {
    display: block;
    background: transparent;
    border: 1px solid #ccc;
    
    /* Ensure it scales but keeps aspect ratio */
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    width: auto;
    height: auto;

    /* Prevent default browser gestures like scroll/zoom on canvas */
    /* touch-action: none;  Removed to allow scroll when not hitting object */
    touch-action: manipulation; /* Allow scroll/zoom but no double-tap zoom */
}

.gif-anime-app .stage-controls {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(0,0,0,0.5);
    padding: 10px;
    border-radius: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.gif-anime-app .stage-controls .control-group-nav {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 5px;
    border-radius: 10px;
}

.gif-anime-app .stage-controls .control-group-settings {
    display: flex;
    gap: 15px;
    align-items: center;
}

.gif-anime-app .video-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Timeline Panel */
.gif-anime-app .timeline-panel {
    height: auto; /* Allow auto height to accommodate new layer panel */
    min-height: 200px; /* Increase min height */
    background-color: #333;
    border-top: 1px solid #1a1a1a;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%; /* Important to force children to overflow/scroll */
    overflow: hidden; /* Contains any rogue overflows */
}

.gif-anime-app .timeline-controls {
    padding: 5px 10px;
    background-color: #252525;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.gif-anime-app .timeline-scroll-area {
    /* Fixed height to prevent layout shift when horizontal scrollbar appears */
    height: 160px;
    min-height: 160px; 
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px;
    white-space: nowrap;
    background: #2a2a2a;
    width: 100%; /* Ensure it spans full width */
    max-width: 100vw; /* Hard stop to prevent page expansion */
    box-sizing: border-box;
}

.gif-anime-app .timeline-frames {
    display: inline-flex;
    gap: 5px;
    height: 100%;
    align-items: center;
}

.gif-anime-app .frame-thumbnail {
    width: 120px;
    height: 120px;
    min-width: 120px; /* Prevent shrinking */
    background: #222;
    border: 2px solid #555;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.gif-anime-app .frame-thumbnail.active {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}

.gif-anime-app .frame-thumbnail canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    flex: 1;
    border: none; /* Override generic canvas border */
    max-width: none;
}

.gif-anime-app .frame-number {
    position: absolute;
    top: 2px;
    left: 2px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 2px;
}

/* Buttons */
.gif-anime-app button {
    background: #555;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s;
}

.gif-anime-app button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #333 !important;
    color: #666 !important;
    pointer-events: none;
}

.gif-anime-app button:hover {
    background: #666;
}

.gif-anime-app .primary-btn {
    background-color: #007bff;
}

.gif-anime-app .primary-btn:hover {
    background-color: #0056b3;
}

.gif-anime-app .drop-zone.small {
    padding: 20px;
    border: 2px dashed #666;
    margin-bottom: 15px;
    text-align: center;
    color: #aaa;
    border-radius: 4px;
}
.gif-anime-app .drop-zone.small:hover {
    background: #444;
    border-color: #888;
}


/* Modal - Moved to body via JS, so we need a global rule or keep the class specific but not nested under .gif-anime-app if moved */
/* We will move it to body, so the selector needs to be top-level or wrapped in a portal class */
.gif-anime-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw; 
    height: 100vh;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2147483647 !important;
    backdrop-filter: blur(2px);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Restore font since it left the app scope */
}

/* Ensure hidden state works */
.gif-anime-modal-overlay.hidden {
    display: none !important;
}

.gif-anime-modal-overlay .modal-content {
    background: #333;
    padding: 20px;
    border-radius: 5px;
    text-align: center;
    position: relative;
    min-width: 300px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    color: #e0e0e0;
    border: 1px solid #555;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.gif-anime-modal-overlay #result-container {
    margin: 15px 0;
    overflow: auto;
    max-height: 70vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gif-anime-modal-overlay #result-image {
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
}

.gif-anime-modal-overlay .close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #fff;
}

/* Button styles that might be lost when moving out of .gif-anime-app */
.gif-anime-modal-overlay button, 
.gif-anime-modal-overlay .download-btn {
    font-family: inherit;
    cursor: pointer;
}

.gif-anime-modal-overlay .download-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #28a745;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    border: none;
}
.gif-anime-modal-overlay .download-btn:hover {
    background: #218838;
}

.gif-anime-app #result-container {
    margin: 20px 0;
    max-height: 70vh;
    overflow: auto;
}
.gif-anime-app #result-image {
    max-width: 100%;
    border: 1px solid #555;
    margin-bottom: 10px;
}

.gif-anime-app .download-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #28a745;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
}
.gif-anime-app .download-btn:hover {
    background: #218838;
}

/* Scrollbars scoped */
.gif-anime-app ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.gif-anime-app ::-webkit-scrollbar-track {
    background: #222;
}

.gif-anime-app ::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

/* Additional specific styles found in original file */

.gif-anime-app .thumbnails-wrapper h3 {
  margin-top: 0;
}

.gif-anime-app .thumbnails-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.gif-anime-app .thumbnail-item {
  position: relative;
  border: 1px solid #ddd;
  padding: 5px;
  background-color: #fff;
  cursor: grab;
}

.gif-anime-app .thumbnail-item img {
  max-width: 100px;
  max-height: 100px;
  display: block;
}

.gif-anime-app .thumbnail-item .remove-btn {
  position: absolute;
  top: 0;
  right: 0;
  background-color: red;
  color: white;
  border: none;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  border-radius: 50%;
  transform: translate(50%, -50%); /* Center on corner */
  box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.gif-anime-app .action-area {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.gif-anime-app #progress-container {
  margin-top: 20px;
  text-align: center;
}

.gif-anime-app #progress-bar {
  width: 100%;
  height: 20px;
}

.gif-anime-app #result-section {
  margin-top: 30px;
  text-align: center;
  border-top: 2px solid #eee;
  padding-top: 20px;
}

.gif-anime-app .download-link-wrapper {
    margin-top: 10px;
}

/* --- Mobile / Responsive Styles --- */
@media screen and (max-width: 768px) {
    html, body {
        overflow-x: hidden; /* 横スクロールバー防止 */
        width: 100%;
    }

    .gif-anime-app {
        /* WordPressのコンテンツ幅を無視して画面いっぱいに広げる */
        width: 100vw;
        position: relative;
        left: 50%;
        right: 50%;
        margin-left: -50vw;
        margin-right: -50vw;
        border-radius: 0;
        border: none;
        padding: 0;
        box-sizing: border-box; /* パディングを含める */
        max-width: 100vw; /* はみ出し防止 */
        overflow-x: hidden; /* 内部のはみ出し防止 */
    }
    
    .gif-anime-app .app-container {
        height: auto; /* Allow scrolling on mobile */
        max-height: none;
        display: flex;
        flex-direction: column;
    }

    .gif-anime-app .app-header {
        flex-direction: column;
        gap: 10px;
        align-items: center; /* stretchからcenterへ変更し、横幅いっぱいに引き伸ばされるのを防ぐ */
    }

    .gif-anime-app .app-header .app-title {
        text-align: center;
        margin-bottom: 5px;
        width: 100%; /* タイトルは中央寄せで全幅 */
    }

    .gif-anime-app .global-controls {
        flex-direction: row; /* ★ 縦並び(column)から横並び(row)へ変更 */
        align-items: center; /* stretchからcenterへ */
        justify-content: center; /* 中央寄せ */
        gap: 10px;
        flex-wrap: wrap; /* 折り返し許可 */
        width: 100%; /* 親要素に合わせて幅確保 */
    }

    .gif-anime-app .control-group {
        justify-content: center; /* space-betweenからcenterへ */
        flex-wrap: wrap;
        width: auto; /* 全幅強制を解除 */
    }

    /* 背景設定グループの調整 */
    .gif-anime-app .control-group.bg-settings {
        align-items: center !important; /* インラインスタイルのflex-startを上書き */
    }

    .gif-anime-app .app-main {
        grid-template-columns: 1fr; /* Stack vertically */
        grid-template-rows: auto auto; /* Library then Stage */
        overflow: visible; /* Allow scrolling */
    }

    .gif-anime-app .library-panel {
        border-right: none;
        border-bottom: 1px solid #1a1a1a;
        max-height: 480px; /* Limit height of library on mobile */
        min-height: 380px; /* Ensure enough height for forms */
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Fix scroll */
    }

    .gif-anime-app .library-tabs {
        width: 100%;
        margin-bottom: 5px;
    }

    .gif-anime-app #content-images,
    .gif-anime-app #content-text,
    .gif-anime-app #content-paint {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    }

    .gif-anime-app .stage-panel {
        padding: 10px;
        min-height: 420px; /* ステージパネルも少し拡大 */
    }

    .gif-anime-app .canvas-wrapper {
        width: 100%;
        overflow: hidden; /* Canvas scrolling removed to prevent accidental scroll */
        display: flex; /* Fix rendering context */
        justify-content: center;
    }
    
    .gif-anime-app #editor-canvas {
        max-width: 100%; /* Scale down canvas if too big */
        height: auto !important; /* Keep aspect ratio */
    }

    .gif-anime-app .timeline-panel {
        height: auto;
        min-height: 150px;
    }

    .gif-anime-app .timeline-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Button disabled state */
.gif-anime-app button:disabled,
.gif-anime-app input:disabled,
.gif-anime-app select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #555 !important;
    color: #888 !important;
    border-color: #555 !important;
}


