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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    background: #1a1a1a;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-x pan-y;
}

/* モード切り替え */
.mode-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.mode-toggle.show {
    opacity: 1;
    pointer-events: auto;
}

.mode-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    background: #444;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.mode-btn:hover {
    background: #555;
}

.mode-btn.active {
    background: #007bff;
}

/* エディターパネル */
.editor-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 500px;
    max-width: 90vw;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    overflow: hidden;
    transition: all 0.3s;
}

.editor-panel.hidden {
    display: none;
}

.editor-header {
    background: #007bff;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header h2 {
    font-size: 20px;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    line-height: 1;
    transition: transform 0.2s;
}

.close-btn:hover {
    transform: scale(1.2);
}

.editor-content {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #007bff;
}

.form-group input[type="color"] {
    width: 100px;
    height: 40px;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
}

.save-btn {
    width: 100%;
    padding: 12px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.save-btn:hover {
    background: #218838;
}

/* AI画像生成セクション */
.form-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.section-title {
    font-size: 18px;
    margin-bottom: 15px;
    color: #007bff;
}

.generation-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.gen-btn {
    padding: 12px 10px;
    border: 2px solid #007bff;
    background: white;
    color: #007bff;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.gen-btn small {
    display: block;
    font-size: 11px;
    margin-top: 2px;
    opacity: 0.8;
}

.gen-btn:hover {
    background: #007bff;
    color: white;
}

.gen-btn.primary {
    grid-column: 1 / -1;
    background: #007bff;
    color: white;
}

.gen-btn.primary:hover {
    background: #0056b3;
}

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

.generation-status {
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 10px;
    font-size: 14px;
    text-align: center;
}

.generation-status.loading {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.generation-status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #28a745;
}

.generation-status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #dc3545;
}

.generated-images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.generated-image-item {
    position: relative;
    border: 2px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
}

.generated-image-item:hover {
    border-color: #007bff;
    transform: scale(1.02);
}

.generated-image-item img {
    width: 100%;
    height: auto;
    display: block;
}

.image-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px;
    font-size: 12px;
    text-align: center;
}

.generated-image-item.selected {
    border-color: #28a745;
    border-width: 3px;
}

.generated-image-item.selected .image-label {
    background: rgba(40, 167, 69, 0.9);
}

/* API設定パネル */
.api-security-notice {
    background: #f8f9fa;
    border: 2px solid #007bff;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

.api-security-notice h3 {
    color: #007bff;
    margin-bottom: 10px;
    font-size: 16px;
}

.security-info {
    font-size: 14px;
    line-height: 1.6;
}

.security-info ul {
    margin: 10px 0;
    padding-left: 20px;
}

.security-info li {
    margin: 5px 0;
}

.api-status {
    padding: 12px;
    border-radius: 5px;
    font-weight: 600;
    text-align: center;
}

.api-status.configured {
    background: #d4edda;
    color: #155724;
    border: 1px solid #28a745;
}

.api-status.not-configured {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #dc3545;
}

.api-status.checking {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.code-block {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.code-block code {
    display: block;
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 10px;
    border-radius: 3px;
    margin-top: 5px;
    overflow-x: auto;
}

.external-link {
    display: inline-block;
    color: #007bff;
    text-decoration: none;
    font-weight: 600;
    padding: 8px 12px;
    border: 2px solid #007bff;
    border-radius: 5px;
    transition: all 0.3s;
}

.external-link:hover {
    background: #007bff;
    color: white;
}

.api-key-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    font-family: monospace;
    transition: border-color 0.3s;
}

.api-key-input:focus {
    outline: none;
    border-color: #007bff;
}

.input-with-button {
    display: flex;
    gap: 5px;
    align-items: stretch;
}

.input-with-button input {
    flex: 1;
}

.toggle-btn {
    padding: 10px 15px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
}

.toggle-btn:hover {
    background: #f0f0f0;
    border-color: #007bff;
}

.help-text {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #666;
}

.divider {
    margin: 20px 0;
    text-align: center;
    position: relative;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #ddd;
}

.divider span {
    position: relative;
    background: white;
    padding: 0 15px;
    color: #999;
    font-size: 14px;
}

.save-btn.secondary {
    background: #6c757d;
}

.save-btn.secondary:hover {
    background: #5a6268;
}

/* コントロールパネル */
.control-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.8);
    padding: 15px;
    border-radius: 8px;
    color: white;
    min-width: 200px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.control-panel.show {
    opacity: 1;
    pointer-events: auto;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.ctrl-btn {
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    background: #444;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.ctrl-btn:hover {
    background: #555;
}

.position-indicator {
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    text-align: center;
    margin-bottom: 10px;
    font-size: 14px;
}

/* ミニマップ */
.minimap {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    background: rgba(255, 255, 255, 0.1);
    padding: 5px;
    border-radius: 5px;
    aspect-ratio: 1;
}

.minimap-cell {
    background: #444;
    border-radius: 2px;
    transition: all 0.3s;
}

.minimap-cell.active {
    background: #007bff;
    box-shadow: 0 0 5px #007bff;
}

.minimap-cell.has-content {
    background: #28a745;
}

.minimap-cell.has-content.active {
    background: #007bff;
}

/* グリッドコンテナ */
.grid-container {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;
    cursor: grab;
    perspective: 2000px;
    perspective-origin: 50% 50%;
}

.grid-container.edit-mode {
    cursor: default;
}

.grid-container.grabbing {
    cursor: grabbing;
}

.grid {
    width: 800vw;
    height: 800vh;
    display: grid;
    grid-template-columns: repeat(8, 100vw);
    grid-template-rows: repeat(8, 100vh);
    /* iOS風スプリングアニメーション */
    transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
    transform-style: preserve-3d;
}

/* ドラッグ中は即座に反応 */
.grid.dragging {
    transition: none;
}

/* スムーズな減速アニメーション（スワイプ後） */
.grid.animating {
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.cell {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    position: relative;
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    /* iOS風の滑らかな3D効果 */
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    /* アンチエイリアス */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* レスポンシブ背景画像 */
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

/* モバイル用 (768px以下) */
@media (max-width: 768px) {
    .cell {
        padding: 20px;
    }
}

.cell.edit-mode {
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.cell.edit-mode::before {
    content: '✏️ クリックして編集';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 123, 255, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 1.2em;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 10;
}

.cell.edit-mode:hover::before {
    opacity: 1;
}

.cell.edit-mode:hover {
    box-shadow: inset 0 0 0 5px #007bff;
}

.cell-title {
    font-size: 3em;
    font-weight: 700;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.cell-content {
    font-size: 1.5em;
    line-height: 1.6;
    max-width: 800px;
}

.cell-index {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.9em;
    opacity: 0;
    font-weight: 600;
    transition: opacity 0.3s;
}

.edit-mode .cell-index {
    opacity: 0.5;
}

/* ナビゲーション矢印 */
.nav-arrows {
    position: fixed;
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.nav-arrows.show {
    opacity: 1;
    pointer-events: auto;
}

.nav-arrow {
    position: fixed;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    font-size: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-arrow:hover {
    background: rgba(0, 123, 255, 0.8);
    transform: scale(1.1);
}

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-arrow:disabled:hover {
    background: rgba(0, 0, 0, 0.6);
    transform: scale(1);
}

.nav-up {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -250px);
}

.nav-down {
    top: 50%;
    left: 50%;
    transform: translate(-50%, 190px);
}

.nav-left {
    top: 50%;
    left: 50%;
    transform: translate(-250px, -50%);
}

.nav-right {
    top: 50%;
    left: 50%;
    transform: translate(190px, -50%);
}

/* スワイプインジケーター */
.swipe-indicator {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.swipe-indicator.show {
    opacity: 1;
}

.swipe-indicator.hide-on-edit {
    display: none;
}

.swipe-icon {
    font-size: 18px;
    animation: swipeHint 2s infinite;
}

@keyframes swipeHint {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

/* レスポンシブ */
@media (max-width: 768px) {
    .mode-toggle {
        top: 10px;
        left: 10px;
        padding: 5px;
    }

    .mode-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .control-panel {
        top: 10px;
        right: 10px;
        padding: 10px;
        min-width: 150px;
    }

    .ctrl-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .nav-arrow {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .cell-title {
        font-size: 2em;
    }

    .cell-content {
        font-size: 1.2em;
    }
    
    .cell {
        padding: 20px;
    }
    
    .editor-panel {
        width: 95vw;
        max-height: 90vh;
    }
    
    .swipe-indicator {
        bottom: 20px;
        padding: 10px 20px;
        font-size: 12px;
    }
}

/* API設定モード通知 */
.info-notice {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding: 15px;
    margin: 15px 0;
    border-radius: 5px;
}

.info-notice p {
    margin: 5px 0;
    color: #1565c0;
}

.info-notice strong {
    color: #0d47a1;
}

.warning-notice {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 15px;
    margin: 15px 0;
    border-radius: 5px;
}

.warning-notice p {
    margin: 5px 0;
    color: #856404;
}

.warning-notice strong {
    color: #663c00;
}

/* プロンプト履歴 */
.prompt-history {
    margin-bottom: 15px;
}

.prompt-history h4 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #555;
}

.prompt-history-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 200px;
    overflow-y: auto;
}

.prompt-history-item {
    background: #f5f5f5;
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #e0e0e0;
}

.prompt-history-item:hover {
    background: #e3f2fd;
    border-color: #2196f3;
    transform: translateX(5px);
}

.no-history {
    font-size: 13px;
    color: #999;
    font-style: italic;
    padding: 10px;
    text-align: center;
}

/* Favicon設定パネル */
.favicon-presets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    margin-top: 10px;
}

.favicon-preset-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

.favicon-preset-btn:hover {
    border-color: #4a90e2;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.favicon-preset-btn.active {
    border-color: #4a90e2;
    background: #f0f7ff;
}

.favicon-preview {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.favicon-preset-btn span {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.current-favicon {
    padding: 15px;
    background: #f5f5f5;
    border-radius: 8px;
    text-align: center;
}

.current-favicon strong {
    color: #4a90e2;
}
